List of usage examples for org.hibernate.criterion Restrictions isNotNull
public static Criterion isNotNull(String propertyName)
From source file:org.jasig.ssp.dao.PersonDao.java
License:Apache License
public PagingWrapper<CoachPersonLiteTO> getAllAssignedCoachesLite(SortingAndPaging sAndP, String homeDepartment) {// ww w.j a v a 2 s. c o m DetachedCriteria coach_ids = DetachedCriteria.forClass(Person.class, "coach_ids"); final ProjectionList projections = Projections.projectionList(); projections.add(Projections.distinct(Projections.property("coach.id"))); coach_ids.setProjection(projections); coach_ids.add(Restrictions.isNotNull("coach")); Criteria criteria = createCriteria().add(Subqueries.propertiesIn(new String[] { "id" }, coach_ids)); if (sAndP != null && sAndP.isFilteredByStatus()) { sAndP.addStatusFilterToCriteria(criteria); } if (homeDepartment != null && homeDepartment.length() >= 0) { criteria.createAlias("staffDetails", "personStaffDetails"); criteria.add(Restrictions.eq("personStaffDetails.departmentName", homeDepartment)); } else { criteria.createAlias("staffDetails", "personStaffDetails", JoinType.LEFT_OUTER_JOIN); } // item count Long totalRows = 0L; if ((sAndP != null) && sAndP.isPaged()) { totalRows = (Long) criteria.setProjection(Projections.rowCount()).uniqueResult(); } criteria.setProjection(null); criteria.setProjection(Projections.projectionList().add(Projections.property("id").as("person_id")) .add(Projections.property("firstName").as("person_firstName")) .add(Projections.property("lastName").as("person_lastName")) .add(Projections.property("primaryEmailAddress").as("person_primaryEmailAddress")) .add(Projections.property("workPhone").as("person_workPhone")) .add(Projections.property("personStaffDetails.departmentName").as("person_departmentName"))) .setResultTransformer( new NamespacedAliasToBeanResultTransformer(CoachPersonLiteTO.class, "person_")); return new PagingWrapper<CoachPersonLiteTO>(totalRows, criteria.list()); }
From source file:org.jasig.ssp.dao.PersonDao.java
License:Apache License
protected Criteria setBasicSearchCriteria(Criteria criteria, final PersonSearchFormTO personSearchTO) { Boolean coachCriteriaCreated = false; if (personSearchTO.getCoach() != null && personSearchTO.getCoach().getId() != null) { coachCriteriaCreated = setCoachAlias(criteria, "c", coachCriteriaCreated); // Not 100% clear whether this should or shouldn't include a coach.objectStatus = ACTIVE // filter. Could argue it's a direct association so the status of coach shouldn't matter. // But it's an operational->operational association (not operational->reference), which // is a little bit different, semantically. E.g. studenttype.objectStatus doesn't matter // for person->studenttype, but journalentry.status does matter for person->journalentry. // In this case we've chosen not to filter since for persons in particular, soft-deletion // is strongly discouraged since ~2.4.0 since it leads to strange UI behaviors. criteria.add(Restrictions.eq("c.id", personSearchTO.getCoach().getId())); }/*from w ww. j a va2s.c om*/ if (personSearchTO.getWatcher() != null && personSearchTO.getWatcher().getId() != null) { criteria.createCriteria("watchers") .add(Restrictions.eq("person.id", personSearchTO.getWatcher().getId())) .add(Restrictions.eq("objectStatus", ObjectStatus.ACTIVE)); } if (personSearchTO.getHomeDepartment() != null && personSearchTO.getHomeDepartment().length() > 0) { coachCriteriaCreated = setCoachAlias(criteria, "c", coachCriteriaCreated); // As with coaches, it's not 100% clear whether or not this should have a objectstatus filter. // If staffdetails were a reference type, we'd ignore its status. But, as noted above, the // status of directly associated operational types usually *does* matter. But in this // case the API and UI effectively ignore staffdetails.objectstatus (e.g. even if // coach.staffdetails.objectstatus=2, the coach's department will still render in the // caseload add/edit form). So we ignore it here as well. criteria.createAlias("c.staffDetails", "coachStaffDetails"); criteria.add(Restrictions.eq("coachStaffDetails.departmentName", personSearchTO.getHomeDepartment())); } if (personSearchTO.getProgramStatus() != null) { criteria.createAlias("programStatuses", "personProgramStatuses"); // Not filtering on object status here b/c throughout the app it's just a filter on expiry criteria.add( Restrictions.eq("personProgramStatuses.programStatus.id", personSearchTO.getProgramStatus())); criteria.add(Restrictions.isNull("personProgramStatuses.expirationDate")); } if (personSearchTO.getSpecialServiceGroupIds() != null) { criteria.createAlias("specialServiceGroups", "personSpecialServiceGroups"); criteria.add(Restrictions.in("personSpecialServiceGroups.specialServiceGroup.id", personSearchTO.getSpecialServiceGroupIds())); criteria.add(Restrictions.eq("personSpecialServiceGroups.objectStatus", ObjectStatus.ACTIVE)); } else if (personSearchTO.getSpecialServiceGroupRequired()) { /* Makes sure that at least one special service group has an active status */ criteria.createAlias("specialServiceGroups", "personSpecialServiceGroups"); criteria.add(Restrictions.eq("personSpecialServiceGroups.objectStatus", ObjectStatus.ACTIVE)); } if (personSearchTO.getReferralSourcesIds() != null) { criteria.createAlias("referralSources", "personReferralSources") .add(Restrictions.in("personReferralSources.referralSource.id", personSearchTO.getReferralSourcesIds())) .add(Restrictions.eq("personReferralSources.objectStatus", ObjectStatus.ACTIVE)); } if (personSearchTO.getAnticipatedStartTerm() != null && personSearchTO.getAnticipatedStartTerm().length() > 0) { criteria.add( Restrictions.eq("anticipatedStartTerm", personSearchTO.getAnticipatedStartTerm()).ignoreCase()); } if (personSearchTO.getAnticipatedStartYear() != null) { criteria.add(Restrictions.eq("anticipatedStartYear", personSearchTO.getAnticipatedStartYear())); } if (personSearchTO.getActualStartTerm() != null && personSearchTO.getActualStartTerm().length() > 0) { criteria.add(Restrictions.eq("actualStartTerm", personSearchTO.getActualStartTerm()).ignoreCase()); } if (personSearchTO.getActualStartYear() != null) { criteria.add(Restrictions.eq("actualStartYear", personSearchTO.getActualStartYear())); } if (personSearchTO.getStudentTypeIds() != null) { criteria.add(Restrictions.in("studentType.id", personSearchTO.getStudentTypeIds())); } if (personSearchTO.getCreateDateFrom() != null) { criteria.add(Restrictions.ge("createdDate", personSearchTO.getCreateDateFrom())); } if (personSearchTO.getCreateDateTo() != null) { criteria.add(Restrictions.le("createdDate", personSearchTO.getCreateDateTo())); } if (personSearchTO.getDisabilityIsNotNull() != null && personSearchTO.getDisabilityIsNotNull() == true) { // Not filtering on object status here b/c technically the person->persondisability association is // direct and thus the status of the associated object (persondisability) doesn't matter criteria.createAlias("disability", "personDisability"); criteria.add(Restrictions.isNotNull("personDisability.id")); } if (personSearchTO.getDisabilityStatusId() != null) { if (personSearchTO.getDisabilityIsNotNull() == null || personSearchTO.getDisabilityIsNotNull() == false) criteria.createAlias("disability", "personDisability"); criteria.add(Restrictions.eq("personDisability.disabilityStatus.id", personSearchTO.getDisabilityStatusId())); // Direct operational-to-operational relationship, so probably should have a persondisability.objectstatus // filter, but the UI completely disregards that field, so have decided against adding such a filter here. } if (personSearchTO.getDisabilityTypeId() != null) { criteria.createAlias("disabilityTypes", "personDisabilityTypes") .add(Restrictions.eq("personDisabilityTypes.disabilityType.id", personSearchTO.getDisabilityTypeId())) .add(Restrictions.eq("personDisabilityTypes.objectStatus", ObjectStatus.ACTIVE)); } if (personSearchTO.getServiceReasonsIds() != null && personSearchTO.getServiceReasonsIds().size() > 0) { criteria.createAlias("serviceReasons", "serviceReasons"); criteria.createAlias("serviceReasons.serviceReason", "serviceReason"); criteria.add(Restrictions.in("serviceReason.id", personSearchTO.getServiceReasonsIds())); criteria.add(Restrictions.eq("serviceReasons.objectStatus", ObjectStatus.ACTIVE)); } // don't bring back any non-students, there will likely be a better way // to do this later criteria.add(Restrictions.isNotNull("studentType")); return criteria; }
From source file:org.jasig.ssp.dao.PersonStaffDetailsDao.java
License:Apache License
@SuppressWarnings("unchecked") public List<String> getAllHomeDepartments(ObjectStatus status) { Criteria criteria = createCriteria(); if (status != null) criteria.add(Restrictions.eq("objectStatus", status)); criteria.add(Restrictions.isNotNull("departmentName")); criteria.setProjection(/*from w w w . ja v a2s.c om*/ Projections.projectionList().add(Projections.distinct(Projections.property("departmentName")))); return ((List<String>) criteria.list()); }
From source file:org.jasig.ssp.dao.TaskDao.java
License:Apache License
private void addCompleteRestriction(final boolean complete, final Criteria criteria) { if (complete) { criteria.add(Restrictions.isNotNull("completedDate")); } else {//ww w . j a v a2 s . c o m criteria.add(Restrictions.isNull("completedDate")); } }
From source file:org.jasig.ssp.dao.TaskDao.java
License:Apache License
@SuppressWarnings(UNCHECKED) public List<Task> getAllWhichNeedRemindersSent(final SortingAndPaging sAndP) { final Criteria criteria = createCriteria(sAndP); criteria.add(Restrictions.isNull("completedDate")); criteria.add(Restrictions.isNull("reminderSentDate")); criteria.add(Restrictions.isNotNull("dueDate")); criteria.add(Restrictions.gt("dueDate", DateTimeUtils.midnight())); return criteria.list(); }
From source file:org.jasig.ssp.dao.TaskDao.java
License:Apache License
public Pair<Long, Long> getOpenVsClosedTaskCountsForPerson(Person person) { //Probably this could be done in one query, but so much simpler to get working with two final Criteria openCriteria = createCriteria().add(Restrictions.eq("person.id", person.getId())) .add(Restrictions.isNull("completedDate")).add(Restrictions.eq("objectStatus", ObjectStatus.ACTIVE)) .setProjection(Projections.rowCount()); final Long openCnt = (Long) openCriteria.list().get(0); final Criteria closedCriteria = createCriteria().add(Restrictions.eq("person.id", person.getId())) .add(Restrictions.isNotNull("completedDate")) .add(Restrictions.eq("objectStatus", ObjectStatus.ACTIVE)).setProjection(Projections.rowCount()); final Long closedCnt = (Long) closedCriteria.list().get(0); return new Pair<Long, Long>(openCnt, closedCnt); }
From source file:org.jspresso.framework.model.persistence.hibernate.criterion.DefaultCriteriaFactory.java
License:Open Source License
/** * Creates a criterion by processing a comparable query structure. * * @param path//from w w w .ja va 2 s. c o m * the path to the comparable property. * @param queryStructure * the comparable query structure. * @param componentDescriptor * the component descriptor * @param queryComponent * the query component * @param context * the context * @return the created criterion or null if no criterion necessary. */ protected Criterion createComparableQueryStructureRestriction(String path, ComparableQueryStructure queryStructure, IComponentDescriptor<?> componentDescriptor, IQueryComponent queryComponent, Map<String, Object> context) { Junction queryStructureRestriction = null; if (queryStructure.isRestricting()) { queryStructureRestriction = Restrictions.conjunction(); String comparator = queryStructure.getComparator(); Object infValue = queryStructure.getInfValue(); Object supValue = queryStructure.getSupValue(); Object compareValue = infValue; if (compareValue == null) { compareValue = supValue; } switch (comparator) { case ComparableQueryStructureDescriptor.EQ: queryStructureRestriction.add(Restrictions.eq(path, compareValue)); break; case ComparableQueryStructureDescriptor.GT: queryStructureRestriction.add(Restrictions.gt(path, compareValue)); break; case ComparableQueryStructureDescriptor.GE: queryStructureRestriction.add(Restrictions.ge(path, compareValue)); break; case ComparableQueryStructureDescriptor.LT: queryStructureRestriction.add(Restrictions.lt(path, compareValue)); break; case ComparableQueryStructureDescriptor.LE: queryStructureRestriction.add(Restrictions.le(path, compareValue)); break; case ComparableQueryStructureDescriptor.NU: queryStructureRestriction.add(Restrictions.isNull(path)); break; case ComparableQueryStructureDescriptor.NN: queryStructureRestriction.add(Restrictions.isNotNull(path)); break; case ComparableQueryStructureDescriptor.BE: if (infValue != null && supValue != null) { queryStructureRestriction.add(Restrictions.between(path, infValue, supValue)); } else if (infValue != null) { queryStructureRestriction.add(Restrictions.ge(path, infValue)); } else { queryStructureRestriction.add(Restrictions.le(path, supValue)); } break; default: break; } } return queryStructureRestriction; }
From source file:org.kaaproject.kaa.server.common.dao.impl.sql.HibernateCtlSchemaMetaInfoDao.java
License:Apache License
@Override public List<CtlSchemaMetaInfo> findSiblingsByFqnTenantIdAndApplicationId(String fqn, String tenantId, String applicationId) {//from w w w .j a v a 2s.com LOG.debug("Searching siblings of ctl by fqn [{}], tenantId [{}] and applicationId [{}]", fqn, tenantId, applicationId); List<CtlSchemaMetaInfo> ctlSchemaMetaInfos; if (isNotBlank(fqn) && isNotBlank(tenantId) && isNotBlank(applicationId)) { ctlSchemaMetaInfos = findListByCriterion(Restrictions.and( Restrictions.eq(CTL_SCHEMA_META_INFO_FQN, fqn), Restrictions.eq(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS, Long.valueOf(tenantId)), Restrictions.isNotNull(CTL_SCHEMA_META_INFO_APPLICATION_ID_ALIAS), Restrictions.ne(CTL_SCHEMA_META_INFO_APPLICATION_ID_ALIAS, Long.valueOf(applicationId)))); } else { ctlSchemaMetaInfos = Collections.emptyList(); } if (LOG.isTraceEnabled()) { LOG.trace("[{}][{}][{}] Search result: [{}].", fqn, tenantId, applicationId, Arrays.toString(ctlSchemaMetaInfos.toArray())); } else { LOG.debug("[{}][{}][{}] Search result: [{}].", fqn, tenantId, applicationId, ctlSchemaMetaInfos.size()); } return ctlSchemaMetaInfos; }
From source file:org.kaaproject.kaa.server.common.dao.impl.sql.HibernateCtlSchemaMetaInfoDao.java
License:Apache License
private Criterion buildExludingSearchCriterion(String fqn, String excludingTenantId, String excludingApplicationId) { List<Criterion> searchCriterions = new ArrayList<>(); if (isNotBlank(excludingTenantId)) { searchCriterions.add(Restrictions.isNull(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS)); if (isNotBlank(excludingApplicationId)) { searchCriterions.add(Restrictions.and( Restrictions.eq(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS, Long.valueOf(excludingTenantId)), Restrictions.isNull(CTL_SCHEMA_META_INFO_APPLICATION_ID_ALIAS))); } else {//from w ww. ja v a 2 s . co m searchCriterions.add(Restrictions.and( Restrictions.eq(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS, Long.valueOf(excludingTenantId)), Restrictions.isNotNull(CTL_SCHEMA_META_INFO_APPLICATION_ID_ALIAS))); } } else { searchCriterions.add(Restrictions.isNotNull(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS)); } return Restrictions.and(Restrictions.eq(CTL_SCHEMA_META_INFO_FQN, fqn), Restrictions.or(searchCriterions.toArray(new Criterion[searchCriterions.size()]))); }
From source file:org.kimios.kernel.dms.hibernate.HWorkflowStatusFactory.java
License:Open Source License
public WorkflowStatus getStartWorkflowStatus(Workflow wf) throws ConfigException, DataSourceException { try {//from ww w.j a v a 2 s. c o m //Liste des successeurs DetachedCriteria successorList = DetachedCriteria.forClass(WorkflowStatus.class) .add(Restrictions.isNotNull("successorUid")).add(Restrictions.eq("workflowUid", wf.getUid())); List<WorkflowStatus> lSList = successorList.getExecutableCriteria(getSession()).list(); //Liste des status List<WorkflowStatus> list = getSession().createCriteria(WorkflowStatus.class) .add(Restrictions.eq("workflowUid", wf.getUid())).list(); //Not In list.removeAll(lSList); return list.get(0); } catch (HibernateException he) { throw he; } }