List of usage examples for javax.persistence.criteria CriteriaBuilder equal
Predicate equal(Expression<?> x, Object y);
From source file:net.groupbuy.dao.impl.ProductDaoImpl.java
public Page<Product> findPage(Member member, Pageable pageable) { if (member == null) { return new Page<Product>(Collections.<Product>emptyList(), 0, pageable); }/*w w w. j ava 2 s . co m*/ CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Product> criteriaQuery = criteriaBuilder.createQuery(Product.class); Root<Product> root = criteriaQuery.from(Product.class); criteriaQuery.select(root); criteriaQuery.where(criteriaBuilder.equal(root.join("favoriteMembers"), member)); return super.findPage(criteriaQuery, pageable); }
From source file:org.openlmis.migration.tool.openlmis.referencedata.repository.custom.impl.OlmisFacilityTypeApprovedProductRepositoryImpl.java
@Override public Collection<FacilityTypeApprovedProduct> searchProducts(UUID facilityId, UUID programId, boolean fullSupply) { checkNotNull(facilityId);/* w ww. j ava 2 s . c o m*/ CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<FacilityTypeApprovedProduct> query = builder.createQuery(FacilityTypeApprovedProduct.class); Root<FacilityTypeApprovedProduct> ftap = query.from(FacilityTypeApprovedProduct.class); Root<Facility> facility = query.from(Facility.class); Join<Facility, FacilityType> fft = facility.join("type"); Join<FacilityTypeApprovedProduct, FacilityType> ft = ftap.join("facilityType"); Join<FacilityTypeApprovedProduct, ProgramOrderable> pp = ftap.join("programOrderable"); Join<ProgramOrderable, Program> program = pp.join("program"); Predicate conjunction = builder.conjunction(); if (programId != null) { conjunction = builder.and(conjunction, builder.equal(program.get("id"), programId)); } conjunction = builder.and(conjunction, builder.equal(fft.get("id"), ft.get("id"))); conjunction = builder.and(conjunction, builder.equal(facility.get("id"), facilityId)); conjunction = builder.and(conjunction, builder.equal(pp.get("fullSupply"), fullSupply)); conjunction = builder.and(conjunction, builder.isTrue(pp.get("active"))); query.select(ftap); query.where(conjunction); Join<ProgramOrderable, OrderableDisplayCategory> category = pp.join("orderableDisplayCategory"); Join<ProgramOrderable, Orderable> orderable = pp.join("product"); query.orderBy(builder.asc(category.get("orderedDisplayValue").get("displayOrder")), builder.asc(category.get("orderedDisplayValue").get("displayName")), builder.asc(orderable.get("productCode"))); return entityManager.createQuery(query).getResultList(); }
From source file:com.sfs.captor.controller.UseCaseFlowAction.java
/** * check for duplicate alternative flow// w w w .j a va 2 s . c o m */ private boolean checkForDuplicateAlternateFlow(final UseCase useCase, final String name) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Flow> c = cb.createQuery(Flow.class); Root<Flow> obj = c.from(Flow.class); c.select(obj).where(cb.equal(obj.<String>get("name"), name), cb.equal(obj.get("useCase"), useCase)); List<Flow> list = em.createQuery(c).getResultList(); return (list.size() > 0); }
From source file:com.expressui.sample.dao.query.AccountQuery.java
@Override public List<Predicate> buildCriteria(CriteriaBuilder builder, CriteriaQuery<Account> query, Root<Account> account) {/*ww w .j a v a 2 s. co m*/ List<Predicate> predicates = new ArrayList<Predicate>(); if (hasValue(name)) { ParameterExpression<String> nameExp = builder.parameter(String.class, "name"); predicates.add(builder.like(builder.upper(account.<String>get("name")), nameExp)); } if (hasValue(states)) { ParameterExpression<Set> statesExp = builder.parameter(Set.class, "states"); predicates.add(builder.in(account.get("billingAddress").get("state")).value(statesExp)); } if (hasValue(country)) { ParameterExpression<Country> countryExp = builder.parameter(Country.class, "country"); predicates.add(builder.equal(account.get("billingAddress").get("country"), countryExp)); } return predicates; }
From source file:com.aimdek.ccm.dao.impl.TransactionRepositoryImpl.java
/** * Adds the filter criteria./* www . ja v a 2s . co m*/ * * @param userId * the user id * @param filters * the filters * @param builder * the builder * @param root * the root * @param query * the query */ private void addFilterCriteria(long userId, Map<String, Object> filters, CriteriaBuilder builder, Root<Transaction> root, CriteriaQuery query) { List<Predicate> predicates = new ArrayList<Predicate>(); if (!filters.isEmpty()) { for (Entry<String, Object> entry : filters.entrySet()) { if (CommonUtil.isNotNull(root.get(entry.getKey()))) { predicates.add(builder.like(root.<String>get(entry.getKey()), entry.getValue() + MODULO)); } } } if (CommonUtil.isNotNull(userId)) { User user = userRepository.findById(userId); if (CommonUtil.isNotNull(user) && user.getRole().equals(ROLE_CUSTOMER)) { predicates.add(builder.equal(root.<Long>get(FIELDCONSTANT_USERID), user.getId())); } } query.where(predicates.toArray(new Predicate[] {})); }
From source file:ch.puzzle.itc.mobiliar.business.resourcerelation.control.ResourceRelationService.java
public List<ConsumedResourceRelationEntity> getConsumedSlaveRelations(ResourceEntity slaveResource) { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<ConsumedResourceRelationEntity> q = cb.createQuery(ConsumedResourceRelationEntity.class); Root<ConsumedResourceRelationEntity> r = q.from(ConsumedResourceRelationEntity.class); Join<ConsumedResourceRelationEntity, ResourceEntity> slaveResourceJoin = r.join("slaveResource"); q.where(cb.equal(slaveResourceJoin.get("id"), slaveResource.getId())); TypedQuery<ConsumedResourceRelationEntity> query = entityManager.createQuery(q); return query.getResultList(); }
From source file:ch.puzzle.itc.mobiliar.business.resourcerelation.control.ResourceRelationService.java
public List<ProvidedResourceRelationEntity> getProvidedSlaveRelations(ResourceEntity slaveResource) { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<ProvidedResourceRelationEntity> q = cb.createQuery(ProvidedResourceRelationEntity.class); Root<ProvidedResourceRelationEntity> r = q.from(ProvidedResourceRelationEntity.class); Join<ProvidedResourceRelationEntity, ResourceEntity> slaveResourceJoin = r.join("slaveResource"); q.where(cb.equal(slaveResourceJoin.get("id"), slaveResource.getId())); TypedQuery<ProvidedResourceRelationEntity> query = entityManager.createQuery(q); return query.getResultList(); }
From source file:com.alliander.osgp.adapter.ws.infra.specifications.JpaDeviceSpecifications.java
@Override public Specification<Device> forOwner(final String organisation) throws ArgumentNullOrEmptyException { if (organisation == null) { throw new ArgumentNullOrEmptyException("owner"); }/* w w w. ja v a 2 s. com*/ return new Specification<Device>() { @Override public Predicate toPredicate(final Root<Device> deviceRoot, final CriteriaQuery<?> query, final CriteriaBuilder cb) { final Subquery<Long> subquery = query.subquery(Long.class); final Root<DeviceAuthorization> deviceAuthorizationRoot = subquery.from(DeviceAuthorization.class); subquery.select(deviceAuthorizationRoot.get("device").get("id").as(Long.class)); subquery.where(cb.and( cb.like(cb.upper(deviceAuthorizationRoot.get("organisation").<String>get("name")), organisation.toUpperCase()), cb.equal(deviceAuthorizationRoot.get("functionGroup"), DeviceFunctionGroup.OWNER.ordinal()))); return cb.in(deviceRoot.get("id")).value(subquery); } }; }
From source file:com.qpark.eip.core.model.analysis.AnalysisDao.java
/** * Get the list of {@link FieldMappingType} with the ids. * * @param modelVersion//from ww w .j a v a 2s .c om * the model version. * @param ids * the list of ids to return. * @return the list of {@link FieldMappingType}. * @since 3.5.1 */ @Transactional(value = EipModelAnalysisPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED) public List<FieldMappingType> getFieldMappingTypesById(final String modelVersion, final List<String> ids) { final CriteriaBuilder cb = this.em.getCriteriaBuilder(); final CriteriaQuery<FieldMappingType> q = cb.createQuery(FieldMappingType.class); final Root<FieldMappingType> f = q.from(FieldMappingType.class); final Predicate orIds = cb.disjunction(); ids.stream().forEach(id -> orIds.getExpressions().add(cb.equal(f.<String>get(FieldMappingType_.id), id))); q.where(cb.equal(f.<String>get(FieldMappingType_.modelVersion), modelVersion), orIds); final TypedQuery<FieldMappingType> typedQuery = this.em.createQuery(q); final List<FieldMappingType> value = typedQuery.getResultList(); value.stream().forEach(ct -> EagerLoader.load(ct)); return value; }