List of usage examples for javax.persistence.criteria CriteriaQuery from
<X> Root<X> from(Class<X> entityClass);
From source file:org.jdal.dao.jpa.JpaUtils.java
/** * Copy criteria without selection and order. * @param from source Criteria./*from w w w .j a v a 2 s . c o m*/ * @param to destination Criteria. */ private static void copyCriteriaWithoutSelectionAndOrder(CriteriaQuery<?> from, CriteriaQuery<?> to) { if (isEclipseLink(from) && from.getRestriction() != null) { // EclipseLink adds roots from predicate paths to critera. Skip copying // roots as workaround. } else { // Copy Roots for (Root<?> root : from.getRoots()) { Root<?> dest = to.from(root.getJavaType()); dest.alias(getOrCreateAlias(root)); copyJoins(root, dest); } } to.groupBy(from.getGroupList()); to.distinct(from.isDistinct()); if (from.getGroupRestriction() != null) to.having(from.getGroupRestriction()); Predicate predicate = from.getRestriction(); if (predicate != null) to.where(predicate); }
From source file:de.widone.services.daos.UserDAO.java
public User findUserByUsername(String username) { CriteriaQuery<User> query = createCriteria(); Root<User> userRoot = query.from(User.class); entityManager.getCriteriaBuilder().equal(userRoot.get("username"), username); List<User> users = entityManager.createQuery(query).getResultList(); if (users.size() == 1) return users.get(0); return null;//from w w w . j a va 2 s .com }
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:core.commonapp.server.dao.geo.GeoDaoHibernateImpl.java
@Override public List<Geo> findByGeoType(GeoType type) { CriteriaBuilder builder = getEntityManager().getCriteriaBuilder(); CriteriaQuery query = builder.createQuery(Geo.class); Root<Geo> root = query.from(Geo.class); builder.equal(root.get("geoType"), type); return getEntityManager().createQuery(query).getResultList(); }
From source file:net.przemkovv.sphinx.dao.impl.DefaultUserDAO.java
@Override public User getUser(String email) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<User> cq = cb.createQuery(User.class); Root<User> user = cq.from(User.class); cq.where(cb.equal(user.get(User_.email), email)); return em.createQuery(cq).getSingleResult(); }
From source file:com.sct.descubriendoturuta.service.PersonServiceImpl.java
@Transactional public List<Person> listPeople() { CriteriaQuery<Person> c = em.getCriteriaBuilder().createQuery(Person.class); c.from(Person.class); return em.createQuery(c).getResultList(); }
From source file:net.przemkovv.sphinx.dao.impl.DefaultUserDAO.java
@Override public boolean existsByEmail(String email) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> cq = cb.createQuery(Long.class); Root<User> user = cq.from(User.class); cq.where(cb.equal(user.get(User_.email), email)); cq.select(cb.count(user));/*from w w w .j ava2s . c o m*/ return em.createQuery(cq).getSingleResult().intValue() == 1; }
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: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();// ww w . ja v a 2 s .com }
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);// w w w .jav a 2s . c o m if (type != null) { criteriaQuery.where(criteriaBuilder.equal(root.get("type"), type)); } criteriaQuery.orderBy(criteriaBuilder.asc(root.get("order"))); return entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT).getResultList(); }