use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.
the class StorageUnitDaoImpl method getStorageUnitByKey.
@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(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()));
}
use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.
the class StorageUnitDaoImpl method getMaximumBusinessObjectFormatVersionSubQuery.
/**
* Builds a sub-query to select the maximum business object data version.
*
* @param builder the criteria builder
* @param criteria the criteria query
* @param businessObjectDefinitionEntity the business object definition entity that appears in the from clause of the main query
* @param businessObjectFormatEntity the business object format entity that appears in the from clause of the main query
* @param fileTypeEntity the file type entity that appears in the from clause of the main query
* @param businessObjectDataEntity the business object data entity that appears in the from clause of the main query
* @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
* @param storageNames the list of storage names where the business object data storage units should be looked for (case-insensitive)
* @param storagePlatformType the optional storage platform type, e.g. S3 for Hive DDL. It is ignored when the list of storages is not empty
* @param excludedStoragePlatformType the optional storage platform type to be excluded from search. It is ignored when the list of storages is not empty or
* the storage platform type is specified
* @param selectOnlyAvailableStorageUnits specifies if only available storage units will be selected or any storage units regardless of their status
*
* @return the sub-query to select the maximum business object data version
*/
private Subquery<Integer> getMaximumBusinessObjectFormatVersionSubQuery(CriteriaBuilder builder, CriteriaQuery<?> criteria, From<?, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity, From<?, BusinessObjectFormatEntity> businessObjectFormatEntity, From<?, FileTypeEntity> fileTypeEntity, From<?, BusinessObjectDataEntity> businessObjectDataEntity, Integer businessObjectDataVersion, String businessObjectDataStatus, List<String> storageNames, String storagePlatformType, String excludedStoragePlatformType, boolean selectOnlyAvailableStorageUnits) {
// 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<StorageEntity, StoragePlatformEntity> subStoragePlatformEntity = subStorageEntity.join(StorageEntity_.storagePlatform);
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);
Join<StorageUnitEntity, StorageUnitStatusEntity> subStorageUnitStatusEntity = subStorageUnitEntity.join(StorageUnitEntity_.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, getQueryRestrictionOnStorage(builder, subStorageEntity, subStoragePlatformEntity, storageNames, storagePlatformType, excludedStoragePlatformType));
// If specified, add a restriction on storage unit status availability flag.
if (selectOnlyAvailableStorageUnits) {
subQueryRestriction = builder.and(subQueryRestriction, builder.isTrue(subStorageUnitStatusEntity.get(StorageUnitStatusEntity_.available)));
}
// Add all of the clauses to the subquery.
subQuery.select(builder.max(subBusinessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion))).where(subQueryRestriction);
return subQuery;
}
use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.
the class BusinessObjectFormatDaoTest method testGetBusinessObjectFormatByAltKeyAllParamsUpperCase.
@Test
public void testGetBusinessObjectFormatByAltKeyAllParamsUpperCase() {
// Create relative database entities.
businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE.toLowerCase(), BDEF_NAME.toLowerCase(), DATA_PROVIDER_NAME.toLowerCase(), BDEF_DESCRIPTION);
fileTypeDaoTestHelper.createFileTypeEntity(FORMAT_FILE_TYPE_CODE.toLowerCase(), "Description of " + FORMAT_FILE_TYPE_CODE);
businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME.toLowerCase(), FORMAT_USAGE_CODE.toLowerCase(), FORMAT_FILE_TYPE_CODE.toLowerCase(), INITIAL_FORMAT_VERSION, "Test format 0", Boolean.TRUE, PARTITION_KEY);
// Retrieve business object format entity by specifying values for all text alternate key fields in upper case.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME.toUpperCase(), FORMAT_USAGE_CODE.toUpperCase(), FORMAT_FILE_TYPE_CODE.toUpperCase(), INITIAL_FORMAT_VERSION));
// Validate the results.
assertNotNull(businessObjectFormatEntity);
assertTrue(businessObjectFormatEntity.getBusinessObjectDefinition().getName().equals(BDEF_NAME.toLowerCase()));
assertTrue(businessObjectFormatEntity.getUsage().equals(FORMAT_USAGE_CODE.toLowerCase()));
assertTrue(businessObjectFormatEntity.getFileType().getCode().equals(FORMAT_FILE_TYPE_CODE.toLowerCase()));
assertTrue(businessObjectFormatEntity.getBusinessObjectFormatVersion().equals(INITIAL_FORMAT_VERSION));
assertTrue(businessObjectFormatEntity.getLatestVersion());
assertTrue(businessObjectFormatEntity.getPartitionKey().equals(PARTITION_KEY));
assertTrue(businessObjectFormatEntity.getDescription().equals("Test format 0"));
}
use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.
the class BusinessObjectFormatDaoTest method testGetBusinessObjectFormatByAltKeyAllParamsLowerCase.
@Test
public void testGetBusinessObjectFormatByAltKeyAllParamsLowerCase() {
// Create relative database entities.
businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE.toUpperCase(), BDEF_NAME.toUpperCase(), DATA_PROVIDER_NAME.toUpperCase(), BDEF_DESCRIPTION);
fileTypeDaoTestHelper.createFileTypeEntity(FORMAT_FILE_TYPE_CODE.toUpperCase(), "Description of " + FORMAT_FILE_TYPE_CODE);
businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME.toUpperCase(), FORMAT_USAGE_CODE.toUpperCase(), FORMAT_FILE_TYPE_CODE.toUpperCase(), INITIAL_FORMAT_VERSION, "Test format 0", Boolean.TRUE, PARTITION_KEY);
// Retrieve business object format entity by specifying values for all text alternate key fields in lower case.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME.toLowerCase(), FORMAT_USAGE_CODE.toLowerCase(), FORMAT_FILE_TYPE_CODE.toLowerCase(), INITIAL_FORMAT_VERSION));
// Validate the results.
assertNotNull(businessObjectFormatEntity);
assertTrue(businessObjectFormatEntity.getBusinessObjectDefinition().getName().equals(BDEF_NAME.toUpperCase()));
assertTrue(businessObjectFormatEntity.getUsage().equals(FORMAT_USAGE_CODE.toUpperCase()));
assertTrue(businessObjectFormatEntity.getFileType().getCode().equals(FORMAT_FILE_TYPE_CODE.toUpperCase()));
assertTrue(businessObjectFormatEntity.getBusinessObjectFormatVersion().equals(INITIAL_FORMAT_VERSION));
assertTrue(businessObjectFormatEntity.getLatestVersion());
assertTrue(businessObjectFormatEntity.getPartitionKey().equals(PARTITION_KEY));
assertTrue(businessObjectFormatEntity.getDescription().equals("Test format 0"));
}
use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.
the class BusinessObjectFormatDaoTestHelper method createBusinessObjectFormatEntity.
/**
* Creates and persists a new business object format entity.
*
* @return the newly created business object format entity.
*/
public BusinessObjectFormatEntity createBusinessObjectFormatEntity(boolean includeAttributeDefinition) {
BusinessObjectFormatEntity businessObjectFormatEntity = new BusinessObjectFormatEntity();
businessObjectFormatEntity.setBusinessObjectDefinition(businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinition());
businessObjectFormatEntity.setDescription("test");
businessObjectFormatEntity.setFileType(fileTypeDaoTestHelper.createFileTypeEntity());
businessObjectFormatEntity.setBusinessObjectFormatVersion(0);
businessObjectFormatEntity.setLatestVersion(true);
businessObjectFormatEntity.setUsage("PRC");
businessObjectFormatEntity.setPartitionKey("testPartitionKey");
if (includeAttributeDefinition) {
List<BusinessObjectDataAttributeDefinitionEntity> attributeDefinitionEntities = new ArrayList<>();
businessObjectFormatEntity.setAttributeDefinitions(attributeDefinitionEntities);
BusinessObjectDataAttributeDefinitionEntity attributeDefinitionEntity = new BusinessObjectDataAttributeDefinitionEntity();
attributeDefinitionEntities.add(attributeDefinitionEntity);
attributeDefinitionEntity.setBusinessObjectFormat(businessObjectFormatEntity);
attributeDefinitionEntity.setName(AbstractDaoTest.ATTRIBUTE_NAME_1_MIXED_CASE);
}
return businessObjectFormatDao.saveAndRefresh(businessObjectFormatEntity);
}
Aggregations