List of usage examples for javax.persistence.criteria CriteriaBuilder equal
Predicate equal(Expression<?> x, Object y);
From source file:se.kth.csc.persist.JPAStore.java
@Override public Account fetchAccountWithPrincipalName(String principalName) { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<Account> q = cb.createQuery(Account.class); Root<Account> account = q.from(Account.class); try {//from w ww . j a va 2s. c o m return entityManager .createQuery( q.select(account).where(cb.equal(account.get(Account_.principalName), principalName))) .getSingleResult(); } catch (NoResultException e) { return null; } }
From source file:org.jboss.spring.quickstarts.kitchensink.kitchensink_spring.repo.MemberDaoImpl.java
public Member findByEmail(String email) { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Member> criteria = builder.createQuery(Member.class); Root<Member> member = criteria.from(Member.class); /*/*from w w w .j av a2 s . c om*/ * Swap criteria statements if you would like to try out type-safe criteria queries, a new * feature in JPA 2.0 criteria.select(member).orderBy(cb.asc(member.get(Member_.name))); */ criteria.select(member).where(builder.equal(member.get("email"), email)); return em.createQuery(criteria).getSingleResult(); }
From source file:core.commonapp.server.dao.party.PersonDaoHibernateImpl.java
@Override @Transactional/*from w w w .ja v a 2s. c o m*/ public List<Person> findAllContactPeople(Integer partyId) { CriteriaBuilder builder = getEntityManager().getCriteriaBuilder(); CriteriaQuery<Person> query = builder.createQuery(Person.class); Root<Person> contactPerson = query.from(Person.class); Join<Person, PartyRelationship> partyToRelationships = contactPerson.join("partyToRelationships"); query.where(builder.equal(partyToRelationships.get("partyFrom.partyId"), partyId), builder.isNull(partyToRelationships.get("thruDate"))); List<Person> people = getEntityManager().createQuery(query).getResultList(); PartyDaoHibernateImpl.lazyLoad((Party) people, true, true, false, false); return people; }
From source file:com.sfs.captor.controller.ProductReleaseAction.java
/** * load product releases//from w w w. j a v a 2 s . co m */ private void loadList() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<ProductRelease> c = cb.createQuery(ProductRelease.class); Root<ProductRelease> obj = c.from(ProductRelease.class); c.select(obj).where(cb.equal(obj.get("project"), this.project)).orderBy(cb.asc(obj.get("id"))); this.productReleases = em.createQuery(c).getResultList(); }
From source file:net.groupbuy.dao.impl.OrderDaoImpl.java
public Page<Order> findPage(Member member, Pageable pageable) { if (member == null) { return new Page<Order>(Collections.<Order>emptyList(), 0, pageable); }// ww w . ja v a 2 s. c om CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Order> criteriaQuery = criteriaBuilder.createQuery(Order.class); Root<Order> root = criteriaQuery.from(Order.class); criteriaQuery.select(root); criteriaQuery.where(criteriaBuilder.equal(root.get("member"), member)); return super.findPage(criteriaQuery, pageable); }
From source file:com.aimdek.ccm.dao.impl.test.UsersDaoImplTest.java
/** * Test retrieve limited user./*w ww . j a va2s .c om*/ */ @Test public void testRetrieveLimitedUser() { int limit = 10; int start = 5; CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<User> query = builder.createQuery(User.class); Root<User> root = query.from(User.class); query.where(builder.equal(root.get(FIELDCONSTANT_USER_ROLE), ROLE_CUSTOMER)); List<User> user = entityManager.createQuery(query).setFirstResult(start).setMaxResults(limit) .getResultList(); assertEquals(user.size(), 5); }
From source file:net.groupbuy.dao.impl.OrderDaoImpl.java
public List<Order> findList(Member member, Integer count, List<Filter> filters, List<net.groupbuy.Order> orders) { if (member == null) { return Collections.<Order>emptyList(); }/*from ww w. j a va 2 s . c o m*/ CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Order> criteriaQuery = criteriaBuilder.createQuery(Order.class); Root<Order> root = criteriaQuery.from(Order.class); criteriaQuery.select(root); criteriaQuery.where(criteriaBuilder.equal(root.get("member"), member)); return super.findList(criteriaQuery, null, count, filters, orders); }
From source file:eu.uqasar.service.user.UserService.java
public List<User> getByCompany(final Company company) { logger.infof("loading User with company %s ...", company); User entity = null;/* w w w .j a v a 2 s.co m*/ CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<User> query = cb.createQuery(User.class); Root<User> root = query.from(User.class); query.where(cb.equal(root.get(User_.company), company)); return em.createQuery(query).getResultList(); }
From source file:eu.uqasar.service.user.UserService.java
public User getByUserName(final String userName) { logger.infof("loading User with username %s ...", userName); User entity = null;//ww w . j ava 2s . c o m CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<User> query = cb.createQuery(User.class); Root<User> root = query.from(User.class); query.where(cb.equal(root.get(User_.userName), userName)); List<User> resultList = em.createQuery(query).setMaxResults(1).getResultList(); if (!resultList.isEmpty()) { return resultList.get(0); } return entity; }
From source file:eu.uqasar.service.user.UserService.java
public User getByMail(final String mail) { logger.infof("loading User with mail %s ...", mail); User entity = null;// w w w.j a v a 2 s . c o m CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<User> query = cb.createQuery(User.class); Root<User> root = query.from(User.class); query.where(cb.equal(root.get(User_.mail), mail)); List<User> resultList = em.createQuery(query).setMaxResults(1).getResultList(); if (!resultList.isEmpty()) { return resultList.get(0); } return entity; }