List of usage examples for javax.persistence.criteria CriteriaQuery select
CriteriaQuery<T> select(Selection<? extends T> selection);
From source file:com.zergiu.tvman.dao.impl.TVShowDaoImpl.java
@Override public Long getTVShowsCount() { CriteriaBuilder criteria = em.getCriteriaBuilder(); CriteriaQuery<Long> query = criteria.createQuery(Long.class); query.select(criteria.countDistinct(query.from(TVShow.class))); Long count = em.createQuery(query).getSingleResult(); log.debug("all count: " + count); return count; }
From source file:com.boxedfolder.carrot.repository.impl.AnalyticsLogRepositoryImpl.java
private TypedQuery<Long> getCountQuery(Class clazz) { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<Long> query = builder.createQuery(Long.class); query.select(builder.count(query.from(clazz))); return entityManager.createQuery(query); }
From source file:pdsanchez.mywebtools.model.dao.jpa.GenericDAOJPAImpl.java
@Override 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:com.ttech.cordovabuild.domain.user.UserRepositoryImpl.java
@Override public User findUserByEmail(String email) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<User> cq = cb.createQuery(User.class); Root<User> root = cq.from(User.class); return em.createQuery(cq.select(root).where(cb.equal(root.get(User_.email), email))).getSingleResult(); }
From source file:cz.muni.expense.data.UserRepository.java
public User findByUsername(String username) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<User> criteria = cb.createQuery(User.class); Root<User> user = criteria.from(User.class); criteria.select(user).where(cb.equal(user.get(User_.username), username)); try {/* w ww. j a v a 2 s . c om*/ return em.createQuery(criteria).getSingleResult(); } catch (NoResultException ex) { return null; } }
From source file:com.ttech.cordovabuild.domain.user.UserRepositoryImpl.java
@Override public User findUserByUserName(String username) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<User> cq = cb.createQuery(User.class); Root<User> root = cq.from(User.class); return em.createQuery(cq.select(root).where(cb.equal(root.get(User_.username), username))) .getSingleResult();//from w w w.j ava 2s . c o m }
From source file:cz.muni.expense.data.UserRepository.java
public User findByUsernameAndAuthToken(String authId, String authToken) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<User> criteria = cb.createQuery(User.class); Root<User> user = criteria.from(User.class); criteria.select(user).where(cb.equal(user.get(User_.username), authId)); try {//from www . j a v a 2s .c o m User userToReturn = em.createQuery(criteria).getSingleResult(); return userToReturn.getAuthToken().equals(authToken) ? userToReturn : null; } catch (NoResultException ex) { return null; } }
From source file:com.nuevebit.persistence.repository.JPASearchableRepository.java
@Override public long count(S searchCriteria) { CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); CriteriaQuery<Long> q = cb.createQuery(Long.class); Root<T> p = createQueryRoot(q, searchCriteria); q.select(cb.count(p)); return getEntityManager().createQuery(q).getSingleResult(); }
From source file:net.carinae.dev.async.dao.DummyEntityDaoJPA2.java
@Override public List<DummyEntity> findByData(String data) { // select de from DummyEntity // where de.data = data CriteriaBuilder cb = this.entityManager.getCriteriaBuilder(); CriteriaQuery<DummyEntity> cq = cb.createQuery(DummyEntity.class); Root<DummyEntity> de = cq.from(DummyEntity.class); cq.select(de).where(cb.equal(de.get(DummyEntity_.data), data)); return this.entityManager.createQuery(cq).getResultList(); }
From source file:net.groupbuy.dao.impl.DepositDaoImpl.java
public Page<Deposit> findPage(Member member, Pageable pageable) { if (member == null) { return new Page<Deposit>(Collections.<Deposit>emptyList(), 0, pageable); }//from ww w . ja v a2 s . c o m CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Deposit> criteriaQuery = criteriaBuilder.createQuery(Deposit.class); Root<Deposit> root = criteriaQuery.from(Deposit.class); criteriaQuery.select(root); criteriaQuery.where(criteriaBuilder.equal(root.get("member"), member)); return super.findPage(criteriaQuery, pageable); }