List of usage examples for javax.persistence.criteria CriteriaBuilder upper
Expression<String> upper(Expression<String> x);
From source file:org.finra.dm.dao.impl.DmDaoImpl.java
/** * {@inheritDoc}//from ww w . j a v a 2 s . c o m */ @Override public BusinessObjectDefinitionEntity getBusinessObjectDefinitionByKey( BusinessObjectDefinitionKey businessObjectDefinitionKey) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<BusinessObjectDefinitionEntity> criteria = builder .createQuery(BusinessObjectDefinitionEntity.class); // The criteria root is the business object definition. Root<BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = criteria .from(BusinessObjectDefinitionEntity.class); // Join to the other tables we can filter on. 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)), businessObjectDefinitionKey.getNamespace().toUpperCase()); queryRestriction = builder.and(queryRestriction, builder.equal( builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)), businessObjectDefinitionKey.getBusinessObjectDefinitionName().toUpperCase())); criteria.select(businessObjectDefinitionEntity).where(queryRestriction); return executeSingleResultQuery(criteria, String.format( "Found more than one business object definition with parameters {namespace=\"%s\", businessObjectDefinitionName=\"%s\"}.", businessObjectDefinitionKey.getNamespace(), businessObjectDefinitionKey.getBusinessObjectDefinitionName())); }
From source file:org.finra.dm.dao.impl.DmDaoImpl.java
/** * {@inheritDoc}/*from w w w .j a v a 2 s. c o m*/ */ @Override public BusinessObjectDefinitionEntity getLegacyBusinessObjectDefinitionByName( String businessObjectDefinitionName) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<BusinessObjectDefinitionEntity> criteria = builder .createQuery(BusinessObjectDefinitionEntity.class); // The criteria root is the business object definition. Root<BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = criteria .from(BusinessObjectDefinitionEntity.class); // Create the standard restrictions (i.e. the standard where clauses). Predicate queryRestriction = builder.equal( builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)), businessObjectDefinitionName.toUpperCase()); queryRestriction = builder.and(queryRestriction, builder.isTrue(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.legacy))); criteria.select(businessObjectDefinitionEntity).where(queryRestriction); return executeSingleResultQuery(criteria, String.format( "Found more than one business object definition with parameters {businessObjectDefinitionName=\"%s\", legacy=\"Y\"}.", businessObjectDefinitionName)); }
From source file:org.finra.dm.dao.impl.DmDaoImpl.java
/** * {@inheritDoc}/*from w w w . j a v a 2s .c o m*/ */ @Override public List<BusinessObjectDefinitionKey> getBusinessObjectDefinitions(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 definition. Root<BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = criteria .from(BusinessObjectDefinitionEntity.class); // Join to the other tables we can filter on. 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); // Add the select clause. criteria.multiselect(namespaceCodeColumn, businessObjectDefinitionNameColumn); // If namespace code is specified, add the where clause. if (StringUtils.isNotBlank(namespaceCode)) { criteria.where(builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)), namespaceCode.toUpperCase())); } // Add the order by clause. if (StringUtils.isNotBlank(namespaceCode)) { criteria.orderBy(builder.asc(namespaceCodeColumn), builder.asc(businessObjectDefinitionNameColumn)); } else { criteria.orderBy(builder.asc(businessObjectDefinitionNameColumn)); } // 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<BusinessObjectDefinitionKey> businessObjectDefinitionKeys = new ArrayList<>(); for (Tuple tuple : tuples) { BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(); businessObjectDefinitionKeys.add(businessObjectDefinitionKey); businessObjectDefinitionKey.setNamespace(tuple.get(namespaceCodeColumn)); businessObjectDefinitionKey .setBusinessObjectDefinitionName(tuple.get(businessObjectDefinitionNameColumn)); } return businessObjectDefinitionKeys; }
From source file:org.finra.dm.dao.impl.DmDaoImpl.java
/** * {@inheritDoc}//from w ww .j ava 2 s. c o m */ @Override public FileTypeEntity getFileTypeByCode(String code) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<FileTypeEntity> criteria = builder.createQuery(FileTypeEntity.class); // The criteria root is the file types. Root<FileTypeEntity> fileType = criteria.from(FileTypeEntity.class); // Create the standard restrictions (i.e. the standard where clauses). Predicate fileTypeCodeRestriction = builder.equal(builder.upper(fileType.get(FileTypeEntity_.code)), code.toUpperCase()); criteria.select(fileType).where(fileTypeCodeRestriction); return executeSingleResultQuery(criteria, String.format("Found more than one file type with code \"%s\".", code)); }
From source file:org.finra.dm.dao.impl.DmDaoImpl.java
/** * {@inheritDoc}/*w ww .j a v a 2s . c o m*/ */ @Override public List<BusinessObjectFormatKey> getBusinessObjectFormats( BusinessObjectDefinitionKey businessObjectDefinitionKey, 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 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; }
From source file:org.finra.dm.dao.impl.DmDaoImpl.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//from w ww .ja v a 2s. c o 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 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 */ private Predicate getQueryRestriction(CriteriaBuilder builder, From<?, BusinessObjectFormatEntity> businessObjectFormatEntity, From<?, FileTypeEntity> fileTypeEntity, From<?, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity, BusinessObjectFormatKey businessObjectFormatKey, boolean ignoreBusinessObjectFormatVersion) { // Join to the other tables we can filter on. Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntity = businessObjectDefinitionEntity .join(BusinessObjectDefinitionEntity_.namespace); // 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.dm.dao.impl.DmDaoImpl.java
/** * {@inheritDoc}//from www. jav a2s . c o m */ @Override public PartitionKeyGroupEntity getPartitionKeyGroupByName(String partitionKeyGroupName) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<PartitionKeyGroupEntity> criteria = builder.createQuery(PartitionKeyGroupEntity.class); // The criteria root is the partition key group. Root<PartitionKeyGroupEntity> partitionKeyGroupEntity = criteria.from(PartitionKeyGroupEntity.class); // Create the standard restrictions (i.e. the standard where clauses). Predicate partitionKeyGroupRestriction = builder.equal( builder.upper(partitionKeyGroupEntity.get(PartitionKeyGroupEntity_.partitionKeyGroupName)), partitionKeyGroupName.toUpperCase()); criteria.select(partitionKeyGroupEntity).where(partitionKeyGroupRestriction); return executeSingleResultQuery(criteria, String.format("Found more than one \"%s\" partition key group.", partitionKeyGroupName)); }
From source file:org.finra.dm.dao.impl.DmDaoImpl.java
/** * {@inheritDoc}/*from w w w . jav a 2 s.co m*/ */ @Override public ExpectedPartitionValueEntity getExpectedPartitionValue( ExpectedPartitionValueKey expectedPartitionValueKey, int offset) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<ExpectedPartitionValueEntity> criteria = builder .createQuery(ExpectedPartitionValueEntity.class); // The criteria root is the expected partition value. Root<ExpectedPartitionValueEntity> expectedPartitionValueEntity = criteria .from(ExpectedPartitionValueEntity.class); // Join to the other tables we can filter on. Join<ExpectedPartitionValueEntity, PartitionKeyGroupEntity> partitionKeyGroupEntity = expectedPartitionValueEntity .join(ExpectedPartitionValueEntity_.partitionKeyGroup); // Add a restriction to filter case insensitive groups that match the user specified group. Predicate whereRestriction = builder.equal( builder.upper(partitionKeyGroupEntity.get(PartitionKeyGroupEntity_.partitionKeyGroupName)), expectedPartitionValueKey.getPartitionKeyGroupName().toUpperCase()); // Depending on the offset, we might need to order the records in the query. Order orderByExpectedPartitionValue = null; // Add additional restrictions to handle expected partition value and an optional offset. if (offset == 0) { // Since there is no offset, we need to match the expected partition value exactly. whereRestriction = builder.and(whereRestriction, builder.equal(expectedPartitionValueEntity.get(ExpectedPartitionValueEntity_.partitionValue), expectedPartitionValueKey.getExpectedPartitionValue())); } else if (offset > 0) { // For a positive offset value, add a restriction to filter expected partition values that are >= the user specified expected partition value. whereRestriction = builder.and(whereRestriction, builder.greaterThanOrEqualTo( expectedPartitionValueEntity.get(ExpectedPartitionValueEntity_.partitionValue), expectedPartitionValueKey.getExpectedPartitionValue())); // Order by expected partition value in ascending order. orderByExpectedPartitionValue = builder .asc(expectedPartitionValueEntity.get(ExpectedPartitionValueEntity_.partitionValue)); } else { // For a negative offset value, add a restriction to filter expected partition values that are <= the user specified expected partition value. whereRestriction = builder.and(whereRestriction, builder.lessThanOrEqualTo( expectedPartitionValueEntity.get(ExpectedPartitionValueEntity_.partitionValue), expectedPartitionValueKey.getExpectedPartitionValue())); // Order by expected partition value in descending order. orderByExpectedPartitionValue = builder .desc(expectedPartitionValueEntity.get(ExpectedPartitionValueEntity_.partitionValue)); } // Add the clauses for the query and execute the query. if (offset == 0) { criteria.select(expectedPartitionValueEntity).where(whereRestriction); return executeSingleResultQuery(criteria, String.format( "Found more than one expected partition value with parameters {partitionKeyGroupName=\"%s\", expectedPartitionValue=\"%s\"}.", expectedPartitionValueKey.getPartitionKeyGroupName(), expectedPartitionValueKey.getExpectedPartitionValue())); } else { criteria.select(expectedPartitionValueEntity).where(whereRestriction) .orderBy(orderByExpectedPartitionValue); List<ExpectedPartitionValueEntity> resultList = entityManager.createQuery(criteria) .setFirstResult(Math.abs(offset)).setMaxResults(1).getResultList(); return resultList.size() > 0 ? resultList.get(0) : null; } }
From source file:org.finra.dm.dao.impl.DmDaoImpl.java
/** * {@inheritDoc}//from w w w . ja v a2s . c o m */ @Override public List<ExpectedPartitionValueEntity> getExpectedPartitionValuesByGroupAndRange( String partitionKeyGroupName, PartitionValueRange partitionValueRange) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<ExpectedPartitionValueEntity> criteria = builder .createQuery(ExpectedPartitionValueEntity.class); // The criteria root is the expected partition value. Root<ExpectedPartitionValueEntity> expectedPartitionValueEntity = criteria .from(ExpectedPartitionValueEntity.class); // Join to the other tables we can filter on. Join<ExpectedPartitionValueEntity, PartitionKeyGroupEntity> partitionKeyGroupEntity = expectedPartitionValueEntity .join(ExpectedPartitionValueEntity_.partitionKeyGroup); // Add a restriction to filter case insensitive groups that match the user specified group. Predicate whereRestriction = builder.equal( builder.upper(partitionKeyGroupEntity.get(PartitionKeyGroupEntity_.partitionKeyGroupName)), partitionKeyGroupName.toUpperCase()); // If we have a possible partition value range, we need to add additional restrictions. if (partitionValueRange != null) { // Add a restriction to filter values that are >= the user specified range start value. if (StringUtils.isNotBlank(partitionValueRange.getStartPartitionValue())) { whereRestriction = builder.and(whereRestriction, builder.greaterThanOrEqualTo( expectedPartitionValueEntity.get(ExpectedPartitionValueEntity_.partitionValue), partitionValueRange.getStartPartitionValue())); } // Add a restriction to filter values that are <= the user specified range end value. if (StringUtils.isNotBlank(partitionValueRange.getEndPartitionValue())) { whereRestriction = builder.and(whereRestriction, builder.lessThanOrEqualTo( expectedPartitionValueEntity.get(ExpectedPartitionValueEntity_.partitionValue), partitionValueRange.getEndPartitionValue())); } } // Order the results by partition value. Order orderByValue = builder .asc(expectedPartitionValueEntity.get(ExpectedPartitionValueEntity_.partitionValue)); // Add the clauses for the query. criteria.select(expectedPartitionValueEntity).where(whereRestriction).orderBy(orderByValue); // Execute the query and return the results. return entityManager.createQuery(criteria).getResultList(); }
From source file:org.finra.dm.dao.impl.DmDaoImpl.java
/** * {@inheritDoc}//from w w w. j ava2s . com */ @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())); }