List of usage examples for org.hibernate.criterion Restrictions ne
public static SimpleExpression ne(String propertyName, Object value)
From source file:es.sm2.openppm.core.dao.TeamMemberDAO.java
License:Open Source License
/** * Capacity planning resource // w w w.java 2s . co m * * @param idEmployee * @param since * @param until * @param statusList * @param joins * @param settings * @param user * @return */ public List<Teammember> capacityPlanningResource(Integer idEmployee, Date since, Date until, String[] statusList, List<String> joins, HashMap<String, String> settings, Employee user) { Criteria crit = getSession().createCriteria(getPersistentClass(), "t"); // Filter by dates (since && until) if (since != null && until != null) { crit.add(Restrictions.disjunction().add(Restrictions.between(Teammember.DATEIN, since, until)) .add(Restrictions.between(Teammember.DATEOUT, since, until)) .add(Restrictions.and(Restrictions.le(Teammember.DATEIN, since), Restrictions.ge(Teammember.DATEOUT, until)))); } else if (since != null) { crit.add(Restrictions.and(Restrictions.le(Teammember.DATEIN, since), Restrictions.ge(Teammember.DATEOUT, since))); } else if (until != null) { crit.add(Restrictions.and(Restrictions.le(Teammember.DATEIN, until), Restrictions.ge(Teammember.DATEOUT, until))); } if (ValidateUtil.isNotNull(statusList)) { crit.add(Restrictions.in(Teammember.STATUS, statusList)); } // Filter By Employee Criteria employeeCrit = crit.createCriteria(Teammember.EMPLOYEE); if (idEmployee != null) { employeeCrit.add(Restrictions.idEq(idEmployee)); } // Joins // Criteria projActCrit = crit.createCriteria(Teammember.PROJECTACTIVITY); Criteria projCrit = projActCrit.createCriteria(Projectactivity.PROJECT); // Remove information if project is closed if (!SettingUtil.getBoolean(settings, SettingType.CLOSED_PROJECTS_CAPACITY_PLANNING)) { projCrit.add(Restrictions.and(Restrictions.ne(Project.STATUS, Constants.STATUS_CLOSED), Restrictions.ne(Project.STATUS, Constants.STATUS_ARCHIVED))); } addJoins(crit, joins); // PM Projects if (!SettingUtil.getBoolean(settings, GeneralSetting.PM_VIEW_OTHER_PROJECTS) && user.getResourceprofiles().getIdProfile() == Constants.ROLE_PM) { projCrit.add(Restrictions.eq(Project.EMPLOYEEBYPROJECTMANAGER, user)); } // Orders // employeeCrit.createCriteria(Employee.CONTACT).addOrder(Order.asc(Contact.FULLNAME)); projCrit.addOrder(Order.asc(Project.PROJECTNAME)); projActCrit.addOrder(Order.asc(Projectactivity.ACTIVITYNAME)); return crit.list(); }
From source file:es.sm2.openppm.core.dao.TimesheetDAO.java
License:Open Source License
/** * Find time sheets of the resource/*from w w w. ja va 2 s .c o m*/ * * @param employee * @param initDate * @param endDate * @param joins * @param project * @param minStatus * @param maxStatus * @param filterUser * @param statusResource * @param settings * @return */ @SuppressWarnings("unchecked") public List<Timesheet> findByCriteria(Employee employee, Date initDate, Date endDate, List<String> joins, Project project, String minStatus, String maxStatus, Employee filterUser, String statusResource, boolean includeClosed, HashMap<String, String> settings) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .add(Restrictions.eq(Timesheet.EMPLOYEE, employee)) .add(Restrictions.eq(Timesheet.INITDATE, initDate)) .add(Restrictions.eq(Timesheet.ENDDATE, endDate)); if (minStatus != null && maxStatus != null) { Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.eq(Timesheet.STATUS, minStatus)); disjunction.add(Restrictions.eq(Timesheet.STATUS, maxStatus)); if (Constants.TIMESTATUS_APP0.equals(minStatus) && (Constants.TIMESTATUS_APP2.equals(maxStatus) || Constants.TIMESTATUS_APP3.equals(maxStatus))) { disjunction.add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP1)); } if (Constants.TIMESTATUS_APP3.equals(maxStatus) && (Constants.TIMESTATUS_APP0.equals(minStatus) || Constants.TIMESTATUS_APP1.equals(minStatus))) { disjunction.add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP2)); } //TODO 21/04/2015 - jordi.ripoll- tarea 1095 -pendiente de confirmacion // Last level be approved hours app1 by setting // // String lastLevelForApprove = SettingUtil.getString(settings, Settings.SETTING_LAST_LEVEL_FOR_APPROVE_SHEET, // Settings.DEFAULT_LAST_LEVEL_FOR_APPROVE_SHEET); // // if ((filterUser != null && lastLevelForApprove.equals(String.valueOf(filterUser.getResourceprofiles().getIdProfile()))) && // (settings != null && SettingUtil.getBoolean(settings, GeneralSetting.LAST_LEVEL_APPROVED_APP1))) { // // disjunction.add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP1)); // } crit.add(disjunction); } Criteria critEmployee = crit.createCriteria(Timesheet.EMPLOYEE); critEmployee.createCriteria(Employee.CONTACT); Criteria critActivity = crit.createCriteria(Timesheet.PROJECTACTIVITY); Criteria critMembers = critActivity.createCriteria(Projectactivity.TEAMMEMBERS) .add(Restrictions.eq(Teammember.EMPLOYEE, employee)); if (ValidateUtil.isNotNull(statusResource)) { critMembers.add(Restrictions.eq(Teammember.STATUS, statusResource)); } Criteria critProject = critActivity.createCriteria(Projectactivity.PROJECT); if (!includeClosed) { critProject.add(Restrictions.and(Restrictions.ne(Project.STATUS, Constants.STATUS_CLOSED), Restrictions.ne(Project.STATUS, Constants.STATUS_ARCHIVED))); } if (project != null) { critProject.add(Restrictions.eq(Project.IDPROJECT, project.getIdProject())); } else if (filterUser != null) { // Filter by User. Settings by company for last approval. Resourceprofiles profile = filterUser.getResourceprofiles(); if (profile.getIdProfile() == Constants.ROLE_FM) { critProject.add(Restrictions.eq(Project.EMPLOYEEBYFUNCTIONALMANAGER, filterUser)); } else if (profile.getIdProfile() == Constants.ROLE_PMO) { critProject.add(Restrictions.eq(Project.PERFORMINGORG, filterUser.getPerformingorg())); } } addJoins(crit, joins); return crit.list(); }
From source file:es.sm2.openppm.utils.hibernate.dao.AbstractGenericHibernateDAO.java
License:Open Source License
public int rowCountNe(String property, Object object) { return rowCount(Restrictions.ne(property, object)); }
From source file:fr.gael.dhus.olingo.v1.SQLVisitor.java
License:Open Source License
private Criterion internalCriterionComparative(BinaryOperator operator, String property, Object value) { Criterion criterion;//from w w w .j ava 2 s . c o m switch (operator) { case EQ: { criterion = Restrictions.eq(property, value); break; } case NE: { criterion = Restrictions.ne(property, value); break; } case GT: { criterion = Restrictions.gt(property, value); break; } case GE: { criterion = Restrictions.ge(property, value); break; } case LT: { criterion = Restrictions.lt(property, value); break; } case LE: { criterion = Restrictions.le(property, value); break; } default: throw new UnsupportedOperationException("Unsupported operation: " + operator.toUriLiteral()); } return criterion; }
From source file:fr.mcc.ginco.dao.hibernate.ThesaurusArrayDAO.java
License:CeCILL license
@Override public List<ThesaurusArray> getConceptSuperOrdinateArrays(String conceptId, String excludeArrayId) { Criteria criteria = getCriteriaBySuperOrdinate(conceptId); criteria.add(Restrictions.ne("ta.identifier", excludeArrayId)); return criteria.list(); }
From source file:fr.mcc.ginco.dao.hibernate.ThesaurusArrayDAO.java
License:CeCILL license
private void excludeAnArrayById(Criteria criteria, String excludedConceptArrayId) { if (excludedConceptArrayId != null) { criteria.add(Restrictions.ne("ta.identifier", (String) excludedConceptArrayId)); }/*from ww w . j av a 2s . c o m*/ }
From source file:fr.mcc.ginco.dao.hibernate.ThesaurusConceptGroupDAO.java
License:CeCILL license
private void excludeAGroupById(Criteria criteria, String excludedConceptGroupId) { if (excludedConceptGroupId != null) { criteria.add(Restrictions.ne("ta.identifier", (String) excludedConceptGroupId)); }/*from www . j ava 2 s.com*/ }
From source file:fr.mcc.ginco.dao.hibernate.ThesaurusTermDAO.java
License:CeCILL license
@Override public Long countSimilarTermsByLexicalValueAndLanguage(ThesaurusTerm term) { return (Long) getCurrentSession().createCriteria(ThesaurusTerm.class) .add(Restrictions.eq(LEXICAL_VALUE, term.getLexicalValue())) .add(Restrictions.eq(LANGUAGE_ID, term.getLanguage().getId())) .add(Restrictions.eq(THESAURUS_IDENTIFIER, term.getThesaurus().getIdentifier())) .add(Restrictions.ne("identifier", term.getIdentifier())).setProjection(Projections.rowCount()) .list().get(0);//w w w . j av a 2 s . c o m }
From source file:fr.mcc.ginco.dao.hibernate.ThesaurusVersionHistoryDAO.java
License:CeCILL license
private void excludeAVersion(Criteria criteria, String excludedVersionId) { criteria.add(Restrictions.ne("tv.identifier", (String) excludedVersionId)); }
From source file:gov.nih.nci.caarray.validation.UniqueConstraintValidator.java
License:BSD License
/** * {@inheritDoc}//from ww w. ja v a 2s .c om */ @SuppressWarnings({ "PMD.CyclomaticComplexity", "PMD.ExcessiveMethodLength" }) public boolean isValid(final Object o) { UnfilteredCallback unfilteredCallback = new UnfilteredCallback() { public Object doUnfiltered(Session s) { FlushMode fm = s.getFlushMode(); try { s.setFlushMode(FlushMode.MANUAL); Class<?> classWithConstraint = findClassDeclaringConstraint( hibernateHelper.unwrapProxy(o).getClass()); Criteria crit = s.createCriteria(classWithConstraint); ClassMetadata metadata = hibernateHelper.getSessionFactory() .getClassMetadata(classWithConstraint); for (UniqueConstraintField field : uniqueConstraint.fields()) { Object fieldVal = metadata.getPropertyValue(o, field.name(), EntityMode.POJO); if (fieldVal == null) { if (field.nullsEqual()) { // nulls are equal, so add it to to criteria crit.add(Restrictions.isNull(field.name())); } else { // nulls are never equal, so uniqueness is automatically satisfied return true; } } else { // special casing for entity-type properties - only include them in the criteria if they are // already // persistent // otherwise, short-circuit the process and return true immediately since if the // entity-type property // is not persistent then it will be a new value and thus different from any currently in // the db, thus satisfying uniqueness ClassMetadata fieldMetadata = hibernateHelper.getSessionFactory() .getClassMetadata(hibernateHelper.unwrapProxy(fieldVal).getClass()); if (fieldMetadata == null || fieldMetadata.getIdentifier(fieldVal, EntityMode.POJO) != null) { crit.add(Restrictions.eq(field.name(), ReflectHelper.getGetter(o.getClass(), field.name()).get(o))); } else { return true; } } } // if object is already persistent, then add condition to exclude it matching itself Object id = metadata.getIdentifier(o, EntityMode.POJO); if (id != null) { crit.add(Restrictions.ne(metadata.getIdentifierPropertyName(), id)); } int numMatches = crit.list().size(); return numMatches == 0; } finally { s.setFlushMode(fm); } } }; return (Boolean) hibernateHelper.doUnfiltered(unfilteredCallback); }