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;
}
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());
}
});
}
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);
}
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;
}
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;
}
Aggregations