List of usage examples for javax.persistence.criteria CriteriaBuilder equal
Predicate equal(Expression<?> x, Object y);
From source file:com.qpark.eip.core.model.analysis.AnalysisDao.java
/** * Get the {@link FieldMappingType} with the id. * * @param modelVersion//from w w w . j a v a 2 s. c om * the model version. * @param id * the id to return. * @return the {@link FieldMappingType}. * @since 3.5.1 */ @Transactional(value = EipModelAnalysisPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED) public Optional<FieldMappingType> getFieldMappingTypeById(final String modelVersion, final String id) { final CriteriaBuilder cb = this.em.getCriteriaBuilder(); final CriteriaQuery<FieldMappingType> q = cb.createQuery(FieldMappingType.class); final Root<FieldMappingType> f = q.from(FieldMappingType.class); q.where(cb.equal(f.<String>get(FieldMappingType_.modelVersion), modelVersion), cb.equal(f.<String>get(FieldMappingType_.id), id)); final TypedQuery<FieldMappingType> typedQuery = this.em.createQuery(q); final List<FieldMappingType> list = typedQuery.getResultList(); final Optional<FieldMappingType> value = list.stream().findFirst(); value.ifPresent(ct -> EagerLoader.load(ct)); return value; }
From source file:com.sfs.captor.controller.AlternativeFlowAction.java
/** * check for duplicate alternative flow//from w w w . j av a2 s.c om */ private boolean checkForDuplicateBusinessRule(String name) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<FlowStepRule> c = cb.createQuery(FlowStepRule.class); Root<FlowStepRule> obj = c.from(FlowStepRule.class); c.select(obj).where(cb.equal(obj.get("name"), name)); List<FlowStepRule> list = em.createQuery(c).getResultList(); return (list.size() > 0); }
From source file:com.expressui.sample.view.account.AccountQuery.java
@Override public List<Predicate> buildCriteria(CriteriaBuilder builder, Root<Account> rootEntity) { List<Predicate> criteria = new ArrayList<Predicate>(); if (!isEmpty(name)) { ParameterExpression<String> p = builder.parameter(String.class, "name"); criteria.add(builder.like(builder.upper(rootEntity.<String>get("name")), p)); }/*from w w w. j a va2s . com*/ if (!isEmpty(states)) { ParameterExpression<Set> p = builder.parameter(Set.class, "states"); criteria.add(builder.in(rootEntity.get("billingAddress").get("state")).value(p)); } if (!isEmpty(country)) { ParameterExpression<Country> p = builder.parameter(Country.class, "country"); criteria.add(builder.equal(rootEntity.get("billingAddress").get("country"), p)); } return criteria; }
From source file:ch.puzzle.itc.mobiliar.business.resourcerelation.control.ResourceRelationService.java
protected List<AbstractResourceRelationEntity> getConsumedRelationsByMasterAndSlave( ResourceEntity masterResource, Set<ResourceEntity> slaveResources, String identifier) { List<AbstractResourceRelationEntity> consumed = new ArrayList<>(); CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<ConsumedResourceRelationEntity> q = cb.createQuery(ConsumedResourceRelationEntity.class); Root<ConsumedResourceRelationEntity> r = q.from(ConsumedResourceRelationEntity.class); Predicate masterResourceIs = cb.equal(r.<ResourceEntity>get("masterResource"), masterResource); Predicate slaveResourceIn = r.<ResourceEntity>get("slaveResource").in(slaveResources); if (!StringUtils.isEmpty(identifier)) { Predicate identifierIs = cb.equal(r.<String>get("identifier"), identifier); q.where(cb.and(masterResourceIs, slaveResourceIn, identifierIs)); } else {/*from w w w.ja v a 2 s. co m*/ q.where(cb.and(masterResourceIs, slaveResourceIn)); } TypedQuery<ConsumedResourceRelationEntity> query = entityManager.createQuery(q); List<ConsumedResourceRelationEntity> result = query.getResultList(); for (ConsumedResourceRelationEntity rel : result) { consumed.add(rel); } return consumed; }
From source file:ch.puzzle.itc.mobiliar.business.resourcerelation.control.ResourceRelationService.java
protected List<AbstractResourceRelationEntity> getProvidedRelationsByMasterAndSlave( ResourceEntity masterResource, Set<ResourceEntity> slaveResources, String identifier) { List<AbstractResourceRelationEntity> provided = new ArrayList<>(); CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<ProvidedResourceRelationEntity> q = cb.createQuery(ProvidedResourceRelationEntity.class); Root<ProvidedResourceRelationEntity> r = q.from(ProvidedResourceRelationEntity.class); Predicate masterResourceIs = cb.equal(r.<ResourceEntity>get("masterResource"), masterResource); Predicate slaveResourceIn = r.<ResourceEntity>get("slaveResource").in(slaveResources); if (!StringUtils.isEmpty(identifier)) { Predicate identifierIs = cb.equal(r.<String>get("identifier"), identifier); q.where(cb.and(masterResourceIs, slaveResourceIn, identifierIs)); } else {/*w w w. ja v a 2 s . c om*/ q.where(cb.and(masterResourceIs, slaveResourceIn)); } TypedQuery<ProvidedResourceRelationEntity> query = entityManager.createQuery(q); List<ProvidedResourceRelationEntity> result = query.getResultList(); for (ProvidedResourceRelationEntity rel : result) { provided.add(rel); } return provided; }
From source file:com.expressui.core.dao.security.query.RoleQuery.java
@Override public List<Predicate> buildCriteria(CriteriaBuilder builder, CriteriaQuery<Role> query, Root<Role> role) { List<Predicate> predicates = new ArrayList<Predicate>(); if (hasValue(name)) { ParameterExpression<String> nameExp = builder.parameter(String.class, "name"); predicates.add(builder.like(builder.upper(role.<String>get("name")), nameExp)); }/* ww w. j av a 2 s.c o m*/ if (hasValue(doesNotBelongToUser)) { Subquery<Role> subquery = query.subquery(Role.class); Root<UserRole> userRole = subquery.from(UserRole.class); ParameterExpression<User> userExp = builder.parameter(User.class, "doesNotBelongToUser"); subquery.select(userRole.<Role>get("role")).where(builder.equal(userRole.get("user"), userExp)); predicates.add(builder.not(role.in(subquery))); } return predicates; }
From source file:com.qpark.eip.core.model.analysis.AnalysisDao.java
private List<String> getFlowProcessTypeIds(final String modelVersion, final String flowId) { final CriteriaBuilder cb = this.em.getCriteriaBuilder(); final CriteriaQuery<String> q = cb.createQuery(String.class); final Root<FlowProcessType> f = q.from(FlowProcessType.class); q.select(f.<String>get(FlowProcessType_.id)); q.where(cb.equal(f.<String>get(FlowProcessType_.modelVersion), modelVersion), cb.equal(f.<String>get(FlowProcessType_.parentId), flowId)); q.orderBy(cb.asc(f.<Long>get(FlowProcessType_.hjid))); final TypedQuery<String> typedQuery = this.em.createQuery(q); final List<String> value = typedQuery.getResultList(); return value; }
From source file:com.expressui.sample.view.contact.ContactQuery.java
@Override public List<Predicate> buildCriteria(CriteriaBuilder builder, Root<Contact> rootEntity) { List<Predicate> criteria = new ArrayList<Predicate>(); if (!isEmpty(lastName)) { ParameterExpression<String> p = builder.parameter(String.class, "lastName"); criteria.add(builder.like(builder.upper(rootEntity.<String>get("lastName")), p)); }/* w w w . j a va 2s . c o m*/ if (!isEmpty(states)) { ParameterExpression<Set> p = builder.parameter(Set.class, "states"); criteria.add(builder.in(rootEntity.get("mailingAddress").get("state")).value(p)); } if (!isEmpty(country)) { ParameterExpression<Country> p = builder.parameter(Country.class, "country"); criteria.add(builder.equal(rootEntity.get("mailingAddress").get("country"), p)); } return criteria; }
From source file:com.qpark.eip.core.model.analysis.AnalysisDao.java
/** * Check if the {@link EnterpriseType} with given name and modelVersion * exists./*from w w w. j av a 2 s. co m*/ * * @param name * the name of the {@link EnterpriseType}. * @param modelVersion * the version of the model. * @return <code>true</code> if exists, else <code>false</code>. */ @Transactional(value = EipModelAnalysisPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED) public boolean existsEnterprise(final String name, final String modelVersion) { boolean value = false; final CriteriaBuilder cb = this.em.getCriteriaBuilder(); final CriteriaQuery<Long> q = cb.createQuery(Long.class); final Root<EnterpriseType> f = q.from(EnterpriseType.class); q.select(f.<Long>get(EnterpriseType_.hjid)); q.where(cb.equal(f.<String>get(EnterpriseType_.name), name), cb.equal(f.<String>get(EnterpriseType_.modelVersion), modelVersion)); final TypedQuery<Long> typedQuery = this.em.createQuery(q); try { final Long l = typedQuery.getSingleResult(); if (l != null && l.longValue() != 0) { value = true; } } catch (final Exception e) { value = false; } return value; }
From source file:com.expressui.core.dao.security.query.UserQuery.java
@Override public List<Predicate> buildCriteria(CriteriaBuilder builder, CriteriaQuery<User> query, Root<User> user) { List<Predicate> predicates = new ArrayList<Predicate>(); if (hasValue(loginName)) { ParameterExpression<String> loginNameExp = builder.parameter(String.class, "loginName"); predicates.add(builder.like(builder.upper(user.<String>get("loginName")), loginNameExp)); }/*from w w w.j a v a 2s.co m*/ if (hasValue(doesNotBelongToRole)) { Subquery<User> subquery = query.subquery(User.class); Root userRole = subquery.from(UserRole.class); ParameterExpression<Role> role = builder.parameter(Role.class, "doesNotBelongToRole"); subquery.select(userRole.get("user")).where(builder.equal(userRole.get("role"), role)); predicates.add(builder.not(user.in(subquery))); } return predicates; }