Example usage for org.hibernate.criterion Restrictions isEmpty

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

Introduction

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

Prototype

public static Criterion isEmpty(String propertyName) 

Source Link

Document

Constrain a collection valued property to be empty

Usage

From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateScanDao.java

License:Mozilla Public License

@Override
public long getNumberWithoutGenericMappings(Integer scanId) {
    return (Long) sessionFactory.getCurrentSession().createCriteria(Finding.class)
            .createAlias("channelVulnerability", "vuln").add(Restrictions.isEmpty("vuln.vulnerabilityMaps"))
            .add(eq("scan.id", scanId)).setProjection(rowCount()).uniqueResult();
}

From source file:com.eharmony.matching.seeking.translator.hibernate.HibernateQueryTranslator.java

License:Apache License

@Override
public Criterion isEmpty(String fieldName) {
    return Restrictions.isEmpty(fieldName);
}

From source file:com.eucalyptus.simpleworkflow.persist.PersistenceDomains.java

License:Open Source License

public <T> List<T> listDeprecatedExpired(final long time, final Function<? super Domain, T> transform)
        throws SwfMetadataException {
    return listByExample(Domain.exampleWithStatus(Domain.Status.Deprecated), Predicates.alwaysTrue(),
            Restrictions.conjunction().add(Restrictions.isEmpty("workflowTypes"))
                    .add(Restrictions.lt("lastUpdateTimestamp",
                            new Date(time - getDeprecatedDomainRetentionDurationMillis()))),
            Collections.<String, String>emptyMap(), transform);
}

From source file:com.eucalyptus.simpleworkflow.persist.PersistenceWorkflowTypes.java

License:Open Source License

public <T> List<T> listDeprecatedExpired(final long time, final Function<? super WorkflowType, T> transform)
        throws SwfMetadataException {
    return listByExample(WorkflowType.exampleWithOwner(null), Predicates.alwaysTrue(),
            Restrictions.conjunction().add(Restrictions.isEmpty("executions"))
                    .add(Restrictions.lt("deprecationTimestamp",
                            new Date(time - getDeprecatedWorkflowTypeRetentionDurationMillis()))),
            Collections.<String, String>emptyMap(), transform);
}

From source file:com.floreantpos.model.dao.MenuGroupDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public boolean hasChildren(Terminal terminal, MenuGroup group, OrderType orderType) throws PosException {
    Session session = null;/*w  w  w  .j  a  va  2 s .  c o  m*/

    try {
        session = getSession();
        Criteria criteria = session.createCriteria(MenuItem.class);
        criteria.add(Restrictions.eq(MenuItem.PROP_PARENT, group));
        criteria.add(Restrictions.eq(MenuItem.PROP_VISIBLE, Boolean.TRUE));

        //         if(terminal!=null) {
        //            criteria.add(Restrictions.eq(MenuItem., criteria))
        //         }
        criteria.setProjection(Projections.rowCount());

        criteria.createAlias("orderTypeList", "type", CriteriaSpecification.LEFT_JOIN);
        criteria.add(Restrictions.or(Restrictions.isEmpty("orderTypeList"),
                Restrictions.eq("type.id", orderType.getId())));

        int uniqueResult = (Integer) criteria.uniqueResult();

        return uniqueResult > 0;
    } catch (Exception e) {
        e.printStackTrace();
        throw new PosException(Messages.getString("MenuItemDAO.0")); //$NON-NLS-1$
    } finally {
        if (session != null) {
            session.close();
        }
    }
}

From source file:com.floreantpos.model.dao.MenuItemDAO.java

License:Open Source License

public List<MenuItem> findByParent(Terminal terminal, MenuGroup menuGroup, Object selectedOrderType,
        boolean includeInvisibleItems) {
    Session session = null;/*from  www.ja  va  2  s.  c  o m*/
    Criteria criteria = null;
    try {
        session = getSession();
        criteria = session.createCriteria(MenuItem.class);

        if (menuGroup != null) {
            criteria.add(Restrictions.eq(MenuItem.PROP_PARENT, menuGroup));
        }
        criteria.addOrder(Order.asc(MenuItem.PROP_SORT_ORDER));

        if (!includeInvisibleItems) {
            criteria.add(Restrictions.eq(MenuItem.PROP_VISIBLE, Boolean.TRUE));
        }

        if (selectedOrderType instanceof OrderType) {
            OrderType orderType = (OrderType) selectedOrderType;
            criteria.createAlias("orderTypeList", "type", CriteriaSpecification.LEFT_JOIN);
            criteria.add(Restrictions.or(Restrictions.isEmpty("orderTypeList"),
                    Restrictions.eq("type.id", orderType.getId())));
        }
        return criteria.list();

    } catch (Exception e) {
    }
    return criteria.list();
}

From source file:com.floreantpos.model.dao.MenuItemDAO.java

License:Open Source License

public List<MenuItem> getMenuItems(String itemName, Object menuGroup, Object selectedType) {
    Session session = null;/*from w  ww. ja  va  2  s .c  o  m*/
    Criteria criteria = null;
    try {
        session = getSession();
        criteria = session.createCriteria(MenuItem.class);

        if (menuGroup != null && menuGroup instanceof MenuGroup) {
            criteria.add(Restrictions.eq(MenuItem.PROP_PARENT, (MenuGroup) menuGroup));
        } else if (menuGroup != null && menuGroup instanceof String) {
            criteria.add(Restrictions.isNull(MenuItem.PROP_PARENT));
        }
        if (StringUtils.isNotEmpty(itemName)) {
            criteria.add(Restrictions.ilike(MenuItem.PROP_NAME, itemName.trim(), MatchMode.ANYWHERE));
        }

        //List<MenuItem> similarItems = criteria.list();

        if (selectedType != null && selectedType instanceof OrderType) {
            OrderType orderType = (OrderType) selectedType;

            criteria.createAlias("orderTypeList", "type");
            criteria.add(Restrictions.eq("type.id", orderType.getId()));

            /*List<MenuItem> selectedMenuItems = new ArrayList();
                    
            List<MenuItem> items = findAll();
                    
            for (MenuItem item : items) {
                    
               List<OrderType> types = item.getOrderTypeList();
               OrderType type = (OrderType) selectedType;
                    
               if (types.contains(type.getName()) || types.isEmpty()) {
                  selectedMenuItems.add(item);
               }
            }
            similarItems.retainAll(selectedMenuItems);*/
        } else if (selectedType != null && selectedType instanceof String) {
            criteria.add(Restrictions.isEmpty("orderTypeList"));
        }
        return criteria.list();

    } catch (Exception e) {
    }
    return criteria.list();
}

From source file:com.floreantpos.model.dao.TicketDAO.java

License:Open Source License

public List<Ticket> findOpenTicketsByOrderType(OrderType orderType) {
    Session session = null;/*w  w  w.jav  a  2  s .c o m*/

    try {
        session = getSession();
        Criteria criteria = session.createCriteria(getReferenceClass());
        User user = Application.getCurrentUser();
        if (user != null && !user.canViewAllOpenTickets()) {
            criteria.add(Restrictions.eq(Ticket.PROP_OWNER, user));
        }
        criteria.add(Restrictions.eq(Ticket.PROP_TICKET_TYPE, orderType.getName()));
        criteria.add(Restrictions.eq(Ticket.PROP_BAR_TAB, true));
        criteria.add(
                Restrictions.or(Restrictions.isEmpty("tableNumbers"), Restrictions.isNull("tableNumbers")));
        criteria.add(Restrictions.eq(Ticket.PROP_CLOSED, Boolean.FALSE));
        criteria.addOrder(getDefaultOrder());

        List list = criteria.list();
        return list;
    } finally {
        closeSession(session);
    }
}

From source file:com.heliosapm.aa4h.parser.XMLQueryParser.java

License:Apache License

/**
 * Element Start SAX ContentHandler Method.
 * @param uri/*from   w w  w . j a  v  a  2 s.  c  o  m*/
 * @param localName
 * @param qName
 * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
 * @throws SAXException
 * TODO: Document supported tags in javadoc.
 */
@SuppressWarnings({ "unchecked" })
public void startElement(String uri, String localNameX, String qName, Attributes attrs) throws SAXException {
    if ("Query".equalsIgnoreCase(qName)) {
        queryName = attrs.getValue("name");
        rootElementName = queryName;
    } else if ("Class".equalsIgnoreCase(qName)) {
        processCriteria(attrs);
    } else if ("Union".equalsIgnoreCase(qName)) {
        inDetached = true;
        DetachedCriteria dc = DetachedCriteria.forEntityName(className);
        criteriaStack.push(dc);
    } else if ("NamedQuery".equalsIgnoreCase(qName)) {
        isNamedQuery = true;
        namedQuery = attrs.getValue("name");
        rootElementName = namedQuery;
        try {
            query = session.getNamedQuery(namedQuery);
        } catch (HibernateException he) {
            throw new SAXException("Failed to retrieve named query[" + namedQuery + "]", he);
        }
    } else if ("qparam".equalsIgnoreCase(qName)) {
        processQueryBind(attrs);
    } else if ("Join".equalsIgnoreCase(qName)) {
        processCriteria(attrs);
    } else if ("Projections".equalsIgnoreCase(qName)) {
        startProjection(attrs);
    } else if ("Projection".equalsIgnoreCase(qName)) {
        addProjection(attrs);
    } else if ("Order".equalsIgnoreCase(qName)) {
        if (isRowCountOnly() == false) {
            try {
                String name = attrs.getValue("name");
                String type = attrs.getValue("type");
                ((Criteria) criteriaStack.peek())
                        .addOrder(type.equalsIgnoreCase("asc") ? Order.asc(name) : Order.desc(name));
            } catch (Exception e) {
                throw new SAXException("Unable To Parse GreaterThan:" + attrs.getValue("name"), e);
            }
        }
    } else if ("GreaterThan".equalsIgnoreCase(qName)) {
        try {
            Operator operator = new Operator(attrs);
            addCriterion(Restrictions.gt(operator.getName(), operator.getNativeValue()));
        } catch (Exception e) {
            throw new SAXException("Unable To Parse GreaterThan:" + attrs.getValue("name"), e);
        }
    } else if ("GreaterThanOrEqual".equalsIgnoreCase(qName)) {
        try {
            Operator operator = new Operator(attrs);
            addCriterion(Restrictions.ge(operator.getName(), operator.getNativeValue()));
        } catch (Exception e) {
            throw new SAXException("Unable To Parse GreaterThanOrEqual:" + attrs.getValue("name"), e);
        }
    } else if ("LessThan".equalsIgnoreCase(qName)) {
        try {
            Operator operator = new Operator(attrs);
            addCriterion(Restrictions.lt(operator.getName(), operator.getNativeValue()));
        } catch (Exception e) {
            throw new SAXException("Unable To Parse LessThan:" + attrs.getValue("name"), e);
        }
    } else if ("LessThanOrEqual".equalsIgnoreCase(qName)) {
        try {
            Operator operator = new Operator(attrs);
            addCriterion(Restrictions.le(operator.getName(), operator.getNativeValue()));
        } catch (Exception e) {
            throw new SAXException("Unable To Parse LessThanOrEqual:" + attrs.getValue("name"), e);
        }
    } else if ("Equals".equalsIgnoreCase(qName)) {
        try {
            Operator operator = new Operator(attrs);
            if ("true".equalsIgnoreCase(attrs.getValue("not"))) {
                addCriterion(Restrictions.not(Restrictions.eq(operator.getName(), operator.getNativeValue())));
            } else {
                addCriterion(Restrictions.eq(operator.getName(), operator.getNativeValue()));
            }

        } catch (Exception e) {
            throw new SAXException("Unable To Parse Equals:" + attrs.getValue("name"), e);
        }
    } else if ("Alias".equalsIgnoreCase(qName)) {
        try {
            Operator operator = new Operator(attrs);
            ((Criteria) criteriaStack.peek()).createAlias(operator.getName(), operator.getValue());
        } catch (Exception e) {
            throw new SAXException("Unable To Create Alias:" + attrs.getValue("name"), e);
        }
    } else if ("GreaterThanProperty".equalsIgnoreCase(qName)) {
        try {
            Operator operator = new Operator(attrs);
            addCriterion(Restrictions.gtProperty(operator.getName(), operator.getName2()));
        } catch (Exception e) {
            throw new SAXException("Unable To Parse GreaterThanProperty:" + attrs.getValue("name"), e);
        }
    } else if ("GreaterThanOrEqualProperty".equalsIgnoreCase(qName)) {
        try {
            Operator operator = new Operator(attrs);
            addCriterion(Restrictions.geProperty(operator.getName(), operator.getName2()));
        } catch (Exception e) {
            throw new SAXException("Unable To Parse GreaterThanOrEqualProperty:" + attrs.getValue("name"), e);
        }
    } else if ("LessThanProperty".equalsIgnoreCase(qName)) {
        try {
            Operator operator = new Operator(attrs);
            addCriterion(Restrictions.ltProperty(operator.getName(), operator.getName2()));
        } catch (Exception e) {
            throw new SAXException("Unable To Parse LessThanProperty:" + attrs.getValue("name"), e);
        }
    } else if ("LessThanOrEqualProperty".equalsIgnoreCase(qName)) {
        try {
            Operator operator = new Operator(attrs);
            addCriterion(Restrictions.leProperty(operator.getName(), operator.getName2()));
        } catch (Exception e) {
            throw new SAXException("Unable To Parse LessThanOrEqualProperty:" + attrs.getValue("name"), e);
        }
    } else if ("EqualsProperty".equalsIgnoreCase(qName)) {
        try {
            Operator operator = new Operator(attrs);
            if ("true".equalsIgnoreCase(attrs.getValue("not"))) {
                addCriterion(
                        Restrictions.not(Restrictions.eqProperty(operator.getName(), operator.getName2())));
            } else {
                addCriterion(Restrictions.eqProperty(operator.getName(), operator.getName2()));
            }
        } catch (Exception e) {
            throw new SAXException("Unable To Parse EqualsProperty:" + attrs.getValue("name"), e);
        }
    } else if ("Like".equalsIgnoreCase(qName)) {
        try {
            Operator operator = new Operator(attrs);
            addCriterion(Restrictions.like(operator.getName(), operator.getNativeValue()));
        } catch (Exception e) {
            throw new SAXException("Unable To Parse Like:" + attrs.getValue("name"), e);
        }
    } else if ("Between".equalsIgnoreCase(qName)) {
        try {
            Operator operator = new Operator(attrs);
            addCriterion(Restrictions.between(operator.getName(), operator.getNativeValue(),
                    operator.getNativeValue2()));
        } catch (Exception e) {
            throw new SAXException("Unable To Parse Between:" + attrs.getValue("name"), e);
        }
    } else if ("IsEmpty".equalsIgnoreCase(qName)) {
        try {
            Operator operator = new Operator(attrs);
            addCriterion(Restrictions.isEmpty(operator.getName()));
        } catch (Exception e) {
            throw new SAXException("Unable To Parse IsEmpty:" + attrs.getValue("name"), e);
        }
    } else if ("IsNotEmpty".equalsIgnoreCase(qName)) {
        try {
            Operator operator = new Operator(attrs);
            addCriterion(Restrictions.isNotEmpty(operator.getName()));
        } catch (Exception e) {
            throw new SAXException("Unable To Parse IsNotEmpty:" + attrs.getValue("name"), e);
        }
    } else if ("IsNull".equalsIgnoreCase(qName)) {
        try {
            Operator operator = new Operator(attrs);
            addCriterion(Restrictions.isNull(operator.getName()));
        } catch (Exception e) {
            throw new SAXException("Unable To Parse IsNull:" + attrs.getValue("name"), e);
        }
    } else if ("IsNotNull".equalsIgnoreCase(qName)) {
        try {
            Operator operator = new Operator(attrs);
            addCriterion(Restrictions.isNotNull(operator.getName()));
        } catch (Exception e) {
            throw new SAXException("Unable To Parse IsNotNull:" + attrs.getValue("name"), e);
        }
    } else if ("In".equalsIgnoreCase(qName)) {
        try {
            Operator operator = new Operator(attrs);
            if (operator.isLiteral()) {
                addCriterion(new LiteralInExpression(operator.getName(), (String) operator.getNativeValue()));
            } else {
                addCriterion(Restrictions.in(operator.getName(), (Collection) operator.getNativeValue()));
            }
        } catch (Exception e) {
            throw new SAXException("Unable To Parse In:" + attrs.getValue("name"), e);
        }
    } else if ("SizeEquals".equalsIgnoreCase(qName)) {
        try {
            Operator operator = new Operator(attrs);
            int i = ((Integer) operator.getNativeValue()).intValue();
            addCriterion(Restrictions.sizeEq(operator.getName(), i));
        } catch (Exception e) {
            throw new SAXException("Unable To Parse SizeEquals:" + attrs.getValue("name"), e);
        }
    } else if ("Not".equalsIgnoreCase(qName)) {
        notStack.push(new Object());
    } else if ("Or".equalsIgnoreCase(qName)) {
        opStack.push(Restrictions.disjunction());
    } else if ("And".equalsIgnoreCase(qName)) {
        opStack.push(Restrictions.conjunction());
    } else {
        throw new SAXException("Element Name[" + qName + "] Not Recognized.");
    }
}

From source file:com.hmsinc.epicenter.model.surveillance.impl.SurveillanceRepositoryImpl.java

License:Open Source License

/**
 * @param c/*from  ww w. ja v a  2 s  .c  o  m*/
 * @param startDate
 * @param endDate
 * @param includeAll
 * @param includeFacilityLocation
 * @param filter
 * @return
 */
private Criteria applyAnomalyCriteria(final Criteria c, final DateTime startDate, final DateTime endDate,
        final boolean includeAll, final Geometry filter, final Geometry excludeFacilityEventsFilter) {

    if (startDate == null && endDate != null) {
        c.add(Restrictions.lt("analysisTimestamp", endDate));
    } else if (startDate != null && endDate == null) {
        c.add(Restrictions.gt("analysisTimestamp", startDate));
    } else if (startDate != null && endDate != null) {
        c.add(Restrictions.between("analysisTimestamp", startDate, endDate));
    }

    if (!includeAll) {
        c.add(Restrictions.isEmpty("investigations")).createCriteria("disposition")
                .add(Restrictions.eq("type", WorkflowStateType.INITIAL));
    }

    if (filter != null && excludeFacilityEventsFilter == null) {

        c.createCriteria("geography").add(SpatialRestrictions.withinOrFilter("geometry", filter, 1000, true));

    } else if (filter == null && excludeFacilityEventsFilter != null) {

        final Conjunction conjunction = Restrictions.conjunction();
        c.createAlias("geography", "eventGeography");
        c.createAlias("task", "eventTask");

        conjunction.add(Restrictions.eq("eventTask.location", AnalysisLocation.FACILITY));
        conjunction.add(SpatialRestrictions.withinOrFilter("eventGeography.geometry",
                excludeFacilityEventsFilter, 1000, true));

        c.add(Restrictions.not(conjunction));

    } else if (filter != null && excludeFacilityEventsFilter != null) {

        final Conjunction conjunction = Restrictions.conjunction();
        c.createAlias("geography", "eventGeography");
        c.createAlias("task", "eventTask");

        // Find events where we have unlimited access
        conjunction.add(SpatialRestrictions.withinOrFilter("eventGeography.geometry", filter, 1000, true));

        // Filter events in the limited region
        final Conjunction facilityEventsConjunction = Restrictions.conjunction();
        facilityEventsConjunction.add(Restrictions.eq("eventTask.location", AnalysisLocation.FACILITY));
        facilityEventsConjunction.add(SpatialRestrictions.withinOrFilter("eventGeography.geometry",
                excludeFacilityEventsFilter, 1000, true));

        conjunction.add(Restrictions.not(facilityEventsConjunction));

        c.add(conjunction);
    }

    return c;
}