List of usage examples for javax.persistence.criteria CriteriaBuilder and
Predicate and(Predicate... restrictions);
From source file:org.finra.herd.dao.impl.StorageUnitDaoImpl.java
@Override public List<StorageUnitEntity> getS3StorageUnitsToCleanup(int maxResult) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<StorageUnitEntity> criteria = builder.createQuery(StorageUnitEntity.class); // The criteria root is the storage unit. Root<StorageUnitEntity> storageUnitEntityRoot = criteria.from(StorageUnitEntity.class); // Join to the other tables we can filter on. Join<StorageUnitEntity, StorageEntity> storageEntityJoin = storageUnitEntityRoot .join(StorageUnitEntity_.storage); Join<StorageEntity, StoragePlatformEntity> storagePlatformEntityJoin = storageEntityJoin .join(StorageEntity_.storagePlatform); Join<StorageUnitEntity, StorageUnitStatusEntity> storageUnitStatusEntityJoin = storageUnitEntityRoot .join(StorageUnitEntity_.status); Join<StorageUnitEntity, BusinessObjectDataEntity> businessObjectDataEntityJoin = storageUnitEntityRoot .join(StorageUnitEntity_.businessObjectData); Join<BusinessObjectDataEntity, BusinessObjectDataStatusEntity> businessObjectDataStatusEntity = businessObjectDataEntityJoin .join(BusinessObjectDataEntity_.status); // Get the current time. Timestamp currentTime = new Timestamp(System.currentTimeMillis()); // Create the standard restrictions (i.e. the standard where clauses). // Restrictions include: // - Storage platform is set to S3 storage // - Storage unit status is DISABLED // - Associated BData has a DELETED status // - Final destroy on timestamp < current time List<Predicate> predicates = new ArrayList<>(); predicates.add(builder.equal(storagePlatformEntityJoin.get(StoragePlatformEntity_.name), StoragePlatformEntity.S3));// w w w. j a va 2 s . c om predicates.add(builder.equal(storageUnitStatusEntityJoin.get(StorageUnitStatusEntity_.code), StorageUnitStatusEntity.DISABLED)); predicates.add(builder.equal(businessObjectDataStatusEntity.get(BusinessObjectDataStatusEntity_.code), BusinessObjectDataStatusEntity.DELETED)); predicates.add(builder.lessThan(storageUnitEntityRoot.get(StorageUnitEntity_.finalDestroyOn), currentTime)); // Order the results. Order orderBy = builder.asc(storageUnitEntityRoot.get(StorageUnitEntity_.finalDestroyOn)); // Add the clauses for the query. criteria.select(storageUnitEntityRoot) .where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(orderBy); // Execute the query and return the results. return entityManager.createQuery(criteria).setMaxResults(maxResult).getResultList(); }
From source file:org.finra.herd.dao.impl.StorageUnitDaoImpl.java
@Override public List<StorageUnitEntity> getS3StorageUnitsToExpire(int maxResult) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<StorageUnitEntity> criteria = builder.createQuery(StorageUnitEntity.class); // The criteria root is the storage unit. Root<StorageUnitEntity> storageUnitEntityRoot = criteria.from(StorageUnitEntity.class); // Join to the other tables we can filter on. Join<StorageUnitEntity, StorageEntity> storageEntityJoin = storageUnitEntityRoot .join(StorageUnitEntity_.storage); Join<StorageEntity, StoragePlatformEntity> storagePlatformEntityJoin = storageEntityJoin .join(StorageEntity_.storagePlatform); Join<StorageUnitEntity, StorageUnitStatusEntity> storageUnitStatusEntityJoin = storageUnitEntityRoot .join(StorageUnitEntity_.status); // Get the current time. Timestamp currentTime = new Timestamp(System.currentTimeMillis()); // Create the standard restrictions (i.e. the standard where clauses). List<Predicate> predicates = new ArrayList<>(); predicates.add(builder.equal(storagePlatformEntityJoin.get(StoragePlatformEntity_.name), StoragePlatformEntity.S3));//from w w w . j ava2s . co m predicates.add(builder.equal(storageUnitStatusEntityJoin.get(StorageUnitStatusEntity_.code), StorageUnitStatusEntity.RESTORED)); predicates.add( builder.lessThan(storageUnitEntityRoot.get(StorageUnitEntity_.restoreExpirationOn), currentTime)); // Order the results. Order orderBy = builder.asc(storageUnitEntityRoot.get(StorageUnitEntity_.restoreExpirationOn)); // Add the clauses for the query. criteria.select(storageUnitEntityRoot) .where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(orderBy); // Execute the query and return the results. return entityManager.createQuery(criteria).setMaxResults(maxResult).getResultList(); }
From source file:org.finra.herd.dao.impl.StorageUnitDaoImpl.java
@Override public List<StorageUnitEntity> getS3StorageUnitsToRestore(int maxResult) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<StorageUnitEntity> criteria = builder.createQuery(StorageUnitEntity.class); // The criteria root is the storage unit. Root<StorageUnitEntity> storageUnitEntityRoot = criteria.from(StorageUnitEntity.class); // Join to the other tables we can filter on. Join<StorageUnitEntity, StorageEntity> storageEntityJoin = storageUnitEntityRoot .join(StorageUnitEntity_.storage); Join<StorageEntity, StoragePlatformEntity> storagePlatformEntityJoin = storageEntityJoin .join(StorageEntity_.storagePlatform); Join<StorageUnitEntity, StorageUnitStatusEntity> storageUnitStatusEntityJoin = storageUnitEntityRoot .join(StorageUnitEntity_.status); // Create the standard restrictions (i.e. the standard where clauses). List<Predicate> predicates = new ArrayList<>(); predicates.add(builder.equal(storagePlatformEntityJoin.get(StoragePlatformEntity_.name), StoragePlatformEntity.S3));/*from ww w . ja v a 2s.c o m*/ predicates.add(builder.equal(storageUnitStatusEntityJoin.get(StorageUnitStatusEntity_.code), StorageUnitStatusEntity.RESTORING)); // Order the results by storage unit updated on timestamp. Order orderBy = builder.asc(storageUnitEntityRoot.get(StorageUnitEntity_.updatedOn)); // Add the clauses for the query. criteria.select(storageUnitEntityRoot) .where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(orderBy); // Execute the query and return the results. return entityManager.createQuery(criteria).setMaxResults(maxResult).getResultList(); }
From source file:org.finra.herd.dao.impl.StorageUnitDaoImpl.java
@Override public StorageUnitEntity getStorageUnitByBusinessObjectDataAndStorage( BusinessObjectDataEntity businessObjectDataEntity, StorageEntity storageEntity) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<StorageUnitEntity> criteria = builder.createQuery(StorageUnitEntity.class); // The criteria root is the storage unit. Root<StorageUnitEntity> storageUnitEntityRoot = criteria.from(StorageUnitEntity.class); // Create the standard restrictions (i.e. the standard where clauses). List<Predicate> predicates = new ArrayList<>(); predicates.add(builder.equal(storageUnitEntityRoot.get(StorageUnitEntity_.businessObjectData), businessObjectDataEntity));/*from w w w .ja v a2s . co m*/ predicates.add( builder.equal(storageUnitEntityRoot.get(StorageUnitEntity_.storageName), storageEntity.getName())); // Add the clauses for the query. criteria.select(storageUnitEntityRoot) .where(builder.and(predicates.toArray(new Predicate[predicates.size()]))); // Execute the query. List<StorageUnitEntity> resultList = entityManager.createQuery(criteria).getResultList(); // Return single result or null. return resultList.size() >= 1 ? resultList.get(0) : null; }
From source file:org.finra.herd.dao.impl.StorageUnitDaoImpl.java
@Override public StorageUnitEntity getStorageUnitByKey( BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<StorageUnitEntity> criteria = builder.createQuery(StorageUnitEntity.class); // The criteria root is the storage unit. Root<StorageUnitEntity> storageUnitEntityRoot = criteria.from(StorageUnitEntity.class); // Join to the other tables we can filter on. Join<StorageUnitEntity, BusinessObjectDataEntity> businessObjectDataEntityJoin = storageUnitEntityRoot .join(StorageUnitEntity_.businessObjectData); Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> businessObjectFormatEntityJoin = businessObjectDataEntityJoin .join(BusinessObjectDataEntity_.businessObjectFormat); Join<BusinessObjectFormatEntity, FileTypeEntity> fileTypeEntityJoin = businessObjectFormatEntityJoin .join(BusinessObjectFormatEntity_.fileType); Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntityJoin = businessObjectFormatEntityJoin .join(BusinessObjectFormatEntity_.businessObjectDefinition); Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntityJoin = businessObjectDefinitionEntityJoin .join(BusinessObjectDefinitionEntity_.namespace); Join<StorageUnitEntity, StorageEntity> storageEntityJoin = storageUnitEntityRoot .join(StorageUnitEntity_.storage); // Create the standard restrictions (i.e. the standard where clauses). List<Predicate> predicates = new ArrayList<>(); predicates.add(builder.equal(builder.upper(namespaceEntityJoin.get(NamespaceEntity_.code)), businessObjectDataStorageUnitKey.getNamespace().toUpperCase())); predicates.add(builder.equal(//from www.j a v a 2 s . c o m builder.upper(businessObjectDefinitionEntityJoin.get(BusinessObjectDefinitionEntity_.name)), businessObjectDataStorageUnitKey.getBusinessObjectDefinitionName().toUpperCase())); predicates.add(builder.equal( builder.upper(businessObjectDefinitionEntityJoin.get(BusinessObjectDefinitionEntity_.name)), businessObjectDataStorageUnitKey.getBusinessObjectDefinitionName().toUpperCase())); predicates.add( builder.equal(builder.upper(businessObjectFormatEntityJoin.get(BusinessObjectFormatEntity_.usage)), businessObjectDataStorageUnitKey.getBusinessObjectFormatUsage().toUpperCase())); predicates.add(builder.equal(builder.upper(fileTypeEntityJoin.get(FileTypeEntity_.code)), businessObjectDataStorageUnitKey.getBusinessObjectFormatFileType().toUpperCase())); predicates.add(builder.equal( businessObjectFormatEntityJoin.get(BusinessObjectFormatEntity_.businessObjectFormatVersion), businessObjectDataStorageUnitKey.getBusinessObjectFormatVersion())); predicates.add(getQueryRestrictionOnPartitionValues(builder, businessObjectDataEntityJoin, businessObjectDataStorageUnitKey.getPartitionValue(), businessObjectDataStorageUnitKey.getSubPartitionValues())); predicates.add(builder.equal(businessObjectDataEntityJoin.get(BusinessObjectDataEntity_.version), businessObjectDataStorageUnitKey.getBusinessObjectDataVersion())); predicates.add(builder.equal(builder.upper(storageEntityJoin.get(StorageEntity_.name)), businessObjectDataStorageUnitKey.getStorageName().toUpperCase())); // Add the clauses for the query. criteria.select(storageUnitEntityRoot) .where(builder.and(predicates.toArray(new Predicate[predicates.size()]))); // Execute the query and return the result. return executeSingleResultQuery(criteria, String.format( "Found more than one business object data storage unit instance with parameters {namespace=\"%s\", businessObjectDefinitionName=\"%s\"," + " businessObjectFormatUsage=\"%s\", businessObjectFormatFileType=\"%s\", businessObjectFormatVersion=\"%d\"," + " businessObjectDataPartitionValue=\"%s\", businessObjectDataSubPartitionValues=\"%s\", businessObjectDataVersion=\"%d\"," + " storageName=\"%s\"}.", businessObjectDataStorageUnitKey.getNamespace(), businessObjectDataStorageUnitKey.getBusinessObjectDefinitionName(), businessObjectDataStorageUnitKey.getBusinessObjectFormatUsage(), businessObjectDataStorageUnitKey.getBusinessObjectFormatFileType(), businessObjectDataStorageUnitKey.getBusinessObjectFormatVersion(), businessObjectDataStorageUnitKey.getPartitionValue(), CollectionUtils.isEmpty(businessObjectDataStorageUnitKey.getSubPartitionValues()) ? "" : StringUtils.join(businessObjectDataStorageUnitKey.getSubPartitionValues(), ","), businessObjectDataStorageUnitKey.getBusinessObjectDataVersion(), businessObjectDataStorageUnitKey.getStorageName())); }
From source file:org.finra.herd.dao.impl.StorageUnitDaoImpl.java
@Override public StorageUnitEntity getStorageUnitByStorageAndDirectoryPath(StorageEntity storageEntity, String directoryPath) {//w w w. ja va 2 s . c o m // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<StorageUnitEntity> criteria = builder.createQuery(StorageUnitEntity.class); // The criteria root is the storage unit. Root<StorageUnitEntity> storageUnitEntityRoot = criteria.from(StorageUnitEntity.class); // Create the standard restrictions (i.e. the standard where clauses). List<Predicate> predicates = new ArrayList<>(); predicates.add(builder.equal(storageUnitEntityRoot.get(StorageUnitEntity_.storage), storageEntity)); predicates.add(builder.equal(storageUnitEntityRoot.get(StorageUnitEntity_.directoryPath), directoryPath)); // Add all clauses for the query. criteria.select(storageUnitEntityRoot) .where(builder.and(predicates.toArray(new Predicate[predicates.size()]))); // Execute the query and return the first found storage unit or null if none were found. List<StorageUnitEntity> storageUnitEntities = entityManager.createQuery(criteria).getResultList(); return storageUnitEntities.size() >= 1 ? storageUnitEntities.get(0) : null; }
From source file:org.finra.herd.dao.impl.StorageUnitDaoImpl.java
@Override public List<StorageUnitEntity> getStorageUnitsByStoragePlatformAndBusinessObjectData(String storagePlatform, BusinessObjectDataEntity businessObjectDataEntity) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<StorageUnitEntity> criteria = builder.createQuery(StorageUnitEntity.class); // The criteria root is the storage unit. Root<StorageUnitEntity> storageUnitEntity = criteria.from(StorageUnitEntity.class); // Join to the other tables we can filter on. Join<StorageUnitEntity, StorageEntity> storageEntity = storageUnitEntity.join(StorageUnitEntity_.storage); Join<StorageEntity, StoragePlatformEntity> storagePlatformEntity = storageEntity .join(StorageEntity_.storagePlatform); // Create the standard restrictions (i.e. the standard where clauses). List<Predicate> predicates = new ArrayList<>(); predicates.add(builder.equal(builder.upper(storagePlatformEntity.get(StoragePlatformEntity_.name)), storagePlatform.toUpperCase())); predicates.add(builder.equal(storageUnitEntity.get(StorageUnitEntity_.businessObjectData), businessObjectDataEntity));/*from w w w.j a v a 2s . c o m*/ // Order by storage name. Order orderBy = builder.asc(storageEntity.get(StorageEntity_.name)); // Add the clauses for the query. criteria.select(storageUnitEntity).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))) .orderBy(orderBy); // Execute the query and return the results. return entityManager.createQuery(criteria).getResultList(); }
From source file:org.finra.herd.dao.impl.StorageUnitNotificationRegistrationDaoImpl.java
@Override public List<NotificationRegistrationKey> getStorageUnitNotificationRegistrationKeysByNotificationFilter( StorageUnitNotificationFilter businessObjectDataNotificationFilter) { // Create the criteria builder and a tuple style criteria query. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<Tuple> criteria = builder.createTupleQuery(); // The criteria root is the storage unit notification registration. Root<StorageUnitNotificationRegistrationEntity> notificationRegistrationEntityRoot = criteria .from(StorageUnitNotificationRegistrationEntity.class); // Join to the other tables we can filter on. Join<StorageUnitNotificationRegistrationEntity, NamespaceEntity> notificationRegistrationNamespaceEntityJoin = notificationRegistrationEntityRoot .join(StorageUnitNotificationRegistrationEntity_.namespace); Join<StorageUnitNotificationRegistrationEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = notificationRegistrationEntityRoot .join(StorageUnitNotificationRegistrationEntity_.businessObjectDefinition); Join<BusinessObjectDefinitionEntity, NamespaceEntity> businessObjectDefinitionNamespaceEntity = businessObjectDefinitionEntity .join(BusinessObjectDefinitionEntity_.namespace); Join<StorageUnitNotificationRegistrationEntity, FileTypeEntity> fileTypeEntity = notificationRegistrationEntityRoot .join(StorageUnitNotificationRegistrationEntity_.fileType, JoinType.LEFT); // Get the columns. Path<String> notificationRegistrationNamespaceColumn = notificationRegistrationNamespaceEntityJoin .get(NamespaceEntity_.code); Path<String> notificationRegistrationNameColumn = notificationRegistrationEntityRoot .get(StorageUnitNotificationRegistrationEntity_.name); // Create the standard restrictions (i.e. the standard where clauses). List<Predicate> predicates = new ArrayList<>(); predicates.add(/*from w w w . j a va 2 s .c om*/ builder.equal(builder.upper(businessObjectDefinitionNamespaceEntity.get(NamespaceEntity_.code)), businessObjectDataNotificationFilter.getNamespace().toUpperCase())); predicates.add(builder.equal( builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)), businessObjectDataNotificationFilter.getBusinessObjectDefinitionName().toUpperCase())); if (StringUtils.isNotBlank(businessObjectDataNotificationFilter.getBusinessObjectFormatUsage())) { predicates.add(builder.or( builder.isNull(notificationRegistrationEntityRoot .get(StorageUnitNotificationRegistrationEntity_.usage)), builder.equal( builder.upper(notificationRegistrationEntityRoot .get(StorageUnitNotificationRegistrationEntity_.usage)), businessObjectDataNotificationFilter.getBusinessObjectFormatUsage().toUpperCase()))); } if (StringUtils.isNotBlank(businessObjectDataNotificationFilter.getBusinessObjectFormatFileType())) { predicates.add(builder.or( builder.isNull(notificationRegistrationEntityRoot .get(StorageUnitNotificationRegistrationEntity_.fileType)), builder.equal(builder.upper(fileTypeEntity.get(FileTypeEntity_.code)), businessObjectDataNotificationFilter.getBusinessObjectFormatFileType().toUpperCase()))); } // Add the select and where clauses to the query. criteria.multiselect(notificationRegistrationNamespaceColumn, notificationRegistrationNameColumn) .where(builder.and(predicates.toArray(new Predicate[predicates.size()]))); // Add the order by clause to the query. criteria.orderBy(builder.asc(notificationRegistrationNamespaceColumn), builder.asc(notificationRegistrationNameColumn)); // Run the query to get a list of tuples back. List<Tuple> tuples = entityManager.createQuery(criteria).getResultList(); // Populate the list of keys from the returned tuples. return getNotificationRegistrationKeys(tuples, notificationRegistrationNamespaceColumn, notificationRegistrationNameColumn); }
From source file:org.finra.herd.dao.impl.StorageUnitNotificationRegistrationDaoImpl.java
@Override public List<StorageUnitNotificationRegistrationEntity> getStorageUnitNotificationRegistrations( String notificationEventTypeCode, BusinessObjectDataKey businessObjectDataKey, String storageName, String newStorageUnitStatus, String oldStorageUnitStatus, String notificationRegistrationStatus) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<StorageUnitNotificationRegistrationEntity> criteria = builder .createQuery(StorageUnitNotificationRegistrationEntity.class); // The criteria root is the storage unit notification registration entity. Root<StorageUnitNotificationRegistrationEntity> storageUnitNotificationRegistrationEntityRoot = criteria .from(StorageUnitNotificationRegistrationEntity.class); // Join to the other tables we can filter on. Join<StorageUnitNotificationRegistrationEntity, NamespaceEntity> namespaceEntityJoin = storageUnitNotificationRegistrationEntityRoot .join(StorageUnitNotificationRegistrationEntity_.namespace); Join<StorageUnitNotificationRegistrationEntity, NotificationEventTypeEntity> notificationEventTypeEntityJoin = storageUnitNotificationRegistrationEntityRoot .join(StorageUnitNotificationRegistrationEntity_.notificationEventType); Join<StorageUnitNotificationRegistrationEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntityJoin = storageUnitNotificationRegistrationEntityRoot .join(StorageUnitNotificationRegistrationEntity_.businessObjectDefinition); Join<BusinessObjectDefinitionEntity, NamespaceEntity> businessObjectDefinitionNamespaceEntityJoin = businessObjectDefinitionEntityJoin .join(BusinessObjectDefinitionEntity_.namespace); Join<StorageUnitNotificationRegistrationEntity, StorageEntity> storageEntityJoin = storageUnitNotificationRegistrationEntityRoot .join(StorageUnitNotificationRegistrationEntity_.storage); Join<StorageUnitNotificationRegistrationEntity, FileTypeEntity> fileTypeEntityJoin = storageUnitNotificationRegistrationEntityRoot .join(StorageUnitNotificationRegistrationEntity_.fileType, JoinType.LEFT); Join<StorageUnitNotificationRegistrationEntity, StorageUnitStatusEntity> newStorageUnitStatusEntityJoin = storageUnitNotificationRegistrationEntityRoot .join(StorageUnitNotificationRegistrationEntity_.newStorageUnitStatus, JoinType.LEFT); Join<StorageUnitNotificationRegistrationEntity, StorageUnitStatusEntity> oldStorageUnitStatusEntityJoin = storageUnitNotificationRegistrationEntityRoot .join(StorageUnitNotificationRegistrationEntity_.oldStorageUnitStatus, JoinType.LEFT); Join<StorageUnitNotificationRegistrationEntity, NotificationRegistrationStatusEntity> notificationRegistrationStatusEntityJoin = storageUnitNotificationRegistrationEntityRoot .join(StorageUnitNotificationRegistrationEntity_.notificationRegistrationStatus); // Create the standard restrictions (i.e. the standard where clauses). List<Predicate> predicates = new ArrayList<>(); predicates.add(/*from w w w . j a v a2s .c o m*/ builder.equal(builder.upper(notificationEventTypeEntityJoin.get(NotificationEventTypeEntity_.code)), notificationEventTypeCode.toUpperCase())); predicates.add( builder.equal(builder.upper(businessObjectDefinitionNamespaceEntityJoin.get(NamespaceEntity_.code)), businessObjectDataKey.getNamespace().toUpperCase())); predicates.add(builder.equal( builder.upper(businessObjectDefinitionEntityJoin.get(BusinessObjectDefinitionEntity_.name)), businessObjectDataKey.getBusinessObjectDefinitionName().toUpperCase())); predicates.add(builder.equal(builder.upper(storageEntityJoin.get(StorageEntity_.name)), storageName.toUpperCase())); predicates.add(builder.or( builder.isNull(storageUnitNotificationRegistrationEntityRoot .get(StorageUnitNotificationRegistrationEntity_.usage)), builder.equal( builder.upper(storageUnitNotificationRegistrationEntityRoot .get(StorageUnitNotificationRegistrationEntity_.usage)), businessObjectDataKey.getBusinessObjectFormatUsage().toUpperCase()))); predicates.add(builder.or( builder.isNull(storageUnitNotificationRegistrationEntityRoot .get(StorageUnitNotificationRegistrationEntity_.fileType)), builder.equal(builder.upper(fileTypeEntityJoin.get(FileTypeEntity_.code)), businessObjectDataKey.getBusinessObjectFormatFileType().toUpperCase()))); predicates.add(builder.or( builder.isNull(storageUnitNotificationRegistrationEntityRoot .get(StorageUnitNotificationRegistrationEntity_.businessObjectFormatVersion)), builder.equal( storageUnitNotificationRegistrationEntityRoot .get(StorageUnitNotificationRegistrationEntity_.businessObjectFormatVersion), businessObjectDataKey.getBusinessObjectFormatVersion()))); predicates.add(builder.or( builder.isNull(storageUnitNotificationRegistrationEntityRoot .get(StorageUnitNotificationRegistrationEntity_.newStorageUnitStatus)), builder.equal(builder.upper(newStorageUnitStatusEntityJoin.get(StorageUnitStatusEntity_.code)), newStorageUnitStatus.toUpperCase()))); // Please note that old business object data status parameter value is null for a business object data registration event. predicates.add(builder.or( builder.isNull(storageUnitNotificationRegistrationEntityRoot .get(StorageUnitNotificationRegistrationEntity_.oldStorageUnitStatus)), builder.equal(builder.upper(oldStorageUnitStatusEntityJoin.get(StorageUnitStatusEntity_.code)), oldStorageUnitStatus == null ? null : oldStorageUnitStatus.toUpperCase()))); predicates.add(builder.equal( builder.upper( notificationRegistrationStatusEntityJoin.get(NotificationRegistrationStatusEntity_.code)), notificationRegistrationStatus.toUpperCase())); // Order the results by namespace and notification name. List<Order> orderBy = new ArrayList<>(); orderBy.add(builder.asc(namespaceEntityJoin.get(NamespaceEntity_.code))); orderBy.add(builder.asc(storageUnitNotificationRegistrationEntityRoot .get(StorageUnitNotificationRegistrationEntity_.name))); // Add the clauses for the query. criteria.select(storageUnitNotificationRegistrationEntityRoot) .where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(orderBy); // Execute the query and return the results. return entityManager.createQuery(criteria).getResultList(); }
From source file:org.finra.herd.dao.impl.TagDaoImpl.java
@Override public TagEntity getTagByKey(TagKey tagKey) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<TagEntity> criteria = builder.createQuery(TagEntity.class); // The criteria root is the tag entity. Root<TagEntity> tagEntityRoot = criteria.from(TagEntity.class); // Join on the other tables we can filter on. Join<TagEntity, TagTypeEntity> tagTypeEntityJoin = tagEntityRoot.join(TagEntity_.tagType); // Create the standard restrictions (i.e. the standard where clauses). List<Predicate> predicates = new ArrayList<>(); predicates.add(builder.equal(builder.upper(tagTypeEntityJoin.get(TagTypeEntity_.code)), tagKey.getTagTypeCode().toUpperCase())); predicates.add(builder.equal(builder.upper(tagEntityRoot.get(TagEntity_.tagCode)), tagKey.getTagCode().toUpperCase())); // Add all clauses to the query. criteria.select(tagEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))); return executeSingleResultQuery(criteria, String.format("Found more than one tag with parameters {tagType=\"%s\", tagCode=\"%s\"}.", tagKey.getTagTypeCode(), tagKey.getTagCode())); }