List of usage examples for javax.persistence.criteria CriteriaQuery where
CriteriaQuery<T> where(Predicate... restrictions);
From source file:de.logicline.splash.dao.UserDaoImpl.java
public UserEntity getUser(String token) { CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); CriteriaQuery<UserEntity> cq = cb.createQuery(UserEntity.class); Root<UserEntity> user = cq.from(UserEntity.class); cq.select(user);//from w w w . j a v a 2 s . c o m cq.where(cb.equal(user.get("token"), token)); List<UserEntity> resultList = getEntityManager().createQuery(cq).getResultList(); UserEntity result = null; if (resultList != null && resultList.size() > 0) { result = resultList.get(0); return result; } return null; }
From source file:de.logicline.splash.dao.UserDaoImpl.java
public UserEntity getUserByName(String username) { CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); CriteriaQuery<UserEntity> cq = cb.createQuery(UserEntity.class); Root<UserEntity> user = cq.from(UserEntity.class); cq.select(user);/*from w w w. j a v a 2 s . c om*/ cq.where(cb.equal(user.get("username"), username)); List<UserEntity> resultList = getEntityManager().createQuery(cq).getResultList(); if (resultList == null || resultList.size() == 0) { log.debug("UserEntity not found"); return null; } else if (resultList.size() > 1) { log.warn("Multiple Users found for User with Username: " + username); return null; } return resultList.get(0); }
From source file:aka.pirana.jdoc.JChart.java
private XYDataset SampleGenerator() { manager.getTransaction().begin();/*from w w w . j a va 2 s . c o m*/ CriteriaBuilder cb = manager.getCriteriaBuilder(); CriteriaQuery<Consultation> query = cb.createQuery(Consultation.class); Root<Consultation> sm = query.from(Consultation.class); query.where(cb.equal(sm.get("patient.id"), id.toString())); TypedQuery<Consultation> q = manager.createQuery(query); List<Consultation> results = q.getResultList(); XYSeries xyWeightSeries = new XYSeries("Weight"); XYSeries xyFatSeries = new XYSeries("Fat"); XYSeries xyMuscleSeries = new XYSeries("Muscle"); XYSeries xyWaterSeries = new XYSeries("Water"); int i = 2; results.stream().map((result) -> { xyWeightSeries.add(i, result.getC_weight()); return result; }).map((result) -> { xyFatSeries.add(i, result.getC_gm()); return result; }).map((result) -> { xyMuscleSeries.add(i, result.getC_mm()); return result; }).forEach((result) -> { xyWaterSeries.add(i, result.getC_hm()); }); XYSeriesCollection xyseriescollection = new XYSeriesCollection(xyWeightSeries); xyseriescollection.addSeries(xyFatSeries); xyseriescollection.addSeries(xyMuscleSeries); xyseriescollection.addSeries(xyWaterSeries); return xyseriescollection; }
From source file:com.juliuskrah.multipart.repository.impl.HibernateAccountRepository.java
@Override public Stream<Account> findByLastName(String lastName) { Session session = this.em.unwrap(Session.class); CriteriaBuilder qb = session.getCriteriaBuilder(); CriteriaQuery<Account> cq = qb.createQuery(Account.class); Root<Account> root = cq.from(Account.class); Predicate predicate = qb.like(root.get(Account_.lastName), lastName); cq.where(predicate); return session.createQuery(cq).stream(); }
From source file:org.jdal.dao.jpa.JpaUtils.java
/** * Copy criteria without selection and order. * @param from source Criteria./*from w w w.ja va 2 s . com*/ * @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:com.juliuskrah.multipart.repository.impl.HibernateAccountRepository.java
@Override public Optional<Account> findByUsername(String username) { CriteriaBuilder qb = this.em.getCriteriaBuilder(); CriteriaQuery<Account> query = qb.createQuery(Account.class); Root<Account> root = query.from(Account.class); Predicate predicate = qb.like(root.get(Account_.username), username); query.where(predicate); Query q = this.em.createQuery(query); return Optional.of((Account) q.getSingleResult()); }
From source file:net.groupbuy.dao.impl.FriendLinkDaoImpl.java
public List<FriendLink> findList(Type type) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<FriendLink> criteriaQuery = criteriaBuilder.createQuery(FriendLink.class); Root<FriendLink> root = criteriaQuery.from(FriendLink.class); criteriaQuery.select(root);// ww w. j a v a 2 s .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(); }
From source file:net.groupbuy.dao.impl.NavigationDaoImpl.java
public List<Navigation> findList(Position position) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Navigation> criteriaQuery = criteriaBuilder.createQuery(Navigation.class); Root<Navigation> root = criteriaQuery.from(Navigation.class); criteriaQuery.select(root);//from w ww . j a va 2 s.c o m if (position != null) { criteriaQuery.where(criteriaBuilder.equal(root.get("position"), position)); } criteriaQuery.orderBy(criteriaBuilder.asc(root.get("order"))); return entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT).getResultList(); }
From source file:com.github.aynu.mosir.core.enterprise.persistence.SmartRepositoryProducer.java
/** * ???/* w ww. ja v a2 s . com*/ * @return ?() */ @Produces public SmartRepository<Testee, TesteeFilter> createTestee() { final SmartRepositoryListener<Testee, TesteeFilter> listener = new AbstractSmartRepositoryListener<Testee, TesteeFilter>() { @Override public CriteriaQuery<Testee> query(final CriteriaBuilder builder, final CriteriaQuery<Testee> query, final Root<Testee> root, final TesteeFilter filter) { query.select(root); if (StringUtils.isNotEmpty(filter.getCode())) { query.where(builder.equal(root.get("code"), filter.getCode())); } return query.orderBy(createOrders(builder, root, filter)); } }; return new SmartRepositoryImpl<>(Testee.class, manager, listener); }
From source file:org.wallride.repository.CategoryRepositoryImpl.java
@Override public void lock(long id) { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<Long> query = cb.createQuery(Long.class); Root<Category> root = query.from(Category.class); query.select(root.get(Category_.id)); query.where(cb.equal(root.get(Category_.id), id)); entityManager.createQuery(query).setLockMode(LockModeType.PESSIMISTIC_WRITE).getSingleResult(); }