Example usage for org.hibernate.criterion Restrictions isNotNull

List of usage examples for org.hibernate.criterion Restrictions isNotNull

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions isNotNull.

Prototype

public static Criterion isNotNull(String propertyName) 

Source Link

Document

Apply an "is not null" constraint to the named property

Usage

From source file:org.headsupdev.agile.web.components.issues.IssueFilterPanel.java

License:Open Source License

public Criterion getAssignmentCriterion() {
    switch (getAssignments()) {
    case 1:/*  w  ww  . j a va2 s .  c om*/
        return Restrictions.eq("assignee.username",
                ((HeadsUpSession) org.apache.wicket.Session.get()).getUser().getUsername());
    case 2:
        return Restrictions.isNotNull("assignee");
    case 3:
        return Restrictions.isNull("assignee");
    }

    return null;
}

From source file:org.infoscoop.dao.OAuthConsumerDAO.java

License:Open Source License

public List<OAuthConsumerProp> getConsumersByUid(String uid) {
    return super.getHibernateTemplate().findByCriteria(DetachedCriteria.forClass(OAuthConsumerProp.class)
            .createAlias("OAuthToken", "ot", CriteriaSpecification.LEFT_JOIN)
            .createAlias("OAuth2Token", "o2t", CriteriaSpecification.LEFT_JOIN)
            .createAlias("OAuthGadgetUrl", "ogu", CriteriaSpecification.LEFT_JOIN)
            .add(Restrictions.or(//  ww w  .  ja  v a2s.c om
                    Restrictions.and(Restrictions.eq("ot.Id.Uid", uid),
                            Restrictions.isNotNull("ot.accessToken")),
                    Restrictions.and(Restrictions.eq("o2t.Id.Uid", uid),
                            Restrictions.isNotNull("o2t.accessToken")))));
}

From source file:org.iternine.jeppetto.dao.hibernate.HibernateQueryModelDAO.java

License:Apache License

@Override
public Condition buildCondition(String conditionField, ConditionType conditionType, Iterator argsIterator) {
    Condition condition = new Condition();

    condition.setField(conditionField);//from w w w .j av  a  2s .c om

    switch (conditionType) {
    case Between:
        condition.setConstraint(Restrictions.between(conditionField, argsIterator.next(), argsIterator.next()));
        break;

    case Equal:
        condition.setConstraint(Restrictions.eq(conditionField, argsIterator.next()));
        break;

    case GreaterThan:
        condition.setConstraint(Restrictions.gt(conditionField, argsIterator.next()));
        break;

    case GreaterThanEqual:
        condition.setConstraint(Restrictions.ge(conditionField, argsIterator.next()));
        break;

    case IsNotNull:
        condition.setConstraint(Restrictions.isNotNull(conditionField));
        break;

    case IsNull:
        condition.setConstraint(Restrictions.isNull(conditionField));
        break;

    case LessThan:
        condition.setConstraint(Restrictions.lt(conditionField, argsIterator.next()));
        break;

    case LessThanEqual:
        condition.setConstraint(Restrictions.le(conditionField, argsIterator.next()));
        break;

    case NotEqual:
        condition.setConstraint(Restrictions.ne(conditionField, argsIterator.next()));
        break;

    case NotWithin:
        condition.setConstraint(
                Restrictions.not(Restrictions.in(conditionField, (Collection) argsIterator.next())));
        break;

    case Within:
        condition.setConstraint(Restrictions.in(conditionField, (Collection) argsIterator.next()));
        break;
    }

    return condition;
}

From source file:org.jasig.ssp.dao.EarlyAlertDao.java

License:Apache License

public Map<UUID, Number> getCountOfClosedAlertsForPeopleIds(@NotNull final Collection<UUID> personIds) {
    return getCountOfAlertsForPeopleId(personIds, new CriteriaCallback() {
        @Override/* w ww . ja va 2 s.  com*/
        public Criteria criteria(Criteria criteria) {
            criteria.add(Restrictions.isNotNull("closedDate"));
            return criteria;
        }
    });
}

From source file:org.jasig.ssp.dao.EarlyAlertDao.java

License:Apache License

public Long getClosedEarlyAlertCountForClosedDateRange(Date closedDateFrom, Date closedDateTo, Campus campus,
        String rosterStatus) {//w  w w .  j  a  v  a  2 s  .c  o m
    final Criteria query = createCriteria();

    if (closedDateFrom != null) {
        query.add(Restrictions.ge("closedDate", closedDateFrom));
    }

    if (closedDateTo != null) {
        query.add(Restrictions.le("closedDate", closedDateTo));
    }

    query.add(Restrictions.isNotNull("closedDate"));

    if (campus != null) {
        query.add(Restrictions.eq("campus", campus));
    }

    return (Long) query.setProjection(Projections.rowCount()).uniqueResult();
}

From source file:org.jasig.ssp.dao.EarlyAlertDao.java

License:Apache License

public Long getClosedEarlyAlertsCountForEarlyAlertCreatedDateRange(String termCode, Date createDatedFrom,
        Date createdDateTo, Campus campus, String rosterStatus) {
    final Criteria query = createCriteria();

    if (termCode != null) {
        query.add(Restrictions.eq("courseTermCode", termCode));
    }//from  w  w  w .j av  a 2 s. c  om

    if (createDatedFrom != null) {
        query.add(Restrictions.ge("createdDate", createDatedFrom));
    }

    if (createdDateTo != null) {
        query.add(Restrictions.le("createdDate", createdDateTo));
    }

    query.add(Restrictions.isNotNull("closedDate"));

    if (campus != null) {
        query.add(Restrictions.eq("campus", campus));
    }

    return (Long) query.setProjection(Projections.rowCount()).uniqueResult();
}

From source file:org.jasig.ssp.dao.EarlyAlertDao.java

License:Apache License

private Criteria setPersonCriteria(Criteria criteria, PersonSearchFormTO personSearchForm) {
    if (personSearchForm.getCoach() != null && personSearchForm.getCoach().getId() != null) {
        // restrict to coach
        // See PersonDao for notes on why no objectstatus filter here
        criteria.add(Restrictions.eq("person.coach.id", personSearchForm.getCoach().getId()));
    }/* w w  w .j a v a  2  s  . c om*/

    if (personSearchForm.getHomeDepartment() != null && personSearchForm.getHomeDepartment().length() > 0) {
        // See PersonDao for notes on why no objectstatus filter here
        criteria.createAlias("person.coach", "c");
        criteria.createAlias("c.staffDetails", "coachStaffDetails");
        criteria.add(Restrictions.eq("coachStaffDetails.departmentName", personSearchForm.getHomeDepartment()));
    }
    if (personSearchForm.getWatcher() != null && personSearchForm.getWatcher().getId() != null) {
        criteria.createAlias("person.watchers", "watchers");
        criteria.add(Restrictions.eq("watchers.person.id", personSearchForm.getWatcher().getId()))
                .add(Restrictions.eq("watchers.objectStatus", ObjectStatus.ACTIVE));
    }
    if (personSearchForm.getProgramStatus() != null) {
        // Not filtering on object status here b/c throughout the app it's just a filter on expiry
        criteria.createAlias("person.programStatuses", "personProgramStatuses");
        criteria.add(
                Restrictions.eq("personProgramStatuses.programStatus.id", personSearchForm.getProgramStatus()));
        criteria.add(Restrictions.isNull("personProgramStatuses.expirationDate"));

    }
    if (personSearchForm.getSpecialServiceGroupIds() != null) {
        criteria.createAlias("person.specialServiceGroups", "personSpecialServiceGroups");
        criteria.add(Restrictions.in("personSpecialServiceGroups.specialServiceGroup.id",
                personSearchForm.getSpecialServiceGroupIds()));
        criteria.add(Restrictions.eq("personSpecialServiceGroups.objectStatus", ObjectStatus.ACTIVE));
    }

    if (personSearchForm.getReferralSourcesIds() != null) {
        criteria.createAlias("person.referralSources", "personReferralSources").add(Restrictions
                .in("personReferralSources.referralSource.id", personSearchForm.getReferralSourcesIds()));
        criteria.add(Restrictions.eq("personReferralSources.objectStatus", ObjectStatus.ACTIVE));
    }

    if (personSearchForm.getAnticipatedStartTerm() != null) {
        criteria.add(Restrictions.eq("person.anticipatedStartTerm", personSearchForm.getAnticipatedStartTerm())
                .ignoreCase());
    }

    if (personSearchForm.getAnticipatedStartYear() != null) {
        criteria.add(
                Restrictions.eq("person.anticipatedStartYear", personSearchForm.getAnticipatedStartYear()));
    }

    if (personSearchForm.getStudentTypeIds() != null) {
        criteria.add(Restrictions.in("person.studentType.id", personSearchForm.getStudentTypeIds()));
    }

    if (personSearchForm.getCreateDateFrom() != null) {
        criteria.add(Restrictions.ge("person.createdDate", personSearchForm.getCreateDateFrom()));
    }

    if (personSearchForm.getCreateDateTo() != null) {
        criteria.add(Restrictions.le("person.createdDate", personSearchForm.getCreateDateTo()));
    }

    if (personSearchForm.getServiceReasonsIds() != null && personSearchForm.getServiceReasonsIds().size() > 0) {
        criteria.createAlias("person.serviceReasons", "serviceReasons");
        criteria.createAlias("serviceReasons.serviceReason", "serviceReason");
        criteria.add(Restrictions.in("serviceReason.id", personSearchForm.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("person.studentType"));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    return criteria;
}

From source file:org.jasig.ssp.dao.EarlyAlertResponseDao.java

License:Apache License

private Criteria setPersonCriteria(Criteria criteria, PersonSearchFormTO personSearchFormTO) {
    if (personSearchFormTO.getCoach() != null && personSearchFormTO.getCoach().getId() != null) {
        // restrict to coach
        // See PersonDao for notes on why no objectstatus filter here
        criteria.add(Restrictions.eq("person.coach.id", personSearchFormTO.getCoach().getId()));
    }/*  w  w w . j a  v  a  2 s  .co m*/

    criteria.createAlias("person.coach", "coach");

    if (personSearchFormTO.getHomeDepartment() != null && personSearchFormTO.getHomeDepartment().length() > 0) {
        // See PersonDao for notes on why no objectstatus filter here
        criteria.createAlias("coach.staffDetails", "staffDetails");
        criteria.add(Restrictions.eq("staffDetails.departmentName", personSearchFormTO.getHomeDepartment()));
    }
    if (personSearchFormTO.getWatcher() != null && personSearchFormTO.getWatcher().getId() != null) {
        criteria.createAlias("person.watchers", "watchers");
        criteria.add(Restrictions.eq("watchers.person.id", personSearchFormTO.getWatcher().getId()));
        criteria.add(Restrictions.eq("watchers.objectStatus", ObjectStatus.ACTIVE));
    }
    if (personSearchFormTO.getProgramStatus() != null) {
        // Not filtering on object status here b/c throughout the app it's just a filter on expiry
        criteria.createAlias("person.programStatuses", "personProgramStatuses");
        criteria.add(Restrictions.eq("personProgramStatuses.programStatus.id",
                personSearchFormTO.getProgramStatus()));
        criteria.add(Restrictions.isNull("personProgramStatuses.expirationDate"));
    }

    if (personSearchFormTO.getSpecialServiceGroupIds() != null) {
        criteria.createAlias("person.specialServiceGroups", "personSpecialServiceGroups");
        criteria.add(Restrictions.in("personSpecialServiceGroups.specialServiceGroup.id",
                personSearchFormTO.getSpecialServiceGroupIds()));
        criteria.add(Restrictions.eq("personSpecialServiceGroups.objectStatus", ObjectStatus.ACTIVE));
    }

    if (personSearchFormTO.getReferralSourcesIds() != null) {
        criteria.createAlias("person.referralSources", "personReferralSources").add(Restrictions
                .in("personReferralSources.referralSource.id", personSearchFormTO.getReferralSourcesIds()));
        criteria.add(Restrictions.eq("personReferralSources.objectStatus", ObjectStatus.ACTIVE));
    }

    if (personSearchFormTO.getAnticipatedStartTerm() != null) {
        criteria.add(Restrictions
                .eq("person.anticipatedStartTerm", personSearchFormTO.getAnticipatedStartTerm()).ignoreCase());
    }

    if (personSearchFormTO.getAnticipatedStartYear() != null) {
        criteria.add(
                Restrictions.eq("person.anticipatedStartYear", personSearchFormTO.getAnticipatedStartYear()));
    }

    if (personSearchFormTO.getStudentTypeIds() != null) {
        criteria.add(Restrictions.in("person.studentType.id", personSearchFormTO.getStudentTypeIds()));
    }

    if (personSearchFormTO.getCreateDateFrom() != null) {
        criteria.add(Restrictions.ge("person.createdDate", personSearchFormTO.getCreateDateFrom()));
    }

    if (personSearchFormTO.getCreateDateTo() != null) {
        criteria.add(Restrictions.le("person.createdDate", personSearchFormTO.getCreateDateTo()));
    }

    if (personSearchFormTO.getServiceReasonsIds() != null
            && personSearchFormTO.getServiceReasonsIds().size() > 0) {
        criteria.createAlias("person.serviceReasons", "serviceReasons");
        criteria.createAlias("serviceReasons.serviceReason", "serviceReason");
        criteria.add(Restrictions.in("serviceReason.id", personSearchFormTO.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("person.studentType"));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    return criteria;
}

From source file:org.jasig.ssp.dao.JournalEntryDao.java

License:Apache License

private Criteria setPersonCriteria(Criteria criteria, PersonSearchFormTO personSearchForm) {
    criteria.createAlias("person", "person");
    criteria.createAlias("person.coach", "coach");
    if (personSearchForm.getCoach() != null && personSearchForm.getCoach().getId() != null) {
        // restrict to coach
        criteria.add(Restrictions.eq("coach.id", personSearchForm.getCoach().getId()));
    }/*from  w w w.jav  a2 s .  c  om*/

    if (personSearchForm.getHomeDepartment() != null && personSearchForm.getHomeDepartment().length() > 0) {
        criteria.createAlias("coach.staffDetails", "coachStaffDetails");
        criteria.add(Restrictions.eq("coachStaffDetails.departmentName", personSearchForm.getHomeDepartment()));
    }
    if (personSearchForm.getWatcher() != null && personSearchForm.getWatcher().getId() != null) {
        criteria.createAlias("person.watchers", "watchers");
        criteria.add(Restrictions.eq("watchers.person.id", personSearchForm.getWatcher().getId()));
    }
    if (personSearchForm.getProgramStatus() != null) {
        criteria.createAlias("person.programStatuses", "personProgramStatuses");
        criteria.add(
                Restrictions.eq("personProgramStatuses.programStatus.id", personSearchForm.getProgramStatus()));
        criteria.add(Restrictions.isNull("personProgramStatuses.expirationDate"));

    } else {
        criteria.createAlias("person.programStatuses", "personProgramStatuses", JoinType.LEFT_OUTER_JOIN);

    }
    if (personSearchForm.getSpecialServiceGroupIds() != null) {
        criteria.createAlias("person.specialServiceGroups", "personSpecialServiceGroups");
        criteria.add(Restrictions.in("personSpecialServiceGroups.specialServiceGroup.id",
                personSearchForm.getSpecialServiceGroupIds()));
        criteria.add(Restrictions.eq("personSpecialServiceGroups.objectStatus", ObjectStatus.ACTIVE));
    } else {
        criteria.createAlias("person.specialServiceGroups", "personSpecialServiceGroups",
                JoinType.LEFT_OUTER_JOIN);
    }

    if (personSearchForm.getReferralSourcesIds() != null) {
        criteria.createAlias("person.referralSources", "personReferralSources").add(Restrictions
                .in("personReferralSources.referralSource.id", personSearchForm.getReferralSourcesIds()));
        criteria.add(Restrictions.eq("personReferralSources.objectStatus", ObjectStatus.ACTIVE));
    }

    if (personSearchForm.getAnticipatedStartTerm() != null) {
        criteria.add(Restrictions.eq("person.anticipatedStartTerm", personSearchForm.getAnticipatedStartTerm())
                .ignoreCase());
    }

    if (personSearchForm.getAnticipatedStartYear() != null) {
        criteria.add(
                Restrictions.eq("person.anticipatedStartYear", personSearchForm.getAnticipatedStartYear()));
    }

    if (personSearchForm.getActualStartTerm() != null) {
        criteria.add(Restrictions.eq("person.actualStartTerm", personSearchForm.getActualStartTerm()));
    }

    if (personSearchForm.getStudentTypeIds() != null) {
        criteria.add(Restrictions.in("person.studentType.id", personSearchForm.getStudentTypeIds()));
    }

    if (personSearchForm.getServiceReasonsIds() != null && personSearchForm.getServiceReasonsIds().size() > 0) {
        criteria.createAlias("person.serviceReasons", "serviceReasons");
        criteria.createAlias("serviceReasons.serviceReason", "serviceReason");
        criteria.add(Restrictions.in("serviceReason.id", personSearchForm.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("person.studentType"));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    return criteria;
}

From source file:org.jasig.ssp.dao.PersonDao.java

License:Apache License

public PagingWrapper<Person> getAllAssignedCoaches(SortingAndPaging sAndP) {

    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);
    }// ww w .  j  av a  2 s .  c  o m

    // item count
    Long totalRows = 0L;
    if ((sAndP != null) && sAndP.isPaged()) {
        totalRows = (Long) criteria.setProjection(Projections.rowCount()).uniqueResult();
    }

    criteria.setProjection(null);

    if (sAndP == null || !(sAndP.isSorted())) {
        criteria.addOrder(Order.asc("lastName")).addOrder(Order.asc("firstName"));
    } else {
        if (sAndP.isSorted()) {
            sAndP.addSortingToCriteria(criteria);
        }
        sAndP.addPagingToCriteria(criteria);
    }

    return new PagingWrapper<Person>(totalRows, criteria.list());

}