List of usage examples for org.hibernate Criteria list
public List list() throws HibernateException;
From source file:at.ac.tuwien.ifs.tita.dao.GenericHibernateDao.java
License:Apache License
/** {@inheritDoc} */ @SuppressWarnings("unchecked") public List<T> findByExample(T exampleInstance, String... excludeProps) { List<T> myList = null;/*from www . j a v a 2 s . co m*/ try { Criteria crit = getSession().createCriteria(this.persistenceClass); Example example = Example.create(exampleInstance); for (String exclude : excludeProps) { example.excludeProperty(exclude); } crit.add(example); // Tell Hibernate to remove duplicates from the result set if there // is a // OneToMany relation in the exampleInstance entity. crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); myList = crit.list(); } catch (Exception e) { throw new PersistenceException("Failure during reading entities (by example). Class=" + this.persistenceClass.getSimpleName() + "\n" + e.getMessage(), e); } return myList; }
From source file:at.ac.tuwien.ifs.tita.dao.GenericHibernateDao.java
License:Apache License
/** * Find several entities via criterion.//from w w w.ja v a2s .com * * @param criterion beliebige Kriterien * @return (leere) Liste von Entities */ @SuppressWarnings("unchecked") protected List<T> findByCriteria(Criterion... criterion) { Criteria crit = getSession().createCriteria(this.persistenceClass); for (Criterion c : criterion) { crit.add(c); } crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return crit.list(); }
From source file:at.ac.tuwien.ifs.tita.dao.GenericHibernateDao.java
License:Apache License
/** * Search by use of the specified search criterions, order by specified * order criterions./*from w w w. ja v a 2 s. c o m*/ * * @param criterions - search criterions * @param orders - order criterions * @param aliases list of aliasnames * @return List of result records */ @SuppressWarnings("unchecked") protected List<T> findByCriteriaOrdered(Criterion criterions[], Order orders[], String aliases[]) { Criteria crit = getSession().createCriteria(this.persistenceClass); if (aliases != null) { for (String alias : aliases) { crit.createAlias(alias, alias); } } for (int i = 0; i < criterions.length; i++) { crit.add(criterions[i]); } for (int j = 0; j < orders.length; j++) { crit.addOrder(orders[j]); } crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return crit.list(); }
From source file:at.ac.tuwien.ifs.tita.dao.project.TiTAProjectDao.java
License:Apache License
/** {@inheritDoc} **/ @SuppressWarnings("unchecked") @Override//from w ww .j ava2 s .co m public List<TiTAProject> findProjectsOrderedByName(int maxResult, String orderBy) throws PersistenceException { Criteria crit = getSession().createCriteria(TiTAProject.class); if (maxResult > 0) { crit.setMaxResults(maxResult); } crit.add(Restrictions.eq("deleted", false)); crit.addOrder(Order.asc(orderBy)); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return crit.list(); }
From source file:at.ac.tuwien.ifs.tita.dao.project.TiTAProjectDao.java
License:Apache License
/** {@inheritDoc} **/ @SuppressWarnings("unchecked") @Override//from ww w .j a va 2 s . c o m public List<ProjectStatus> getAvailableProjectStati() throws PersistenceException { Criteria crit = getSession().createCriteria(ProjectStatus.class); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return crit.list(); }
From source file:at.ac.tuwien.ifs.tita.dao.user.UserDAO.java
License:Apache License
/** {@inheritDoc} **/ @Override/*from ww w . jav a2 s. c o m*/ @SuppressWarnings("unchecked") public List<TiTAUser> findUsersOrdered(int maxResult) throws PersistenceException { Criteria crit = getSession().createCriteria(TiTAUser.class); if (maxResult > 0) { crit.setMaxResults(maxResult); } crit.addOrder(Order.asc("userName")); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return crit.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)); }//from w ww . ja va2s .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:au.com.optus.mcas.sdp.bizservice.ott.ordertracking.batchjob.dao.impl.AbstractDaoImpl.java
License:Open Source License
/** * {@inheritDoc}// w w w .j ava 2s .co m */ @SuppressWarnings("unchecked") public List<E> findByCriteria(final DetachedCriteria criteria) { Assert.notNull(criteria, "Detached criterial cannot be null in call to findByCriteria()"); if (getLogger().isDebugEnabled()) { getLogger().debug(String.format("Finding instances of '%s' using detached criteria: %s", getEntityClass(), criteria)); } final Criteria executableCriteria = criteria.getExecutableCriteria(getHibernateSession()); return executableCriteria.list(); }
From source file:au.com.optus.mcas.sdp.bizservice.ott.ordertracking.batchjob.dao.impl.AbstractDaoImpl.java
License:Open Source License
/** * {@inheritDoc}//from w w w . ja v a2s . c om */ @SuppressWarnings("unchecked") public List<E> findByCriteria(final DetachedCriteria criteria, final int firstResult, final int maxResults) { Assert.notNull(criteria, "Detached criterial cannot be null in call to findByCriteria()"); if (getLogger().isDebugEnabled()) { getLogger().debug(String.format( "Finding instances of '%s' using detached criteria: %s [firstResult = %d, maxResults = %d]", getEntityClass(), criteria, firstResult, maxResults)); } final Criteria executableCriteria = criteria.getExecutableCriteria(getHibernateSession()); if (firstResult >= 0) { executableCriteria.setFirstResult(firstResult); } if (maxResults > 0) { executableCriteria.setMaxResults(maxResults); } return executableCriteria.list(); }
From source file:au.edu.archer.dimsim.buffer.pool.impl.HibernateBuffer.java
License:Open Source License
public int getSize() { if (this.sessionFactory == null) return -1; Criteria criteria = this.sessionFactory.getCurrentSession().createCriteria(DimsimORMStore.class); criteria.setProjection(Projections.rowCount()); return ((Integer) criteria.list().get(0)).intValue(); }