List of usage examples for javax.persistence EntityManagerFactory getCriteriaBuilder
public CriteriaBuilder getCriteriaBuilder();
CriteriaBuilder
for the creation of CriteriaQuery
objects. From source file:org.jasig.jpa.BaseJpaDao.java
protected final <T> ParameterExpression<T> createParameterExpression(Class<T> paramClass) { final EntityManagerFactory entityManagerFactory = entityManager.getEntityManagerFactory(); final CriteriaBuilder criteriaBuilder = entityManagerFactory.getCriteriaBuilder(); return criteriaBuilder.parameter(paramClass); }
From source file:org.jasig.jpa.BaseJpaDao.java
protected final <T> ParameterExpression<T> createParameterExpression(Class<T> paramClass, String name) { final EntityManagerFactory entityManagerFactory = entityManager.getEntityManagerFactory(); final CriteriaBuilder criteriaBuilder = entityManagerFactory.getCriteriaBuilder(); return criteriaBuilder.parameter(paramClass, name); }
From source file:org.jasig.jpa.BaseJpaDao.java
protected final <T> CriteriaQuery<T> createCriteriaQuery(Function<CriteriaBuilder, CriteriaQuery<T>> builder) { final EntityManagerFactory entityManagerFactory = entityManager.getEntityManagerFactory(); final CriteriaBuilder criteriaBuilder = entityManagerFactory.getCriteriaBuilder(); final CriteriaQuery<T> criteriaQuery = builder.apply(criteriaBuilder); //Do in TX so the EM gets closed correctly transactionOperations.execute(new TransactionCallbackWithoutResult() { @Override/*from ww w. j av a 2 s . c o m*/ protected void doInTransactionWithoutResult(TransactionStatus status) { entityManager.createQuery(criteriaQuery); //pre-compile critera query to avoid race conditions when setting aliases } }); return criteriaQuery; }
From source file:it.attocchi.jpa2.JPAEntityFilter.java
public Predicate getWherePredicate(Class<T> clazz, EntityManagerFactory emf) throws Exception { // CriteriaBuilder CriteriaBuilder criteriaBuilder = emf.getCriteriaBuilder(); CriteriaQuery<T> criteriaQuery = criteriaBuilder.createQuery(clazz); Root<T> root = criteriaQuery.from(clazz); criteriaQuery.select(root);/*from w w w .j a v a 2 s.c o m*/ List<Predicate> predicateList = new ArrayList<Predicate>(); // return getWherePredicates(emf, predicateList, criteriaQuery, // criteriaBuilder, root); Predicate[] predicates = getWherePredicates(emf, predicateList, criteriaQuery, criteriaBuilder, root); Predicate wherePredicate = criteriaBuilder.and(predicates); return wherePredicate; }
From source file:it.attocchi.jpa2.JPAEntityFilter.java
public CriteriaQuery<T> getCriteria(Class<T> clazz, EntityManagerFactory emf) throws Exception { // CriteriaBuilder CriteriaBuilder criteriaBuilder = emf.getCriteriaBuilder(); CriteriaQuery<T> criteriaQuery = criteriaBuilder.createQuery(clazz); Root<T> root = criteriaQuery.from(clazz); criteriaQuery.select(root);// ww w. ja v a 2s . com // criteria.where( builder.equal( personRoot.get( Utente_.eyeColor ), // "brown" ) ); List<Predicate> predicateList = new ArrayList<Predicate>(); // buildWhere(emf, predicateList, criteriaQuery, criteriaBuilder, root); // // Predicate[] predicates = new Predicate[predicateList.size()]; // predicateList.toArray(predicates); Predicate[] predicates = getWherePredicates(emf, predicateList, criteriaQuery, criteriaBuilder, root); Predicate wherePredicate = criteriaBuilder.and(predicates); criteriaQuery.where(wherePredicate); // buildSort(criteriaQuery, criteriaBuilder, root); List<Order> orders = new ArrayList<Order>(); buildSort(orders, criteriaQuery, criteriaBuilder, root); if (ListUtils.isNotEmpty(orders)) criteriaQuery.orderBy(orders); return criteriaQuery; }
From source file:org.batoo.jpa.benchmark.BenchmarkTest.java
private void test(final EntityManagerFactory emf, Queue<Runnable> workQueue, int length) { final CriteriaBuilder cb = emf.getCriteriaBuilder(); final CriteriaQuery<Address> cq = cb.createQuery(Address.class); final Root<Person> r = cq.from(Person.class); final Join<Person, Address> a = r.join("addresses"); a.fetch("country", JoinType.LEFT); a.fetch("person", JoinType.LEFT); cq.select(a);/* w ww . ja v a 2 s .c o m*/ final ParameterExpression<Person> p = cb.parameter(Person.class); cq.where(cb.equal(r, p)); for (int i = 0; i < length; i++) { workQueue.add(new Runnable() { @Override public void run() { try { BenchmarkTest.this.singleTest(emf, BenchmarkTest.this.createPersons(), cq, p); } catch (final Exception e) { BenchmarkTest.LOG.error(e, "Error while running the test"); } } }); } }