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

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

    return true;
}

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");
    }/*from   w w w.j a va 2 s  .  c o  m*/
    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

/**
 * Returns the CSM IDs for all the users who are marked as the primary for
 * an assignment./*from  w w w.ja  v a  2s  .  c  o  m*/
 */
@SuppressWarnings({ "unchecked" })
public Map<Integer, Long> getManagerCsmUserIdCounts() {
    String idField = "managerCsmUserId";
    List<Object[]> counts = getHibernateTemplate().findByCriteria(
            criteria().setProjection(projectionList().add(count(idField)).add(groupProperty(idField)))
                    .add(Restrictions.isNotNull(idField)));
    Map<Integer, Long> result = new HashMap<Integer, Long>();
    for (Object[] item : counts) {
        result.put((Integer) item[1], (Long) item[0]);
    }
    return result;
}

From source file:edu.nps.moves.mmowgli.modules.administration.SubCardsGameDesignPanel.java

License:Open Source License

private boolean isInMoveConstructionTL() {
    if (isPriorMove())
        return false; // previous move
    if (!isThisMove())
        return true; // future move

    // Here if we're editing the running move. Report if we detect a significant number of child cards played in this move so the
    // designer can be warned

    Criteria criteria = HSess.get().createCriteria(Card.class)
            .add(Restrictions.eq("createdInMove", moveBeingEdited)).add(Restrictions.isNotNull("parentCard"))
            .setProjection(Projections.rowCount());

    int count = ((Long) criteria.list().get(0)).intValue();
    return count < 10;
}

From source file:es.emergya.bbdd.dao.RoutingHome.java

License:Open Source License

/**
 * Devuelve la primera calle que encuentre con este nombre:
 * /*from  w  ww  . j  a va2  s  . c om*/
 * @param pattern
 * @param num
 * @return list of streets
 */
@Transactional(readOnly = true, rollbackFor = Throwable.class)
public Routing find(final String calle) {
    Routing res = null;
    try {
        res = (Routing) getSession().createCriteria(Routing.class).add(Restrictions.eq("name", calle))
                .add(Restrictions.isNotNull("geometria")).addOrder(Order.asc("id")).setMaxResults(1)
                .uniqueResult();

    } catch (Exception e) {
        log.error("Error al buscar las calles :" + calle, e);
    }

    return res;
}

From source file:es.sm2.openppm.core.dao.ActivitysellerDAO.java

License:Open Source License

/**
 * ActivitySeller has associated projects
 * @param activityseller//from   w  w  w . j a va  2  s.co  m
 * @return
 */
public boolean hasAssociatedProjects(Activityseller activityseller) {
    Criteria crit = getSession().createCriteria(getPersistentClass());

    crit.setProjection(Projections.rowCount())
            .add(Restrictions.eq(Activityseller.PROJECTACTIVITY, activityseller.getProjectactivity()))
            .add(Restrictions.isNotNull(Activityseller.PROJECT));

    Integer count = (Integer) crit.uniqueResult();

    return (count != null && count > 0);
}

From source file:es.sm2.openppm.core.dao.ActivitysellerDAO.java

License:Open Source License

/**
 * Find seller associated project//from  w  w w .j av  a  2s . c om
 * @param projectactivity
 * @param joins
 * @return
 */
@SuppressWarnings("unchecked")
public List<Activityseller> findSellerAssociatedProject(Projectactivity projectactivity, List<String> joins) {
    Criteria crit = getSession().createCriteria(getPersistentClass());

    for (String join : joins) {
        crit.setFetchMode(join, FetchMode.JOIN);
    }

    crit.add(Restrictions.eq(Activityseller.PROJECTACTIVITY, projectactivity))
            .add(Restrictions.isNotNull(Activityseller.PROJECT));

    return crit.list();
}

From source file:es.sm2.openppm.core.dao.ActivitysellerDAO.java

License:Open Source License

/**
 * Find by seller and project//  w  w w  .ja  va  2  s.  c om
 * 
 * @param seller
 * @param project
 * @return
 */
@SuppressWarnings("unchecked")
public List<Activityseller> findBySellerAndProject(Seller seller, Project project) {

    Criteria crit = getSession().createCriteria(getPersistentClass());

    // Filter by seller
    crit.add(Restrictions.eq(Activityseller.SELLER, seller))
            .add(Restrictions.isNotNull(Activityseller.INDIRECT));

    Criteria critProjectActivity = crit.createCriteria(Activityseller.PROJECTACTIVITY);

    // Filter by project
    critProjectActivity.add(Restrictions.eq(Projectactivity.PROJECT, project));

    return crit.list();
}

From source file:es.sm2.openppm.core.dao.ContactDAO.java

License:Open Source License

/**
 * These contact has a resource pool in company
 * @param contact//from  w  ww .j a  va2 s.  c  o  m
 * @return
 */
public boolean hasResourcePool(Contact contact, Resourceprofiles teamMember) {
    Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(Projections.rowCount())
            .add(Restrictions.idEq(contact.getIdContact()));

    crit.createCriteria(Contact.EMPLOYEES).add(Restrictions.eq(Employee.RESOURCEPROFILES, teamMember))
            .add(Restrictions.isNotNull(Employee.RESOURCEPOOL));

    return ((Integer) crit.uniqueResult() > 0);
}

From source file:es.sm2.openppm.core.dao.DocumentprojectDAO.java

License:Open Source License

/**
 * Find documents by type in the project
 * @param project/*from   w  ww  .  j  a  va 2s  .  c  om*/
 * @param type
 * @return
 */
@SuppressWarnings("unchecked")
public List<Documentproject> findListByType(Project project, String type, Boolean isFile) {

    List<Documentproject> list = null;

    // Filter by project
    Criteria crit = getSession().createCriteria(getPersistentClass())
            .add(Restrictions.eq(Documentproject.PROJECT, project));

    if (isFile) {
        crit.add(Restrictions.isNotNull(Documentproject.MIME));
    } else {
        crit.add(Restrictions.isNull(Documentproject.MIME));
    }

    // Filter by type
    if (type != null) {
        crit.add(Restrictions.eq(Documentproject.TYPE, type));
    } else {

        crit.add(Restrictions.disjunction()
                .add(Restrictions.eq(Documentproject.TYPE, Constants.DOCUMENT_INITIATING))
                .add(Restrictions.eq(Documentproject.TYPE, Constants.DOCUMENT_RISK))
                .add(Restrictions.eq(Documentproject.TYPE, Constants.DOCUMENT_PLANNING))
                .add(Restrictions.eq(Documentproject.TYPE, Constants.DOCUMENT_CONTROL))
                .add(Restrictions.eq(Documentproject.TYPE, Constants.DOCUMENT_PROCUREMENT))
                .add(Restrictions.eq(Documentproject.TYPE, Constants.DOCUMENT_CLOSURE))
                .add(Restrictions.eq(Documentproject.TYPE, Constants.DOCUMENT_INVESTMENT)));
    }

    // Order
    crit.addOrder(Order.asc(Documentproject.TYPE));

    list = crit.list();
    return list;
}