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:org.candlepin.model.CuratorPaginationTest.java

License:Open Source License

@Test
public void testPagingWithCriteria() {
    PageRequest pageRequest = new PageRequest();
    pageRequest.setSortBy("key");
    pageRequest.setOrder(PageRequest.Order.ASCENDING);
    pageRequest.setPage(1);//from w w w . j ava 2  s. c o m
    pageRequest.setPerPage(2);

    Criteria criteria = session.createCriteria(Owner.class).add(Restrictions.gt("key", "5"));

    Page<List<Owner>> p = ownerCurator.listByCriteria(criteria, pageRequest);
    assertEquals(Integer.valueOf(4), p.getMaxRecords());

    List<Owner> ownerList = p.getPageData();
    assertEquals(2, ownerList.size());
    assertEquals("6", ownerList.get(0).getKey());

    PageRequest pageRequest2 = p.getPageRequest();
    assertEquals(pageRequest, pageRequest2);
}

From source file:org.candlepin.model.CuratorPaginationTest.java

License:Open Source License

@Test
public void testNoPagingWithCriteria() {
    Criteria criteria = session.createCriteria(Owner.class).add(Restrictions.gt("key", "5"));

    Page<List<Owner>> p = ownerCurator.listByCriteria(criteria, null);
    List<Owner> ownerList = p.getPageData();
    assertEquals(4, ownerList.size());//w  w w  .  j  av a2 s.  c om
}

From source file:org.candlepin.model.CuratorPaginationTest.java

License:Open Source License

@Test
public void testReturnsAllResultsWhenPostFilteringByCriteria() {
    PageRequest pageRequest = new PageRequest();
    pageRequest.setSortBy("key");
    pageRequest.setOrder(PageRequest.Order.ASCENDING);
    pageRequest.setPage(1);/*from  w ww.  j  a va 2 s .  com*/
    pageRequest.setPerPage(2);

    Criteria criteria = session.createCriteria(Owner.class).add(Restrictions.gt("key", "5"));

    /* Since we are telling listByCriteria that we are doing post-filtering
     * it should return us all results, but ordered and sorted by what we
     * provide
     */
    Page<List<Owner>> p = ownerCurator.listByCriteria(criteria, pageRequest, true);
    assertEquals(Integer.valueOf(4), p.getMaxRecords());

    List<Owner> ownerList = p.getPageData();
    assertEquals(4, ownerList.size());
    assertEquals("6", ownerList.get(0).getKey());

    PageRequest pageRequest2 = p.getPageRequest();
    assertEquals(pageRequest, pageRequest2);
}

From source file:org.candlepin.model.OwnerCurator.java

License:Open Source License

/**
 * Note that this query looks up only provided products.
 * @param productIds//from   ww  w  .j a va2 s .c om
 * @return a list of owners
 */
public List<Owner> lookupOwnersByActiveProduct(List<String> productIds) {
    // NOTE: only used by superadmin API calls, no permissions filtering needed here.
    DetachedCriteria poolIdQuery = DetachedCriteria.forClass(ProvidedProduct.class, "pp");
    poolIdQuery.add(Restrictions.in("pp.productId", productIds)).setProjection(Property.forName("pp.pool.id"));

    DetachedCriteria ownerIdQuery = DetachedCriteria.forClass(Entitlement.class, "e")
            .add(Subqueries.propertyIn("e.pool.id", poolIdQuery)).createCriteria("pool")
            .add(Restrictions.gt("endDate", new Date())).setProjection(Property.forName("e.owner.id"));

    DetachedCriteria distinctQuery = DetachedCriteria.forClass(Owner.class, "o2")
            .add(Subqueries.propertyIn("o2.id", ownerIdQuery))
            .setProjection(Projections.distinct(Projections.property("o2.key")));

    return currentSession().createCriteria(Owner.class, "o").add(Subqueries.propertyIn("o.key", distinctQuery))
            .list();
}

From source file:org.caratarse.auth.model.util.CriteriaFilterHelper.java

License:Apache License

public static void addQueryFilter(final DetachedCriteria crit, QueryFilter filter) {
    if (filter == null) {
        return;/*from   w ww  .  j  a va2 s . co  m*/
    }

    filter.iterate(new FilterCallback() {
        @Override
        public void filterOn(FilterComponent c) {
            switch (c.getOperator()) {
            case CONTAINS: // String-related
                crit.add(Restrictions.ilike(c.getField(), c.getValue().toString(), MatchMode.ANYWHERE));
                break;
            case STARTS_WITH: // String-related
                crit.add(Restrictions.ilike(c.getField(), c.getValue().toString(), MatchMode.START));
                break;
            case GREATER_THAN:
                crit.add(Restrictions.gt(c.getField(), c.getValue()));
                break;
            case GREATER_THAN_OR_EQUAL_TO:
                crit.add(Restrictions.ge(c.getField(), c.getValue()));
                break;
            case LESS_THAN:
                crit.add(Restrictions.lt(c.getField(), c.getValue()));
                break;
            case LESS_THAN_OR_EQUAL_TO:
                crit.add(Restrictions.le(c.getField(), c.getValue()));
                break;
            case NOT_EQUALS:
                crit.add(Restrictions.ne(c.getField(), c.getValue()));
                break;
            case EQUALS:
            default:
                crit.add(Restrictions.eq(c.getField(), c.getValue()));
                break;
            }
        }
    });
}

From source file:org.codehaus.groovy.grails.orm.hibernate.query.AbstractHibernateCriterionAdapter.java

License:Apache License

protected void addSimplePropertyCriterionAdapters() {
    criterionAdaptors.put(Query.IdEquals.class, new CriterionAdaptor() {
        @Override/*from ww w .  j  ava 2s  .  com*/
        public org.hibernate.criterion.Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery,
                Query.Criterion criterion, String alias) {
            return Restrictions.idEq(((Query.IdEquals) criterion).getValue());
        }
    });
    criterionAdaptors.put(Query.Equals.class, new CriterionAdaptor<Query.Equals>() {
        @Override
        public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.Equals criterion,
                String alias) {
            String propertyName = getPropertyName(criterion, alias);
            Object value = criterion.getValue();
            if (value instanceof DetachedCriteria) {
                return Property.forName(propertyName).eq((DetachedCriteria) value);
            }
            return Restrictions.eq(propertyName, value);
        }
    });
    criterionAdaptors.put(Query.NotEquals.class, new CriterionAdaptor<Query.NotEquals>() {
        @Override
        public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.NotEquals criterion,
                String alias) {
            String propertyName = getPropertyName(criterion, alias);
            Object value = criterion.getValue();
            if (value instanceof DetachedCriteria) {
                return Property.forName(propertyName).ne((DetachedCriteria) value);
            }
            return Restrictions.ne(propertyName, value);
        }
    });
    criterionAdaptors.put(Query.GreaterThan.class, new CriterionAdaptor<Query.GreaterThan>() {
        @Override
        public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery,
                Query.GreaterThan criterion, String alias) {
            String propertyName = getPropertyName(criterion, alias);
            Object value = criterion.getValue();
            if (value instanceof DetachedCriteria) {
                return Property.forName(propertyName).gt((DetachedCriteria) value);
            }
            return Restrictions.gt(propertyName, value);
        }
    });
    criterionAdaptors.put(Query.GreaterThanEquals.class, new CriterionAdaptor<Query.GreaterThanEquals>() {
        @Override
        public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery,
                Query.GreaterThanEquals criterion, String alias) {
            String propertyName = getPropertyName(criterion, alias);
            Object value = criterion.getValue();
            if (value instanceof DetachedCriteria) {
                return Property.forName(propertyName).ge((DetachedCriteria) value);
            }
            return Restrictions.ge(propertyName, value);
        }
    });
    criterionAdaptors.put(Query.LessThan.class, new CriterionAdaptor<Query.LessThan>() {
        @Override
        public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.LessThan criterion,
                String alias) {
            String propertyName = getPropertyName(criterion, alias);
            Object value = criterion.getValue();
            if (value instanceof DetachedCriteria) {
                return Property.forName(propertyName).lt((DetachedCriteria) value);
            }
            return Restrictions.lt(propertyName, value);
        }
    });
    criterionAdaptors.put(Query.LessThanEquals.class, new CriterionAdaptor<Query.LessThanEquals>() {
        @Override
        public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery,
                Query.LessThanEquals criterion, String alias) {
            String propertyName = getPropertyName(criterion, alias);
            Object value = criterion.getValue();
            if (value instanceof DetachedCriteria) {
                return Property.forName(propertyName).le((DetachedCriteria) value);
            }
            return Restrictions.le(propertyName, value);
        }
    });
}

From source file:org.codehaus.groovy.grails.orm.hibernate.query.AbstractHibernateQuery.java

License:Apache License

@Override
public Query gt(String property, Object value) {
    addToCriteria(Restrictions.gt(calculatePropertyName(property), value));
    return this;
}

From source file:org.codehaus.groovy.grails.orm.hibernate.query.HibernateQuery.java

License:Apache License

@Override
public Query gt(String property, Object value) {
    criteria.add(Restrictions.gt(property, value));
    return this;
}

From source file:org.dspace.checker.dao.impl.MostRecentChecksumDAOImpl.java

License:BSD License

@Override
public List<MostRecentChecksum> findByNotProcessedInDateRange(Context context, Date startDate, Date endDate)
        throws SQLException {
    //                    + "most_recent_checksum.last_process_start_date, most_recent_checksum.last_process_end_date, "
    //                    + "most_recent_checksum.expected_checksum, most_recent_checksum.current_checksum, "
    //                    + "result_description "
    //                    + "from checksum_results, most_recent_checksum "
    //                    + "where most_recent_checksum.to_be_processed = false "
    //                    + "and most_recent_checksum.result = checksum_results.result_code "
    //                    + "and most_recent_checksum.last_process_start_date >= ? "
    //                    + "and most_recent_checksum.last_process_start_date < ? "
    //                    + "order by most_recent_checksum.bitstream_id

    Criteria criteria = createCriteria(context, MostRecentChecksum.class);
    criteria.add(Restrictions.and(Restrictions.eq("toBeProcessed", false),
            Restrictions.le("processStartDate", startDate), Restrictions.gt("processStartDate", endDate)));
    criteria.addOrder(Order.asc("bitstream.id"));
    return list(criteria);
}

From source file:org.dspace.checker.dao.impl.MostRecentChecksumDAOImpl.java

License:BSD License

@Override
public List<MostRecentChecksum> findByResultTypeInDateRange(Context context, Date startDate, Date endDate,
        ChecksumResultCode resultCode) throws SQLException {
    //        "select bitstream_id, last_process_start_date, last_process_end_date, "
    //                    + "expected_checksum, current_checksum, result_description "
    //                    + "from most_recent_checksum, checksum_results "
    //                    + "where most_recent_checksum.result = checksum_results.result_code "
    //                    + "and most_recent_checksum.result= ? "
    //                    + "and most_recent_checksum.last_process_start_date >= ? "
    //                    + "and most_recent_checksum.last_process_start_date < ? "
    //                    + "order by bitstream_id";
    Criteria criteria = createCriteria(context, MostRecentChecksum.class);
    criteria.add(Restrictions.and(Restrictions.eq("checksumResult.resultCode", resultCode),
            Restrictions.le("processStartDate", startDate), Restrictions.gt("processStartDate", endDate)));
    criteria.addOrder(Order.asc("bitstream.id"));
    return list(criteria);

}