List of usage examples for javax.persistence.criteria Root get
<Y> Path<Y> get(SingularAttribute<? super X, Y> attribute);
From source file:org.businessmanager.dao.security.UserDaoImpl.java
@Override public User findUserByName(String username) { CriteriaBuilder queryBuilder = getEntityManager().getCriteriaBuilder(); CriteriaQuery<User> query = queryBuilder.createQuery(User.class); Root<User> userQuery = query.from(User.class); query.select(userQuery).where(queryBuilder.equal(userQuery.get(User_.username), username)); try {/*from w w w.j a v a 2s . c om*/ return getEntityManager().createQuery(query).getSingleResult(); } catch (NoResultException e) { return null; } }
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(); }
From source file:com.ttech.cordovabuild.domain.application.ApplicationRepositoryImpl.java
@Override public ApplicationBuilt getLatestBuilt(Application application) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<ApplicationBuilt> cq = cb.createQuery(ApplicationBuilt.class); Root<ApplicationBuilt> from = cq.from(ApplicationBuilt.class); cq = cq.where(cb.equal(from.get(ApplicationBuilt_.application), application)) .orderBy(cb.desc(from.get(ApplicationBuilt_.startDate))); try {/*from w w w. j a va 2 s . c o m*/ return em.createQuery(cq).setMaxResults(1).getSingleResult(); } catch (NoResultException e) { throw new ApplicationBuiltNotFoundException(e); } }
From source file:de.ks.idnadrev.information.view.InformationOverviewDS.java
protected List<Tag> getTags(List<String> tagNames, EntityManager em) { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Tag> query = builder.createQuery(Tag.class); Root<Tag> root = query.from(Tag.class); Path<String> namePath = root.get(KEY_NAME); query.select(root);/*w ww . j a v a2s . c o m*/ query.where(namePath.in(tagNames)); return em.createQuery(query).getResultList(); }
From source file:eu.uqasar.service.company.CompanyService.java
/** * //from www . jav a2s.c o m * @param innovationObjective * @return */ public List<Company> getAllByAscendingName() { logger.infof("loading all Company ordered by ascending name ..."); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Company> criteria = cb.createQuery(Company.class); Root<Company> root = criteria.from(Company.class); criteria.orderBy(cb.asc(root.get(Company_.name))); return em.createQuery(criteria).getResultList(); }
From source file:eu.uqasar.service.company.CompanyService.java
/** * //ww w.jav a 2s . c o m * @param companyId * @return */ public boolean companyExists(Long companyId) { logger.info(String.format("checking if Company with ID %d exists ...", companyId)); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> criteria = cb.createQuery(Long.class); Root<Company> from = criteria.from(Company.class); criteria.where(cb.equal(from.get(Company_.id), companyId)); criteria.select(cb.countDistinct(from)); return (em.createQuery(criteria).getSingleResult().longValue() == 1); }
From source file:de.logicline.splash.dao.ContactDaoImpl.java
public ContactEntity getContactByUserId(String userId) { CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); CriteriaQuery<ContactEntity> cq = cb.createQuery(ContactEntity.class); Root<ContactEntity> userInfo = cq.from(ContactEntity.class); cq.select(userInfo);//from w w w . j av a 2 s. co m cq.where(cb.equal(userInfo.get("userIdFk"), userId)); List<ContactEntity> resultList = em.createQuery(cq).getResultList(); ContactEntity result = null; if (resultList != null && resultList.size() > 0) { result = resultList.get(0); } return result; }
From source file:aka.pirana.jdoc.JChart.java
private XYDataset SampleGenerator() { manager.getTransaction().begin();//from w w w.j a va 2 s .c om 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:eu.uqasar.service.company.CompanyService.java
public long countAllFiltered(final CompanyFilterStructure filter) { logger.infof("counting all Companies matching the filter %s ...", filter); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> criteria = cb.createQuery(Long.class); Root<Company> from = criteria.from(Company.class); criteria.where(cb.or(cb.equal(from.get(Company_.name), filter.getName()), cb.equal(from.get(Company_.shortName), filter.getShortName()), cb.equal(from.get(Company_.country), filter.getCountry()))); criteria.select(cb.countDistinct(from)); return em.createQuery(criteria).getSingleResult(); }
From source file:com.datapine.dao.impl.UserDAOImpl.java
/** * Looks for the user by email./* w w w . j a va 2 s. c om*/ * @param email The specified email. * @return Found user. */ @Override public final User findByEmail(final String email) { final CriteriaBuilder builder = this.manager.getCriteriaBuilder(); final CriteriaQuery<User> query = builder.createQuery(User.class); final Root<User> root = query.from(User.class); query.where(builder.equal(root.get("email"), email)); return this.manager.createQuery(query).getResultList().get(0); }