List of usage examples for javax.persistence.criteria CriteriaBuilder upper
Expression<String> upper(Expression<String> x);
From source file:com.expressui.sample.dao.query.OpportunityQuery.java
@Override public List<Predicate> buildCriteria(CriteriaBuilder builder, CriteriaQuery<Opportunity> query, Root<Opportunity> opportunity) { List<Predicate> predicates = new ArrayList<Predicate>(); if (hasValue(accountName)) { ParameterExpression<String> accountNameExp = builder.parameter(String.class, "accountName"); predicates.add(// w w w. j a v a2 s . c o m builder.like(builder.upper(opportunity.get("account").<String>get("name")), accountNameExp)); } if (hasValue(salesStages)) { ParameterExpression<Set> salesStagesExp = builder.parameter(Set.class, "salesStages"); predicates.add(builder.in(opportunity.get("salesStage")).value(salesStagesExp)); } return predicates; }
From source file:org.sloth.persistence.impl.ObservationDaoImpl.java
@Override public Collection<Observation> getByKeyWord(String key) throws NullPointerException { if (key == null) { throw new NullPointerException(); }/*from w w w.ja v a 2 s.c om*/ key = "%" + key.trim().replace('*', '%').toUpperCase() + "%"; CriteriaBuilder b = getEntityManager().getCriteriaBuilder(); CriteriaQuery<Observation> q = b.createQuery(Observation.class); Root<Observation> o = q.from(Observation.class); Join<Observation, Categorie> j = o.join(Observation_.categorie); Collection<Observation> result = getEntityManager().createQuery(q.select(o).distinct(true) .where(b.or(b.like(b.upper(j.get(Categorie_.title)), key), b.like(b.upper(j.get(Categorie_.description)), key), b.like(b.upper(o.get(Observation_.title)), key), b.like(b.upper(o.get(Observation_.description)), key)))) .getResultList(); logger.info("Searched for {}. Got {} Results.", key, result.size()); return result; }
From source file:eu.uqasar.service.user.UserService.java
public List<User> getAllExceptAndFilter(Collection<User> usersToExclude, final String filter) { if (usersToExclude == null || usersToExclude.isEmpty()) { return this.getAll(); }/* www . j a va 2 s . c o m*/ logger.infof("loading all Users except %s ...", usersToExclude); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<User> query = cb.createQuery(User.class); Root<User> root = query.from(User.class); if (filter != null && !filter.isEmpty()) { Expression<String> literal = cb.upper(cb.literal(LIKE_WILDCARD + filter + LIKE_WILDCARD)); Predicate likeFirstName = cb.like(cb.upper(root.get(User_.firstName)), literal); Predicate likeLastName = cb.like(cb.upper(root.get(User_.lastName)), literal); Predicate likeUserName = cb.like(cb.upper(root.get(User_.userName)), literal); Predicate orLikeName = cb.or(likeFirstName, likeLastName, likeUserName); query.where(cb.and(cb.not(root.in(usersToExclude)), orLikeName)); } else { query.where(cb.not(root.in(usersToExclude))); } return em.createQuery(query).getResultList(); }
From source file:br.com.sementesdoamanha.repository.Servidores.java
public List<Servidor> filtrados(ServidorFilter filtro) { //select, from, where, like... --> select(), from(), where() //JPQL: from Servidor //JPQL: select s from Servidor s where c.nome like = 'Joo%' and c.cpf = like '046.244.901-77' CriteriaBuilder builder = manager.getCriteriaBuilder(); CriteriaQuery<Servidor> criteriaQuery = builder.createQuery(Servidor.class); Root<Servidor> s = criteriaQuery.from(Servidor.class); criteriaQuery.select(s);//from w w w .j a v a 2 s. c o m List<Predicate> predicates = new ArrayList<>(); if (StringUtils.isNotBlank(filtro.getCpf())) { predicates.add(builder.equal(s.<String>get("cpf"), filtro.getCpf())); } if (StringUtils.isNotBlank(filtro.getNome())) { predicates .add(builder.like(builder.upper(s.<String>get("nome")), filtro.getNome().toUpperCase() + "%")); } criteriaQuery.where(predicates.toArray(new Predicate[0])); TypedQuery<Servidor> query = manager.createQuery(criteriaQuery); return query.getResultList(); }
From source file:com.alliander.osgp.adapter.ws.infra.specifications.JpaDeviceSpecifications.java
@Override public Specification<Device> forManufacturer(final Manufacturer manufacturer) throws ArgumentNullOrEmptyException { if (manufacturer == null) { throw new ArgumentNullOrEmptyException("manufacturer"); }/*from w ww .ja va2s . c o m*/ 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<DeviceModel> deviceModelRoot = subquery.from(DeviceModel.class); subquery.select(deviceModelRoot.get("id").as(Long.class)); subquery.where(cb.equal(cb.upper(deviceModelRoot.get("manufacturerId").<String>get("name")), manufacturer.getName().toUpperCase())); return cb.in(deviceRoot.get("deviceModel").get("id").as(Long.class)).value(subquery); } }; }
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"); }/*from ww w. j a v a 2s . co m*/ 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.movies.dao.impl.BaseDaoImpl.java
@Override public <T> List<T> getObjectsByCriteria(Map<String, Object> map, Class returnClass, List<SingularAttribute> singleAttributes, List<ListAttribute> listAttributes, List<SetAttribute> setAttributes) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<T> cq = cb.createQuery(returnClass).distinct(true); Root<T> root = cq.from(returnClass); if (CollectionUtils.isNotEmpty(singleAttributes)) { for (SingularAttribute attribute : singleAttributes) { root.join(attribute);//from www . j av a2 s . co m root.fetch(attribute); } } if (CollectionUtils.isNotEmpty(listAttributes)) { for (ListAttribute attribute : listAttributes) { root.join(attribute, JoinType.LEFT); root.fetch(attribute, JoinType.LEFT); } } if (CollectionUtils.isNotEmpty(setAttributes)) { for (SetAttribute attribute : setAttributes) { root.join(attribute, JoinType.LEFT); root.fetch(attribute, JoinType.LEFT); } } Set<Entry<String, Object>> set = map.entrySet(); int numberOfClauses = set.size(); Predicate[] predicates = new Predicate[numberOfClauses]; int i = 0; for (Entry<String, Object> entry : set) { String key = entry.getKey(); if (MovieConstants.NAME_FIELD.equals(key) || MovieConstants.SURNAME_FIELD.equals(key)) { predicates[i++] = cb.like(cb.upper(root.<String>get(key)), LIKE + entry.getValue() + LIKE); } else if (MovieConstants.MOVIE_DIRECTOR_FIELD.equals(key)) { //predicates[i++] = cb.equal( ,entry.getValue()); } else { predicates[i++] = cb.equal(root.get(key), entry.getValue()); } } return em.createQuery(cq.select(root).where(predicates)).getResultList(); }
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"); }/*from w ww. jav a 2s . c o 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:org.finra.dm.dao.AbstractDaoTest.java
/** * Returns a list of {@link EmrClusterCreationLogEntity} objects for the given cluster namespace, cluster definition name, and EMR cluster name. All the * given parameters are case insensitive. The returned list's order is not guaranteed. * * @param namespace - EMR cluster namespace * @param definitionName - EMR cluster definition name * @param clusterName - EMR cluster name * * @return list of EMR cluster creation logs *///from w ww . j a v a 2 s . c o m public List<EmrClusterCreationLogEntity> getEmrClusterCreationLogEntities(String namespace, String definitionName, String clusterName) { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<EmrClusterCreationLogEntity> query = builder.createQuery(EmrClusterCreationLogEntity.class); Root<EmrClusterCreationLogEntity> emrClusterCreationLogEntity = query .from(EmrClusterCreationLogEntity.class); Join<?, NamespaceEntity> namespaceEntity = emrClusterCreationLogEntity .join(EmrClusterCreationLogEntity_.namespace); Predicate namespacePredicate = builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)), namespace.toUpperCase()); Predicate definitionNamePredicate = builder.equal( builder.upper( emrClusterCreationLogEntity.get(EmrClusterCreationLogEntity_.emrClusterDefinitionName)), definitionName.toUpperCase()); Predicate clusterNamePredicate = builder.equal( builder.upper(emrClusterCreationLogEntity.get(EmrClusterCreationLogEntity_.emrClusterName)), clusterName.toUpperCase()); query.select(emrClusterCreationLogEntity) .where(builder.and(namespacePredicate, definitionNamePredicate, clusterNamePredicate)); return entityManager.createQuery(query).getResultList(); }
From source file:org.finra.dm.dao.impl.DmDaoImpl.java
/** * {@inheritDoc}//from w w w . j a va 2 s. c o m */ @Override public NamespaceEntity getNamespaceByCd(String namespaceCode) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<NamespaceEntity> criteria = builder.createQuery(NamespaceEntity.class); // The criteria root is the namespace. Root<NamespaceEntity> namespaceEntity = criteria.from(NamespaceEntity.class); // Create the standard restrictions (i.e. the standard where clauses). Predicate queryRestriction = builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)), namespaceCode.toUpperCase()); criteria.select(namespaceEntity).where(queryRestriction); return executeSingleResultQuery(criteria, String.format("Found more than one namespace with namespaceCode=\"%s\".", namespaceCode)); }