List of usage examples for javax.persistence.criteria CriteriaQuery select
CriteriaQuery<T> select(Selection<? extends T> selection);
From source file:org.jdal.dao.jpa.JpaUtils.java
/** * Create a row count CriteriaQuery from a CriteriaQuery * @param em entity manager//from w ww . j av a 2s. c om * @param criteria source criteria * @return row count CriteriaQuery */ public static <T> CriteriaQuery<Long> countCriteria(EntityManager em, CriteriaQuery<T> criteria) { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Long> countCriteria = builder.createQuery(Long.class); copyCriteriaWithoutSelectionAndOrder(criteria, countCriteria); Expression<Long> countExpression; if (criteria.isDistinct()) { countExpression = builder.countDistinct(findRoot(countCriteria, criteria.getResultType())); } else { countExpression = builder.count(findRoot(countCriteria, criteria.getResultType())); } return countCriteria.select(countExpression); }
From source file:org.apache.cxf.fediz.service.idp.service.jpa.DBInitApplicationListener.java
protected boolean isDBEmpty() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> cq = cb.createQuery(Long.class); cq.select(cb.count(cq.from(ClaimEntity.class))); return em.createQuery(cq).getSingleResult() == 0; }
From source file:org.hellospring4.dao.AbstractDAO.java
public List<T> findAll() { javax.persistence.criteria.CriteriaQuery cq = entityManager.getCriteriaBuilder().createQuery(); cq.select(cq.from(entityClass)); return entityManager.createQuery(cq).getResultList(); }
From source file:fi.helsinki.opintoni.repository.CommonRepository.java
public <T> List<T> find(Class<T> entityClass, List<Long> ids) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<T> query = criteriaBuilder.createQuery(entityClass); Root<T> from = query.from(entityClass); query.select(from).where(from.get("id").in(ids)); return entityManager.createQuery(query).getResultList(); }
From source file:ro.alexdutescu.coduribare.service.AbstractFacade.java
public List<T> findAll() { javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); cq.select(cq.from(entityClass)); return getEntityManager().createQuery(cq).getResultList(); }
From source file:ro.alexdutescu.coduribare.service.AbstractFacade.java
public List<T> findRange(int[] range) { javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); cq.select(cq.from(entityClass)); javax.persistence.Query q = getEntityManager().createQuery(cq); q.setMaxResults(range[1] - range[0] + 1); q.setFirstResult(range[0]);/*from w w w . j av a2 s. c om*/ return q.getResultList(); }
From source file:top.knos.user.UserRepositoryImpl.java
public List<User> myCustomBatchOperation() { CriteriaQuery<User> criteriaQuery = em.getCriteriaBuilder().createQuery(User.class); criteriaQuery.select(criteriaQuery.from(User.class)); return em.createQuery(criteriaQuery).getResultList(); }
From source file:com.github.aynu.mosir.core.enterprise.persistence.SmartRepositoryProducer.java
/** * ???// www . j av a2s . com * @return ?() */ @Produces public SmartRepository<Testee, TesteeFilter> createTestee() { final SmartRepositoryListener<Testee, TesteeFilter> listener = new AbstractSmartRepositoryListener<Testee, TesteeFilter>() { @Override public CriteriaQuery<Testee> query(final CriteriaBuilder builder, final CriteriaQuery<Testee> query, final Root<Testee> root, final TesteeFilter filter) { query.select(root); if (StringUtils.isNotEmpty(filter.getCode())) { query.where(builder.equal(root.get("code"), filter.getCode())); } return query.orderBy(createOrders(builder, root, filter)); } }; return new SmartRepositoryImpl<>(Testee.class, manager, listener); }
From source file:vn.edu.vnuk.tasks_jpa.dao.TaskDao.java
public List<Task> read() throws SQLException { EntityManager manager = getEntityManager(); CriteriaQuery criteria = manager.getCriteriaBuilder().createQuery(); criteria.select(criteria.from(Task.class)); return manager.createQuery(criteria).getResultList(); }
From source file:net.groupbuy.dao.impl.TagDaoImpl.java
public List<Tag> findList(Type type) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Tag> criteriaQuery = criteriaBuilder.createQuery(Tag.class); Root<Tag> root = criteriaQuery.from(Tag.class); criteriaQuery.select(root); if (type != null) { criteriaQuery.where(criteriaBuilder.equal(root.get("type"), type)); }//from w w w .j a va 2s. co m criteriaQuery.orderBy(criteriaBuilder.asc(root.get("order"))); return entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT).getResultList(); }