List of usage examples for javax.persistence.criteria CriteriaBuilder parameter
<T> ParameterExpression<T> parameter(Class<T> paramClass);
From source file:com.enioka.jqm.tools.ResourceParser.java
private static JndiResourceDescriptor fromDatabase(String alias) throws NamingException { JndiObjectResource resource = null;//www .ja v a2s . com EntityManager em = null; try { // Using the horrible CriteriaBuilder API instead of a string query. This avoids classloading issues - Hibernate binds // the entities at run time with the thread current classloader... em = Helpers.getNewEm(); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<JndiObjectResource> q = cb.createQuery(JndiObjectResource.class); Root<JndiObjectResource> c = q.from(JndiObjectResource.class); ParameterExpression<String> p = cb.parameter(String.class); q.select(c).where(cb.equal(c.get("name"), p)); TypedQuery<JndiObjectResource> query = em.createQuery(q); query.setParameter(p, alias); resource = query.getSingleResult(); } catch (Exception e) { NamingException ex = new NamingException("Could not find a JNDI object resource of name " + alias); ex.setRootCause(e); throw ex; } finally { if (em != null) { em.close(); } } // Create the ResourceDescriptor from the JPA object JndiResourceDescriptor d = new JndiResourceDescriptor(resource.getType(), resource.getDescription(), null, resource.getAuth(), resource.getFactory(), resource.getSingleton()); for (JndiObjectResourceParameter prm : resource.getParameters()) { d.add(new StringRefAddr(prm.getKey(), prm.getValue())); } return d; }
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:com.saake.invoicer.sessionbean.PurchaseOrderFacade.java
@Override public List<PurchaseOrder> findAll() { CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); javax.persistence.criteria.CriteriaQuery cq = cb.createQuery(); Root<PurchaseOrder> root = cq.from(PurchaseOrder.class); cq.select(root);// ww w . j a v a 2 s. c om ParameterExpression<String> status = cb.parameter(String.class); // cq.where(cb.notEqual(invRoot.get("status"), status)); cq.where(cb.notEqual(root.get("deleted"), 'Y')); cq.orderBy(cb.desc(root.get("purchaseOrderId"))); Query query = getEntityManager().createQuery(cq); // query.setParameter(status, PaymentStatusEnum.DELETE.getValue()); List<PurchaseOrder> list = query.getResultList(); for (PurchaseOrder wo : list) { List<PurchaseOrderItems> tempDel = new ArrayList<>(); for (PurchaseOrderItems wot : wo.getPurchaseOrderItems()) { if (wot.isDeleted()) { tempDel.add(wot); } } wo.getPurchaseOrderItems().removeAll(tempDel); } return list; }
From source file:org.jasig.portal.groups.pags.dao.jpa.JpaPersonAttributesGroupDefinitionDao.java
@OpenEntityManager(unitName = PERSISTENCE_UNIT_NAME) @Override/*from w ww. jav a 2s . c o m*/ public Set<IPersonAttributesGroupDefinition> getPersonAttributesGroupDefinitionByName(String name) { CriteriaBuilder criteriaBuilder = this.getEntityManager().getCriteriaBuilder(); CriteriaQuery<PersonAttributesGroupDefinitionImpl> criteriaQuery = criteriaBuilder .createQuery(PersonAttributesGroupDefinitionImpl.class); Root<PersonAttributesGroupDefinitionImpl> root = criteriaQuery .from(PersonAttributesGroupDefinitionImpl.class); ParameterExpression<String> nameParameter = criteriaBuilder.parameter(String.class); criteriaQuery.select(root).where(criteriaBuilder.equal(root.get("name"), nameParameter)); TypedQuery<PersonAttributesGroupDefinitionImpl> query = this.getEntityManager().createQuery(criteriaQuery); query.setParameter(nameParameter, name); Set<IPersonAttributesGroupDefinition> groups = new HashSet<IPersonAttributesGroupDefinition>(); for (IPersonAttributesGroupDefinition group : query.getResultList()) { groups.add(group); } if (groups.size() > 1) { logger.error("More than one PAGS Group found for name: {}", name); } return groups; }
From source file:ch.sdi.plugins.oxwall.job.OxSqlJob.java
/** * @see ch.sdi.core.intf.SqlJob#isAlreadyPresent(ch.sdi.core.impl.data.Person) *///from w ww . ja va2 s . c om @Override public boolean isAlreadyPresent(Person<?> aPerson) throws SdiException { if (myDryRun && !myCheckDuplicateOnDryRun) { myLog.debug("DryRun is active. Not checking for duplicate person"); return false; } // if myDryRun CriteriaBuilder cb = myEntityManager.getCriteriaBuilder(); CriteriaQuery<OxUser> criteria = cb.createQuery(OxUser.class); Root<OxUser> root = criteria.from(OxUser.class); ParameterExpression<String> mailParam = cb.parameter(String.class); criteria.select(root).where(cb.equal(root.get("email"), mailParam)); TypedQuery<OxUser> queryEMail = myEntityManager.createQuery(criteria); queryEMail.setParameter(mailParam, aPerson.getEMail()); List<OxUser> results = queryEMail.getResultList(); if (results.size() > 0) { myLog.debug("given Person is already present: " + results.get(0)); return true; } // if results.size() > 0 return false; }
From source file:ch.sdi.plugins.oxwall.job.OxSqlJob.java
/** * Checks if the given hash is present in the ow_base_avatar table * * @param aHash/*from ww w . jav a2 s . co m*/ * @return */ public boolean isAvatarHashPresent(Long aHash) { if (myDryRun) { myLog.debug("DryRun is active. Not checking for duplicate avatar hash"); return false; } // if myDryRun CriteriaBuilder cb = myEntityManager.getCriteriaBuilder(); CriteriaQuery<OxAvatar> criteria = cb.createQuery(OxAvatar.class); Root<OxAvatar> root = criteria.from(OxAvatar.class); ParameterExpression<Long> avatarParam = cb.parameter(Long.class); avatarParam = cb.parameter(Long.class); criteria.select(root).where(cb.equal(root.get("hash"), avatarParam)); TypedQuery<OxAvatar> query = myEntityManager.createQuery(criteria); query.setParameter(avatarParam, aHash); List<OxAvatar> results = query.getResultList(); if (results.size() > 0) { myLog.debug("given avatar hash is already present: " + aHash); return true; } // if results.size() > 0 return false; }
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);/* www .ja v a2s .co 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"); } } }); } }