Search in sources :

Example 96 with Criteria

use of org.hibernate.Criteria in project dhis2-core by dhis2.

the class HibernateGenericStore method getCriteria.

/**
     * Creates a Criteria for the implementation Class type restricted by the
     * given Criterions.
     *
     * @param expressions the Criterions for the Criteria.
     * @return a Criteria instance.
     */
protected final Criteria getCriteria(Criterion... expressions) {
    Criteria criteria = getCriteria();
    for (Criterion expression : expressions) {
        criteria.add(expression);
    }
    criteria.setCacheable(cacheable);
    return criteria;
}
Also used : Criterion(org.hibernate.criterion.Criterion) Criteria(org.hibernate.Criteria) DetachedCriteria(org.hibernate.criterion.DetachedCriteria)

Example 97 with Criteria

use of org.hibernate.Criteria in project gocd by gocd.

the class UserSqlMapDao method findNotificationSubscribingUsers.

public Users findNotificationSubscribingUsers() {
    return (Users) transactionTemplate.execute(new TransactionCallback() {

        @Override
        public Object doInTransaction(TransactionStatus transactionStatus) {
            Criteria criteria = sessionFactory.getCurrentSession().createCriteria(User.class);
            criteria.setCacheable(true);
            criteria.add(Restrictions.isNotEmpty("notificationFilters"));
            return new Users(criteria.list());
        }
    });
}
Also used : TransactionCallback(org.springframework.transaction.support.TransactionCallback) TransactionStatus(org.springframework.transaction.TransactionStatus) Users(com.thoughtworks.go.domain.Users) Criteria(org.hibernate.Criteria)

Example 98 with Criteria

use of org.hibernate.Criteria in project gocd by gocd.

the class ServerBackupRepository method lastBackup.

public ServerBackup lastBackup() {
    List results = (List) getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Criteria criteria = session.createCriteria(ServerBackup.class);
            criteria.setMaxResults(1);
            criteria.addOrder(Order.desc("id"));
            return criteria.list();
        }
    });
    return results.isEmpty() ? null : (ServerBackup) results.get(0);
}
Also used : List(java.util.List) HibernateCallback(org.springframework.orm.hibernate3.HibernateCallback) Criteria(org.hibernate.Criteria) Session(org.hibernate.Session)

Example 99 with Criteria

use of org.hibernate.Criteria in project java-design-patterns by iluwatar.

the class DaoBaseImpl method find.

@Override
public E find(Long id) {
    Session session = getSession();
    Transaction tx = null;
    E result = null;
    try {
        tx = session.beginTransaction();
        Criteria criteria = session.createCriteria(persistentClass);
        criteria.add(Restrictions.idEq(id));
        result = (E) criteria.uniqueResult();
        tx.commit();
    } catch (Exception e) {
        if (tx != null) {
            tx.rollback();
        }
        throw e;
    } finally {
        session.close();
    }
    return result;
}
Also used : Transaction(org.hibernate.Transaction) Criteria(org.hibernate.Criteria) Session(org.hibernate.Session)

Example 100 with Criteria

use of org.hibernate.Criteria in project java-design-patterns by iluwatar.

the class DaoBaseImpl method findAll.

@Override
public List<E> findAll() {
    Session session = getSession();
    Transaction tx = null;
    List<E> result = null;
    try {
        tx = session.beginTransaction();
        Criteria criteria = session.createCriteria(persistentClass);
        result = criteria.list();
    } catch (Exception e) {
        if (tx != null) {
            tx.rollback();
        }
        throw e;
    } finally {
        session.close();
    }
    return result;
}
Also used : Transaction(org.hibernate.Transaction) Criteria(org.hibernate.Criteria) Session(org.hibernate.Session)

Aggregations

Criteria (org.hibernate.Criteria)174 Session (org.hibernate.Session)92 Test (org.junit.Test)69 Transaction (org.hibernate.Transaction)39 List (java.util.List)35 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)27 ArrayList (java.util.ArrayList)15 TestForIssue (org.hibernate.testing.TestForIssue)12 Iterator (java.util.Iterator)9 Period (org.hisp.dhis.period.Period)8 Map (java.util.Map)6 State (org.hibernate.test.cache.infinispan.functional.entities.State)5 OnmsCriteria (org.opennms.netmgt.model.OnmsCriteria)4 HibernateCallback (org.springframework.orm.hibernate3.HibernateCallback)4 HashSet (java.util.HashSet)3 Criterion (org.hibernate.criterion.Criterion)3 Example (org.hibernate.criterion.Example)3 Statistics (org.hibernate.stat.Statistics)3 Pager (org.hisp.dhis.common.Pager)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2