List of usage examples for javax.persistence.criteria Root get
<Y> Path<Y> get(SingularAttribute<? super X, Y> attribute);
From source file:com.sfs.ucm.controller.HelpContentAction.java
/** * load resources/*from w w w .java 2 s . c o m*/ * * @throws UCMException */ private void loadList() throws UCMException { try { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Help> c = cb.createQuery(Help.class); Root<Help> obj = c.from(Help.class); c.select(obj).orderBy(cb.asc(obj.get("keyword"))); this.helpItems = em.createQuery(c).getResultList(); this.itemCount = this.helpItems.size(); } catch (Exception e) { throw new UCMException(e); } }
From source file:edu.umm.radonc.ca_dash.model.ActivityFacade.java
public List<ActivityAIPC> itemsDateRange(Date start, Date end, int[] range) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(ActivityAIPC.class); Root<ActivityAIPC> rt = cq.from(ActivityAIPC.class); cq.where(cb.and(rt.get(ActivityAIPC_.fromdateofservice).isNotNull(), cb.and(cb.notEqual(rt.get(ActivityAIPC_.procedurecodeser), 528), cb.notEqual(rt.get(ActivityAIPC_.procedurecodeser), 529), cb.notEqual(rt.get(ActivityAIPC_.procedurecodeser), 530), cb.between(rt.get(ActivityAIPC_.fromdateofservice), start, end)))); cq.orderBy(cb.asc(rt.get(ActivityAIPC_.fromdateofservice))); Query q = em.createQuery(cq); q.setMaxResults(range[1] - range[0] + 1); q.setFirstResult(range[0]);//from w ww . j ava 2 s . c om return q.getResultList(); }
From source file:edu.umm.radonc.ca_dash.model.ActivityFacade.java
public int itemsDateRangeCount(Date start, Date end) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(ActivityAIPC.class); Root<ActivityAIPC> rt = cq.from(ActivityAIPC.class); cq.select(cb.count(rt.get(ActivityAIPC_.actinstproccodeser))); cq.where(cb.and(rt.get(ActivityAIPC_.fromdateofservice).isNotNull(), cb.and(cb.notEqual(rt.get(ActivityAIPC_.procedurecodeser), 528), cb.notEqual(rt.get(ActivityAIPC_.procedurecodeser), 529), cb.notEqual(rt.get(ActivityAIPC_.procedurecodeser), 530), cb.between(rt.get(ActivityAIPC_.fromdateofservice), start, end)))); Query q = em.createQuery(cq); return ((Long) (q.getSingleResult())).intValue(); }
From source file:com.alliander.osgp.adapter.ws.infra.specifications.JpaDeviceSpecifications.java
@Override public Specification<Device> forFirmwareModuleVersion(final FirmwareModuleFilterType firmwareModuleFilterType, final String firmwareModuleVersion) throws ArgumentNullOrEmptyException { if (StringUtils.isEmpty(firmwareModuleVersion)) { throw new ArgumentNullOrEmptyException("firmwareModuleVersion"); }/* ww w . j a va2s . co m*/ if (firmwareModuleFilterType == null) { throw new ArgumentNullOrEmptyException("firmwareModuleType"); } return new Specification<Device>() { @Override public Predicate toPredicate(final Root<Device> deviceRoot, final CriteriaQuery<?> query, final CriteriaBuilder cb) { String moduleFieldName = ""; switch (firmwareModuleFilterType) { case COMMUNICATION: moduleFieldName = "moduleVersionComm"; break; case FUNCTIONAL: moduleFieldName = "moduleVersionFunc"; break; case SECURITY: moduleFieldName = "moduleVersionSec"; break; case M_BUS: moduleFieldName = "moduleVersionMbus"; break; case MODULE_ACTIVE: moduleFieldName = "moduleVersionMa"; break; case ACTIVE_FIRMWARE: break; default: break; } final Subquery<Long> subquery = query.subquery(Long.class); final Root<DeviceFirmware> deviceFirmwareRoot = subquery.from(DeviceFirmware.class); subquery.select(deviceFirmwareRoot.get("device").get("id").as(Long.class)); subquery.where(cb.and( cb.like(cb.upper(deviceFirmwareRoot.get("firmware").<String>get(moduleFieldName)), firmwareModuleVersion.toUpperCase()), cb.equal(deviceFirmwareRoot.<Boolean>get("active"), true))); return cb.in(deviceRoot.get("id").as(Long.class)).value(subquery); } }; }
From source file:bq.jpa.demo.query.criteria.service.CriteriaService.java
/** * subquery: in/*from w w w .j a va 2s. c o m*/ * SELECT e FROM jpa_query_employee e WHERE e IN (SELECT emp FROM jpa_query_project p JOIN p.employees pe WHERE p.name = :projectname) */ @Transactional public void doWhere1() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Employee> c = cb.createQuery(Employee.class); Root<Employee> e = c.from(Employee.class); // subquery Subquery<Employee> sq = c.subquery(Employee.class); Root<Project> p = sq.from(Project.class); Join<Project, Employee> pe = p.join("employees"); sq.select(pe).where(cb.equal(p.get("name"), cb.parameter(String.class, "projectname"))); // c.select(e).where(cb.in(e).value(sq)); }
From source file:com.aimdek.ccm.dao.impl.CreditCardRepositoryImpl.java
/** * Adds the sorting./*from ww w . j av a 2 s . c o m*/ * * @param sortField the sort field * @param sortOrder the sort order * @param query the query * @param builder the builder * @param root the root */ private void addSorting(String sortField, String sortOrder, CriteriaQuery query, CriteriaBuilder builder, Root<CreditCard> root) { if (CommonUtil.isNotNull(sortField) && (sortField.equalsIgnoreCase(FIELDCONSTANT_CARDNUMBER) || sortField.equalsIgnoreCase(FIELDCONSTANT_CREDITLIMIT) || sortField.equalsIgnoreCase(FIELDCONSTANT_BALANCE))) { if (sortOrder.startsWith(SORT_ORDER_ASCENDING)) { query.orderBy(builder.asc(root.get(sortField))); } else { query.orderBy(builder.desc(root.get(sortField))); } } }
From source file:org.jnap.core.persistence.jpa.DaoSupport.java
@Override public boolean exists(Serializable id) { CriteriaBuilder builder = getCriteriaBuilder(); CriteriaQuery<Long> count = builder.createQuery(Long.class); Root<?> root = count.from(getEntityClass()); count.select(builder.count(root));//from w w w . j a v a 2 s. c o m count.where(builder.equal(root.get("id"), id)); return entityManager.createQuery(count).getSingleResult() == 1; }
From source file:com.sfs.captor.controller.RequirementAction.java
/** * load requirements//from w w w . j a va 2 s . c om */ private void loadList() throws UCMException { Set<String> versions = this.projectService.findActiveProductReleaseVersions(this.authUser, this.project); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Requirement> c = cb.createQuery(Requirement.class); Root<Requirement> obj = c.from(Requirement.class); c.select(obj).where(cb.equal(obj.get("project"), this.project), obj.get("productRelease").get("version").in(versions)).orderBy(cb.asc(obj.get("id"))); this.requirements = em.createQuery(c).getResultList(); }
From source file:eu.uqasar.service.dataadapter.JiraDataService.java
/** * /*from w ww . j a va 2 s . c om*/ * @param first * @param count * @return */ public List<JiraMetricMeasurement> getAllByAscendingName(int first, int count) { logger.infof("loading all JiraMetricMeasurement ordered by ascending name ..."); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<JiraMetricMeasurement> criteria = cb.createQuery(JiraMetricMeasurement.class); Root<JiraMetricMeasurement> root = criteria.from(JiraMetricMeasurement.class); criteria.orderBy(cb.asc(root.get(JiraMetricMeasurement_.self))); return em.createQuery(criteria).setFirstResult(first).setMaxResults(count).getResultList(); }
From source file:com.sfs.captor.controller.RequirementAction.java
/** * find tests associated with this artifact *//*from w ww . j a va 2s . c om*/ private List<RequirementTest> findRequirementTests(Requirement requirement) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<RequirementTest> c = cb.createQuery(RequirementTest.class); Root<RequirementTest> obj = c.from(RequirementTest.class); c.select(obj).where(cb.equal(obj.get("requirement"), requirement)); return em.createQuery(c).getResultList(); }