List of usage examples for javax.persistence.criteria CriteriaBuilder asc
Order asc(Expression<?> x);
From source file:org.finra.herd.dao.impl.BusinessObjectDataDaoImpl.java
@Override public Map<BusinessObjectDataEntity, StoragePolicyEntity> getBusinessObjectDataEntitiesMatchingStoragePolicies( StoragePolicyPriorityLevel storagePolicyPriorityLevel, List<String> supportedBusinessObjectDataStatuses, int storagePolicyTransitionMaxAllowedAttempts, int startPosition, int maxResult) { // Create the criteria builder and a tuple style criteria query. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<Tuple> criteria = builder.createTupleQuery(); // The criteria root is the business object data along with the storage policy. Root<BusinessObjectDataEntity> businessObjectDataEntityRoot = criteria.from(BusinessObjectDataEntity.class); Root<StoragePolicyEntity> storagePolicyEntityRoot = criteria.from(StoragePolicyEntity.class); // Join to the other tables we can filter on. Join<BusinessObjectDataEntity, StorageUnitEntity> storageUnitEntityJoin = businessObjectDataEntityRoot .join(BusinessObjectDataEntity_.storageUnits); Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> businessObjectFormatEntityJoin = businessObjectDataEntityRoot .join(BusinessObjectDataEntity_.businessObjectFormat); // Create main query restrictions based on the specified parameters. List<Predicate> predicates = new ArrayList<>(); // Add restriction on business object definition. predicates.add(storagePolicyPriorityLevel.isBusinessObjectDefinitionIsNull() ? builder.isNull(storagePolicyEntityRoot.get(StoragePolicyEntity_.businessObjectDefinitionId)) : builder.equal(/*from w w w.ja v a 2s . c o m*/ businessObjectFormatEntityJoin.get(BusinessObjectFormatEntity_.businessObjectDefinitionId), storagePolicyEntityRoot.get(StoragePolicyEntity_.businessObjectDefinitionId))); // Add restriction on business object format usage. predicates.add(storagePolicyPriorityLevel.isUsageIsNull() ? builder.isNull(storagePolicyEntityRoot.get(StoragePolicyEntity_.usage)) : builder.equal( builder.upper(businessObjectFormatEntityJoin.get(BusinessObjectFormatEntity_.usage)), builder.upper(storagePolicyEntityRoot.get(StoragePolicyEntity_.usage)))); // Add restriction on business object format file type. predicates.add(storagePolicyPriorityLevel.isFileTypeIsNull() ? builder.isNull(storagePolicyEntityRoot.get(StoragePolicyEntity_.fileType)) : builder.equal(businessObjectFormatEntityJoin.get(BusinessObjectFormatEntity_.fileTypeCode), storagePolicyEntityRoot.get(StoragePolicyEntity_.fileTypeCode))); // Add restriction on storage policy filter storage. predicates.add(builder.equal(storageUnitEntityJoin.get(StorageUnitEntity_.storageName), storagePolicyEntityRoot.get(StoragePolicyEntity_.storageName))); // Add restriction on storage policy latest version flag. predicates.add(builder.isTrue(storagePolicyEntityRoot.get(StoragePolicyEntity_.latestVersion))); // Add restriction on storage policy status. predicates.add(builder.equal(storagePolicyEntityRoot.get(StoragePolicyEntity_.statusCode), StoragePolicyStatusEntity.ENABLED)); // Add restriction on supported business object data statuses. predicates.add(businessObjectDataEntityRoot.get(BusinessObjectDataEntity_.statusCode) .in(supportedBusinessObjectDataStatuses)); // Add restrictions as per storage policy transition type. predicates.add( builder.equal(storagePolicyEntityRoot.get(StoragePolicyEntity_.storagePolicyTransitionTypeCode), StoragePolicyTransitionTypeEntity.GLACIER)); predicates.add(storageUnitEntityJoin.get(StorageUnitEntity_.statusCode) .in(Lists.newArrayList(StorageUnitStatusEntity.ENABLED, StorageUnitStatusEntity.ARCHIVING))); // If specified, add restriction on maximum allowed attempts for a storage policy transition. if (storagePolicyTransitionMaxAllowedAttempts > 0) { predicates.add(builder.or( builder.isNull( storageUnitEntityJoin.get(StorageUnitEntity_.storagePolicyTransitionFailedAttempts)), builder.lessThan( storageUnitEntityJoin.get(StorageUnitEntity_.storagePolicyTransitionFailedAttempts), storagePolicyTransitionMaxAllowedAttempts))); } // Order the results by business object data "created on" value. Order orderByCreatedOn = builder.asc(businessObjectDataEntityRoot.get(BusinessObjectDataEntity_.createdOn)); // Add the select clause to the main query. criteria.multiselect(businessObjectDataEntityRoot, storagePolicyEntityRoot); // Add the where clause to the main query. criteria.where(predicates.toArray(new Predicate[] {})); // Add the order by clause to the main query. criteria.orderBy(orderByCreatedOn); // Run the query to get a list of tuples back. List<Tuple> tuples = entityManager.createQuery(criteria).setFirstResult(startPosition) .setMaxResults(maxResult).getResultList(); // Populate the result map from the returned tuples (i.e. 1 tuple for each row). Map<BusinessObjectDataEntity, StoragePolicyEntity> result = new LinkedHashMap<>(); for (Tuple tuple : tuples) { // Since multiple storage policies can contain identical filters, we add the below check to select each business object data instance only once. if (!result.containsKey(tuple.get(businessObjectDataEntityRoot))) { result.put(tuple.get(businessObjectDataEntityRoot), tuple.get(storagePolicyEntityRoot)); } } return result; }
From source file:org.finra.herd.dao.impl.BusinessObjectDataDaoImpl.java
/** * Retrieves a list of business object data entities per specified parameters. This method processes a sublist of partition filters specified by * partitionFilterSubListFromIndex and partitionFilterSubListSize parameters. * * @param businessObjectFormatKey the business object format key (case-insensitive). If a business object format version isn't specified, the latest * available format version for each partition value will be used. * @param partitionFilters the list of partition filter to be used to select business object data instances. Each partition filter contains a list of * primary and sub-partition values in the right order up to the maximum partition levels allowed by business object data registration - with partition * values for the relative partitions not to be used for selection passed as nulls. * @param businessObjectDataVersion the business object data version. If a business object data version isn't specified, the latest data version based on * the specified business object data status is returned. * @param businessObjectDataStatus the business object data status. This parameter is ignored when the business object data version is specified. When * business object data version and business object data status both are not specified, the latest data version for each set of partition values will be * used regardless of the status./*from w w w .ja v a 2s . c om*/ * @param storageName the name of the storage where the business object data storage unit is located (case-insensitive) * @param partitionFilterSubListFromIndex the index of the first element in the partition filter sublist * @param partitionFilterSubListSize the size of the partition filter sublist * * @return the list of business object data entities sorted by partition values */ private List<BusinessObjectDataEntity> getBusinessObjectDataEntities( BusinessObjectFormatKey businessObjectFormatKey, List<List<String>> partitionFilters, Integer businessObjectDataVersion, String businessObjectDataStatus, String storageName, int partitionFilterSubListFromIndex, int partitionFilterSubListSize) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<BusinessObjectDataEntity> criteria = builder.createQuery(BusinessObjectDataEntity.class); // The criteria root is the business object data. Root<BusinessObjectDataEntity> businessObjectDataEntity = criteria.from(BusinessObjectDataEntity.class); // Join to the other tables we can filter on. Join<BusinessObjectDataEntity, StorageUnitEntity> storageUnitEntity = businessObjectDataEntity .join(BusinessObjectDataEntity_.storageUnits); Join<StorageUnitEntity, StorageEntity> storageEntity = storageUnitEntity.join(StorageUnitEntity_.storage); Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> businessObjectFormatEntity = businessObjectDataEntity .join(BusinessObjectDataEntity_.businessObjectFormat); Join<BusinessObjectFormatEntity, FileTypeEntity> fileTypeEntity = businessObjectFormatEntity .join(BusinessObjectFormatEntity_.fileType); Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = businessObjectFormatEntity .join(BusinessObjectFormatEntity_.businessObjectDefinition); // Create the standard restrictions (i.e. the standard where clauses). // Create a standard restriction based on the business object format key values. // Please note that we specify not to ignore the business object format version. Predicate mainQueryRestriction = getQueryRestriction(builder, businessObjectFormatEntity, fileTypeEntity, businessObjectDefinitionEntity, businessObjectFormatKey, false); // If a format version was not specified, use the latest available for this set of partition values. if (businessObjectFormatKey.getBusinessObjectFormatVersion() == null) { // Business object format version is not specified, so just use the latest available for this set of partition values. Subquery<Integer> subQuery = criteria.subquery(Integer.class); // The criteria root is the business object data. Root<BusinessObjectDataEntity> subBusinessObjectDataEntity = subQuery .from(BusinessObjectDataEntity.class); // Join to the other tables we can filter on. Join<BusinessObjectDataEntity, StorageUnitEntity> subStorageUnitEntity = subBusinessObjectDataEntity .join(BusinessObjectDataEntity_.storageUnits); Join<StorageUnitEntity, StorageEntity> subStorageEntity = subStorageUnitEntity .join(StorageUnitEntity_.storage); Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> subBusinessObjectFormatEntity = subBusinessObjectDataEntity .join(BusinessObjectDataEntity_.businessObjectFormat); Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> subBusinessObjectDefinitionEntity = subBusinessObjectFormatEntity .join(BusinessObjectFormatEntity_.businessObjectDefinition); Join<BusinessObjectFormatEntity, FileTypeEntity> subBusinessObjectFormatFileTypeEntity = subBusinessObjectFormatEntity .join(BusinessObjectFormatEntity_.fileType); Join<BusinessObjectDataEntity, BusinessObjectDataStatusEntity> subBusinessObjectDataStatusEntity = subBusinessObjectDataEntity .join(BusinessObjectDataEntity_.status); // Create the standard restrictions (i.e. the standard where clauses). Predicate subQueryRestriction = builder.equal(subBusinessObjectDefinitionEntity, businessObjectDefinitionEntity); subQueryRestriction = builder.and(subQueryRestriction, builder.equal(subBusinessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage), businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage))); subQueryRestriction = builder.and(subQueryRestriction, builder.equal(subBusinessObjectFormatFileTypeEntity, fileTypeEntity)); // Create and add standard restrictions on primary and sub-partition values. subQueryRestriction = builder.and(subQueryRestriction, getQueryRestrictionOnPartitionValues(builder, subBusinessObjectDataEntity, businessObjectDataEntity)); // Add restrictions on business object data version and business object data status. Predicate subQueryRestrictionOnBusinessObjectDataVersionAndStatus = getQueryRestrictionOnBusinessObjectDataVersionAndStatus( builder, subBusinessObjectDataEntity, subBusinessObjectDataStatusEntity, businessObjectDataVersion, businessObjectDataStatus); if (subQueryRestrictionOnBusinessObjectDataVersionAndStatus != null) { subQueryRestriction = builder.and(subQueryRestriction, subQueryRestrictionOnBusinessObjectDataVersionAndStatus); } // Create and add a standard restriction on storage. subQueryRestriction = builder.and(subQueryRestriction, builder.equal(subStorageEntity, storageEntity)); subQuery.select(builder.max( subBusinessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion))) .where(subQueryRestriction); mainQueryRestriction = builder.and(mainQueryRestriction, builder.in( businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion)) .value(subQuery)); } // Add restriction as per specified primary and/or sub-partition values. mainQueryRestriction = builder.and(mainQueryRestriction, getQueryRestrictionOnPartitionValues(builder, businessObjectDataEntity, partitionFilters.subList(partitionFilterSubListFromIndex, partitionFilterSubListFromIndex + partitionFilterSubListSize))); // If a data version was specified, use it. Otherwise, use the latest one as per specified business object data status. if (businessObjectDataVersion != null) { mainQueryRestriction = builder.and(mainQueryRestriction, builder.equal( businessObjectDataEntity.get(BusinessObjectDataEntity_.version), businessObjectDataVersion)); } else { // Business object data version is not specified, so get the latest one as per specified business object data status, if any. // Meaning, when both business object data version and business object data status are not specified, we just return // the latest business object data version in the specified storage. Subquery<Integer> subQuery = getMaximumBusinessObjectDataVersionSubQuery(builder, criteria, businessObjectDataEntity, businessObjectFormatEntity, businessObjectDataStatus, Collections.singletonList(storageName), null, null, false); mainQueryRestriction = builder.and(mainQueryRestriction, builder.in(businessObjectDataEntity.get(BusinessObjectDataEntity_.version)).value(subQuery)); } // Add a storage name restriction to the main query where clause. mainQueryRestriction = builder.and(mainQueryRestriction, builder.equal(builder.upper(storageEntity.get(StorageEntity_.name)), storageName.toUpperCase())); // Add the clauses for the query. criteria.select(businessObjectDataEntity).where(mainQueryRestriction); // Order by partitions. List<Order> orderBy = new ArrayList<>(); for (SingularAttribute<BusinessObjectDataEntity, String> businessObjectDataPartition : BUSINESS_OBJECT_DATA_PARTITIONS) { orderBy.add(builder.asc(businessObjectDataEntity.get(businessObjectDataPartition))); } criteria.orderBy(orderBy); return entityManager.createQuery(criteria).getResultList(); }
From source file:org.finra.herd.dao.impl.BusinessObjectDataDaoImpl.java
/** * Create search restrictions.// ww w . java 2 s . c om * * @param builder the criteria builder * @param criteria the criteria * @param businessObjectDataEntity the root business object data entity * @param businessObjectDataSearchKey the business object data search key * @param namespaceEntity the namespace entity * @param fileTypeEntity the file type entity * @param isCountQuery specifies if this is a count query * * @return the search restrictions */ private Predicate getPredict(CriteriaBuilder builder, CriteriaQuery<?> criteria, Root<BusinessObjectDataEntity> businessObjectDataEntity, BusinessObjectDataSearchKey businessObjectDataSearchKey, NamespaceEntity namespaceEntity, FileTypeEntity fileTypeEntity, boolean isCountQuery) { // Join to the other tables we can filter on. Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> businessObjectFormatEntity = businessObjectDataEntity .join(BusinessObjectDataEntity_.businessObjectFormat); Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = businessObjectFormatEntity .join(BusinessObjectFormatEntity_.businessObjectDefinition); if (!isCountQuery) { List<Order> orderList = new ArrayList<>(); orderList.add( builder.asc(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.namespace))); orderList.add(builder.asc(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name))); orderList.add(builder.asc(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage))); orderList.add(builder.asc(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.fileType))); orderList.add(builder .desc(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion))); orderList.add(builder.desc(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue))); orderList.add(builder.desc(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue2))); orderList.add(builder.desc(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue3))); orderList.add(builder.desc(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue4))); orderList.add(builder.desc(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue5))); orderList.add(builder.desc(businessObjectDataEntity.get(BusinessObjectDataEntity_.version))); criteria.orderBy(orderList); } // Create the standard restrictions based on the business object search key values (i.e. the standard where clauses). // Create a restriction on namespace code. Predicate predicate = builder.equal( businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.namespace), namespaceEntity); // Create and append a restriction on business object definition name. predicate = builder.and(predicate, builder.equal( builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)), businessObjectDataSearchKey.getBusinessObjectDefinitionName().toUpperCase())); // Create and append a restriction on business object format usage. if (!StringUtils.isEmpty(businessObjectDataSearchKey.getBusinessObjectFormatUsage())) { predicate = builder.and(predicate, builder.equal(builder.upper(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage)), businessObjectDataSearchKey.getBusinessObjectFormatUsage().toUpperCase())); } // If specified, create and append a restriction on business object format file type. if (fileTypeEntity != null) { predicate = builder.and(predicate, builder .equal(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.fileType), fileTypeEntity)); } // If specified, create and append a restriction on business object format version. if (businessObjectDataSearchKey.getBusinessObjectFormatVersion() != null) { predicate = builder.and(predicate, builder.equal( businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion), businessObjectDataSearchKey.getBusinessObjectFormatVersion())); } predicate = createPartitionValueFilters(businessObjectDataSearchKey, businessObjectDataEntity, businessObjectFormatEntity, builder, predicate); List<AttributeValueFilter> attributeValueFilters = businessObjectDataSearchKey.getAttributeValueFilters(); if (attributeValueFilters != null && !attributeValueFilters.isEmpty()) { predicate = applyAttributeValueFilters(businessObjectDataSearchKey, businessObjectDataEntity, builder, predicate); } // Apply registration date range filter, if specified. if (businessObjectDataSearchKey.getRegistrationDateRangeFilter() != null) { predicate = applyRegistrationDateRangeFilter( businessObjectDataSearchKey.getRegistrationDateRangeFilter(), businessObjectDataEntity, builder, predicate); } if (BooleanUtils.isTrue(businessObjectDataSearchKey.isFilterOnLatestValidVersion())) { String validStatus = BusinessObjectDataStatusEntity.VALID; Subquery<Integer> subQuery = getMaximumBusinessObjectDataVersionSubQuery(builder, criteria, businessObjectDataEntity, businessObjectFormatEntity, validStatus); predicate = builder.and(predicate, builder.in(businessObjectDataEntity.get(BusinessObjectDataEntity_.version)).value(subQuery)); } if (BooleanUtils.isTrue(businessObjectDataSearchKey.isFilterOnRetentionExpiration())) { predicate = applyRetentionExpirationFilter(businessObjectDataSearchKey, businessObjectDataEntity, businessObjectFormatEntity, builder, predicate); } return predicate; }
From source file:org.finra.herd.dao.impl.BusinessObjectDataNotificationRegistrationDaoImpl.java
@Override public List<NotificationRegistrationKey> getBusinessObjectDataNotificationRegistrationKeysByNamespace( String namespace) {/*from ww w .j a v a 2 s . c o m*/ // Create the criteria builder and a tuple style criteria query. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<Tuple> criteria = builder.createTupleQuery(); // The criteria root is the business object data notification registration. Root<BusinessObjectDataNotificationRegistrationEntity> businessObjectDataNotificationEntity = criteria .from(BusinessObjectDataNotificationRegistrationEntity.class); // Join to the other tables we can filter on. Join<BusinessObjectDataNotificationRegistrationEntity, NamespaceEntity> namespaceEntity = businessObjectDataNotificationEntity .join(BusinessObjectDataNotificationRegistrationEntity_.namespace); // Get the columns. Path<String> notificationRegistrationNamespaceColumn = namespaceEntity.get(NamespaceEntity_.code); Path<String> notificationRegistrationNameColumn = businessObjectDataNotificationEntity .get(BusinessObjectDataNotificationRegistrationEntity_.name); // Create the standard restrictions (i.e. the standard where clauses). Predicate queryRestriction = builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)), namespace.toUpperCase()); // Add the select clause. criteria.multiselect(notificationRegistrationNamespaceColumn, notificationRegistrationNameColumn); // Add the where clause. criteria.where(queryRestriction); // Add the order by clause. criteria.orderBy(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.BusinessObjectDataNotificationRegistrationDaoImpl.java
@Override public List<NotificationRegistrationKey> getBusinessObjectDataNotificationRegistrationKeysByNotificationFilter( BusinessObjectDataNotificationFilter 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 business object data notification registration. Root<BusinessObjectDataNotificationRegistrationEntity> notificationRegistrationEntityRoot = criteria .from(BusinessObjectDataNotificationRegistrationEntity.class); // Join to the other tables we can filter on. Join<BusinessObjectDataNotificationRegistrationEntity, NamespaceEntity> notificationRegistrationNamespaceEntityJoin = notificationRegistrationEntityRoot .join(BusinessObjectDataNotificationRegistrationEntity_.namespace); Join<BusinessObjectDataNotificationRegistrationEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = notificationRegistrationEntityRoot .join(BusinessObjectDataNotificationRegistrationEntity_.businessObjectDefinition); Join<BusinessObjectDefinitionEntity, NamespaceEntity> businessObjectDefinitionNamespaceEntity = businessObjectDefinitionEntity .join(BusinessObjectDefinitionEntity_.namespace); Join<BusinessObjectDataNotificationRegistrationEntity, FileTypeEntity> fileTypeEntity = notificationRegistrationEntityRoot .join(BusinessObjectDataNotificationRegistrationEntity_.fileType, JoinType.LEFT); // Get the columns. Path<String> notificationRegistrationNamespaceColumn = notificationRegistrationNamespaceEntityJoin .get(NamespaceEntity_.code); Path<String> notificationRegistrationNameColumn = notificationRegistrationEntityRoot .get(BusinessObjectDataNotificationRegistrationEntity_.name); // Create the standard restrictions (i.e. the standard where clauses). List<Predicate> predicates = new ArrayList<>(); predicates.add(/*from www . j ava2s . 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(BusinessObjectDataNotificationRegistrationEntity_.usage)), builder.equal( builder.upper(notificationRegistrationEntityRoot .get(BusinessObjectDataNotificationRegistrationEntity_.usage)), businessObjectDataNotificationFilter.getBusinessObjectFormatUsage().toUpperCase()))); } if (StringUtils.isNotBlank(businessObjectDataNotificationFilter.getBusinessObjectFormatFileType())) { predicates.add(builder.or( builder.isNull(notificationRegistrationEntityRoot .get(BusinessObjectDataNotificationRegistrationEntity_.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.BusinessObjectDataNotificationRegistrationDaoImpl.java
@Override public List<BusinessObjectDataNotificationRegistrationEntity> getBusinessObjectDataNotificationRegistrations( String notificationEventTypeCode, BusinessObjectDataKey businessObjectDataKey, String newBusinessObjectDataStatus, String oldBusinessObjectDataStatus, String notificationRegistrationStatus) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<BusinessObjectDataNotificationRegistrationEntity> criteria = builder .createQuery(BusinessObjectDataNotificationRegistrationEntity.class); // The criteria root is the business object data notification registration entity. Root<BusinessObjectDataNotificationRegistrationEntity> businessObjectDataNotificationEntityRoot = criteria .from(BusinessObjectDataNotificationRegistrationEntity.class); // Join to the other tables we can filter on. Join<BusinessObjectDataNotificationRegistrationEntity, NamespaceEntity> namespaceEntityJoin = businessObjectDataNotificationEntityRoot .join(BusinessObjectDataNotificationRegistrationEntity_.namespace); Join<BusinessObjectDataNotificationRegistrationEntity, NotificationEventTypeEntity> notificationEventTypeEntityJoin = businessObjectDataNotificationEntityRoot .join(BusinessObjectDataNotificationRegistrationEntity_.notificationEventType); Join<BusinessObjectDataNotificationRegistrationEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntityJoin = businessObjectDataNotificationEntityRoot .join(BusinessObjectDataNotificationRegistrationEntity_.businessObjectDefinition); Join<BusinessObjectDefinitionEntity, NamespaceEntity> businessObjectDefinitionNamespaceEntityJoin = businessObjectDefinitionEntityJoin .join(BusinessObjectDefinitionEntity_.namespace); Join<BusinessObjectDataNotificationRegistrationEntity, FileTypeEntity> fileTypeEntityJoin = businessObjectDataNotificationEntityRoot .join(BusinessObjectDataNotificationRegistrationEntity_.fileType, JoinType.LEFT); Join<BusinessObjectDataNotificationRegistrationEntity, BusinessObjectDataStatusEntity> newBusinessObjectDataStatusEntityJoin = businessObjectDataNotificationEntityRoot .join(BusinessObjectDataNotificationRegistrationEntity_.newBusinessObjectDataStatus, JoinType.LEFT); Join<BusinessObjectDataNotificationRegistrationEntity, BusinessObjectDataStatusEntity> oldBusinessObjectDataStatusEntityJoin = businessObjectDataNotificationEntityRoot .join(BusinessObjectDataNotificationRegistrationEntity_.oldBusinessObjectDataStatus, JoinType.LEFT); Join<BusinessObjectDataNotificationRegistrationEntity, NotificationRegistrationStatusEntity> notificationRegistrationStatusEntityJoin = businessObjectDataNotificationEntityRoot .join(BusinessObjectDataNotificationRegistrationEntity_.notificationRegistrationStatus); // Create the standard restrictions (i.e. the standard where clauses). List<Predicate> predicates = new ArrayList<>(); predicates.add(//from w ww . ja va 2 s .com 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.or( builder.isNull(businessObjectDataNotificationEntityRoot .get(BusinessObjectDataNotificationRegistrationEntity_.usage)), builder.equal( builder.upper(businessObjectDataNotificationEntityRoot .get(BusinessObjectDataNotificationRegistrationEntity_.usage)), businessObjectDataKey.getBusinessObjectFormatUsage().toUpperCase()))); predicates.add(builder.or( builder.isNull(businessObjectDataNotificationEntityRoot .get(BusinessObjectDataNotificationRegistrationEntity_.fileType)), builder.equal(builder.upper(fileTypeEntityJoin.get(FileTypeEntity_.code)), businessObjectDataKey.getBusinessObjectFormatFileType().toUpperCase()))); predicates.add(builder.or( builder.isNull(businessObjectDataNotificationEntityRoot .get(BusinessObjectDataNotificationRegistrationEntity_.businessObjectFormatVersion)), builder.equal( businessObjectDataNotificationEntityRoot .get(BusinessObjectDataNotificationRegistrationEntity_.businessObjectFormatVersion), businessObjectDataKey.getBusinessObjectFormatVersion()))); predicates.add(builder.or( builder.isNull(businessObjectDataNotificationEntityRoot .get(BusinessObjectDataNotificationRegistrationEntity_.newBusinessObjectDataStatus)), builder.equal( builder.upper( newBusinessObjectDataStatusEntityJoin.get(BusinessObjectDataStatusEntity_.code)), newBusinessObjectDataStatus.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(businessObjectDataNotificationEntityRoot .get(BusinessObjectDataNotificationRegistrationEntity_.oldBusinessObjectDataStatus)), builder.equal( builder.upper( oldBusinessObjectDataStatusEntityJoin.get(BusinessObjectDataStatusEntity_.code)), oldBusinessObjectDataStatus == null ? null : oldBusinessObjectDataStatus.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(businessObjectDataNotificationEntityRoot .get(BusinessObjectDataNotificationRegistrationEntity_.name))); // Add the clauses for the query. criteria.select(businessObjectDataNotificationEntityRoot) .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.BusinessObjectDefinitionDaoImpl.java
@Override public List<BusinessObjectDefinitionEntity> getAllBusinessObjectDefinitions(Integer startPosition, Integer maxResult) {//from ww w . j av a2s. c om // Create the criteria builder and a tuple style criteria query. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<BusinessObjectDefinitionEntity> criteria = builder .createQuery(BusinessObjectDefinitionEntity.class); // The criteria root is the business object definition. Root<BusinessObjectDefinitionEntity> businessObjectDefinitionEntityRoot = criteria .from(BusinessObjectDefinitionEntity.class); // Join to the other tables we can filter on. Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntity = businessObjectDefinitionEntityRoot .join(BusinessObjectDefinitionEntity_.namespace); // Get the columns. Path<String> namespaceCodeColumn = namespaceEntity.get(NamespaceEntity_.code); Path<String> businessObjectDefinitionNameColumn = businessObjectDefinitionEntityRoot .get(BusinessObjectDefinitionEntity_.name); // Add all clauses to the query. criteria.select(businessObjectDefinitionEntityRoot).orderBy(builder.asc(businessObjectDefinitionNameColumn), builder.asc(namespaceCodeColumn)); // Get an instance of the query ready for execution. TypedQuery<BusinessObjectDefinitionEntity> query = entityManager.createQuery(criteria); // If start position is specified, set it for the query. if (startPosition != null) { query.setFirstResult(startPosition.intValue()); } // If start position is specified, set it for the query. if (maxResult != null) { query.setMaxResults(maxResult.intValue()); } // Execute the query and return the results. return query.getResultList(); }
From source file:org.finra.herd.dao.impl.BusinessObjectDefinitionDaoImpl.java
@Override public List<BusinessObjectDefinitionKey> getBusinessObjectDefinitionKeysByNamespace(String namespaceCode) { // Create the criteria builder and a tuple style criteria query. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<Tuple> criteria = builder.createTupleQuery(); // The criteria root is the business object definition. Root<BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = criteria .from(BusinessObjectDefinitionEntity.class); // Join to the other tables we can filter on. Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntity = businessObjectDefinitionEntity .join(BusinessObjectDefinitionEntity_.namespace); // Get the columns. Path<String> namespaceCodeColumn = namespaceEntity.get(NamespaceEntity_.code); Path<String> businessObjectDefinitionNameColumn = businessObjectDefinitionEntity .get(BusinessObjectDefinitionEntity_.name); // Add the select clause. criteria.multiselect(namespaceCodeColumn, businessObjectDefinitionNameColumn); // If namespace code is specified, add the where clause. if (StringUtils.isNotBlank(namespaceCode)) { criteria.where(builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)), namespaceCode.toUpperCase())); }/*from www. j a v a 2 s . com*/ // Add the order by clause. if (StringUtils.isNotBlank(namespaceCode)) { criteria.orderBy(builder.asc(businessObjectDefinitionNameColumn)); } else { criteria.orderBy(builder.asc(businessObjectDefinitionNameColumn), builder.asc(namespaceCodeColumn)); } // Run the query to get a list of tuples back. List<Tuple> tuples = entityManager.createQuery(criteria).getResultList(); // Populate the "keys" objects from the returned tuples (i.e. 1 tuple for each row). List<BusinessObjectDefinitionKey> businessObjectDefinitionKeys = new ArrayList<>(); for (Tuple tuple : tuples) { BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(); businessObjectDefinitionKeys.add(businessObjectDefinitionKey); businessObjectDefinitionKey.setNamespace(tuple.get(namespaceCodeColumn)); businessObjectDefinitionKey .setBusinessObjectDefinitionName(tuple.get(businessObjectDefinitionNameColumn)); } return businessObjectDefinitionKeys; }
From source file:org.finra.herd.dao.impl.BusinessObjectDefinitionDaoImpl.java
@Override public List<BusinessObjectDefinitionEntity> getBusinessObjectDefinitions(List<TagEntity> tagEntities) { // Create the criteria builder and a tuple style criteria query. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<BusinessObjectDefinitionEntity> criteria = builder .createQuery(BusinessObjectDefinitionEntity.class); // The criteria root is the business object definition. Root<BusinessObjectDefinitionEntity> businessObjectDefinitionEntityRoot = criteria .from(BusinessObjectDefinitionEntity.class); // Join to the other tables we can filter on. Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntity = businessObjectDefinitionEntityRoot .join(BusinessObjectDefinitionEntity_.namespace); // Get the columns. Path<String> namespaceCodeColumn = namespaceEntity.get(NamespaceEntity_.code); Path<String> businessObjectDefinitionNameColumn = businessObjectDefinitionEntityRoot .get(BusinessObjectDefinitionEntity_.name); Predicate predicate;//from ww w.j a v a 2 s.c o m if (!CollectionUtils.isEmpty(tagEntities)) { //join the business object definition tags Join<BusinessObjectDefinitionEntity, BusinessObjectDefinitionTagEntity> businessObjectDefinitionTagEntityJoin = businessObjectDefinitionEntityRoot .join(BusinessObjectDefinitionEntity_.businessObjectDefinitionTags); // Create the standard restrictions (i.e. the standard where clauses). predicate = getPredicateForInClause(builder, businessObjectDefinitionTagEntityJoin.get(BusinessObjectDefinitionTagEntity_.tag), tagEntities); // Add all clauses to the query. criteria.select(businessObjectDefinitionEntityRoot).where(predicate) .orderBy(builder.asc(businessObjectDefinitionNameColumn), builder.asc(namespaceCodeColumn)); } else { criteria.select(businessObjectDefinitionEntityRoot) .orderBy(builder.asc(businessObjectDefinitionNameColumn), builder.asc(namespaceCodeColumn)); } //Returns duplicate business object definition. When a bdef is associated with multiple tags. return entityManager.createQuery(criteria).getResultList(); }
From source file:org.finra.herd.dao.impl.BusinessObjectFormatDaoImpl.java
@Override public List<Integer> getBusinessObjectFormatIdsByBusinessObjectDefinition( BusinessObjectDefinitionEntity businessObjectDefinitionEntity) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<Integer> criteria = builder.createQuery(Integer.class); // The criteria root is the business object format. Root<BusinessObjectFormatEntity> businessObjectFormatEntityRoot = criteria .from(BusinessObjectFormatEntity.class); // Create path. Expression<Integer> businessObjectFormatIdColumn = businessObjectFormatEntityRoot .get(BusinessObjectFormatEntity_.id); // Create standard restrictions. Predicate predicate = builder.equal( businessObjectFormatEntityRoot.get(BusinessObjectFormatEntity_.businessObjectDefinitionId), businessObjectDefinitionEntity.getId()); // Build an order by clause. Order orderBy = builder.asc(businessObjectFormatEntityRoot.get(BusinessObjectFormatEntity_.id)); // Add all clauses to the query. criteria.select(businessObjectFormatIdColumn).where(predicate).orderBy(orderBy); // Execute the query and return the results. return entityManager.createQuery(criteria).getResultList(); }