Example usage for javax.persistence.criteria CriteriaBuilder upper

List of usage examples for javax.persistence.criteria CriteriaBuilder upper

Introduction

In this page you can find the example usage for javax.persistence.criteria CriteriaBuilder upper.

Prototype

Expression<String> upper(Expression<String> x);

Source Link

Document

Create expression for converting a string to uppercase.

Usage

From source file:org.finra.herd.dao.impl.JobDefinitionDaoImpl.java

@Override
public List<JobDefinitionEntity> getJobDefinitionsByFilter(String namespace, String jobName) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<JobDefinitionEntity> criteria = builder.createQuery(JobDefinitionEntity.class);

    // The criteria root is the job definition.
    Root<JobDefinitionEntity> jobDefinitionEntityRoot = criteria.from(JobDefinitionEntity.class);

    // Join to the other tables we can filter on.
    Join<JobDefinitionEntity, NamespaceEntity> namespaceEntityJoin = jobDefinitionEntityRoot
            .join(JobDefinitionEntity_.namespace);

    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    if (StringUtils.isNotBlank(namespace)) {
        predicates.add(builder.equal(builder.upper(namespaceEntityJoin.get(NamespaceEntity_.code)),
                namespace.toUpperCase()));
    }/* w ww  .  jav  a  2 s.  c  o m*/
    if (StringUtils.isNotBlank(jobName)) {
        predicates.add(builder.equal(builder.upper(jobDefinitionEntityRoot.get(JobDefinitionEntity_.name)),
                jobName.toUpperCase()));
    }

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

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

    // Execute the query and return the result list.
    return entityManager.createQuery(criteria).getResultList();
}

From source file:org.finra.herd.dao.impl.JobDefinitionDaoImpl.java

@Override
public List<JobDefinitionEntity> getJobDefinitionsByFilter(Collection<String> namespaces, String jobName) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<JobDefinitionEntity> criteria = builder.createQuery(JobDefinitionEntity.class);

    // The criteria root is the job definition.
    Root<JobDefinitionEntity> jobDefinitionEntityRoot = criteria.from(JobDefinitionEntity.class);

    // Join to the other tables we can filter on.
    Join<JobDefinitionEntity, NamespaceEntity> namespaceEntityJoin = jobDefinitionEntityRoot
            .join(JobDefinitionEntity_.namespace);

    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    if (CollectionUtils.isNotEmpty(namespaces)) {
        predicates.add(namespaceEntityJoin.get(NamespaceEntity_.code).in(namespaces));
    }// ww  w . j a  v  a  2  s .  c o m
    if (StringUtils.isNotBlank(jobName)) {
        predicates.add(builder.equal(builder.upper(jobDefinitionEntityRoot.get(JobDefinitionEntity_.name)),
                jobName.toUpperCase()));
    }

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

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

    // Execute the query and return the result list.
    return entityManager.createQuery(criteria).getResultList();
}

From source file:org.finra.herd.dao.impl.StorageFileDaoImpl.java

@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());/*from   ww  w . j  a  v  a 2 s .  co  m*/

    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));
}

From source file:org.finra.herd.dao.impl.StorageFileDaoImpl.java

@Override
public Long getStorageFileCount(String storageName, String filePathPrefix) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Long> criteria = builder.createQuery(Long.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 path.
    Expression<Long> storageFileCount = builder.count(storageFileEntity.get(StorageFileEntity_.id));

    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate storageNameRestriction = builder.equal(builder.upper(storageEntity.get(StorageEntity_.name)),
            storageName.toUpperCase());/*from   w  ww .jav  a2  s .c  om*/
    Predicate filePathRestriction = builder.like(storageFileEntity.get(StorageFileEntity_.path),
            String.format("%s%%", filePathPrefix));

    // Add the clauses for the query.
    criteria.select(storageFileCount).where(builder.and(storageNameRestriction, filePathRestriction));

    return entityManager.createQuery(criteria).getSingleResult();
}

From source file:org.finra.herd.dao.impl.StorageFileDaoImpl.java

@Override
public List<String> getStorageFilesByStorageAndFilePathPrefix(String storageName, String filePathPrefix) {
    // 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.like(storageFileEntity.get(StorageFileEntity_.path),
            String.format("%s%%", filePathPrefix));
    Predicate storageNameRestriction = builder.equal(builder.upper(storageEntity.get(StorageEntity_.name)),
            storageName.toUpperCase());/*from   w ww . j  av  a 2s  .  co m*/

    // Order the results by file path.
    Order orderByFilePath = builder.asc(storageFileEntity.get(StorageFileEntity_.path));

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

    // Retrieve the storage files.
    List<StorageFileEntity> storageFileEntities = entityManager.createQuery(criteria).getResultList();

    // Build the result list.
    List<String> storageFilePaths = new ArrayList<>();
    for (StorageFileEntity storageFile : storageFileEntities) {
        storageFilePaths.add(storageFile.getPath());
    }

    return storageFilePaths;
}

From source file:org.finra.herd.dao.impl.StorageUnitDaoImpl.java

@Override
public List<StorageUnitEntity> getLatestVersionStorageUnitsByStoragePlatformAndFileType(String storagePlatform,
        String businessObjectFormatFileType) {
    // 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, BusinessObjectDataEntity> businessObjectDataEntityJoin = storageUnitEntityRoot
            .join(StorageUnitEntity_.businessObjectData);
    Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> businessObjectFormatEntityJoin = businessObjectDataEntityJoin
            .join(BusinessObjectDataEntity_.businessObjectFormat);
    Join<BusinessObjectFormatEntity, FileTypeEntity> fileTypeEntityJoin = businessObjectFormatEntityJoin
            .join(BusinessObjectFormatEntity_.fileType);

    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(builder.upper(storagePlatformEntityJoin.get(StoragePlatformEntity_.name)),
            storagePlatform.toUpperCase()));
    predicates.add(builder.equal(builder.upper(fileTypeEntityJoin.get(FileTypeEntity_.code)),
            businessObjectFormatFileType.toUpperCase()));
    predicates//  w ww  .  j a  v a  2  s  . c  om
            .add(builder.isTrue(businessObjectFormatEntityJoin.get(BusinessObjectFormatEntity_.latestVersion)));
    predicates.add(builder.isTrue(businessObjectDataEntityJoin.get(BusinessObjectDataEntity_.latestVersion)));

    // Order by storage unit created on timestamp.
    Order orderBy = builder.asc(storageUnitEntityRoot.get(StorageUnitEntity_.createdOn));

    // 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).getResultList();
}

From source file:org.finra.herd.dao.impl.StorageUnitDaoImpl.java

@Override
public StorageUnitEntity getStorageUnitByBusinessObjectDataAndStorageName(
        BusinessObjectDataEntity businessObjectDataEntity, String storageName) {
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<StorageUnitEntity> criteria = builder.createQuery(StorageUnitEntity.class);
    Root<StorageUnitEntity> storageUnitEntity = criteria.from(StorageUnitEntity.class);

    // join storage unit to storage to retrieve name
    Join<StorageUnitEntity, StorageEntity> storageEntity = storageUnitEntity.join(StorageUnitEntity_.storage);

    // where business object data equals
    Predicate businessObjectDataRestriction = builder
            .equal(storageUnitEntity.get(StorageUnitEntity_.businessObjectData), businessObjectDataEntity);
    // where storage name equals, ignoring case
    Predicate storageNameRestriction = builder.equal(builder.upper(storageEntity.get(StorageEntity_.name)),
            storageName.toUpperCase());/* ww  w  .j  ava 2 s . c  o m*/

    criteria.select(storageUnitEntity)
            .where(builder.and(businessObjectDataRestriction, storageNameRestriction));

    List<StorageUnitEntity> resultList = entityManager.createQuery(criteria).getResultList();

    // return single result or null
    return resultList.size() >= 1 ? resultList.get(0) : null;
}

From source file:org.finra.herd.dao.impl.StorageUnitDaoImpl.java

@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(/*ww w .ja va2  s. c om*/
            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()));
}

From source file:org.finra.herd.dao.impl.StorageUnitDaoImpl.java

@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));//from  ww w  .j av  a  2s  . c o  m

    // 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();
}

From source file:org.finra.herd.dao.impl.StorageUnitNotificationRegistrationDaoImpl.java

@Override
public StorageUnitNotificationRegistrationEntity getStorageUnitNotificationRegistrationByAltKey(
        NotificationRegistrationKey key) {
    // 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> businessObjectDataNotificationEntity = criteria
            .from(StorageUnitNotificationRegistrationEntity.class);

    // Join to the other tables we can filter on.
    Join<StorageUnitNotificationRegistrationEntity, NamespaceEntity> namespaceEntity = businessObjectDataNotificationEntity
            .join(StorageUnitNotificationRegistrationEntity_.namespace);

    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate queryRestriction = builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)),
            key.getNamespace().toUpperCase());
    queryRestriction = builder.and(queryRestriction, builder.equal(
            builder.upper(/*from  ww  w .  j av a 2s  .  c  o  m*/
                    businessObjectDataNotificationEntity.get(StorageUnitNotificationRegistrationEntity_.name)),
            key.getNotificationName().toUpperCase()));

    criteria.select(businessObjectDataNotificationEntity).where(queryRestriction);

    return executeSingleResultQuery(criteria, String.format(
            "Found more than one storage unit notification registration with with parameters {namespace=\"%s\", notificationName=\"%s\"}.",
            key.getNamespace(), key.getNotificationName()));
}