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.dm.dao.impl.DmDaoImpl.java

/**
 * {@inheritDoc}//  w ww.jav a  2  s .  com
 */
@Override
public JobDefinitionEntity getJobDefinitionByAltKey(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> jobDefinition = criteria.from(JobDefinitionEntity.class);

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

    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate namespaceRestriction = builder.equal(builder.upper(namespaceJoin.get(NamespaceEntity_.code)),
            namespace.toUpperCase());
    Predicate jobNameRestriction = builder.equal(builder.upper(jobDefinition.get(JobDefinitionEntity_.name)),
            jobName.toUpperCase());

    criteria.select(jobDefinition).where(builder.and(namespaceRestriction, jobNameRestriction));

    return executeSingleResultQuery(criteria, String.format(
            "Found more than one Activiti job definition with parameters {namespace=\"%s\", jobName=\"%s\"}.",
            namespace, jobName));
}

From source file:org.finra.dm.dao.impl.DmDaoImpl.java

/**
 * {@inheritDoc}/* w  w  w. j  a  va 2s . c  om*/
 */
@Override
public EmrClusterDefinitionEntity getEmrClusterDefinitionByAltKey(String namespaceCd, String definitionName) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<EmrClusterDefinitionEntity> criteria = builder.createQuery(EmrClusterDefinitionEntity.class);

    // The criteria root is the EMR cluster definition.
    Root<EmrClusterDefinitionEntity> emrClusterDefinition = criteria.from(EmrClusterDefinitionEntity.class);

    // Join to the other tables we can filter on.
    Join<EmrClusterDefinitionEntity, NamespaceEntity> namespace = emrClusterDefinition
            .join(EmrClusterDefinitionEntity_.namespace);

    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate namespaceRestriction = builder.equal(builder.upper(namespace.get(NamespaceEntity_.code)),
            namespaceCd.toUpperCase());
    Predicate definitionNameRestriction = builder.equal(
            builder.upper(emrClusterDefinition.get(EmrClusterDefinitionEntity_.name)),
            definitionName.toUpperCase());

    criteria.select(emrClusterDefinition).where(builder.and(namespaceRestriction, definitionNameRestriction));

    return executeSingleResultQuery(criteria, String.format(
            "Found more than one EMR cluster definition with parameters {namespace=\"%s\", clusterDefinitionName=\"%s\"}.",
            namespace, definitionName));
}

From source file:org.finra.dm.dao.impl.DmDaoImpl.java

/**
 * {@inheritDoc}//from w  w w .j a  v  a  2 s  . co m
 */
@Override
public NotificationEventTypeEntity getNotificationEventTypeByCode(String code) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<NotificationEventTypeEntity> criteria = builder
            .createQuery(NotificationEventTypeEntity.class);

    // The criteria root is the notification event type.
    Root<NotificationEventTypeEntity> notificationEventTypeEntity = criteria
            .from(NotificationEventTypeEntity.class);

    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate queryRestriction = builder.equal(
            builder.upper(notificationEventTypeEntity.get(NotificationEventTypeEntity_.code)),
            code.toUpperCase());

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

    return executeSingleResultQuery(criteria,
            String.format("Found more than one notification event type with code \"%s\".", code));
}

From source file:org.finra.dm.dao.impl.DmDaoImpl.java

/**
 * {@inheritDoc}/*ww  w . ja  v  a  2s. co  m*/
 */
@Override
public BusinessObjectDataNotificationRegistrationEntity getBusinessObjectDataNotificationByAltKey(
        BusinessObjectDataNotificationRegistrationKey key) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<BusinessObjectDataNotificationRegistrationEntity> criteria = builder
            .createQuery(BusinessObjectDataNotificationRegistrationEntity.class);

    // The criteria root is the business object data notification registration entity.
    Root<BusinessObjectDataNotificationRegistrationEntity> businessObjectDataNotificationEntity = criteria
            .from(BusinessObjectDataNotificationRegistrationEntity.class);

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

    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate queryRestriction = builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)),
            key.getNamespace().toUpperCase());
    queryRestriction = builder.and(queryRestriction,
            builder.equal(
                    builder.upper(businessObjectDataNotificationEntity
                            .get(BusinessObjectDataNotificationRegistrationEntity_.name)),
                    key.getNotificationName().toUpperCase()));

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

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

From source file:org.finra.dm.dao.impl.DmDaoImpl.java

/**
 * {@inheritDoc}//from w  w w. j  ava  2s.  c  o  m
 */
@Override
public List<BusinessObjectDataNotificationRegistrationKey> getBusinessObjectDataNotificationRegistrationKeys(
        String namespaceCode) {
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tuple> criteria = builder.createTupleQuery();

    // The criteria root is the business object data notification.
    Root<BusinessObjectDataNotificationRegistrationEntity> businessObjectDataNotificationEntity = criteria
            .from(BusinessObjectDataNotificationRegistrationEntity.class);

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

    // Get the columns.
    Path<String> namespaceCodeColumn = namespaceEntity.get(NamespaceEntity_.code);
    Path<String> notificationNameColumn = businessObjectDataNotificationEntity
            .get(BusinessObjectDataNotificationRegistrationEntity_.name);

    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate queryRestriction = builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)),
            namespaceCode.toUpperCase());

    // Add the select clause.
    criteria.multiselect(namespaceCodeColumn, notificationNameColumn);

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

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

    // 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<BusinessObjectDataNotificationRegistrationKey> businessObjectDataNotificationKeys = new ArrayList<>();
    for (Tuple tuple : tuples) {
        BusinessObjectDataNotificationRegistrationKey businessObjectDataNotificationKey = new BusinessObjectDataNotificationRegistrationKey();
        businessObjectDataNotificationKeys.add(businessObjectDataNotificationKey);
        businessObjectDataNotificationKey.setNamespace(tuple.get(namespaceCodeColumn));
        businessObjectDataNotificationKey.setNotificationName(tuple.get(notificationNameColumn));
    }

    return businessObjectDataNotificationKeys;
}

From source file:org.finra.dm.dao.impl.DmDaoImpl.java

/**
 * {@inheritDoc}/*  www. ja  va2  s  .  co  m*/
 */
@Override
public List<BusinessObjectDataNotificationRegistrationEntity> getBusinessObjectDataNotificationRegistrations(
        String notificationEventTypeCode, BusinessObjectDataKey businessObjectDataKey) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<BusinessObjectDataNotificationRegistrationEntity> criteria = builder
            .createQuery(BusinessObjectDataNotificationRegistrationEntity.class);

    // The criteria root is the business object data notification registration entity.
    Root<BusinessObjectDataNotificationRegistrationEntity> businessObjectDataNotificationEntity = criteria
            .from(BusinessObjectDataNotificationRegistrationEntity.class);

    // Join to the other tables we can filter on.
    Join<BusinessObjectDataNotificationRegistrationEntity, NamespaceEntity> namespaceEntity = businessObjectDataNotificationEntity
            .join(BusinessObjectDataNotificationRegistrationEntity_.namespace);
    Join<BusinessObjectDataNotificationRegistrationEntity, NotificationEventTypeEntity> notificationEventTypeEntity = businessObjectDataNotificationEntity
            .join(BusinessObjectDataNotificationRegistrationEntity_.notificationEventType);
    Join<BusinessObjectDataNotificationRegistrationEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = businessObjectDataNotificationEntity
            .join(BusinessObjectDataNotificationRegistrationEntity_.businessObjectDefinition);
    Join<BusinessObjectDefinitionEntity, NamespaceEntity> businessObjectDefinitionNamespaceEntity = businessObjectDefinitionEntity
            .join(BusinessObjectDefinitionEntity_.namespace);
    Join<BusinessObjectDataNotificationRegistrationEntity, FileTypeEntity> fileTypeEntity = businessObjectDataNotificationEntity
            .join(BusinessObjectDataNotificationRegistrationEntity_.fileType, JoinType.LEFT);

    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate queryRestriction = builder.equal(
            builder.upper(notificationEventTypeEntity.get(NotificationEventTypeEntity_.code)),
            notificationEventTypeCode.toUpperCase());
    queryRestriction = builder.and(queryRestriction,
            builder.equal(builder.upper(businessObjectDefinitionNamespaceEntity.get(NamespaceEntity_.code)),
                    businessObjectDataKey.getNamespace().toUpperCase()));
    queryRestriction = builder.and(queryRestriction,
            builder.equal(
                    builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)),
                    businessObjectDataKey.getBusinessObjectDefinitionName().toUpperCase()));
    queryRestriction = builder.and(queryRestriction,
            builder.or(
                    builder.isNull(businessObjectDataNotificationEntity
                            .get(BusinessObjectDataNotificationRegistrationEntity_.usage)),
                    builder.equal(
                            builder.upper(businessObjectDataNotificationEntity
                                    .get(BusinessObjectDataNotificationRegistrationEntity_.usage)),
                            businessObjectDataKey.getBusinessObjectFormatUsage().toUpperCase())));
    queryRestriction = builder.and(queryRestriction,
            builder.or(
                    builder.isNull(businessObjectDataNotificationEntity
                            .get(BusinessObjectDataNotificationRegistrationEntity_.fileType)),
                    builder.equal(builder.upper(fileTypeEntity.get(FileTypeEntity_.code)),
                            businessObjectDataKey.getBusinessObjectFormatFileType().toUpperCase())));
    queryRestriction = builder.and(queryRestriction, builder.or(
            builder.isNull(businessObjectDataNotificationEntity
                    .get(BusinessObjectDataNotificationRegistrationEntity_.businessObjectFormatVersion)),
            builder.equal(
                    businessObjectDataNotificationEntity
                            .get(BusinessObjectDataNotificationRegistrationEntity_.businessObjectFormatVersion),
                    businessObjectDataKey.getBusinessObjectFormatVersion())));

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

    // Add the clauses for the query.
    criteria.select(businessObjectDataNotificationEntity).where(queryRestriction).orderBy(orderBy);

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

From source file:org.finra.dm.dao.impl.DmDaoImpl.java

/**
 * {@inheritDoc}/*  w w  w  .ja v  a  2s .com*/
 */
@Override
@Cacheable(DaoSpringModuleConfig.DM_CACHE_NAME)
public List<String> getSecurityFunctionsForRole(String roleCd) {
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    // CriteriaQuery<Tuple> criteria = builder.createTupleQuery();
    CriteriaQuery<String> criteria = builder.createQuery(String.class);

    // The criteria root is the business object definition.
    Root<SecurityRoleFunctionEntity> securityRoleFunctionEntity = criteria
            .from(SecurityRoleFunctionEntity.class);

    // Join to the other tables we can filter on.
    Join<SecurityRoleFunctionEntity, SecurityRoleEntity> securityRoleEntity = securityRoleFunctionEntity
            .join(SecurityRoleFunctionEntity_.securityRole);
    Join<SecurityRoleFunctionEntity, SecurityFunctionEntity> securityFunctionEntity = securityRoleFunctionEntity
            .join(SecurityRoleFunctionEntity_.securityFunction);

    // Get the columns.
    Path<String> functionCodeColumn = securityFunctionEntity.get(SecurityFunctionEntity_.code);

    // Add the select clause.
    criteria.select(functionCodeColumn);

    criteria.where(builder.equal(builder.upper(securityRoleEntity.get(SecurityRoleEntity_.code)),
            roleCd.toUpperCase()));

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

    // Run the query to get a list of tuples back.
    return entityManager.createQuery(criteria).getResultList();
}

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.ja v  a 2 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 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.//from   w w  w .  ja  v  a2 s . co 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  v  a2  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()]));
}