List of usage examples for javax.persistence.criteria CriteriaBuilder upper
Expression<String> upper(Expression<String> x);
From source file:org.finra.herd.dao.impl.BusinessObjectDataDaoImpl.java
/** * Creates a predicate for partition value filters. * * @param businessDataSearchKey businessDataSearchKey * @param businessObjectDataEntity businessObjectDataEntity * @param businessObjectFormatEntity businessObjectFormatEntity * @param builder builder/*from w w w. ja v a 2s .com*/ * @param predicatePram predicate parameter * * @return the predicate */ private Predicate createPartitionValueFilters(BusinessObjectDataSearchKey businessDataSearchKey, Root<BusinessObjectDataEntity> businessObjectDataEntity, Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> businessObjectFormatEntity, CriteriaBuilder builder, Predicate predicatePram) { Predicate predicate = predicatePram; if (businessDataSearchKey.getPartitionValueFilters() != null && !businessDataSearchKey.getPartitionValueFilters().isEmpty()) { for (PartitionValueFilter partitionFilter : businessDataSearchKey.getPartitionValueFilters()) { Join<BusinessObjectFormatEntity, SchemaColumnEntity> schemaEntity = businessObjectFormatEntity .join(BusinessObjectFormatEntity_.schemaColumns); List<String> partitionValues = partitionFilter.getPartitionValues(); predicate = builder.and(predicate, builder.equal(builder.upper(schemaEntity.get(SchemaColumnEntity_.name)), partitionFilter.getPartitionKey().toUpperCase())); predicate = builder.and(predicate, builder.isNotNull(schemaEntity.get(SchemaColumnEntity_.partitionLevel))); if (partitionValues != null && !partitionValues.isEmpty()) { predicate = builder.and(predicate, builder.or( builder.and(builder.equal(schemaEntity.get(SchemaColumnEntity_.partitionLevel), 1), businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue) .in(partitionValues)), builder.and(builder.equal(schemaEntity.get(SchemaColumnEntity_.partitionLevel), 2), businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue2) .in(partitionValues)), builder.and(builder.equal(schemaEntity.get(SchemaColumnEntity_.partitionLevel), 3), businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue3) .in(partitionValues)), builder.and(builder.equal(schemaEntity.get(SchemaColumnEntity_.partitionLevel), 4), businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue4) .in(partitionValues)), builder.and(builder.equal(schemaEntity.get(SchemaColumnEntity_.partitionLevel), 5), businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue5) .in(partitionValues)))); } else if (partitionFilter.getPartitionValueRange() != null) { PartitionValueRange partitionRange = partitionFilter.getPartitionValueRange(); String startPartitionValue = partitionRange.getStartPartitionValue(); String endPartitionValue = partitionRange.getEndPartitionValue(); predicate = builder.and(predicate, builder.or( builder.and(builder.equal(schemaEntity.get(SchemaColumnEntity_.partitionLevel), 1), builder.greaterThanOrEqualTo( businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue), startPartitionValue), builder.lessThanOrEqualTo( businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue), endPartitionValue)), builder.and(builder.equal(schemaEntity.get(SchemaColumnEntity_.partitionLevel), 2), builder.greaterThanOrEqualTo( businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue2), startPartitionValue), builder.lessThanOrEqualTo( businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue2), endPartitionValue)), builder.and(builder.equal(schemaEntity.get(SchemaColumnEntity_.partitionLevel), 3), builder.greaterThanOrEqualTo( businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue3), startPartitionValue), builder.lessThanOrEqualTo( businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue3), endPartitionValue)), builder.and(builder.equal(schemaEntity.get(SchemaColumnEntity_.partitionLevel), 4), builder.greaterThanOrEqualTo( businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue4), startPartitionValue), builder.lessThanOrEqualTo( businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue4), endPartitionValue)), builder.and(builder.equal(schemaEntity.get(SchemaColumnEntity_.partitionLevel), 5), builder.greaterThanOrEqualTo( businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue5), startPartitionValue), builder.lessThanOrEqualTo( businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue5), endPartitionValue)))); } } } return predicate; }
From source file:org.finra.herd.dao.impl.BusinessObjectDataDaoImpl.java
/** * Apply retention expiration filter to the main query predicate. * * @param businessObjectDataSearchKey the business object data search key * @param businessObjectDataEntityRoot the criteria root which is a business object data entity * @param businessObjectFormatEntityJoin the join with the business object format table * @param builder the criteria builder//w w w. j a va 2 s .c o m * @param mainQueryPredicate the main query predicate to be updated * * @return the updated main query predicate */ private Predicate applyRetentionExpirationFilter(BusinessObjectDataSearchKey businessObjectDataSearchKey, Root<BusinessObjectDataEntity> businessObjectDataEntityRoot, Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> businessObjectFormatEntityJoin, CriteriaBuilder builder, Predicate mainQueryPredicate) { // Create a business object definition key per specified search key. BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey( businessObjectDataSearchKey.getNamespace(), businessObjectDataSearchKey.getBusinessObjectDefinitionName()); // Get latest versions of all business object formats that registered with the business object definition. List<BusinessObjectFormatEntity> businessObjectFormatEntities = businessObjectFormatDao .getLatestVersionBusinessObjectFormatsByBusinessObjectDefinition(businessObjectDefinitionKey); // Create a result predicate to join all retention expiration predicates created per selected business object formats. Predicate businessObjectDefinitionRetentionExpirationPredicate = null; // Get the current database timestamp to be used to select expired business object data per BDATA_RETENTION_DATE retention type. Timestamp currentTimestamp = getCurrentTimestamp(); // Create a predicate for each business object format with the retention information. for (BusinessObjectFormatEntity businessObjectFormatEntity : businessObjectFormatEntities) { if (businessObjectFormatEntity.getRetentionType() != null) { // Create a retention expiration predicate for this business object format. Predicate businessObjectFormatRetentionExpirationPredicate = null; if (StringUtils.equals(businessObjectFormatEntity.getRetentionType().getCode(), RetentionTypeEntity.BDATA_RETENTION_DATE)) { // Select business object data that has expired per its explicitly configured retention expiration date. businessObjectFormatRetentionExpirationPredicate = builder.lessThan( businessObjectDataEntityRoot.get(BusinessObjectDataEntity_.retentionExpiration), currentTimestamp); } else if (StringUtils.equals(businessObjectFormatEntity.getRetentionType().getCode(), RetentionTypeEntity.PARTITION_VALUE) && businessObjectFormatEntity.getRetentionPeriodInDays() != null) { // Compute the retention expiration date and convert it to the date format to match against partition values. String retentionExpirationDate = DateFormatUtils.format( DateUtils.addDays(new Date(), -1 * businessObjectFormatEntity.getRetentionPeriodInDays()), DEFAULT_SINGLE_DAY_DATE_MASK); // Create a predicate to compare business object data primary partition value against the retention expiration date. businessObjectFormatRetentionExpirationPredicate = builder.lessThan( businessObjectDataEntityRoot.get(BusinessObjectDataEntity_.partitionValue), retentionExpirationDate); } // If it was initialize, complete processing of retention expiration predicate for this business object format. if (businessObjectFormatRetentionExpirationPredicate != null) { // Update the predicate to match this business object format w/o version. businessObjectFormatRetentionExpirationPredicate = builder.and( businessObjectFormatRetentionExpirationPredicate, builder.equal( builder.upper( businessObjectFormatEntityJoin.get(BusinessObjectFormatEntity_.usage)), businessObjectFormatEntity.getUsage().toUpperCase())); businessObjectFormatRetentionExpirationPredicate = builder.and( businessObjectFormatRetentionExpirationPredicate, builder.equal(businessObjectFormatEntityJoin.get(BusinessObjectFormatEntity_.fileType), businessObjectFormatEntity.getFileType())); // Add this business object format specific retention expiration predicate to other // retention expiration predicates created for the specified business object definition. if (businessObjectDefinitionRetentionExpirationPredicate == null) { businessObjectDefinitionRetentionExpirationPredicate = businessObjectFormatRetentionExpirationPredicate; } else { businessObjectDefinitionRetentionExpirationPredicate = builder.or( businessObjectDefinitionRetentionExpirationPredicate, businessObjectFormatRetentionExpirationPredicate); } } } } // Fail if no retention expiration predicates got created per specified business objject definition. Assert.notNull(businessObjectDefinitionRetentionExpirationPredicate, String.format( "Business object definition with name \"%s\" and namespace \"%s\" has no business object formats with supported retention type.", businessObjectDefinitionKey.getBusinessObjectDefinitionName(), businessObjectDefinitionKey.getNamespace())); // Add created business object definition retention expiration predicate to the main query predicate passed to this method and return the result. return builder.and(mainQueryPredicate, businessObjectDefinitionRetentionExpirationPredicate); }
From source file:org.finra.herd.dao.impl.BusinessObjectDataDaoImpl.java
/** * Creates a sub query for the maximum business object data version. * * @param builder criteria builder/*from w w w . ja va 2s . c o m*/ * @param criteria criteria query * @param businessObjectDataEntity business object data entity * @param businessObjectFormatEntity business object format entity * @param businessObjectDataStatus business object status, case insensitive * * @return the sub query to select the maximum business object data version */ private Subquery<Integer> getMaximumBusinessObjectDataVersionSubQuery(CriteriaBuilder builder, CriteriaQuery<?> criteria, From<?, BusinessObjectDataEntity> businessObjectDataEntity, From<?, BusinessObjectFormatEntity> businessObjectFormatEntity, String businessObjectDataStatus) { // Create a sub query for the business object data version. 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, BusinessObjectFormatEntity> subBusinessObjectFormatEntity = subBusinessObjectDataEntity .join(BusinessObjectDataEntity_.businessObjectFormat); // Add a standard restriction on business object format. Predicate subQueryRestriction = builder.equal(subBusinessObjectFormatEntity, businessObjectFormatEntity); // Create and add standard restrictions on primary and sub-partition values. subQueryRestriction = builder.and(subQueryRestriction, getQueryRestrictionOnPartitionValues(builder, subBusinessObjectDataEntity, businessObjectDataEntity)); // If specified, create and add a standard restriction on business object data status. if (businessObjectDataStatus != null) { Join<BusinessObjectDataEntity, BusinessObjectDataStatusEntity> subBusinessObjectDataStatusEntity = subBusinessObjectDataEntity .join(BusinessObjectDataEntity_.status); subQueryRestriction = builder.and(subQueryRestriction, builder.equal( builder.upper( subBusinessObjectDataStatusEntity.get(BusinessObjectDataStatusEntity_.code)), businessObjectDataStatus.toUpperCase())); } // Add all clauses to the sub query. subQuery.select(builder.max(subBusinessObjectDataEntity.get(BusinessObjectDataEntity_.version))) .where(subQueryRestriction); return subQuery; }
From source file:org.finra.herd.dao.impl.BusinessObjectDataNotificationRegistrationDaoImpl.java
@Override public BusinessObjectDataNotificationRegistrationEntity getBusinessObjectDataNotificationRegistrationByAltKey( NotificationRegistrationKey key) { // 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> businessObjectDataNotificationEntity = criteria .from(BusinessObjectDataNotificationRegistrationEntity.class); // Join to the other tables we can filter on. Join<BusinessObjectDataNotificationRegistrationEntity, NamespaceEntity> namespaceEntity = businessObjectDataNotificationEntity .join(BusinessObjectDataNotificationRegistrationEntity_.namespace); // Create the standard restrictions (i.e. the standard where clauses). Predicate queryRestriction = builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)), key.getNamespace().toUpperCase()); queryRestriction = builder.and(queryRestriction, builder.equal(/*from w w w. j a va 2 s .c om*/ builder.upper(businessObjectDataNotificationEntity .get(BusinessObjectDataNotificationRegistrationEntity_.name)), key.getNotificationName().toUpperCase())); criteria.select(businessObjectDataNotificationEntity).where(queryRestriction); return executeSingleResultQuery(criteria, String.format( "Found more than one business object data notification registration with with parameters {namespace=\"%s\", notificationName=\"%s\"}.", key.getNamespace(), key.getNotificationName())); }
From source file:org.finra.herd.dao.impl.BusinessObjectDataNotificationRegistrationDaoImpl.java
@Override public List<NotificationRegistrationKey> getBusinessObjectDataNotificationRegistrationKeysByNamespace( String namespace) {/* w w w .ja v a2 s . co 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 ww w.j a v a 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(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 v a 2s. 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.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 BusinessObjectDefinitionEntity getBusinessObjectDefinitionByKey( BusinessObjectDefinitionKey businessObjectDefinitionKey) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<BusinessObjectDefinitionEntity> criteria = builder .createQuery(BusinessObjectDefinitionEntity.class); // 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); // Create the standard restrictions (i.e. the standard where clauses). Predicate queryRestriction = builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)), businessObjectDefinitionKey.getNamespace().toUpperCase()); queryRestriction = builder.and(queryRestriction, builder.equal(// w w w. j a v a 2s.c o m builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)), businessObjectDefinitionKey.getBusinessObjectDefinitionName().toUpperCase())); criteria.select(businessObjectDefinitionEntity).where(queryRestriction); return executeSingleResultQuery(criteria, String.format( "Found more than one business object definition with parameters {namespace=\"%s\", businessObjectDefinitionName=\"%s\"}.", businessObjectDefinitionKey.getNamespace(), businessObjectDefinitionKey.getBusinessObjectDefinitionName())); }
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())); }/* w w w. ja va 2 s . co m*/ // 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.BusinessObjectFormatDaoImpl.java
@Override public Long getBusinessObjectFormatCountByPartitionKeys(String namespace, String businessObjectDefinitionName, String businessObjectFormatUsage, String businessObjectFormatFileType, Integer businessObjectFormatVersion, List<String> partitionKeys) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<Long> criteria = builder.createQuery(Long.class); // The criteria root is the business object format. Root<BusinessObjectFormatEntity> businessObjectFormatEntityRoot = criteria .from(BusinessObjectFormatEntity.class); // Create path. Expression<Long> businessObjectFormatRecordCount = builder.count(businessObjectFormatEntityRoot); // Namespace is a required parameter, so fetch the relative entity to optimize the main query. NamespaceEntity namespaceEntity = namespaceDao.getNamespaceByCd(namespace); // If specified namespace does not exist, then return a zero record count. if (namespaceEntity == null) { return 0L; }/*from w ww .ja v a 2 s. c o m*/ // If file type is specified, fetch the relative entity to optimize the main query. FileTypeEntity fileTypeEntity = null; if (StringUtils.isNotBlank(businessObjectFormatFileType)) { fileTypeEntity = fileTypeDao.getFileTypeByCode(businessObjectFormatFileType); // If specified file type does not exist, then return a zero record count. if (fileTypeEntity == null) { return 0L; } } // Join to the other tables we can filter on. Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = businessObjectFormatEntityRoot .join(BusinessObjectFormatEntity_.businessObjectDefinition); // Create main query restrictions based on the specified parameters. List<Predicate> predicates = new ArrayList<>(); // Create restriction on namespace code and business object definition name. predicates.add(builder.equal(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.namespace), namespaceEntity)); predicates.add(builder.equal( builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)), businessObjectDefinitionName.toUpperCase())); // If specified, create restriction on business object format usage. if (!StringUtils.isEmpty(businessObjectFormatUsage)) { predicates.add(builder.equal( builder.upper(businessObjectFormatEntityRoot.get(BusinessObjectFormatEntity_.usage)), businessObjectFormatUsage.toUpperCase())); } // If specified, create restriction on business object format file type. if (fileTypeEntity != null) { predicates .add(builder.equal(businessObjectFormatEntityRoot.get(BusinessObjectFormatEntity_.fileTypeCode), fileTypeEntity.getCode())); } // If specified, create restriction on business object format version. if (businessObjectFormatVersion != null) { predicates.add(builder.equal( businessObjectFormatEntityRoot.get(BusinessObjectFormatEntity_.businessObjectFormatVersion), businessObjectFormatVersion)); } // If specified, create restriction on partition keys. if (CollectionUtils.isNotEmpty(partitionKeys)) { for (String partitionKey : partitionKeys) { // Add restriction on partition key (partition column). // Partition key must identify a partition column that is at partition level that could be explicitly registered. // Partition level uses one-based numbering. Join<BusinessObjectFormatEntity, SchemaColumnEntity> schemaColumnEntityJoin = businessObjectFormatEntityRoot .join(BusinessObjectFormatEntity_.schemaColumns); predicates.add(builder.equal(builder.upper(schemaColumnEntityJoin.get(SchemaColumnEntity_.name)), partitionKey.toUpperCase())); predicates.add(builder.isNotNull(schemaColumnEntityJoin.get(SchemaColumnEntity_.partitionLevel))); predicates.add(builder.lessThan(schemaColumnEntityJoin.get(SchemaColumnEntity_.partitionLevel), BusinessObjectDataEntity.MAX_SUBPARTITIONS + 2)); } } // Add all clauses for the query. criteria.select(businessObjectFormatRecordCount) .where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).distinct(true); // Execute the query and return the result. return entityManager.createQuery(criteria).getSingleResult(); }