Example usage for org.hibernate.criterion Restrictions lt

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

Introduction

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

Prototype

public static SimpleExpression lt(String propertyName, Object value) 

Source Link

Document

Apply a "less than" constraint to the named property

Usage

From source file:com.metropolitan.formulasport727.dao.VestDAOImpl.java

@Override
public List<Vest> getListaPoslednjihObjavljenihVesti() {
    Calendar c = Calendar.getInstance();
    Date trenutnoVreme = c.getTime();
    return session.createCriteria(Vest.class).add(Restrictions.lt("vremeObjave", trenutnoVreme))
            .addOrder(Order.desc("vremeObjave")).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();
}

From source file:com.metropolitan.methotels727.dao.RezervacijaDAOImpl.java

@Override
public boolean aktivnaRezervacijaKorisnika(Korisnik korisnik) {
    Date sad = Calendar.getInstance().getTime();
    return !(session.createCriteria(Rezervacija.class).add(Restrictions.eq("korId", korisnik))
            .add(Restrictions.lt("datumPrijave", sad)).add(Restrictions.gt("datumOdjave", sad)).list()
            .isEmpty());/*from  w  ww . j a  va  2s  .c o  m*/
}

From source file:com.ponysdk.hibernate.query.decorator.AbstractCriteriaDecorator.java

License:Apache License

@SuppressWarnings("rawtypes")
@Override//  www  .j ava 2  s. c  o  m
public void render(final CriteriaContext context) {
    final Criterion field = context.getCriterion();
    Criteria criteria = context.getOrderingCriteria();

    final List<String> propertyNamePath = Arrays.asList(field.getPojoProperty().split(REGEX_SPLIT));
    final Iterator<String> iter = propertyNamePath.iterator();
    String key = null;
    String associationPath = null;
    if (propertyNamePath.size() == 1) {
        associationPath = iter.next();
    } else
        while (iter.hasNext()) {
            key = iter.next();
            if (associationPath == null) {
                associationPath = new String(key);
            } else {
                associationPath += "." + key;
            }
            if (iter.hasNext()) {
                criteria = criteria.createCriteria(associationPath, key, CriteriaSpecification.INNER_JOIN);
                associationPath = new String(key);
            }
        }

    final T value = getObjectValue(field);
    ComparatorType comparator = field.getComparator();

    if (value != null) {
        if (value.toString().contains("%")) {
            comparator = ComparatorType.LIKE;
        }
    }

    if (field.getValue() != null || field.getComparator() == ComparatorType.IS_NULL
            || field.getComparator() == ComparatorType.IS_NOT_NULL) {

        switch (comparator) {
        case EQ:
            criteria.add(Restrictions.eq(associationPath, value));
            break;
        case GE:
            criteria.add(Restrictions.ge(associationPath, value));
            break;
        case GT:
            criteria.add(Restrictions.gt(associationPath, value));
            break;
        case LE:
            criteria.add(Restrictions.le(associationPath, value));
            break;
        case LT:
            criteria.add(Restrictions.lt(associationPath, value));
            break;
        case NE:
            criteria.add(Restrictions.ne(associationPath, value));
            break;
        case LIKE:
            criteria.add(Restrictions.ilike(associationPath, value));
            break;
        case IS_NULL:
            criteria.add(Restrictions.isNull(associationPath));
            break;
        case IS_NOT_NULL:
            criteria.add(Restrictions.isNotNull(associationPath));
            break;
        case IN:
            if (value instanceof Collection) {
                criteria.add(Restrictions.in(associationPath, (Collection) value));
            } else if (value instanceof Object[]) {
                criteria.add(Restrictions.in(associationPath, (Object[]) value));
            } else {
                log.warn("Type not allowed for IN clause: " + value.getClass() + ", value: " + value);
            }
            break;

        default:
            log.warn("Restriction not supported: " + comparator);
            break;
        }
    }

    switch (field.getSortingType()) {
    case ASCENDING:
        criteria.addOrder(Order.asc(associationPath));
        break;
    case DESCENDING:
        criteria.addOrder(Order.desc(associationPath));
        break;
    case NONE:
        break;
    }

}

From source file:com.qcadoo.model.api.search.SearchRestrictions.java

License:Open Source License

/**
 * Creates criterion which checks if field is less than given value.
 * /*from  w  w  w  .j  a v a2 s.c o  m*/
 * @param field
 *            field
 * @param value
 *            value
 * @return criterion
 */
public static SearchCriterion lt(final String field, final Object value) {
    return new SearchCriterionImpl(Restrictions.lt(field, value));
}

From source file:com.reignite.parser.QueryParser.java

License:Open Source License

private Criterion processField(JSONObject where) throws ParserException {
    String field = JSONObject.getNames(where)[0];
    JSONObject exp;/*from  w w  w  .  ja  v  a2s  .c  o  m*/
    try {
        exp = where.getJSONObject(field);
    } catch (JSONException e) {
        throw new ParserException("field expressions must be JSON Object: " + field);
    }
    ExpressionType type = ExpressionType.get(JSONObject.getNames(exp)[0]);
    Object value = null;
    // if the field is a join
    if (field.indexOf(".") > -1) {
        String join = field.substring(0, field.indexOf("."));
        query.createJoin(join);
    }
    switch (type) {
    case IN:
    case NOT_IN:
        try {
            value = createArray(exp.getJSONArray(type.getName()));
        } catch (JSONException e) {
            throw new ParserException("in and not in expressions must be arrays: " + exp);
        }
        break;
    default:
        try {
            value = createValue(exp.get(type.getName()));
        } catch (JSONException e) {
            throw new ParserException("expressions must have a value: " + exp);
        }
    }

    switch (type) {
    case GREATER_THAN:
        return Restrictions.gt(field, value);
    case IN:
        return Restrictions.in(field, (Object[]) value);
    case LESS_THAN:
        return Restrictions.lt(field, value);
    case LIKE:
        MatchMode match = MatchMode.EXACT;
        String toMatch = value.toString();
        if (value.toString().startsWith("%")) {
            match = MatchMode.END;
            toMatch = toMatch.substring(1);
        }
        if (value.toString().endsWith("%")) {
            toMatch = toMatch.substring(0, toMatch.length() - 1);
            if (match == MatchMode.END) {
                match = MatchMode.ANYWHERE;
            } else {
                match = MatchMode.START;
            }
        }
        return Restrictions.ilike(field, toMatch, match);
    case NOT_EQUAL:
        if (value == null) {
            return Restrictions.isNotNull(field);
        }
        return Restrictions.ne(field, value);
    case NOT_IN:
        return Restrictions.not(Restrictions.in(field, (Object[]) value));
    case EQUAL:
    default:
        if (value == null) {
            return Restrictions.isNull(field);
        }
        return Restrictions.eq(field, value);
    }

}

From source file:com.romeikat.datamessie.core.base.dao.impl.DocumentDao.java

License:Open Source License

public List<Document> getForSourceAndDownloaded(final SharedSessionContract ssc, final long sourceId,
        final LocalDate downloaded) {
    final LocalDateTime minDownloaded = LocalDateTime.of(downloaded, LocalTime.MIDNIGHT);
    final LocalDateTime maxDownloaded = LocalDateTime.of(downloaded.plusDays(1), LocalTime.MIDNIGHT);

    // Query: Document
    final EntityWithIdQuery<Document> documentQuery = new EntityWithIdQuery<>(Document.class);
    documentQuery.addRestriction(Restrictions.eq("sourceId", sourceId));
    documentQuery.addRestriction(Restrictions.ge("downloaded", minDownloaded));
    documentQuery.addRestriction(Restrictions.lt("downloaded", maxDownloaded));

    // Done/*  w  w  w .j  av  a2  s  .  c  om*/
    final List<Document> entities = documentQuery.listObjects(ssc);
    return entities;
}

From source file:com.romeikat.datamessie.core.base.query.entity.entities.DocumentQuery.java

License:Open Source License

private void addRestrictions() {
    // Published// w w w .j  a va2s. c o m
    if (dfs.getFromDate() != null) {
        addRestriction(Restrictions.ge("published", LocalDateTime.of(dfs.getFromDate(), LocalTime.MIDNIGHT)));
    }
    if (dfs.getToDate() != null) {
        addRestriction(Restrictions.lt("published",
                LocalDateTime.of(dfs.getToDate(), LocalTime.MIDNIGHT).plusDays(1)));
    }

    // States
    if (!CollectionUtils.isEmpty(dfs.getStates())) {
        addRestriction(Restrictions.in("state", dfs.getStates()));
    }

    // Document IDs from DFS
    final Collection<Long> documentIds = dfs.getDocumentIds();
    final boolean documentIdsApply = documentIds != null;
    if (documentIdsApply) {
        addIdRestriction(documentIds);
    }

    // Additional document IDs
    for (final Collection<Long> idRestriction : idRestrictions) {
        addIdRestriction(idRestriction);
    }
}

From source file:com.romeikat.datamessie.core.processing.dao.DocumentDao.java

License:Open Source License

public List<Document> getToProcess(final SharedSessionContract ssc, final LocalDate downloaded,
        final int maxResults) {
    final LocalDateTime minDownloaded = LocalDateTime.of(downloaded, LocalTime.MIDNIGHT);
    final LocalDateTime maxDownloaded = LocalDateTime.of(downloaded.plusDays(1), LocalTime.MIDNIGHT);

    // Query: Project
    final EntityWithIdQuery<Project> projectQuery = new EntityWithIdQuery<>(Project.class);
    projectQuery.addRestriction(Restrictions.eq("preprocessingEnabled", true));
    final Collection<Long> projectIds = projectQuery.listIds(ssc);
    if (projectIds.isEmpty()) {
        return Collections.emptyList();
    }/* ww w  .  j a va2  s  .  c  om*/
    // Query: Project2Source
    final Project2SourceQuery project2SourceQuery = new Project2SourceQuery();
    project2SourceQuery.addRestriction(Restrictions.in("projectId", projectIds));
    final Collection<Long> sourceIds = project2SourceQuery.listIdsForProperty(ssc, "sourceId");
    if (sourceIds.isEmpty()) {
        return Collections.emptyList();
    }

    // Query: Document
    final EntityWithIdQuery<Document> documentQuery = new EntityWithIdQuery<>(Document.class);
    documentQuery.addRestriction(Restrictions.in("sourceId", sourceIds));
    documentQuery.addRestriction(Restrictions.ge("downloaded", minDownloaded));
    documentQuery.addRestriction(Restrictions.lt("downloaded", maxDownloaded));
    final Object[] statesForProcessing = new DocumentProcessingState[] { DocumentProcessingState.DOWNLOADED,
            DocumentProcessingState.REDIRECTED, DocumentProcessingState.CLEANED };
    documentQuery.addRestriction(Restrictions.in("state", statesForProcessing));
    documentQuery.setMaxResults(maxResults);

    // Done
    final List<Document> entities = documentQuery.listObjects(ssc);
    return entities;
}

From source file:com.romeikat.datamessie.core.statistics.dao.DocumentDao.java

License:Open Source License

public List<DocumentStatisticsDto> getAsDocumentStatisticsDtos(final SharedSessionContract ssc,
        final Long sourceId, final LocalDate published) {
    final LocalDateTime minPublished = published == null ? null
            : LocalDateTime.of(published, LocalTime.MIDNIGHT);
    final LocalDateTime maxPublished = published == null ? null
            : LocalDateTime.of(published.plusDays(1), LocalTime.MIDNIGHT);

    // Query: Document
    final EntityWithIdQuery<Document> documentQuery = new EntityWithIdQuery<>(Document.class);
    if (sourceId != null) {
        documentQuery.addRestriction(Restrictions.eq("sourceId", sourceId));
    }//from   www.  j a v  a2s .com
    if (minPublished != null) {
        documentQuery.addRestriction(Restrictions.ge("published", minPublished));
    }
    if (maxPublished != null) {
        documentQuery.addRestriction(Restrictions.lt("published", maxPublished));
    }
    documentQuery.setResultTransformer(new AliasToBeanResultTransformer(DocumentStatisticsDto.class));

    // Done
    final ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("id"), "documentId");
    projectionList.add(Projections.property("sourceId"), "sourceId");
    projectionList.add(Projections.property("published"), "published");
    projectionList.add(Projections.property("state"), "state");
    @SuppressWarnings("unchecked")
    final List<DocumentStatisticsDto> dtos = (List<DocumentStatisticsDto>) documentQuery.listForProjection(ssc,
            projectionList);
    return dtos;
}

From source file:com.sapienter.jbilling.server.invoice.db.InvoiceDAS.java

License:Open Source License

private void addPeriodCriteria(Criteria criteria, Date start, Date end) {
    criteria.add(Restrictions.ge("createDatetime", start)).add(Restrictions.lt("createDatetime", end));
}