List of usage examples for javax.persistence.criteria From get
<Y> Path<Y> get(SingularAttribute<? super X, Y> attribute);
From source file:org.finra.herd.dao.impl.AbstractHerdDao.java
/** * Builds a query restriction predicate for the specified business object format entity as per business object format key values. * * @param builder the criteria builder// w w w .j a va2 s . co m * @param businessObjectFormatEntity the business object format entity that appears in the from clause * @param fileTypeEntity the file type entity that appears in the from clause * @param businessObjectDefinitionEntity the business object definition entity that appears in the from clause * @param namespaceEntity the namespace entity that appears in the from clause * @param businessObjectFormatKey the business object format key * @param ignoreBusinessObjectFormatVersion specifies whether to ignore the business object format version when building the predicate * * @return the query restriction predicate */ protected Predicate getQueryRestriction(CriteriaBuilder builder, From<?, BusinessObjectFormatEntity> businessObjectFormatEntity, From<?, FileTypeEntity> fileTypeEntity, From<?, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity, From<?, NamespaceEntity> namespaceEntity, BusinessObjectFormatKey businessObjectFormatKey, boolean ignoreBusinessObjectFormatVersion) { // Create the standard restrictions based on the business object format key values (i.e. the standard where clauses). // Create a restriction on namespace code. Predicate predicate = builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)), businessObjectFormatKey.getNamespace().toUpperCase()); // Create and append a restriction on business object definition name. predicate = builder.and(predicate, builder.equal( builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)), businessObjectFormatKey.getBusinessObjectDefinitionName().toUpperCase())); // Create and append a restriction on business object format usage. predicate = builder.and(predicate, builder.equal(builder.upper(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage)), businessObjectFormatKey.getBusinessObjectFormatUsage().toUpperCase())); // Create and append a restriction on business object format file type. predicate = builder.and(predicate, builder.equal(builder.upper(fileTypeEntity.get(FileTypeEntity_.code)), businessObjectFormatKey.getBusinessObjectFormatFileType().toUpperCase())); // If specified, create and append a restriction on business object format version. if (!ignoreBusinessObjectFormatVersion && businessObjectFormatKey.getBusinessObjectFormatVersion() != null) { predicate = builder.and(predicate, builder.equal( businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion), businessObjectFormatKey.getBusinessObjectFormatVersion())); } return predicate; }
From source file:org.finra.herd.dao.impl.AbstractHerdDao.java
/** * TODO This method may be bdata specific. Consider creating new abstract class to group all bdata related DAO. Builds a query restriction predicate for the * sub-query business object data entity as per partition values from the specified main query business object data entity. * * @param builder the criteria builder/* www . j av a2s.c om*/ * @param businessObjectDataEntity the business object data entity that appears in the from clause * @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. * * @return the query restriction predicate */ protected Predicate getQueryRestrictionOnPartitionValues(CriteriaBuilder builder, From<?, BusinessObjectDataEntity> businessObjectDataEntity, List<List<String>> partitionFilters) { // Create a query restriction as per specified primary and/or sub-partition values. Predicate predicate = null; for (List<String> partitionFilter : partitionFilters) { // Add restriction for each partition level if the relative partition value is specified in the partition filter. Predicate partitionRestriction = null; for (int partitionLevel = 0; partitionLevel < BusinessObjectDataEntity.MAX_SUBPARTITIONS + 1; partitionLevel++) { String partitionValue = partitionFilter.get(partitionLevel); if (StringUtils.isNotBlank(partitionValue)) { Predicate partitionValueRestriction = builder.equal( businessObjectDataEntity.get(BUSINESS_OBJECT_DATA_PARTITIONS.get(partitionLevel)), partitionValue); partitionRestriction = (partitionRestriction == null ? partitionValueRestriction : builder.and(partitionRestriction, partitionValueRestriction)); } } predicate = (predicate == null ? partitionRestriction : builder.or(predicate, partitionRestriction)); } return predicate; }
From source file:org.finra.herd.dao.impl.AbstractHerdDao.java
/** * TODO This method may be bdata specific. Consider creating new abstract class to group all bdata related DAO. Builds a query restriction predicate for the * sub-query business object data entity as per partition values from the specified main query business object data entity. * * @param builder the criteria builder// w ww. j a va 2s . c o m * @param subBusinessObjectDataEntity the sub-query business object data entity that appears in the from clause * @param mainBusinessObjectDataEntity the main query business object data entity that appears in the from clause * * @return the query restriction predicate */ protected Predicate getQueryRestrictionOnPartitionValues(CriteriaBuilder builder, From<?, BusinessObjectDataEntity> subBusinessObjectDataEntity, From<?, BusinessObjectDataEntity> mainBusinessObjectDataEntity) { // Create a standard restriction on primary partition value. Predicate predicate = builder.equal( subBusinessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue), mainBusinessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue)); // Create and add standard restrictions on sub-partition values. Please note that the subpartition value columns are nullable. for (SingularAttribute<BusinessObjectDataEntity, String> businessObjectDataPartitionValueSingularAttribute : BUSINESS_OBJECT_DATA_SUBPARTITIONS) { predicate = builder.and(predicate, builder.or( builder.and( builder.isNull(subBusinessObjectDataEntity .get(businessObjectDataPartitionValueSingularAttribute)), builder.isNull(mainBusinessObjectDataEntity .get(businessObjectDataPartitionValueSingularAttribute))), builder.equal( subBusinessObjectDataEntity.get(businessObjectDataPartitionValueSingularAttribute), mainBusinessObjectDataEntity.get(businessObjectDataPartitionValueSingularAttribute)))); } return predicate; }
From source file:org.finra.herd.dao.impl.AbstractHerdDao.java
/** * TODO This method may be bdata specific. Consider creating new abstract class to group all bdata related DAO. Builds query restriction predicates and adds * them to the query restriction as per specified business object data version and status. If a business object data version is specified, the business * object data status is ignored. When both business object data version and business object data status are not specified, the sub-query restriction is not * getting updated./*w w w . ja va 2s . c o m*/ * * @param builder the criteria builder * @param businessObjectDataEntity the business object data entity that appears in the from clause * @param businessObjectDataStatusEntity the business object data status entity that appears in the from clause * @param businessObjectDataVersion the business object data version * @param businessObjectDataStatus the business object data status. This parameter is ignored when the business object data version is specified. * * @return the query restriction predicate or null if both business object data version and business object data status are not specified */ protected Predicate getQueryRestrictionOnBusinessObjectDataVersionAndStatus(CriteriaBuilder builder, From<?, BusinessObjectDataEntity> businessObjectDataEntity, From<?, BusinessObjectDataStatusEntity> businessObjectDataStatusEntity, Integer businessObjectDataVersion, String businessObjectDataStatus) { Predicate predicate = null; // If specified, create a standard restriction on the business object data version. if (businessObjectDataVersion != null) { predicate = builder.equal(businessObjectDataEntity.get(BusinessObjectDataEntity_.version), businessObjectDataVersion); } // Only if a business object data version is not specified, check if we need to add a restriction on the business object data status. else if (businessObjectDataStatus != null) { predicate = builder.equal( builder.upper(businessObjectDataStatusEntity.get(BusinessObjectDataStatusEntity_.code)), businessObjectDataStatus.toUpperCase()); } return predicate; }
From source file:org.finra.herd.dao.impl.AbstractHerdDao.java
/** * Builds a query restriction predicate for the storage. * * @param builder the criteria builder/*from w w w . j a va 2 s . c om*/ * @param storageEntity the storage entity that appears in the from clause * @param storagePlatformEntity the storage platform entity that appears in the from clause * @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 * * @return the query restriction predicate */ protected Predicate getQueryRestrictionOnStorage(CriteriaBuilder builder, From<?, StorageEntity> storageEntity, From<?, StoragePlatformEntity> storagePlatformEntity, List<String> storageNames, String storagePlatformType, String excludedStoragePlatformType) { List<Predicate> predicates = new ArrayList<>(); // If specified, add restriction on storage. if (!CollectionUtils.isEmpty(storageNames)) { // Add a storage name restriction to the main query where clause. List<String> uppercaseStorageNames = new ArrayList<>(); for (String storageName : storageNames) { uppercaseStorageNames.add(storageName.toUpperCase()); } predicates.add(builder.upper(storageEntity.get(StorageEntity_.name)).in(uppercaseStorageNames)); } else if (StringUtils.isNotBlank(storagePlatformType)) { // Select storage units only from the storages of the specified storage platform type. predicates.add( builder.equal(storagePlatformEntity.get(StoragePlatformEntity_.name), storagePlatformType)); } else if (StringUtils.isNotBlank(excludedStoragePlatformType)) { // Ignore any storages of the excluded storage platform type. predicates.add(builder.notEqual(storagePlatformEntity.get(StoragePlatformEntity_.name), excludedStoragePlatformType)); } return builder.and(predicates.toArray(new Predicate[predicates.size()])); }
From source file:org.finra.herd.dao.impl.HerdDaoImpl.java
/** * Builds a sub-query to select the maximum business object data version. * * @param builder the criteria builder//from www .j a v a 2 s . c om * @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 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, From<?, StorageEntity> storageEntity, 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<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, builder.equal(subStorageEntity, storageEntity)); // 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; }
From source file:org.finra.herd.dao.impl.StorageUnitDaoImpl.java
/** * Builds a sub-query to select the maximum business object data version. * * @param builder the criteria builder//from ww w.j av a 2 s.c o m * @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; }