List of usage examples for javax.persistence.criteria CriteriaBuilder and
Predicate and(Predicate... restrictions);
From source file:org.finra.herd.dao.impl.AttributeValueListDaoImpl.java
@Override public List<AttributeValueListKey> getAttributeValueLists(Collection<String> namespaces) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<AttributeValueListEntity> criteria = builder.createQuery(AttributeValueListEntity.class); // The criteria root is the attribute value list entity. Root<AttributeValueListEntity> attributeValueListEntityRoot = criteria.from(AttributeValueListEntity.class); // Join to the other tables we can filter on. Join<AttributeValueListEntity, NamespaceEntity> namespaceEntityJoin = attributeValueListEntityRoot .join(AttributeValueListEntity_.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)); }// w ww.ja v a 2 s . c o m // 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(attributeValueListEntityRoot.get(AttributeValueListEntity_.name))); // Add all clauses to the query. criteria.select(attributeValueListEntityRoot) .where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(orderBy); // Execute the query and build a list of keys. List<AttributeValueListKey> attributeValueListKeys = new ArrayList<>(); for (AttributeValueListEntity attributeValueListEntity : entityManager.createQuery(criteria) .getResultList()) { attributeValueListKeys.add(new AttributeValueListKey(attributeValueListEntity.getNamespace().getCode(), attributeValueListEntity.getName())); } return attributeValueListKeys; }
From source file:org.finra.herd.dao.impl.BusinessObjectDataAttributeDaoImpl.java
@Override public BusinessObjectDataAttributeEntity getBusinessObjectDataAttributeByKey( BusinessObjectDataAttributeKey businessObjectDataAttributeKey) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<BusinessObjectDataAttributeEntity> criteria = builder .createQuery(BusinessObjectDataAttributeEntity.class); // The criteria root is the business object data attribute. Root<BusinessObjectDataAttributeEntity> businessObjectDataAttributeEntityRoot = criteria .from(BusinessObjectDataAttributeEntity.class); // Join to the other tables we can filter on. Join<BusinessObjectDataAttributeEntity, BusinessObjectDataEntity> businessObjectDataEntityJoin = businessObjectDataAttributeEntityRoot .join(BusinessObjectDataAttributeEntity_.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); // 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)), businessObjectDataAttributeKey.getNamespace().toUpperCase())); predicates.add(builder.equal(// w w w .j av a 2 s .co m builder.upper(businessObjectDefinitionEntityJoin.get(BusinessObjectDefinitionEntity_.name)), businessObjectDataAttributeKey.getBusinessObjectDefinitionName().toUpperCase())); predicates.add(builder.equal( builder.upper(businessObjectDefinitionEntityJoin.get(BusinessObjectDefinitionEntity_.name)), businessObjectDataAttributeKey.getBusinessObjectDefinitionName().toUpperCase())); predicates.add( builder.equal(builder.upper(businessObjectFormatEntityJoin.get(BusinessObjectFormatEntity_.usage)), businessObjectDataAttributeKey.getBusinessObjectFormatUsage().toUpperCase())); predicates.add(builder.equal(builder.upper(fileTypeEntityJoin.get(FileTypeEntity_.code)), businessObjectDataAttributeKey.getBusinessObjectFormatFileType().toUpperCase())); predicates.add(builder.equal( businessObjectFormatEntityJoin.get(BusinessObjectFormatEntity_.businessObjectFormatVersion), businessObjectDataAttributeKey.getBusinessObjectFormatVersion())); predicates.add(getQueryRestrictionOnPartitionValues(builder, businessObjectDataEntityJoin, businessObjectDataAttributeKey.getPartitionValue(), businessObjectDataAttributeKey.getSubPartitionValues())); predicates.add(builder.equal(businessObjectDataEntityJoin.get(BusinessObjectDataEntity_.version), businessObjectDataAttributeKey.getBusinessObjectDataVersion())); predicates.add(builder.equal( builder.upper(businessObjectDataAttributeEntityRoot.get(BusinessObjectDataAttributeEntity_.name)), businessObjectDataAttributeKey.getBusinessObjectDataAttributeName().toUpperCase())); // Add the clauses for the query. criteria.select(businessObjectDataAttributeEntityRoot) .where(builder.and(predicates.toArray(new Predicate[predicates.size()]))); return executeSingleResultQuery(criteria, String.format( "Found more than one business object data attribute instance with parameters {namespace=\"%s\", businessObjectDefinitionName=\"%s\"," + " businessObjectFormatUsage=\"%s\", businessObjectFormatFileType=\"%s\", businessObjectFormatVersion=\"%d\"," + " businessObjectDataPartitionValue=\"%s\", businessObjectDataSubPartitionValues=\"%s\", businessObjectDataVersion=\"%d\"," + " businessObjectDataAttributeName=\"%s\"}.", businessObjectDataAttributeKey.getNamespace(), businessObjectDataAttributeKey.getBusinessObjectDefinitionName(), businessObjectDataAttributeKey.getBusinessObjectFormatUsage(), businessObjectDataAttributeKey.getBusinessObjectFormatFileType(), businessObjectDataAttributeKey.getBusinessObjectFormatVersion(), businessObjectDataAttributeKey.getPartitionValue(), CollectionUtils.isEmpty(businessObjectDataAttributeKey.getSubPartitionValues()) ? "" : StringUtils.join(businessObjectDataAttributeKey.getSubPartitionValues(), ","), businessObjectDataAttributeKey.getBusinessObjectDataVersion(), businessObjectDataAttributeKey.getBusinessObjectDataAttributeName())); }
From source file:org.finra.herd.dao.impl.BusinessObjectDataDaoImpl.java
@Override public List<BusinessObjectDataEntity> getBusinessObjectDataFromStorageOlderThan(StorageEntity storageEntity, int thresholdMinutes, List<String> businessObjectDataStatuses) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<BusinessObjectDataEntity> criteria = builder.createQuery(BusinessObjectDataEntity.class); // The criteria root is the business object data. Root<BusinessObjectDataEntity> businessObjectDataEntityRoot = criteria.from(BusinessObjectDataEntity.class); // Join to the other tables we can filter on. Join<BusinessObjectDataEntity, StorageUnitEntity> storageUnitEntityJoin = businessObjectDataEntityRoot .join(BusinessObjectDataEntity_.storageUnits); // Compute threshold timestamp based on the current database timestamp and threshold minutes. Timestamp thresholdTimestamp = HerdDateUtils.addMinutes(getCurrentTimestamp(), -thresholdMinutes); // Create the standard restrictions (i.e. the standard where clauses). List<Predicate> predicates = new ArrayList<>(); predicates.add(// w ww . ja va 2 s.c o m builder.equal(storageUnitEntityJoin.get(StorageUnitEntity_.storageName), storageEntity.getName())); predicates.add(businessObjectDataEntityRoot.get(BusinessObjectDataEntity_.statusCode) .in(businessObjectDataStatuses)); predicates.add(builder.lessThanOrEqualTo( businessObjectDataEntityRoot.get(BusinessObjectDataEntity_.createdOn), thresholdTimestamp)); // Order results by "created on" timestamp. Order orderBy = builder.asc(businessObjectDataEntityRoot.get(BusinessObjectDataEntity_.createdOn)); // Add all clauses to the query. criteria.select(businessObjectDataEntityRoot) .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.BusinessObjectDataNotificationRegistrationDaoImpl.java
@Override public List<NotificationRegistrationKey> getBusinessObjectDataNotificationRegistrationKeysByNotificationFilter( BusinessObjectDataNotificationFilter 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 business object data notification registration. Root<BusinessObjectDataNotificationRegistrationEntity> notificationRegistrationEntityRoot = criteria .from(BusinessObjectDataNotificationRegistrationEntity.class); // Join to the other tables we can filter on. Join<BusinessObjectDataNotificationRegistrationEntity, NamespaceEntity> notificationRegistrationNamespaceEntityJoin = notificationRegistrationEntityRoot .join(BusinessObjectDataNotificationRegistrationEntity_.namespace); Join<BusinessObjectDataNotificationRegistrationEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = notificationRegistrationEntityRoot .join(BusinessObjectDataNotificationRegistrationEntity_.businessObjectDefinition); Join<BusinessObjectDefinitionEntity, NamespaceEntity> businessObjectDefinitionNamespaceEntity = businessObjectDefinitionEntity .join(BusinessObjectDefinitionEntity_.namespace); Join<BusinessObjectDataNotificationRegistrationEntity, FileTypeEntity> fileTypeEntity = notificationRegistrationEntityRoot .join(BusinessObjectDataNotificationRegistrationEntity_.fileType, JoinType.LEFT); // Get the columns. Path<String> notificationRegistrationNamespaceColumn = notificationRegistrationNamespaceEntityJoin .get(NamespaceEntity_.code); Path<String> notificationRegistrationNameColumn = notificationRegistrationEntityRoot .get(BusinessObjectDataNotificationRegistrationEntity_.name); // Create the standard restrictions (i.e. the standard where clauses). List<Predicate> predicates = new ArrayList<>(); predicates.add(/*from www.j ava2 s . c o m*/ 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(BusinessObjectDataNotificationRegistrationEntity_.usage)), builder.equal( builder.upper(notificationRegistrationEntityRoot .get(BusinessObjectDataNotificationRegistrationEntity_.usage)), businessObjectDataNotificationFilter.getBusinessObjectFormatUsage().toUpperCase()))); } if (StringUtils.isNotBlank(businessObjectDataNotificationFilter.getBusinessObjectFormatFileType())) { predicates.add(builder.or( builder.isNull(notificationRegistrationEntityRoot .get(BusinessObjectDataNotificationRegistrationEntity_.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); }
From source file:org.finra.herd.dao.impl.BusinessObjectDataNotificationRegistrationDaoImpl.java
@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(/* w w w.j a v a2s.c om*/ 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(); }
From source file:org.finra.herd.dao.impl.BusinessObjectFormatDaoImpl.java
@Override public Long getBusinessObjectFormatCountByPartitionKeys(String namespace, String businessObjectDefinitionName, String businessObjectFormatUsage, String businessObjectFormatFileType, Integer businessObjectFormatVersion, List<String> partitionKeys) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<Long> criteria = builder.createQuery(Long.class); // The criteria root is the business object format. Root<BusinessObjectFormatEntity> businessObjectFormatEntityRoot = criteria .from(BusinessObjectFormatEntity.class); // Create path. Expression<Long> businessObjectFormatRecordCount = builder.count(businessObjectFormatEntityRoot); // Namespace is a required parameter, so fetch the relative entity to optimize the main query. NamespaceEntity namespaceEntity = namespaceDao.getNamespaceByCd(namespace); // If specified namespace does not exist, then return a zero record count. if (namespaceEntity == null) { return 0L; }/* w w w . j a v a2 s. c o m*/ // If file type is specified, fetch the relative entity to optimize the main query. FileTypeEntity fileTypeEntity = null; if (StringUtils.isNotBlank(businessObjectFormatFileType)) { fileTypeEntity = fileTypeDao.getFileTypeByCode(businessObjectFormatFileType); // If specified file type does not exist, then return a zero record count. if (fileTypeEntity == null) { return 0L; } } // Join to the other tables we can filter on. Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = businessObjectFormatEntityRoot .join(BusinessObjectFormatEntity_.businessObjectDefinition); // Create main query restrictions based on the specified parameters. List<Predicate> predicates = new ArrayList<>(); // Create restriction on namespace code and business object definition name. predicates.add(builder.equal(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.namespace), namespaceEntity)); predicates.add(builder.equal( builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)), businessObjectDefinitionName.toUpperCase())); // If specified, create restriction on business object format usage. if (!StringUtils.isEmpty(businessObjectFormatUsage)) { predicates.add(builder.equal( builder.upper(businessObjectFormatEntityRoot.get(BusinessObjectFormatEntity_.usage)), businessObjectFormatUsage.toUpperCase())); } // If specified, create restriction on business object format file type. if (fileTypeEntity != null) { predicates .add(builder.equal(businessObjectFormatEntityRoot.get(BusinessObjectFormatEntity_.fileTypeCode), fileTypeEntity.getCode())); } // If specified, create restriction on business object format version. if (businessObjectFormatVersion != null) { predicates.add(builder.equal( businessObjectFormatEntityRoot.get(BusinessObjectFormatEntity_.businessObjectFormatVersion), businessObjectFormatVersion)); } // If specified, create restriction on partition keys. if (CollectionUtils.isNotEmpty(partitionKeys)) { for (String partitionKey : partitionKeys) { // Add restriction on partition key (partition column). // Partition key must identify a partition column that is at partition level that could be explicitly registered. // Partition level uses one-based numbering. Join<BusinessObjectFormatEntity, SchemaColumnEntity> schemaColumnEntityJoin = businessObjectFormatEntityRoot .join(BusinessObjectFormatEntity_.schemaColumns); predicates.add(builder.equal(builder.upper(schemaColumnEntityJoin.get(SchemaColumnEntity_.name)), partitionKey.toUpperCase())); predicates.add(builder.isNotNull(schemaColumnEntityJoin.get(SchemaColumnEntity_.partitionLevel))); predicates.add(builder.lessThan(schemaColumnEntityJoin.get(SchemaColumnEntity_.partitionLevel), BusinessObjectDataEntity.MAX_SUBPARTITIONS + 2)); } } // Add all clauses for the query. criteria.select(businessObjectFormatRecordCount) .where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).distinct(true); // Execute the query and return the result. return entityManager.createQuery(criteria).getSingleResult(); }
From source file:org.finra.herd.dao.impl.HerdDaoImpl.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> jobDefinition = criteria.from(JobDefinitionEntity.class); // Join to the other tables we can filter on. Join<JobDefinitionEntity, NamespaceEntity> namespaceJoin = jobDefinition .join(JobDefinitionEntity_.namespace); List<Predicate> predicates = new ArrayList<>(); // Create the restrictions (i.e. the where clauses). if (StringUtils.isNotBlank(namespace)) { predicates.add(builder.equal(builder.upper(namespaceJoin.get(NamespaceEntity_.code)), namespace.toUpperCase())); }/*ww w . java 2 s .c o m*/ if (StringUtils.isNotBlank(jobName)) { predicates.add(builder.equal(builder.upper(jobDefinition.get(JobDefinitionEntity_.name)), jobName.toUpperCase())); } criteria.select(jobDefinition); if (predicates.size() > 0) { criteria.where(builder.and(predicates.toArray(new Predicate[predicates.size()]))); } return entityManager.createQuery(criteria).getResultList(); }
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())); }/*from w ww. j av a2 s . c om*/ 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)); }/* w w w . j a va2 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.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/*www. j a va 2s .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(); }