List of usage examples for javax.persistence.criteria CriteriaQuery from
<X> Root<X> from(Class<X> entityClass);
From source file:org.osiam.resource_server.storage.dao.ExtensionDao.java
/** * Get all stored extensions./*from w w w . j av a 2 s. c om*/ * * @return all extensions. */ public List<ExtensionEntity> getAllExtensions() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<ExtensionEntity> cq = cb.createQuery(ExtensionEntity.class); Root<ExtensionEntity> extension = cq.from(ExtensionEntity.class); cq.select(extension); TypedQuery<ExtensionEntity> query = em.createQuery(cq); return query.getResultList(); }
From source file:de.egore911.persistence.selector.AbstractSelector.java
private TypedQuery<T> buildQuery() { EntityManager em = EntityManagerUtil.getEntityManager(); CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<T> cq = builder.createQuery(getEntityClass()); Root<T> from = cq.from(getEntityClass()); List<Predicate> predicates = generatePredicateList(builder, from, cq); cq.where(predicates.toArray(new Predicate[predicates.size()])); cq.orderBy(generateOrderList(builder, from)); cq.select(from);/* w ww .j a v a 2s . c o m*/ return em.createQuery(cq); }
From source file:com.aimdek.ccm.dao.impl.BasicAbstractGenericDaoImpl.java
/** * {@inheritDoc}//from w w w.j a v a 2s . c om */ public EntityType findById(IDType id, Class<EntityType> entityClass) { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<EntityType> query = builder.createQuery(entityClass); Root<EntityType> root = query.from(entityClass); query.select(root); query.where(builder.equal(root.get(FIELD_CONSTANT_ID), id)); return entityManager.createQuery(query).getSingleResult(); }
From source file:com.aimdek.ccm.dao.impl.BasicAbstractGenericDaoImpl.java
/** * {@inheritDoc}/*from w w w .j a va 2 s . co m*/ */ public List<EntityType> findExactList(String key, IDType value, Class<EntityType> entityClass) { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<EntityType> query = builder.createQuery(entityClass); Root<EntityType> root = query.from(entityClass); query.select(root); query.where(builder.equal(root.get(key), value)); return entityManager.createQuery(query).getResultList(); }
From source file:com.beto.test.securityinterceptor.model.dao.generic.AbstractDao.java
@SuppressWarnings("unchecked") public List<T> findAll() { try {//from ww w . j a v a 2 s .c o m CriteriaQuery<Object> cq = getEntityManager().getCriteriaBuilder().createQuery(); cq.select(cq.from(entityClass)); return (List<T>) getEntityManager().createQuery(cq).getResultList(); } catch (NoResultException e) { LOGGER.debug("NO DATA FOUND..."); } return null; }
From source file:net.przemkovv.sphinx.dao.impl.DefaultGenericDAO.java
@Transactional(readOnly = true) @Override/*from w ww . j a va 2 s. co m*/ public List<T> getAll() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<T> cq = cb.createQuery(type); cq.from(type); return em.createQuery(cq).getResultList(); }
From source file:pdsanchez.mywebtools.model.dao.jpa.GenericDAOJPAImpl.java
@Override public int count() { javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); javax.persistence.criteria.Root<T> rt = cq.from(entityClass); cq.select(getEntityManager().getCriteriaBuilder().count(rt)); javax.persistence.Query q = getEntityManager().createQuery(cq); return ((Long) q.getSingleResult()).intValue(); }
From source file:eu.uqasar.service.ProductService.java
public List<Product> getAllProducts() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Product> query = cb.createQuery(Product.class); query.from(Product.class); return em.createQuery(query).getResultList(); }
From source file:com.samples.platform.core.SystemUserInitDao.java
/** * Get the {@link AuthenticationType}s out of the database. * * @param enabled// ww w.j a v a 2s. c om * if not <code>null</code> and <code>true</code> only the * enabled {@link AuthenticationType}s are replied. * @return the list of {@link AuthenticationType}s. */ @Transactional(value = EipPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED) public void enterSystemUser(final String contextName, final String userName, final String password, final String... roleNames) { AuthenticationType ac = this.of.createAuthenticationType(); ac.setContext(contextName); ac.setEnabled(true); GrantedAuthorityType r; for (String roleName : roleNames) { r = this.of.createGrantedAuthorityType(); r.setRoleName(roleName); ac.getGrantedAuthority().add(r); } ac.setPassword(password); ac.setUserName(userName); CriteriaBuilder cb = this.em.getCriteriaBuilder(); CriteriaQuery<AuthenticationType> q = cb.createQuery(AuthenticationType.class); Root<AuthenticationType> c = q.from(AuthenticationType.class); Predicate ands = cb.conjunction(); ands.getExpressions().add(cb.equal(c.<String>get(AuthenticationType_.context), contextName)); ands.getExpressions().add(cb.equal(c.<String>get(AuthenticationType_.userName), userName)); q.where(ands); q.orderBy(cb.asc(c.<String>get(AuthenticationType_.userName))); TypedQuery<AuthenticationType> typedQuery = this.em.createQuery(q); try { AuthenticationType stored = typedQuery.getSingleResult(); if (stored != null) { this.em.persist(ac); } } catch (NoResultException e) { this.em.persist(ac); } }
From source file:net.groupbuy.dao.impl.ConsultationDaoImpl.java
public Page<Consultation> findPage(Member member, Product product, Boolean isShow, Pageable pageable) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Consultation> criteriaQuery = criteriaBuilder.createQuery(Consultation.class); Root<Consultation> root = criteriaQuery.from(Consultation.class); criteriaQuery.select(root);/*from w ww . j ava 2 s.co m*/ Predicate restrictions = criteriaBuilder.conjunction(); restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.isNull(root.get("forConsultation"))); if (member != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("member"), member)); } if (product != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("product"), product)); } if (isShow != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("isShow"), isShow)); } criteriaQuery.where(restrictions); return super.findPage(criteriaQuery, pageable); }