Java Code Examples for javax.persistence.criteria.Join#join()

The following examples show how to use javax.persistence.criteria.Join#join() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StorageFileDaoImpl.java    From herd with Apache License 2.0 11 votes vote down vote up
@Override
public StorageFileEntity getStorageFileByStorageNameAndFilePath(String storageName, String filePath)
{
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<StorageFileEntity> criteria = builder.createQuery(StorageFileEntity.class);

    // The criteria root is the storage files.
    Root<StorageFileEntity> storageFileEntity = criteria.from(StorageFileEntity.class);

    // Join to the other tables we can filter on.
    Join<StorageFileEntity, StorageUnitEntity> storageUnitEntity = storageFileEntity.join(StorageFileEntity_.storageUnit);
    Join<StorageUnitEntity, StorageEntity> storageEntity = storageUnitEntity.join(StorageUnitEntity_.storage);

    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate filePathRestriction = builder.equal(storageFileEntity.get(StorageFileEntity_.path), filePath);
    Predicate storageNameRestriction = builder.equal(builder.upper(storageEntity.get(StorageEntity_.name)), storageName.toUpperCase());

    criteria.select(storageFileEntity).where(builder.and(filePathRestriction, storageNameRestriction));

    return executeSingleResultQuery(criteria,
        String.format("Found more than one storage file with parameters {storageName=\"%s\"," + " filePath=\"%s\"}.", storageName, filePath));
}
 
Example 2
Source File: HibernateCategoryOptionComboStore.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 8 votes vote down vote up
@Override
public List<CategoryOptionCombo> getCategoryOptionCombosByGroupUid( String groupUid )
{
    CriteriaBuilder builder = getCriteriaBuilder();
    CriteriaQuery<CategoryOptionCombo> query = builder.createQuery( CategoryOptionCombo.class );
    Root<CategoryOptionCombo> root = query.from( CategoryOptionCombo.class );
    Join<Object, Object> joinCatOption = root.join( "categoryOptions", JoinType.INNER );
    Join<Object, Object> joinCatOptionGroup = joinCatOption.join( "groups", JoinType.INNER );
    query.where( builder.equal( joinCatOptionGroup.get( "uid" ), groupUid ) );
    return getSession().createQuery( query ).list();
}
 
Example 3
Source File: BranchStatisticSpecification.java    From mojito with Apache License 2.0 6 votes vote down vote up
public static SingleParamSpecification<BranchStatistic> createdByUserNameEquals(final String createdByUserName) {
    return new SingleParamSpecification<BranchStatistic>(createdByUserName) {
        @Override
        public Predicate toPredicate(Root<BranchStatistic> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
            Join<BranchStatistic, Branch> branchJoin = root.join(BranchStatistic_.branch, JoinType.LEFT);
            Join<Branch, User> userJoin = branchJoin.join(Branch_.createdByUser, JoinType.LEFT);
            return builder.equal(userJoin.get(User_.username), createdByUserName);
        }
    };
}
 
Example 4
Source File: StorageUnitDaoImpl.java    From herd with Apache License 2.0 5 votes vote down vote up
@Override
public List<StorageUnitEntity> getStorageUnitsByStoragePlatformAndBusinessObjectData(String storagePlatform,
    BusinessObjectDataEntity businessObjectDataEntity)
{
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<StorageUnitEntity> criteria = builder.createQuery(StorageUnitEntity.class);

    // The criteria root is the storage unit.
    Root<StorageUnitEntity> storageUnitEntity = criteria.from(StorageUnitEntity.class);

    // Join to the other tables we can filter on.
    Join<StorageUnitEntity, StorageEntity> storageEntity = storageUnitEntity.join(StorageUnitEntity_.storage);
    Join<StorageEntity, StoragePlatformEntity> storagePlatformEntity = storageEntity.join(StorageEntity_.storagePlatform);

    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(builder.upper(storagePlatformEntity.get(StoragePlatformEntity_.name)), storagePlatform.toUpperCase()));
    predicates.add(builder.equal(storageUnitEntity.get(StorageUnitEntity_.businessObjectData), businessObjectDataEntity));

    // Order by storage name.
    Order orderBy = builder.asc(storageEntity.get(StorageEntity_.name));

    // Add the clauses for the query.
    criteria.select(storageUnitEntity).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(orderBy);

    // Execute the query and return the results.
    return entityManager.createQuery(criteria).getResultList();
}
 
Example 5
Source File: StorageUnitDaoImpl.java    From herd with Apache License 2.0 5 votes vote down vote up
@Override
public List<StorageUnitEntity> getS3StorageUnitsToRestore(int maxResult)
{
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<StorageUnitEntity> criteria = builder.createQuery(StorageUnitEntity.class);

    // The criteria root is the storage unit.
    Root<StorageUnitEntity> storageUnitEntityRoot = criteria.from(StorageUnitEntity.class);

    // Join to the other tables we can filter on.
    Join<StorageUnitEntity, StorageEntity> storageEntityJoin = storageUnitEntityRoot.join(StorageUnitEntity_.storage);
    Join<StorageEntity, StoragePlatformEntity> storagePlatformEntityJoin = storageEntityJoin.join(StorageEntity_.storagePlatform);
    Join<StorageUnitEntity, StorageUnitStatusEntity> storageUnitStatusEntityJoin = storageUnitEntityRoot.join(StorageUnitEntity_.status);

    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(storagePlatformEntityJoin.get(StoragePlatformEntity_.name), StoragePlatformEntity.S3));
    predicates.add(builder.equal(storageUnitStatusEntityJoin.get(StorageUnitStatusEntity_.code), StorageUnitStatusEntity.RESTORING));

    // Order the results by storage unit updated on timestamp.
    Order orderBy = builder.asc(storageUnitEntityRoot.get(StorageUnitEntity_.updatedOn));

    // Add the clauses for the query.
    criteria.select(storageUnitEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(orderBy);

    // Execute the query and return the results.
    return entityManager.createQuery(criteria).setMaxResults(maxResult).getResultList();
}
 
Example 6
Source File: StorageUnitDaoImpl.java    From herd with Apache License 2.0 5 votes vote down vote up
@Override
public List<StorageUnitEntity> getS3StorageUnitsToExpire(int maxResult)
{
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<StorageUnitEntity> criteria = builder.createQuery(StorageUnitEntity.class);

    // The criteria root is the storage unit.
    Root<StorageUnitEntity> storageUnitEntityRoot = criteria.from(StorageUnitEntity.class);

    // Join to the other tables we can filter on.
    Join<StorageUnitEntity, StorageEntity> storageEntityJoin = storageUnitEntityRoot.join(StorageUnitEntity_.storage);
    Join<StorageEntity, StoragePlatformEntity> storagePlatformEntityJoin = storageEntityJoin.join(StorageEntity_.storagePlatform);
    Join<StorageUnitEntity, StorageUnitStatusEntity> storageUnitStatusEntityJoin = storageUnitEntityRoot.join(StorageUnitEntity_.status);

    // Get the current time.
    Timestamp currentTime = new Timestamp(System.currentTimeMillis());

    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(storagePlatformEntityJoin.get(StoragePlatformEntity_.name), StoragePlatformEntity.S3));
    predicates.add(builder.equal(storageUnitStatusEntityJoin.get(StorageUnitStatusEntity_.code), StorageUnitStatusEntity.RESTORED));
    predicates.add(builder.lessThan(storageUnitEntityRoot.get(StorageUnitEntity_.restoreExpirationOn), currentTime));

    // Order the results.
    Order orderBy = builder.asc(storageUnitEntityRoot.get(StorageUnitEntity_.restoreExpirationOn));

    // Add the clauses for the query.
    criteria.select(storageUnitEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(orderBy);

    // Execute the query and return the results.
    return entityManager.createQuery(criteria).setMaxResults(maxResult).getResultList();
}
 
Example 7
Source File: BusinessObjectDefinitionSubjectMatterExpertDaoImpl.java    From herd with Apache License 2.0 5 votes vote down vote up
@Override
public BusinessObjectDefinitionSubjectMatterExpertEntity getBusinessObjectDefinitionSubjectMatterExpertByKey(
    BusinessObjectDefinitionSubjectMatterExpertKey key)
{
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<BusinessObjectDefinitionSubjectMatterExpertEntity> criteria =
        builder.createQuery(BusinessObjectDefinitionSubjectMatterExpertEntity.class);

    // The criteria root is the business object definition subject matter expert.
    Root<BusinessObjectDefinitionSubjectMatterExpertEntity> businessObjectDefinitionSubjectMatterExpertEntityRoot =
        criteria.from(BusinessObjectDefinitionSubjectMatterExpertEntity.class);

    // Join to the other tables we can filter on.
    Join<BusinessObjectDefinitionSubjectMatterExpertEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntityJoin =
        businessObjectDefinitionSubjectMatterExpertEntityRoot.join(BusinessObjectDefinitionSubjectMatterExpertEntity_.businessObjectDefinition);
    Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntityJoin =
        businessObjectDefinitionEntityJoin.join(BusinessObjectDefinitionEntity_.namespace);

    // 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)), key.getNamespace().toUpperCase()));
    predicates.add(builder.equal(builder.upper(businessObjectDefinitionEntityJoin.get(BusinessObjectDefinitionEntity_.name)),
        key.getBusinessObjectDefinitionName().toUpperCase()));
    predicates.add(builder
        .equal(builder.upper(businessObjectDefinitionSubjectMatterExpertEntityRoot.get(BusinessObjectDefinitionSubjectMatterExpertEntity_.userId)),
            key.getUserId().toUpperCase()));

    // Add the clauses for the query.
    criteria.select(businessObjectDefinitionSubjectMatterExpertEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()])));

    // Execute the query and return the results.
    return executeSingleResultQuery(criteria, String.format(
        "Found more than one business object definition subject matter expert instance with parameters {namespace=\"%s\", " +
            "businessObjectDefinitionName=\"%s\", userId=\"%s\"}.", key.getNamespace(), key.getBusinessObjectDefinitionName(), key.getUserId()));
}
 
Example 8
Source File: CustomDdlDaoImpl.java    From herd with Apache License 2.0 5 votes vote down vote up
@Override
public CustomDdlEntity getCustomDdlByKey(CustomDdlKey customDdlKey)
{
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<CustomDdlEntity> criteria = builder.createQuery(CustomDdlEntity.class);

    // The criteria root is the custom DDL.
    Root<CustomDdlEntity> customDdlEntity = criteria.from(CustomDdlEntity.class);

    // Join to the other tables we can filter on.
    Join<CustomDdlEntity, BusinessObjectFormatEntity> businessObjectFormatEntity = customDdlEntity.join(CustomDdlEntity_.businessObjectFormat);
    Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = businessObjectFormatEntity.join(
        BusinessObjectFormatEntity_.businessObjectDefinition);
    Join<BusinessObjectFormatEntity, FileTypeEntity> fileTypeEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.fileType);
    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)), customDdlKey.getNamespace().toUpperCase());
    queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)),
        customDdlKey.getBusinessObjectDefinitionName().toUpperCase()));
    queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage)),
        customDdlKey.getBusinessObjectFormatUsage().toUpperCase()));
    queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(fileTypeEntity.get(FileTypeEntity_.code)), customDdlKey
        .getBusinessObjectFormatFileType().toUpperCase()));
    queryRestriction = builder.and(queryRestriction, builder.equal(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion),
        customDdlKey.getBusinessObjectFormatVersion()));
    queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(customDdlEntity.get(CustomDdlEntity_.customDdlName)), customDdlKey
        .getCustomDdlName().toUpperCase()));

    // Add select and where clauses.
    criteria.select(customDdlEntity).where(queryRestriction);

    return executeSingleResultQuery(criteria, String.format("Found more than one custom DDL instance with parameters {businessObjectDefinitionName=\"%s\","
        + " businessObjectFormatUsage=\"%s\", businessObjectFormatFileType=\"%s\", businessObjectFormatVersion=\"%d\", customDdlName=\"%s\"}.", customDdlKey
            .getBusinessObjectDefinitionName(), customDdlKey.getBusinessObjectFormatUsage(), customDdlKey.getBusinessObjectFormatFileType(), customDdlKey
                .getBusinessObjectFormatVersion(), customDdlKey.getCustomDdlName()));
}
 
Example 9
Source File: AllowedAttributeValueDaoImpl.java    From herd with Apache License 2.0 5 votes vote down vote up
@Override
public List<AllowedAttributeValueEntity> getAllowedAttributeValuesByAttributeValueListKey(AttributeValueListKey attributeValueListKey)
{
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<AllowedAttributeValueEntity> criteria = builder.createQuery(AllowedAttributeValueEntity.class);

    // The criteria root is the allowed attribute value.
    Root<AllowedAttributeValueEntity> allowedAttributeValueEntityRoot = criteria.from(AllowedAttributeValueEntity.class);

    // Join to the other tables we can filter on.
    Join<AllowedAttributeValueEntity, AttributeValueListEntity> attributeValueListEntityJoin =
        allowedAttributeValueEntityRoot.join(AllowedAttributeValueEntity_.attributeValueList);
    Join<AttributeValueListEntity, NamespaceEntity> namespaceEntityJoin = attributeValueListEntityJoin.join(AttributeValueListEntity_.namespace);

    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(builder.upper(attributeValueListEntityJoin.get(AttributeValueListEntity_.name)),
        attributeValueListKey.getAttributeValueListName().toUpperCase()));
    predicates.add(builder.equal(builder.upper(namespaceEntityJoin.get(NamespaceEntity_.code)), attributeValueListKey.getNamespace().toUpperCase()));

    // Order the results by allowed attribute value.
    Order orderByAllowedAttributeValue = builder.asc(allowedAttributeValueEntityRoot.get(AllowedAttributeValueEntity_.allowedAttributeValue));

    // Add the clauses for the query.
    criteria.select(allowedAttributeValueEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()])))
        .orderBy(orderByAllowedAttributeValue);

    // Execute the query and return the results.
    return entityManager.createQuery(criteria).getResultList();
}
 
Example 10
Source File: BusinessObjectDefinitionColumnDaoImpl.java    From herd with Apache License 2.0 5 votes vote down vote up
@Override
public BusinessObjectDefinitionColumnEntity getBusinessObjectDefinitionColumnByKey(BusinessObjectDefinitionColumnKey businessObjectDefinitionColumnKey)
{
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<BusinessObjectDefinitionColumnEntity> criteria = builder.createQuery(BusinessObjectDefinitionColumnEntity.class);

    // The criteria root is the business object definition column.
    Root<BusinessObjectDefinitionColumnEntity> businessObjectDefinitionColumnEntityRoot = criteria.from(BusinessObjectDefinitionColumnEntity.class);

    // Join to the other tables we can filter on.
    Join<BusinessObjectDefinitionColumnEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntityJoin =
        businessObjectDefinitionColumnEntityRoot.join(BusinessObjectDefinitionColumnEntity_.businessObjectDefinition);
    Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntityJoin =
        businessObjectDefinitionEntityJoin.join(BusinessObjectDefinitionEntity_.namespace);

    // 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)), businessObjectDefinitionColumnKey.getNamespace().toUpperCase()));
    predicates.add(builder.equal(builder.upper(businessObjectDefinitionEntityJoin.get(BusinessObjectDefinitionEntity_.name)),
        businessObjectDefinitionColumnKey.getBusinessObjectDefinitionName().toUpperCase()));
    predicates.add(builder.equal(builder.upper(businessObjectDefinitionColumnEntityRoot.get(BusinessObjectDefinitionColumnEntity_.name)),
        businessObjectDefinitionColumnKey.getBusinessObjectDefinitionColumnName().toUpperCase()));

    // Add the clauses for the query.
    criteria.select(businessObjectDefinitionColumnEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()])));

    return executeSingleResultQuery(criteria, String.format(
        "Found more than one business object definition column instance with parameters {namespace=\"%s\", businessObjectDefinitionName=\"%s\"," +
            " businessObjectDefinitionColumnName=\"%s\"}.", businessObjectDefinitionColumnKey.getNamespace(),
        businessObjectDefinitionColumnKey.getBusinessObjectDefinitionName(), businessObjectDefinitionColumnKey.getBusinessObjectDefinitionColumnName()));
}
 
Example 11
Source File: BusinessObjectDataDaoImpl.java    From herd with Apache License 2.0 4 votes vote down vote up
/**
 * Adds partition value filters to the query predicate.
 *
 * @param partitionValueFilters the list of partition value filters, not empty
 * @param businessObjectDataEntity the business object data entity
 * @param businessObjectFormatEntity the business object format entity
 * @param builder the builder
 * @param predicate the query predicate to be updated, not null
 *
 * @return the updated query predicate
 */
private Predicate addPartitionValueFiltersToPredicate(List<PartitionValueFilter> partitionValueFilters,
    Root<BusinessObjectDataEntity> businessObjectDataEntity, Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> businessObjectFormatEntity,
    CriteriaBuilder builder, Predicate predicate)
{
    for (PartitionValueFilter partitionValueFilter : partitionValueFilters)
    {
        Join<BusinessObjectFormatEntity, SchemaColumnEntity> schemaEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.schemaColumns);

        List<String> partitionValues = partitionValueFilter.getPartitionValues();

        predicate = builder
            .and(predicate, builder.equal(builder.upper(schemaEntity.get(SchemaColumnEntity_.name)), partitionValueFilter.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 (partitionValueFilter.getPartitionValueRange() != null)
        {
            PartitionValueRange partitionRange = partitionValueFilter.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;
}
 
Example 12
Source File: BusinessObjectDefinitionTagDaoImpl.java    From herd with Apache License 2.0 4 votes vote down vote up
@Override
public List<BusinessObjectDefinitionTagKey> getBusinessObjectDefinitionTagsByBusinessObjectDefinitionEntity(
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity)
{
    // 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<TagEntity> tagEntityRoot = criteria.from(TagEntity.class);

    // Join to the other tables we can filter on.
    Join<TagEntity, TagTypeEntity> tagTypeEntityJoin = tagEntityRoot.join(TagEntity_.tagType);
    Join<TagEntity, BusinessObjectDefinitionTagEntity> businessObjectDefinitionTagEntityJoin = tagEntityRoot.join(TagEntity_.businessObjectDefinitionTags);
    Join<BusinessObjectDefinitionTagEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntityJoin =
        businessObjectDefinitionTagEntityJoin.join(BusinessObjectDefinitionTagEntity_.businessObjectDefinition);

    // Get the columns.
    Path<String> tagTypeCodeColumn = tagTypeEntityJoin.get(TagTypeEntity_.code);
    Path<String> tagCodeColumn = tagEntityRoot.get(TagEntity_.tagCode);
    Path<String> tagDisplayNameColumn = tagEntityRoot.get(TagEntity_.displayName);

    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(businessObjectDefinitionEntityJoin, businessObjectDefinitionEntity));

    // Add the clauses for the query.
    criteria.multiselect(tagTypeCodeColumn, tagCodeColumn).where(builder.and(predicates.toArray(new Predicate[predicates.size()])))
        .orderBy(builder.asc(tagDisplayNameColumn));

    // Run the query to get a list of tuples back.
    List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();

    // Get the business object definition key.
    BusinessObjectDefinitionKey businessObjectDefinitionKey =
        new BusinessObjectDefinitionKey(businessObjectDefinitionEntity.getNamespace().getCode(), businessObjectDefinitionEntity.getName());

    // Populate the "keys" objects from the returned tuples (i.e. 1 tuple for each row).
    List<BusinessObjectDefinitionTagKey> businessObjectDefinitionTagKeys = new ArrayList<>();
    for (Tuple tuple : tuples)
    {
        businessObjectDefinitionTagKeys
            .add(new BusinessObjectDefinitionTagKey(businessObjectDefinitionKey, new TagKey(tuple.get(tagTypeCodeColumn), tuple.get(tagCodeColumn))));
    }

    return businessObjectDefinitionTagKeys;
}
 
Example 13
Source File: BusinessObjectDataNotificationRegistrationDaoImpl.java    From herd with Apache License 2.0 4 votes vote down vote up
@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(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();
}
 
Example 14
Source File: StorageUnitNotificationRegistrationDaoImpl.java    From herd with Apache License 2.0 4 votes vote down vote up
@Override
public List<NotificationRegistrationKey> getStorageUnitNotificationRegistrationKeysByNotificationFilter(
    StorageUnitNotificationFilter businessObjectDataNotificationFilter)
{
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tuple> criteria = builder.createTupleQuery();

    // The criteria root is the storage unit notification registration.
    Root<StorageUnitNotificationRegistrationEntity> notificationRegistrationEntityRoot = criteria.from(StorageUnitNotificationRegistrationEntity.class);

    // Join to the other tables we can filter on.
    Join<StorageUnitNotificationRegistrationEntity, NamespaceEntity> notificationRegistrationNamespaceEntityJoin =
        notificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.namespace);
    Join<StorageUnitNotificationRegistrationEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity =
        notificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.businessObjectDefinition);
    Join<BusinessObjectDefinitionEntity, NamespaceEntity> businessObjectDefinitionNamespaceEntity =
        businessObjectDefinitionEntity.join(BusinessObjectDefinitionEntity_.namespace);
    Join<StorageUnitNotificationRegistrationEntity, FileTypeEntity> fileTypeEntity =
        notificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.fileType, JoinType.LEFT);

    // Get the columns.
    Path<String> notificationRegistrationNamespaceColumn = notificationRegistrationNamespaceEntityJoin.get(NamespaceEntity_.code);
    Path<String> notificationRegistrationNameColumn = notificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.name);

    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(builder.upper(businessObjectDefinitionNamespaceEntity.get(NamespaceEntity_.code)),
        businessObjectDataNotificationFilter.getNamespace().toUpperCase()));
    predicates.add(builder.equal(builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)),
        businessObjectDataNotificationFilter.getBusinessObjectDefinitionName().toUpperCase()));
    if (StringUtils.isNotBlank(businessObjectDataNotificationFilter.getBusinessObjectFormatUsage()))
    {
        predicates.add(builder.or(builder.isNull(notificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.usage)), builder
            .equal(builder.upper(notificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.usage)),
                businessObjectDataNotificationFilter.getBusinessObjectFormatUsage().toUpperCase())));
    }
    if (StringUtils.isNotBlank(businessObjectDataNotificationFilter.getBusinessObjectFormatFileType()))
    {
        predicates.add(builder.or(builder.isNull(notificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.fileType)), builder
            .equal(builder.upper(fileTypeEntity.get(FileTypeEntity_.code)),
                businessObjectDataNotificationFilter.getBusinessObjectFormatFileType().toUpperCase())));
    }

    // Add the select and where clauses to the query.
    criteria.multiselect(notificationRegistrationNamespaceColumn, notificationRegistrationNameColumn)
        .where(builder.and(predicates.toArray(new Predicate[predicates.size()])));

    // Add the order by clause to the query.
    criteria.orderBy(builder.asc(notificationRegistrationNamespaceColumn), builder.asc(notificationRegistrationNameColumn));

    // Run the query to get a list of tuples back.
    List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();

    // Populate the list of keys from the returned tuples.
    return getNotificationRegistrationKeys(tuples, notificationRegistrationNamespaceColumn, notificationRegistrationNameColumn);
}
 
Example 15
Source File: StorageUnitNotificationRegistrationDaoImpl.java    From herd with Apache License 2.0 4 votes vote down vote up
@Override
public List<StorageUnitNotificationRegistrationEntity> getStorageUnitNotificationRegistrations(String notificationEventTypeCode,
    BusinessObjectDataKey businessObjectDataKey, String storageName, String newStorageUnitStatus, String oldStorageUnitStatus,
    String notificationRegistrationStatus)
{
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<StorageUnitNotificationRegistrationEntity> criteria = builder.createQuery(StorageUnitNotificationRegistrationEntity.class);

    // The criteria root is the storage unit notification registration entity.
    Root<StorageUnitNotificationRegistrationEntity> storageUnitNotificationRegistrationEntityRoot =
        criteria.from(StorageUnitNotificationRegistrationEntity.class);

    // Join to the other tables we can filter on.
    Join<StorageUnitNotificationRegistrationEntity, NamespaceEntity> namespaceEntityJoin =
        storageUnitNotificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.namespace);
    Join<StorageUnitNotificationRegistrationEntity, NotificationEventTypeEntity> notificationEventTypeEntityJoin =
        storageUnitNotificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.notificationEventType);
    Join<StorageUnitNotificationRegistrationEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntityJoin =
        storageUnitNotificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.businessObjectDefinition);
    Join<BusinessObjectDefinitionEntity, NamespaceEntity> businessObjectDefinitionNamespaceEntityJoin =
        businessObjectDefinitionEntityJoin.join(BusinessObjectDefinitionEntity_.namespace);
    Join<StorageUnitNotificationRegistrationEntity, StorageEntity> storageEntityJoin =
        storageUnitNotificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.storage);
    Join<StorageUnitNotificationRegistrationEntity, FileTypeEntity> fileTypeEntityJoin =
        storageUnitNotificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.fileType, JoinType.LEFT);
    Join<StorageUnitNotificationRegistrationEntity, StorageUnitStatusEntity> newStorageUnitStatusEntityJoin =
        storageUnitNotificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.newStorageUnitStatus, JoinType.LEFT);
    Join<StorageUnitNotificationRegistrationEntity, StorageUnitStatusEntity> oldStorageUnitStatusEntityJoin =
        storageUnitNotificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.oldStorageUnitStatus, JoinType.LEFT);
    Join<StorageUnitNotificationRegistrationEntity, NotificationRegistrationStatusEntity> notificationRegistrationStatusEntityJoin =
        storageUnitNotificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.notificationRegistrationStatus);

    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates
        .add(builder.equal(builder.upper(notificationEventTypeEntityJoin.get(NotificationEventTypeEntity_.code)), notificationEventTypeCode.toUpperCase()));
    predicates.add(builder
        .equal(builder.upper(businessObjectDefinitionNamespaceEntityJoin.get(NamespaceEntity_.code)), businessObjectDataKey.getNamespace().toUpperCase()));
    predicates.add(builder.equal(builder.upper(businessObjectDefinitionEntityJoin.get(BusinessObjectDefinitionEntity_.name)),
        businessObjectDataKey.getBusinessObjectDefinitionName().toUpperCase()));
    predicates.add(builder.equal(builder.upper(storageEntityJoin.get(StorageEntity_.name)), storageName.toUpperCase()));
    predicates.add(builder.or(builder.isNull(storageUnitNotificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.usage)), builder
        .equal(builder.upper(storageUnitNotificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.usage)),
            businessObjectDataKey.getBusinessObjectFormatUsage().toUpperCase())));
    predicates.add(builder.or(builder.isNull(storageUnitNotificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.fileType)),
        builder.equal(builder.upper(fileTypeEntityJoin.get(FileTypeEntity_.code)), businessObjectDataKey.getBusinessObjectFormatFileType().toUpperCase())));
    predicates.add(builder
        .or(builder.isNull(storageUnitNotificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.businessObjectFormatVersion)),
            builder.equal(storageUnitNotificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.businessObjectFormatVersion),
                businessObjectDataKey.getBusinessObjectFormatVersion())));
    predicates.add(builder
        .or(builder.isNull(storageUnitNotificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.newStorageUnitStatus)),
            builder.equal(builder.upper(newStorageUnitStatusEntityJoin.get(StorageUnitStatusEntity_.code)), newStorageUnitStatus.toUpperCase())));
    // Please note that old business object data status parameter value is null for a business object data registration event.
    predicates.add(builder
        .or(builder.isNull(storageUnitNotificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.oldStorageUnitStatus)), builder
            .equal(builder.upper(oldStorageUnitStatusEntityJoin.get(StorageUnitStatusEntity_.code)),
                oldStorageUnitStatus == null ? null : oldStorageUnitStatus.toUpperCase())));
    predicates.add(builder.equal(builder.upper(notificationRegistrationStatusEntityJoin.get(NotificationRegistrationStatusEntity_.code)),
        notificationRegistrationStatus.toUpperCase()));

    // Order the results by namespace and notification name.
    List<Order> orderBy = new ArrayList<>();
    orderBy.add(builder.asc(namespaceEntityJoin.get(NamespaceEntity_.code)));
    orderBy.add(builder.asc(storageUnitNotificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.name)));

    // Add the clauses for the query.
    criteria.select(storageUnitNotificationRegistrationEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()])))
        .orderBy(orderBy);

    // Execute the query and return the results.
    return entityManager.createQuery(criteria).getResultList();
}
 
Example 16
Source File: CustomDdlDaoImpl.java    From herd with Apache License 2.0 4 votes vote down vote up
@Override
public List<CustomDdlKey> getCustomDdls(BusinessObjectFormatKey businessObjectFormatKey)
{
    // 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 format.
    Root<CustomDdlEntity> customDdlEntity = criteria.from(CustomDdlEntity.class);

    // Join to the other tables we can filter on.
    Join<CustomDdlEntity, BusinessObjectFormatEntity> businessObjectFormatEntity = customDdlEntity.join(CustomDdlEntity_.businessObjectFormat);
    Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = businessObjectFormatEntity.join(
        BusinessObjectFormatEntity_.businessObjectDefinition);
    Join<BusinessObjectFormatEntity, FileTypeEntity> fileTypeEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.fileType);
    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);
    Path<String> businessObjectFormatUsageColumn = businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage);
    Path<String> fileTypeCodeColumn = fileTypeEntity.get(FileTypeEntity_.code);
    Path<Integer> businessObjectFormatVersionColumn = businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion);
    Path<String> customDdlNameColumn = customDdlEntity.get(CustomDdlEntity_.customDdlName);

    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate queryRestriction = builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)), businessObjectFormatKey.getNamespace()
        .toUpperCase());
    queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)),
        businessObjectFormatKey.getBusinessObjectDefinitionName().toUpperCase()));
    queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage)),
        businessObjectFormatKey.getBusinessObjectFormatUsage().toUpperCase()));
    queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(fileTypeEntity.get(FileTypeEntity_.code)), businessObjectFormatKey
        .getBusinessObjectFormatFileType().toUpperCase()));
    queryRestriction = builder.and(queryRestriction, builder.equal(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion),
        businessObjectFormatKey.getBusinessObjectFormatVersion()));

    // Add the select clause.
    criteria.multiselect(namespaceCodeColumn, businessObjectDefinitionNameColumn, businessObjectFormatUsageColumn, fileTypeCodeColumn,
        businessObjectFormatVersionColumn, customDdlNameColumn);

    // Add the where clause.
    criteria.where(queryRestriction);

    // Add the order by clause.
    criteria.orderBy(builder.asc(customDdlNameColumn));

    // 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<CustomDdlKey> customDdlKeys = new ArrayList<>();
    for (Tuple tuple : tuples)
    {
        CustomDdlKey customDdlKey = new CustomDdlKey();
        customDdlKeys.add(customDdlKey);
        customDdlKey.setNamespace(tuple.get(namespaceCodeColumn));
        customDdlKey.setBusinessObjectDefinitionName(tuple.get(businessObjectDefinitionNameColumn));
        customDdlKey.setBusinessObjectFormatUsage(tuple.get(businessObjectFormatUsageColumn));
        customDdlKey.setBusinessObjectFormatFileType(tuple.get(fileTypeCodeColumn));
        customDdlKey.setBusinessObjectFormatVersion(tuple.get(businessObjectFormatVersionColumn));
        customDdlKey.setCustomDdlName(tuple.get(customDdlNameColumn));
    }

    return customDdlKeys;
}
 
Example 17
Source File: StorageUnitDaoImpl.java    From herd with Apache License 2.0 4 votes vote down vote up
@Override
public List<StorageUnitEntity> getS3StorageUnitsToCleanup(int maxResult)
{
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<StorageUnitEntity> criteria = builder.createQuery(StorageUnitEntity.class);

    // The criteria root is the storage unit.
    Root<StorageUnitEntity> storageUnitEntityRoot = criteria.from(StorageUnitEntity.class);

    // Join to the other tables we can filter on.
    Join<StorageUnitEntity, StorageEntity> storageEntityJoin = storageUnitEntityRoot.join(StorageUnitEntity_.storage);
    Join<StorageEntity, StoragePlatformEntity> storagePlatformEntityJoin = storageEntityJoin.join(StorageEntity_.storagePlatform);
    Join<StorageUnitEntity, StorageUnitStatusEntity> storageUnitStatusEntityJoin = storageUnitEntityRoot.join(StorageUnitEntity_.status);
    Join<StorageUnitEntity, BusinessObjectDataEntity> businessObjectDataEntityJoin = storageUnitEntityRoot.join(StorageUnitEntity_.businessObjectData);
    Join<BusinessObjectDataEntity, BusinessObjectDataStatusEntity> businessObjectDataStatusEntity =
        businessObjectDataEntityJoin.join(BusinessObjectDataEntity_.status);


    // Get the current time.
    Timestamp currentTime = new Timestamp(System.currentTimeMillis());

    // Create the standard restrictions (i.e. the standard where clauses).
    // Restrictions include:
    //      - Storage platform is set to S3 storage
    //      - Storage unit status is DISABLED
    //      - Associated BData has a DELETED status
    //      - Final destroy on timestamp < current time
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(storagePlatformEntityJoin.get(StoragePlatformEntity_.name), StoragePlatformEntity.S3));
    predicates.add(builder.equal(storageUnitStatusEntityJoin.get(StorageUnitStatusEntity_.code), StorageUnitStatusEntity.DISABLED));
    predicates.add(builder.equal(businessObjectDataStatusEntity.get(BusinessObjectDataStatusEntity_.code), BusinessObjectDataStatusEntity.DELETED));
    predicates.add(builder.lessThan(storageUnitEntityRoot.get(StorageUnitEntity_.finalDestroyOn), currentTime));

    // Order the results.
    Order orderBy = builder.asc(storageUnitEntityRoot.get(StorageUnitEntity_.finalDestroyOn));

    // Add the clauses for the query.
    criteria.select(storageUnitEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(orderBy);

    // Execute the query and return the results.
    return entityManager.createQuery(criteria).setMaxResults(maxResult).getResultList();
}
 
Example 18
Source File: BusinessObjectFormatDaoImpl.java    From herd with Apache License 2.0 4 votes vote down vote up
@Override
public List<BusinessObjectFormatKey> getBusinessObjectFormatsWithFilters(BusinessObjectDefinitionKey businessObjectDefinitionKey,
    String businessObjectFormatUsage, boolean latestBusinessObjectFormatVersion)
{
    // 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 format.
    Root<BusinessObjectFormatEntity> businessObjectFormatEntity = criteria.from(BusinessObjectFormatEntity.class);

    // Join to the other tables we can filter on.
    Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity =
        businessObjectFormatEntity.join(BusinessObjectFormatEntity_.businessObjectDefinition);
    Join<BusinessObjectFormatEntity, FileTypeEntity> fileTypeEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.fileType);
    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);
    Path<String> businessObjectFormatUsageColumn = businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage);
    Path<String> fileTypeCodeColumn = fileTypeEntity.get(FileTypeEntity_.code);
    Path<Integer> businessObjectFormatVersionColumn = businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion);
    Expression<Integer> maxBusinessObjectFormatVersionExpression =
        builder.max(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion));

    // 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(builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)),
        businessObjectDefinitionKey.getBusinessObjectDefinitionName().toUpperCase()));

    // Add the business object format usage where parameter is not empty
    if (StringUtils.isNotEmpty(businessObjectFormatUsage))
    {
        queryRestriction = builder.and(queryRestriction,
            builder.equal(builder.upper(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage)), businessObjectFormatUsage.toUpperCase()));
    }

    // Add the select clause.
    criteria.multiselect(namespaceCodeColumn, businessObjectDefinitionNameColumn, businessObjectFormatUsageColumn, fileTypeCodeColumn,
        latestBusinessObjectFormatVersion ? maxBusinessObjectFormatVersionExpression : businessObjectFormatVersionColumn);

    // Add the where clause.
    criteria.where(queryRestriction);

    // If only the latest (maximum) business object format versions to be returned, create and apply the group by clause.
    if (latestBusinessObjectFormatVersion)
    {
        List<Expression<?>> grouping = new ArrayList<>();
        grouping.add(namespaceCodeColumn);
        grouping.add(businessObjectDefinitionNameColumn);
        grouping.add(businessObjectFormatUsageColumn);
        grouping.add(fileTypeCodeColumn);
        criteria.groupBy(grouping);
    }

    // Add the order by clause.
    List<Order> orderBy = new ArrayList<>();
    orderBy.add(builder.asc(businessObjectFormatUsageColumn));
    orderBy.add(builder.asc(fileTypeCodeColumn));
    if (!latestBusinessObjectFormatVersion)
    {
        orderBy.add(builder.asc(businessObjectFormatVersionColumn));
    }
    criteria.orderBy(orderBy);

    // 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<BusinessObjectFormatKey> businessObjectFormatKeys = new ArrayList<>();
    for (Tuple tuple : tuples)
    {
        BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey();
        businessObjectFormatKeys.add(businessObjectFormatKey);
        businessObjectFormatKey.setNamespace(tuple.get(namespaceCodeColumn));
        businessObjectFormatKey.setBusinessObjectDefinitionName(tuple.get(businessObjectDefinitionNameColumn));
        businessObjectFormatKey.setBusinessObjectFormatUsage(tuple.get(businessObjectFormatUsageColumn));
        businessObjectFormatKey.setBusinessObjectFormatFileType(tuple.get(fileTypeCodeColumn));
        businessObjectFormatKey.setBusinessObjectFormatVersion(
            tuple.get(latestBusinessObjectFormatVersion ? maxBusinessObjectFormatVersionExpression : businessObjectFormatVersionColumn));
    }

    return businessObjectFormatKeys;
}
 
Example 19
Source File: ActionSpecifications.java    From hawkbit with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Specification which joins all necessary tables to retrieve the dependency
 * between a target and a local file assignment through the assigned action
 * of the target. All actions are included, not only active actions.
 * 
 * @param targetId
 *            the target to verify if the given artifact is currently
 *            assigned or had been assigned
 * @param sha1Hash
 *            of the local artifact to check wherever the target had ever
 *            been assigned
 * @return a specification to use with spring JPA
 */
public static Specification<JpaAction> hasTargetAssignedArtifact(final Long targetId, final String sha1Hash) {
    return (actionRoot, query, criteriaBuilder) -> {
        final Join<JpaAction, JpaDistributionSet> dsJoin = actionRoot.join(JpaAction_.distributionSet);
        final SetJoin<JpaDistributionSet, JpaSoftwareModule> modulesJoin = dsJoin.join(JpaDistributionSet_.modules);
        final ListJoin<JpaSoftwareModule, JpaArtifact> artifactsJoin = modulesJoin
                .join(JpaSoftwareModule_.artifacts);
        return criteriaBuilder.and(criteriaBuilder.equal(artifactsJoin.get(JpaArtifact_.sha1Hash), sha1Hash),
                criteriaBuilder.equal(actionRoot.get(JpaAction_.target).get(JpaTarget_.id), targetId));
    };
}
 
Example 20
Source File: ActionSpecifications.java    From hawkbit with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Specification which joins all necessary tables to retrieve the dependency
 * between a target and a local file assignment through the assigned action
 * of the target. All actions are included, not only active actions.
 * 
 * @param controllerId
 *            the target to verify if the given artifact is currently
 *            assigned or had been assigned
 * @param sha1Hash
 *            of the local artifact to check wherever the target had ever
 *            been assigned
 * @return a specification to use with spring JPA
 */
public static Specification<JpaAction> hasTargetAssignedArtifact(final String controllerId, final String sha1Hash) {
    return (actionRoot, query, criteriaBuilder) -> {
        final Join<JpaAction, JpaDistributionSet> dsJoin = actionRoot.join(JpaAction_.distributionSet);
        final SetJoin<JpaDistributionSet, JpaSoftwareModule> modulesJoin = dsJoin.join(JpaDistributionSet_.modules);
        final ListJoin<JpaSoftwareModule, JpaArtifact> artifactsJoin = modulesJoin
                .join(JpaSoftwareModule_.artifacts);
        return criteriaBuilder.and(criteriaBuilder.equal(artifactsJoin.get(JpaArtifact_.sha1Hash), sha1Hash),
                criteriaBuilder.equal(actionRoot.get(JpaAction_.target).get(JpaTarget_.controllerId),
                        controllerId));
    };
}