List of usage examples for org.hibernate Criteria setCacheable
public Criteria setCacheable(boolean cacheable);
From source file:abid.password.swing.dao.hibernate.AbstractHibernateDao.java
License:Apache License
@SuppressWarnings("unchecked") public List<T> get(int first, int fetchSize) { Session session = sessionFactory.openSession(); try {//from www . j a v a 2 s.c o m Criteria criteria = session.createCriteria(persistentClass); criteria.setFirstResult(first); criteria.setMaxResults(fetchSize); criteria.setFetchSize(fetchSize); criteria.setCacheable(true); List<T> dataList = (List<T>) criteria.list(); return dataList; } finally { session.close(); } }
From source file:abid.password.swing.dao.hibernate.AbstractHibernateDao.java
License:Apache License
@SuppressWarnings("unchecked") public List<T> getSorted(int first, int fetchSize, String propertyName, boolean ascending) { Session session = sessionFactory.openSession(); try {/* w w w. j a v a2 s . co m*/ Criteria criteria = session.createCriteria(persistentClass); criteria.setFirstResult(first); criteria.setMaxResults(fetchSize); criteria.setFetchSize(fetchSize); criteria.setCacheable(true); if (ascending) { criteria.addOrder(Order.asc(propertyName)); } else { criteria.addOrder(Order.desc(propertyName)); } List<T> dataList = (List<T>) criteria.list(); return dataList; } finally { session.close(); } }
From source file:abid.password.swing.dao.hibernate.AbstractHibernateDao.java
License:Apache License
@SuppressWarnings("unchecked") protected List<T> findByCriteria(Criterion... criterion) { Session session = sessionFactory.openSession(); try {/*w ww . j ava2 s . c om*/ Criteria criteria = session.createCriteria(getPersistentClass()); criteria.setCacheable(true); for (Criterion c : criterion) { criteria.add(c); } return criteria.list(); } finally { session.close(); } }
From source file:abid.password.wicket.dao.AbstractHibernateDao.java
License:Apache License
@Transactional(type = TransactionType.READ_ONLY) @SuppressWarnings("unchecked") public List<T> get(int first, int fetchSize) { Criteria criteria = session.get().createCriteria(persistentClass); criteria.setFirstResult(first);// ww w . j av a 2s .c o m criteria.setMaxResults(fetchSize); criteria.setFetchSize(fetchSize); criteria.setCacheable(true); List<T> dataList = (List<T>) criteria.list(); return dataList; }
From source file:abid.password.wicket.dao.AbstractHibernateDao.java
License:Apache License
@Transactional(type = TransactionType.READ_ONLY) @SuppressWarnings("unchecked") public List<T> getSorted(int first, int fetchSize, String propertyName, boolean ascending) { Criteria criteria = session.get().createCriteria(persistentClass); criteria.setFirstResult(first);/* www. j a v a2s. c o m*/ criteria.setMaxResults(fetchSize); criteria.setFetchSize(fetchSize); criteria.setCacheable(true); if (ascending) { criteria.addOrder(Order.asc(propertyName)); } else { criteria.addOrder(Order.desc(propertyName)); } List<T> dataList = (List<T>) criteria.list(); return dataList; }
From source file:abid.password.wicket.dao.AbstractHibernateDao.java
License:Apache License
@Transactional(type = TransactionType.READ_ONLY) @SuppressWarnings("unchecked") protected List<T> findByCriteria(Criterion... criterion) { Criteria criteria = session.get().createCriteria(getPersistentClass()); criteria.setCacheable(true); for (Criterion c : criterion) { criteria.add(c);//from w w w . ja va 2s. c om } return criteria.list(); }
From source file:ar.com.zauber.commons.repository.SpringHibernateRepository.java
License:Apache License
/** @see Repository#find(Query) */ @SuppressWarnings("unchecked") public final <T extends Persistible> List<T> find(final Query<T> query) { CriteriaSpecification criteria = getCriteriaSpecification(null, query, false); final SimpleQuery<T> simpleQuery = (SimpleQuery<T>) query; Criteria aCriteria;// www .java 2s . com // TODO Esto debera ir en el metodo que hace getCriteriaSpecification // pero como no tiene DetachedCriteria posibilidad de setearle valores // para paginacin hubo que hacerlo as. if (simpleQuery.getPaging() != null) { int firstResult = (simpleQuery.getPaging().getPageNumber() - 1) * simpleQuery.getPaging().getResultsPerPage(); DetachedCriteria idsDetachedCriteria = (DetachedCriteria) criteria; idsDetachedCriteria.setProjection(Projections.id()); Criteria idsCriteria = idsDetachedCriteria.getExecutableCriteria(this.getSession()); idsCriteria.setCacheable(query.getCacheable()); idsCriteria.setFirstResult(firstResult); idsCriteria.setMaxResults(simpleQuery.getPaging().getResultsPerPage()); // Se hace primero el select de los IDs y luego el de los objetos en // si ya que de otra manera en aquellos casos que haya objetos // que tienen colecciones cuenta los mismos varias veces haciendo // que se devuelvan menos resultados. List<Long> ids = idsCriteria.list(); DetachedCriteria theCriteria = (DetachedCriteria) getCriteriaSpecification(null, query, false); if (ids.isEmpty()) { return new ArrayList<T>(); } theCriteria.add(Restrictions.in("id", ids)); aCriteria = theCriteria.getExecutableCriteria(this.getSession()); } else { aCriteria = ((DetachedCriteria) criteria).getExecutableCriteria(this.getSession()); } aCriteria.setCacheable(query.getCacheable()); return aCriteria.list(); }
From source file:at.molindo.esi4j.module.hibernate.scrolling.DefaultQueryScrollingSession.java
License:Apache License
@Override public List<?> fetch(Session session, int batchSize) { Criteria criteria = session.createCriteria(_type); if (_lastId != null) { criteria.add(Restrictions.gt("id", _lastId)); }// ww w . j av a2s. co m criteria.addOrder(Order.asc("id")); criteria.setMaxResults(batchSize); criteria.setCacheable(false); for (Map.Entry<String, FetchMode> e : _fetchModes.entrySet()) { criteria.setFetchMode(e.getKey(), e.getValue()); } List<?> list = criteria.list(); if (list.size() > 0) { ClassMetadata meta = session.getSessionFactory().getClassMetadata(_type); Object last = list.get(list.size() - 1); _lastId = meta.getIdentifier(last, (SessionImpl) session); } return list; }
From source file:br.com.loja.framework.hibernate.dao.AbstractDAOHibernate.java
@Override public List<T> list(boolean cacheable) { List<T> entities = null; if (getSession() != null) { entities = new ArrayList<>(); try {/*from ww w . j ava 2s . co m*/ begin(); Criteria criteria = getSession().createCriteria(clazz).add(Restrictions.eq("dead", false)); entities = criteria.setCacheable(cacheable).list(); commit(); } catch (HibernateException e) { //TODO implemetar log System.err.println(e.getMessage()); rollback(); e.printStackTrace(); } finally { close(); } } return entities; }
From source file:br.com.muranodesign.dao.impl.GrupoDAOImpl.java
License:Creative Commons License
@SuppressWarnings("unchecked") public List<Grupo> listAll() { Criteria criteria = getSession().createCriteria(Grupo.class); criteria.setCacheable(true); criteria.add(Restrictions.eq("status", "0")); List<Grupo> result = criteria.list(); return result; }