Example usage for org.hibernate.criterion Restrictions isNull

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

Introduction

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

Prototype

public static Criterion isNull(String propertyName) 

Source Link

Document

Apply an "is null" constraint to the named property

Usage

From source file:edu.emory.library.tast.database.SourceInformationLookup.java

License:Open Source License

private SourceInformationLookup(Session sess) {
    List response = sess.createCriteria(Source.class, "s")
            .add(Restrictions.not(Restrictions.isNull("s.sourceId"))).list();
    sources = new Source[response.size()];
    index = new SourceIndexPosition[response.size()];
    int i = 0;/*from   w w w. j  a  v  a  2 s . com*/
    for (Iterator sourceIt = response.iterator(); sourceIt.hasNext();) {
        Source source = (Source) sourceIt.next();
        sources[i] = source;
        index[i] = new SourceIndexPosition(source.getSourceId(), i);
        i++;
    }

    Arrays.sort(index);

    sourceNames = new String[response.size()];
    for (int j = 0; j < index.length; j++) {
        sourceNames[j] = index[j].getSourceName();
    }
}

From source file:edu.ku.brc.specify.dbsupport.customqueries.CustomStatQueries.java

License:Open Source License

protected boolean overdueLoans() {
    //String sql = "select loanId from Loan where (not (currentDueDate is null)) and (IsClosed = false or IsClosed is null) and datediff(CURDATE(), currentduedate) > 0;
    //select count(loanid) as OpenLoanCount from loan where loanid in (select loanid from loan where (not (currentduedate is null)) and loan.IsGift = false and (IsClosed = false or IsClosed is null) and datediff(CURDATE(), currentduedate) > 0)

    Session session = HibernateUtil.getNewSession();

    Calendar today = Calendar.getInstance();

    Criteria criteria = session.createCriteria(Loan.class);
    criteria.add(Restrictions.isNotNull("currentDueDate"));
    criteria.add(Restrictions.lt("currentDueDate", today));
    criteria.add(Restrictions.or(Restrictions.isNull("isClosed"), Restrictions.eq("isClosed", false)));

    Criteria dsp = criteria.createCriteria("discipline");
    dsp.add(Restrictions.eq("disciplineId",
            AppContextMgr.getInstance().getClassObject(Discipline.class).getDisciplineId()));

    criteria.setProjection(Projections.rowCount());
    resultsList = criteria.list();/*from  w w  w  .  ja v  a  2 s . c o m*/

    /*for (Object data : resultsList)
    {
    System.out.println("overdueLoans "+data);
    }*/
    session.close();

    return true;
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.wbuploader.UploadTable.java

License:Open Source License

/**
 * @param critter/*from   w w w . jav  a  2s .  c o m*/
 * @param propName
 * @param arg
 * 
 * returns string representation of the restriction added.
 * 
 * Adds a restriction to critter for propName.
 */
protected String addRestriction(final CriteriaIFace critter, final String propName, final Object arg,
        boolean ignoreNulls) {
    if (arg != null && (!(arg instanceof String) || StringUtils.isNotBlank((String) arg))) {
        critter.add(Restrictions.eq(propName, arg));
        if (arg instanceof DataModelObjBase) {
            String value = DataObjFieldFormatMgr.getInstance().format(arg, arg.getClass());
            if (StringUtils.isNotBlank(value)) {
                return value;
            }
            return ((DataModelObjBase) arg).getId().toString();
        }
        return arg.toString();
    }

    if (!ignoreNulls || matchSetting.isMatchEmptyValues()) {
        critter.add(Restrictions.isNull(propName));
        return getNullRestrictionText();
    }

    return "";
}

From source file:edu.northwestern.bioinformatics.studycalendar.dao.StudyDao.java

License:BSD License

@SuppressWarnings({ "unchecked" })
private Collection<Integer> searchForVisibleIds(VisibleStudyParameters parameters, String search,
        boolean includeManaging, boolean includeParticipating, boolean includeSpecific) {
    if (log.isDebugEnabled()) {
        log.debug("Searching visible studies for {} with {}", parameters,
                search == null ? "no term" : "term \"" + search + '"');
        if (!includeManaging)
            log.debug("- Excluding managing");
        if (!includeParticipating)
            log.debug("- Excluding participating");
        if (!includeSpecific)
            log.debug("- Excluding specific studies");
    }//  w  w w.j  av  a 2s  . c  om
    List<DetachedCriteria> separateCriteria = new LinkedList<DetachedCriteria>();
    if (parameters.isAllManagingSites() && includeManaging) {
        if (search == null) {
            return null; // shortcut for all
        } else {
            separateCriteria.add(criteria().add(searchRestriction(search)));
        }
    } else {
        // These are implemented as separate queries and then merged because
        // the criteria are too complex to reliably express in a single statement.

        if (includeSpecific && !parameters.getSpecificStudyIdentifiers().isEmpty()) {
            separateCriteria.add(criteria()
                    .add(MoreRestrictions.in("assignedIdentifier", parameters.getSpecificStudyIdentifiers())));
        }
        if (includeManaging && !parameters.getManagingSiteIdentifiers().isEmpty()) {
            separateCriteria.add(criteria().createAlias("managingSites", "ms", Criteria.LEFT_JOIN)
                    .add(Restrictions.disjunction()
                            .add(MoreRestrictions.in("ms.assignedIdentifier",
                                    parameters.getManagingSiteIdentifiers()))
                            .add(Restrictions.isNull("ms.assignedIdentifier")) // <- unmanaged studies
            ));
        }
        if (includeParticipating) {
            if (parameters.isAllParticipatingSites()) {
                separateCriteria
                        .add(criteria().createAlias("studySites", "ss").add(Restrictions.isNotNull("ss.id")));
            } else if (!parameters.getParticipatingSiteIdentifiers().isEmpty()) {
                separateCriteria.add(criteria().createAlias("studySites", "ss").createAlias("ss.site", "s")
                        .add(MoreRestrictions.in("s.assignedIdentifier",
                                parameters.getParticipatingSiteIdentifiers())));
            }
        }

        for (DetachedCriteria criteria : separateCriteria) {
            if (search != null) {
                criteria.add(searchRestriction(search));
            }
        }
    }

    Set<Integer> ids = new LinkedHashSet<Integer>();
    for (DetachedCriteria criteria : separateCriteria) {
        ids.addAll(getHibernateTemplate().findByCriteria(criteria.setProjection(Projections.id())));
    }
    log.debug("Found IDs {}", ids);
    return ids;
}

From source file:edu.northwestern.bioinformatics.studycalendar.dao.StudySubjectAssignmentDao.java

License:BSD License

@SuppressWarnings({ "unchecked" })
public List<StudySubjectAssignment> getAssignmentsWithoutManagerCsmUserId() {
    return getHibernateTemplate().findByCriteria(criteria().add(Restrictions.isNull("managerCsmUserId")));
}

From source file:edu.nps.moves.mmowgli.export.CardVisualizerBuilder.java

License:Open Source License

@SuppressWarnings("unchecked")
public JsonObject buildJsonTree(Move roundToShow) // null if all
{
    cardDays.clear();/* w w w.  j  av  a 2  s  . co m*/
    rootDays.clear();

    HSess.init();
    // Scan all cards to get master, ordered list of game days, i.e., days when cards were played ; same for only root cards
    Criteria crit = HSess.get().createCriteria(Card.class);
    crit.add(Restrictions.ne("hidden", true));
    List<Card> lis = crit.list();
    HSess.close();

    for (Card cd : lis) {
        String ds = mangleCardDate(cd);
        cardDays.add(ds);
        if (cd.getParentCard() == null) {
            rootDays.add(ds);
        }
    }

    JsonObjectBuilder treeBuilder = null;
    JsonArrayBuilder rootArray = null;
    try {
        treeBuilder = Json.createObjectBuilder();
        treeBuilder.add("type", "Mmowgli Card Tree");
        treeBuilder.add("text", "Click on a card to zoom in, center to zoom out.");
        treeBuilder.add("color", "white");
        treeBuilder.add("value", "1");
        treeBuilder.add("cardGameDays", createGameDaysArray(cardDays, STRINGDATE));
        treeBuilder.add("cardGameDaysLong", createGameDaysArray(cardDays, LONGDATE));
        treeBuilder.add("rootGameDays", createGameDaysArray(rootDays, STRINGDATE));
        treeBuilder.add("rootGameDaysLong", createGameDaysArray(rootDays, LONGDATE));

        rootArray = Json.createArrayBuilder();

        HSess.init();
        crit = HSess.get().createCriteria(Card.class);
        crit.add(Restrictions.isNull("parentCard")); // Gets only the top level
        crit.add(Restrictions.ne("hidden", true));

        CardIncludeFilter filter = roundToShow == null ? new AllNonHiddenCards()
                : new CardsInSingleMove(roundToShow);

        lis = crit.list();
        HSess.close();

        for (Card c : lis) {
            int rootDayIndex = getRootDayIndex(c);
            addCard(c.getId(), rootArray, filter, rootDayIndex);
        }
    } catch (Throwable ex) {
        System.err.println(ex.getClass().getSimpleName() + ": " + ex.getLocalizedMessage());
    }

    treeBuilder.add("children", rootArray);
    return treeBuilder == null ? null : treeBuilder.build();
}

From source file:edu.uoc.dao.impl.UserMeetingDaoHistoryImpl.java

@Override
public UserMeetingHistory findUserMeetingByPK(UserMeetingId umID) {
    Criteria criteria;//www .jav  a 2  s. c  om
    criteria = this.getSession().createCriteria(UserMeetingHistory.class, "usermeetinghistory");
    criteria.add(Restrictions.eq("usermeetinghistory.user_id", umID.getUser().getId()));
    criteria.add(Restrictions.eq("usermeetinghistory.meeting_id", umID.getMeeting().getId()));
    criteria.add(Restrictions.isNull("usermeetinghistory.deleted"));
    logger.info("Criteria " + criteria.toString());

    List list = criteria.list();

    if (list.size() > 0)
        return (UserMeetingHistory) list.get(0);
    else
        return new UserMeetingHistory();
}

From source file:edu.ur.hibernate.ir.researcher.db.HbResearcherInstitutionalItemDAO.java

License:Apache License

/**
 * Get the root researcher institutional Items for given researcher
 * //from w  ww .j  a v  a  2s.c  om
 * @see edu.ur.ir.researcher.ResearcherInstitutionalItemDAO#getRootResearcherInstitutionalItems(Long)
 */
@SuppressWarnings("unchecked")
public List<ResearcherInstitutionalItem> getRootResearcherInstitutionalItems(final Long researcherId) {
    log.debug("getRootResearcherInstitutionalItems::");
    Criteria criteria = hbCrudDAO.getSessionFactory().getCurrentSession().createCriteria(hbCrudDAO.getClazz());
    criteria.createCriteria("researcher").add(Restrictions.idEq(researcherId));
    criteria.add(Restrictions.isNull("parentFolder"));
    return criteria.list();
}

From source file:edu.ur.hibernate.ir.researcher.db.HbResearcherLinkDAO.java

License:Apache License

/**
 * Get the root researcher links for given researcher
 * //from   w w w.  j  a  v  a  2s . com
 * @see edu.ur.ir.researcher.ResearcherLinkDAO#getRootResearcherLinks(Long)
 */
@SuppressWarnings("unchecked")
public List<ResearcherLink> getRootResearcherLinks(final Long researcherId) {
    Criteria criteria = hbCrudDAO.getSessionFactory().getCurrentSession().createCriteria(hbCrudDAO.getClazz());
    criteria.createCriteria("researcher").add(Restrictions.idEq(researcherId));
    criteria.add(Restrictions.isNull("parentFolder"));
    return criteria.list();

}

From source file:edu.ur.hibernate.ir.researcher.db.HbResearcherPublicationDAO.java

License:Apache License

/**
 * Get the root researcher publications for given researcher
 * /*from www  . j  a  va2  s . co m*/
 * @see edu.ur.ir.researcher.ResearcherPublicationDAO#getRootResearcherPublications(Long)
 */
@SuppressWarnings("unchecked")
public List<ResearcherPublication> getRootResearcherPublications(final Long researcherId) {
    log.debug("getRootResearcherPublications::");
    Criteria criteria = hbCrudDAO.getSessionFactory().getCurrentSession().createCriteria(hbCrudDAO.getClazz());
    criteria.createCriteria("researcher").add(Restrictions.idEq(researcherId));
    criteria.add(Restrictions.isNull("parentFolder"));
    return criteria.list();
}