Example usage for org.hibernate.criterion Restrictions gt

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

Introduction

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

Prototype

public static SimpleExpression gt(String propertyName, Object value) 

Source Link

Document

Apply a "greater than" constraint to the named property

Usage

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.JobAttributeReportHelper.java

License:Apache License

private void initDate() {
    totalCells = new TreeMap<Integer, List<Integer>>();

    Session session = HibernateUtil.getSession();
    Criteria c = session.createCriteria(JobImpl.class);
    c.add(Restrictions.in("createUserId", submitIds));
    c.add(Restrictions.in("state", status));

    if (startDate != null) {
        c.add(Restrictions.gt("createDate", startDate));
    }//from   w  w  w  .  jav  a  2  s .  c  o  m

    if (endDate != null) {
        c.add(Restrictions.le("createDate", endDate));
    }

    jobAttributes = c.list();

    for (int i = jobAttributes.size() - 1; i >= 0; i--) {
        JobImpl job = jobAttributes.get(i);
        long projectId = job.getL10nProfile().getProject().getId();
        if (projectIds.indexOf(projectId) < 0) {
            jobAttributes.remove(i);
            continue;
        }

        boolean found = false;
        for (Workflow w : job.getWorkflows()) {
            String targetLang = Long.toString(w.getTargetLocale().getId());
            if (trgLocaleList.contains(targetLang)) {
                found = true;
                break;
            }
        }
        if (!found) {
            jobAttributes.remove(i);
            continue;
        }
    }

    SortUtil.sort(jobAttributes, getComparator());
}

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

License:Apache License

/**
 * Element Start SAX ContentHandler Method.
 * @param uri/*from  w ww. jav  a 2s . 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.hm.modelo.DAOUsu.java

public String obtenerPorNOmbre(String nombre) throws Exception {
    SessionFactory factory = HIbernate.getSessionFactory();
    Session sesion = factory.openSession();
    Transaction tranza = sesion.beginTransaction();

    Criteria cri = sesion.createCriteria(Usu.class).add(Restrictions.like("nombre", nombre + "%"));
    Criteria cri2 = sesion.createCriteria(Usu.class).add(Restrictions.eq("nombre", nombre));
    Criteria cri3 = sesion.createCriteria(Usu.class).add(Restrictions.between("edad", 18, 40))
            .addOrder(Order.asc("nombre"));
    Criteria cri4 = sesion.createCriteria(Usu.class).add(Restrictions.lt("sueldo", new Integer(4000)));
    Criteria cri5 = sesion.createCriteria(Usu.class).add(Restrictions.gt("sueldo", new Integer(4000)));

    ArrayList<Usu> usuarios = (ArrayList<Usu>) cri.list();

    ObjectMapper mapper = new ObjectMapper();

    Map<String, ArrayList<Usu>> singletonMap = Collections.singletonMap("usuarios", usuarios);

    tranza.commit();/*  ww w.ja  va 2s  .com*/
    sesion.close();

    return mapper.writeValueAsString(singletonMap);
}

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

License:Open Source License

/**
 * @param c/*from  w ww  .j  a va  2  s  .  co  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;
}

From source file:com.hmsinc.epicenter.model.workflow.impl.WorkflowRepositoryImpl.java

License:Open Source License

/**
 * Basic filter for investigations.//from w  w  w  .ja  v  a 2s. co m
 * 
 * @param c
 * @param startDate
 * @param endDate
 * @param geometry
 * @param organizations
 * @param showAll
 * @return
 */
private Criteria applyInvestigationCriteria(final Criteria c, DateTime startDate, DateTime endDate,
        Geometry geometry, Collection<Organization> organizations, boolean showAll) {

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

    if (organizations != null && organizations.size() > 0) {
        c.add(Restrictions.in("organization", organizations));
    }

    if (geometry != null) {
        c.add(Subqueries.exists(getInvestigationGeometryFilter(geometry)));
    }

    if (showAll == false) {
        c.createCriteria("state").add(Restrictions.ne("stateType", WorkflowStateType.TERMINAL));
    }

    return c;
}

From source file:com.hmsinc.epicenter.tools.reclassifier.Reclassifier.java

License:Open Source License

@Transactional
public void run() {

    setup();//  ww w  .java  2 s .co m

    final String destinationTable = (arguments.length > 4) ? arguments[4] : DEFAULT_TABLE_NAME;
    final String query = new StringBuilder("INSERT INTO ").append(destinationTable)
            .append(INSERT_CLASSIFICATION).toString();

    final BatchSqlUpdate updater = new BatchSqlUpdate(modelDataSource, query);
    updater.declareParameter(new SqlParameter(Types.BIGINT));
    updater.declareParameter(new SqlParameter(Types.BIGINT));
    updater.setBatchSize(BATCH_SIZE);
    updater.compile();

    final StatelessSession ss = ((Session) entityManager.getDelegate()).getSessionFactory()
            .openStatelessSession();

    final Criteria c = ss.createCriteria(target.getInteractionClass())
            .add(Restrictions.eq("patientClass", target.getPatientClass())).addOrder(Order.asc("id"))
            .setCacheable(false);

    if (arguments.length > 2) {
        c.add(Restrictions.gt("id", Long.valueOf(arguments[2])));
    }

    if (arguments.length > 3) {
        c.add(Restrictions.lt("id", Long.valueOf(arguments[3])));
    }

    final ScrollableResults sr = c.scroll(ScrollMode.FORWARD_ONLY);
    int i = 0;
    while (sr.next()) {

        final Interaction interaction = (Interaction) sr.get(0);
        final Set<Classification> classifications = classificationService.classify(interaction, target);

        save(interaction, classifications, updater);

        i++;
        if (i % BATCH_SIZE == 0) {
            logger.info("Processed {} interactions (current id: {})", i, interaction.getId());
        }

        ((Session) entityManager.getDelegate()).evict(interaction);
    }

    sr.close();

    updater.flush();
}

From source file:com.hyzy.core.orm.hibernate.HibernateDao.java

License:Apache License

/**
 * ??Criterion,.//from  w w w . j av  a  2s  .c om
 */
protected Criterion buildCriterion(final String propertyName, final Object propertyValue,
        final MatchType matchType) {
    Assert.hasText(propertyName, "propertyName?");
    Criterion criterion = null;
    //?MatchTypecriterion
    switch (matchType) {
    case EQ:
        criterion = Restrictions.eq(propertyName, propertyValue);
        break;
    case LIKE:
        criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE);
        break;
    case LIKEEXACT:
        criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.EXACT);
        break;
    case LIKESTART:
        criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.START);
        break;
    case LIKEEND:
        criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.END);
        break;
    case LE:
        criterion = Restrictions.le(propertyName, propertyValue);
        break;
    case LT:
        criterion = Restrictions.lt(propertyName, propertyValue);
        break;
    case GE:
        criterion = Restrictions.ge(propertyName, propertyValue);
        break;
    case GT:
        criterion = Restrictions.gt(propertyName, propertyValue);
        break;
    case NEQ:
        criterion = Restrictions.ne(propertyName, propertyValue);
        break;
    case ISN:
        criterion = Restrictions.isNull(propertyName);
        break;
    case ISNN:
        criterion = Restrictions.isNotNull(propertyName);
        break;
    case IN:
        criterion = Restrictions.in(propertyName, (Object[]) propertyValue);
        break;

    }
    return criterion;
}

From source file:com.ihsolution.hqipo.dao.utils.QueryHelper.java

License:Open Source License

/**
 * Main conversion method//from   www . j a v a 2  s .  co m
 * @param fieldName
 * @param fieldVal
 * @param oper (=, equal, IN ...)
 * @param j (AND OR)
 * @return
 */
public QueryHelper addFieldAndVal(String fieldName, Object fieldVal, String oper, Junction j) {

    boolean isValString = fieldVal instanceof String;
    String str = "";
    if (oper == null || "".equals(oper)) {
        oper = "equal";
    }

    if (isValString)
        str = ((String) fieldVal).trim();
    if ("equal".equals(oper)) {
        if (isValString) {
            j.add(Restrictions.eq(fieldName, str).ignoreCase());
        } else
            j.add(Restrictions.eq(fieldName, fieldVal));
    } else if ("notEqual".equals(oper)) {
        if (isValString) {
            j.add(Restrictions.ne(fieldName, str).ignoreCase());
        } else
            j.add(Restrictions.ne(fieldName, fieldVal));
    } else if ("null".equals(oper)) {
        j.add(Restrictions.isNull(fieldName));
    } else if ("notNull".equals(oper)) {
        j.add(Restrictions.isNotNull(fieldName));
    } else if ("notExists".equals(oper)) {
        j.add(Restrictions.sqlRestriction(fieldVal.toString()));
    } else if ("Exists".equals(oper)) {
        j.add(Restrictions.sqlRestriction(fieldVal.toString()));
    } else if (isValString) {
        MatchMode mm = getMatchMode(oper);
        if (mm != null)
            j.add(Restrictions.ilike(fieldName, str, mm));
    } else if ("le".equals(oper))
        j.add(Restrictions.le(fieldName, fieldVal));

    else if ("ge".equals(oper))
        j.add(Restrictions.ge(fieldName, fieldVal));
    else if ("gtProperty".equals(oper)) {
        String[] spl = ((String) fieldVal).split(";");
        if (spl.length == 2)
            j.add(Restrictions.gtProperty(spl[0], spl[1]));
        else
            j.add(Restrictions.gt(fieldName, fieldVal));
    } else if ("in".equals(oper)) {
        if (fieldVal instanceof Collection)
            j.add(Restrictions.in(fieldName, (Collection) fieldVal));
        else if (fieldVal instanceof Object[])
            j.add(Restrictions.in(fieldName, (Object[]) fieldVal));
        else
            throw new IllegalArgumentException(
                    "QueryHelper.IN illegal argument type. Should be Collection or Object[]");
    } else if ("notIn".equals(oper)) {
        if (fieldVal instanceof Collection)
            j.add(Restrictions.not(Restrictions.in(fieldName, (Collection) fieldVal)));
        else if (fieldVal instanceof Object[])
            j.add(Restrictions.not(Restrictions.in(fieldName, (Object[]) fieldVal)));
        else
            throw new IllegalArgumentException(
                    "QueryHelper.NOTIN illegal argument type. Should be Collection or Object[]");

    } else if ("between".equals(oper)) {
        Collection objs = (Collection) fieldVal;
        Iterator it2 = objs.iterator();
        Object obj1 = it2.next();
        Object obj2 = it2.next();

        j.add(Restrictions.between(fieldName, obj1 instanceof String ? obj1.toString().toLowerCase() : obj1,
                obj2 instanceof String ? obj2.toString().toLowerCase() : obj2));
    } else
        j.add(Restrictions.eq(fieldName, fieldVal));

    return this;
}

From source file:com.inkubator.hrm.dao.impl.ApprovalDefinitionDaoImpl.java

@Override
public List<ApprovalDefinition> getAllDataByNameAndProcessTypeAndSequenceGreater(String name,
        String processType, int sequence) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.add(Restrictions.eq("name", name));
    criteria.add(Restrictions.eq("processType", processType));
    criteria.add(Restrictions.gt("sequence", sequence));
    criteria.addOrder(Order.asc("sequence"));
    return criteria.list();
}

From source file:com.inkubator.hrm.dao.impl.ApprovalDefinitionDaoImpl.java

@Override
public List<ApprovalDefinition> getAllDataByNameAndProcessTypeAndSpecificNameAndSequenceGreater(String name,
        String processType, String specificName, int sequence) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.add(Restrictions.eq("name", name));
    criteria.add(Restrictions.eq("processType", processType));
    criteria.add(Restrictions.eq("specificName", specificName));
    criteria.add(Restrictions.eq("isNoLongerInUse", false));
    criteria.add(Restrictions.gt("sequence", sequence));
    criteria.addOrder(Order.asc("sequence"));
    return criteria.list();
}