List of usage examples for javax.persistence.criteria JoinType LEFT
JoinType LEFT
To view the source code for javax.persistence.criteria JoinType LEFT.
Click Source Link
From source file:org.finra.dm.dao.impl.DmDaoImpl.java
/** * {@inheritDoc}/*from ww w . j a va 2s . 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.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(/* w w w. j a va 2s.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 av a 2 s. 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.StorageUnitNotificationRegistrationDaoImpl.java
@Override public List<NotificationRegistrationKey> getStorageUnitNotificationRegistrationKeysByNotificationFilter( StorageUnitNotificationFilter businessObjectDataNotificationFilter) { // Create the criteria builder and a tuple style criteria query. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<Tuple> criteria = builder.createTupleQuery(); // The criteria root is the storage unit notification registration. Root<StorageUnitNotificationRegistrationEntity> notificationRegistrationEntityRoot = criteria .from(StorageUnitNotificationRegistrationEntity.class); // Join to the other tables we can filter on. Join<StorageUnitNotificationRegistrationEntity, NamespaceEntity> notificationRegistrationNamespaceEntityJoin = notificationRegistrationEntityRoot .join(StorageUnitNotificationRegistrationEntity_.namespace); Join<StorageUnitNotificationRegistrationEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = notificationRegistrationEntityRoot .join(StorageUnitNotificationRegistrationEntity_.businessObjectDefinition); Join<BusinessObjectDefinitionEntity, NamespaceEntity> businessObjectDefinitionNamespaceEntity = businessObjectDefinitionEntity .join(BusinessObjectDefinitionEntity_.namespace); Join<StorageUnitNotificationRegistrationEntity, FileTypeEntity> fileTypeEntity = notificationRegistrationEntityRoot .join(StorageUnitNotificationRegistrationEntity_.fileType, JoinType.LEFT); // Get the columns. Path<String> notificationRegistrationNamespaceColumn = notificationRegistrationNamespaceEntityJoin .get(NamespaceEntity_.code); Path<String> notificationRegistrationNameColumn = notificationRegistrationEntityRoot .get(StorageUnitNotificationRegistrationEntity_.name); // Create the standard restrictions (i.e. the standard where clauses). List<Predicate> predicates = new ArrayList<>(); predicates.add(//from ww w . java 2 s. co 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(StorageUnitNotificationRegistrationEntity_.usage)), builder.equal( builder.upper(notificationRegistrationEntityRoot .get(StorageUnitNotificationRegistrationEntity_.usage)), businessObjectDataNotificationFilter.getBusinessObjectFormatUsage().toUpperCase()))); } if (StringUtils.isNotBlank(businessObjectDataNotificationFilter.getBusinessObjectFormatFileType())) { predicates.add(builder.or( builder.isNull(notificationRegistrationEntityRoot .get(StorageUnitNotificationRegistrationEntity_.fileType)), builder.equal(builder.upper(fileTypeEntity.get(FileTypeEntity_.code)), businessObjectDataNotificationFilter.getBusinessObjectFormatFileType().toUpperCase()))); } // Add the select and where clauses to the query. criteria.multiselect(notificationRegistrationNamespaceColumn, notificationRegistrationNameColumn) .where(builder.and(predicates.toArray(new Predicate[predicates.size()]))); // Add the order by clause to the query. criteria.orderBy(builder.asc(notificationRegistrationNamespaceColumn), builder.asc(notificationRegistrationNameColumn)); // Run the query to get a list of tuples back. List<Tuple> tuples = entityManager.createQuery(criteria).getResultList(); // Populate the list of keys from the returned tuples. return getNotificationRegistrationKeys(tuples, notificationRegistrationNamespaceColumn, notificationRegistrationNameColumn); }
From source file:org.finra.herd.dao.impl.StorageUnitNotificationRegistrationDaoImpl.java
@Override public List<StorageUnitNotificationRegistrationEntity> getStorageUnitNotificationRegistrations( String notificationEventTypeCode, BusinessObjectDataKey businessObjectDataKey, String storageName, String newStorageUnitStatus, String oldStorageUnitStatus, String notificationRegistrationStatus) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<StorageUnitNotificationRegistrationEntity> criteria = builder .createQuery(StorageUnitNotificationRegistrationEntity.class); // The criteria root is the storage unit notification registration entity. Root<StorageUnitNotificationRegistrationEntity> storageUnitNotificationRegistrationEntityRoot = criteria .from(StorageUnitNotificationRegistrationEntity.class); // Join to the other tables we can filter on. Join<StorageUnitNotificationRegistrationEntity, NamespaceEntity> namespaceEntityJoin = storageUnitNotificationRegistrationEntityRoot .join(StorageUnitNotificationRegistrationEntity_.namespace); Join<StorageUnitNotificationRegistrationEntity, NotificationEventTypeEntity> notificationEventTypeEntityJoin = storageUnitNotificationRegistrationEntityRoot .join(StorageUnitNotificationRegistrationEntity_.notificationEventType); Join<StorageUnitNotificationRegistrationEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntityJoin = storageUnitNotificationRegistrationEntityRoot .join(StorageUnitNotificationRegistrationEntity_.businessObjectDefinition); Join<BusinessObjectDefinitionEntity, NamespaceEntity> businessObjectDefinitionNamespaceEntityJoin = businessObjectDefinitionEntityJoin .join(BusinessObjectDefinitionEntity_.namespace); Join<StorageUnitNotificationRegistrationEntity, StorageEntity> storageEntityJoin = storageUnitNotificationRegistrationEntityRoot .join(StorageUnitNotificationRegistrationEntity_.storage); Join<StorageUnitNotificationRegistrationEntity, FileTypeEntity> fileTypeEntityJoin = storageUnitNotificationRegistrationEntityRoot .join(StorageUnitNotificationRegistrationEntity_.fileType, JoinType.LEFT); Join<StorageUnitNotificationRegistrationEntity, StorageUnitStatusEntity> newStorageUnitStatusEntityJoin = storageUnitNotificationRegistrationEntityRoot .join(StorageUnitNotificationRegistrationEntity_.newStorageUnitStatus, JoinType.LEFT); Join<StorageUnitNotificationRegistrationEntity, StorageUnitStatusEntity> oldStorageUnitStatusEntityJoin = storageUnitNotificationRegistrationEntityRoot .join(StorageUnitNotificationRegistrationEntity_.oldStorageUnitStatus, JoinType.LEFT); Join<StorageUnitNotificationRegistrationEntity, NotificationRegistrationStatusEntity> notificationRegistrationStatusEntityJoin = storageUnitNotificationRegistrationEntityRoot .join(StorageUnitNotificationRegistrationEntity_.notificationRegistrationStatus); // Create the standard restrictions (i.e. the standard where clauses). List<Predicate> predicates = new ArrayList<>(); predicates.add(//from w ww. j a v a 2s. co m builder.equal(builder.upper(notificationEventTypeEntityJoin.get(NotificationEventTypeEntity_.code)), notificationEventTypeCode.toUpperCase())); predicates.add( builder.equal(builder.upper(businessObjectDefinitionNamespaceEntityJoin.get(NamespaceEntity_.code)), businessObjectDataKey.getNamespace().toUpperCase())); predicates.add(builder.equal( builder.upper(businessObjectDefinitionEntityJoin.get(BusinessObjectDefinitionEntity_.name)), businessObjectDataKey.getBusinessObjectDefinitionName().toUpperCase())); predicates.add(builder.equal(builder.upper(storageEntityJoin.get(StorageEntity_.name)), storageName.toUpperCase())); predicates.add(builder.or( builder.isNull(storageUnitNotificationRegistrationEntityRoot .get(StorageUnitNotificationRegistrationEntity_.usage)), builder.equal( builder.upper(storageUnitNotificationRegistrationEntityRoot .get(StorageUnitNotificationRegistrationEntity_.usage)), businessObjectDataKey.getBusinessObjectFormatUsage().toUpperCase()))); predicates.add(builder.or( builder.isNull(storageUnitNotificationRegistrationEntityRoot .get(StorageUnitNotificationRegistrationEntity_.fileType)), builder.equal(builder.upper(fileTypeEntityJoin.get(FileTypeEntity_.code)), businessObjectDataKey.getBusinessObjectFormatFileType().toUpperCase()))); predicates.add(builder.or( builder.isNull(storageUnitNotificationRegistrationEntityRoot .get(StorageUnitNotificationRegistrationEntity_.businessObjectFormatVersion)), builder.equal( storageUnitNotificationRegistrationEntityRoot .get(StorageUnitNotificationRegistrationEntity_.businessObjectFormatVersion), businessObjectDataKey.getBusinessObjectFormatVersion()))); predicates.add(builder.or( builder.isNull(storageUnitNotificationRegistrationEntityRoot .get(StorageUnitNotificationRegistrationEntity_.newStorageUnitStatus)), builder.equal(builder.upper(newStorageUnitStatusEntityJoin.get(StorageUnitStatusEntity_.code)), newStorageUnitStatus.toUpperCase()))); // Please note that old business object data status parameter value is null for a business object data registration event. predicates.add(builder.or( builder.isNull(storageUnitNotificationRegistrationEntityRoot .get(StorageUnitNotificationRegistrationEntity_.oldStorageUnitStatus)), builder.equal(builder.upper(oldStorageUnitStatusEntityJoin.get(StorageUnitStatusEntity_.code)), oldStorageUnitStatus == null ? null : oldStorageUnitStatus.toUpperCase()))); predicates.add(builder.equal( builder.upper( notificationRegistrationStatusEntityJoin.get(NotificationRegistrationStatusEntity_.code)), notificationRegistrationStatus.toUpperCase())); // Order the results by namespace and notification name. List<Order> orderBy = new ArrayList<>(); orderBy.add(builder.asc(namespaceEntityJoin.get(NamespaceEntity_.code))); orderBy.add(builder.asc(storageUnitNotificationRegistrationEntityRoot .get(StorageUnitNotificationRegistrationEntity_.name))); // Add the clauses for the query. criteria.select(storageUnitNotificationRegistrationEntityRoot) .where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(orderBy); // Execute the query and return the results. return entityManager.createQuery(criteria).getResultList(); }
From source file:org.jasig.portal.events.aggr.JpaBaseAggregationDao.java
@Override public final void afterPropertiesSet() throws Exception { this.timeDimensionParameter = this.createParameterExpression(TimeDimension.class, "timeDimension"); this.dateDimensionParameter = this.createParameterExpression(DateDimension.class, "dateDimension"); this.intervalParameter = this.createParameterExpression(AggregationInterval.class, "interval"); this.aggregatedGroupParameter = this.createParameterExpression(AggregatedGroupMapping.class, "aggregatedGroup"); this.aggregatedGroupsParameter = this.createParameterExpression(Set.class, "aggregatedGroups"); this.startDate = this.createParameterExpression(LocalDate.class, "startDate"); this.endMinusOneDate = this.createParameterExpression(LocalDate.class, "endMinusOneDate"); this.endDate = this.createParameterExpression(LocalDate.class, "endDate"); this.startTime = this.createParameterExpression(LocalTime.class, "startTime"); this.endTime = this.createParameterExpression(LocalTime.class, "endTime"); this.createParameterExpressions(); this.findAggregationByDateTimeIntervalQuery = this .createCriteriaQuery(new Function<CriteriaBuilder, CriteriaQuery<T>>() { @Override// ww w .j a v a 2 s . com public CriteriaQuery<T> apply(CriteriaBuilder cb) { final CriteriaQuery<T> criteriaQuery = cb.createQuery(aggregationEntityType); final Root<T> ba = criteriaQuery.from(aggregationEntityType); addFetches(ba); criteriaQuery.select(ba); criteriaQuery.where( cb.equal(ba.get(BaseAggregationImpl_.dateDimension), dateDimensionParameter), cb.equal(ba.get(BaseAggregationImpl_.timeDimension), timeDimensionParameter), cb.equal(ba.get(BaseAggregationImpl_.interval), intervalParameter)); return criteriaQuery; } }); this.findAggregationByDateTimeIntervalGroupQuery = this .createCriteriaQuery(new Function<CriteriaBuilder, CriteriaQuery<T>>() { @Override public CriteriaQuery<T> apply(CriteriaBuilder cb) { final CriteriaQuery<T> criteriaQuery = cb.createQuery(aggregationEntityType); final Root<T> ba = criteriaQuery.from(aggregationEntityType); final List<Predicate> keyPredicates = new ArrayList<Predicate>(); keyPredicates .add(cb.equal(ba.get(BaseAggregationImpl_.dateDimension), dateDimensionParameter)); keyPredicates .add(cb.equal(ba.get(BaseAggregationImpl_.timeDimension), timeDimensionParameter)); keyPredicates.add(cb.equal(ba.get(BaseAggregationImpl_.interval), intervalParameter)); keyPredicates.add( cb.equal(ba.get(BaseAggregationImpl_.aggregatedGroup), aggregatedGroupParameter)); addAggregationSpecificKeyPredicate(cb, ba, keyPredicates); criteriaQuery.select(ba); criteriaQuery.where(keyPredicates.toArray(new Predicate[keyPredicates.size()])); return criteriaQuery; } }); this.findAggregationsByDateRangeQuery = this .createCriteriaQuery(new Function<CriteriaBuilder, CriteriaQuery<T>>() { @Override public CriteriaQuery<T> apply(CriteriaBuilder cb) { final CriteriaQuery<T> criteriaQuery = cb.createQuery(aggregationEntityType); final Root<T> ba = criteriaQuery.from(aggregationEntityType); final Join<T, DateDimensionImpl> dd = ba.join(BaseAggregationImpl_.dateDimension, JoinType.LEFT); final Join<T, TimeDimensionImpl> td = ba.join(BaseAggregationImpl_.timeDimension, JoinType.LEFT); final List<Predicate> keyPredicates = new ArrayList<Predicate>(); keyPredicates.add(cb.and( //Restrict results by outer date range cb.greaterThanOrEqualTo(dd.get(DateDimensionImpl_.date), startDate), cb.lessThan(dd.get(DateDimensionImpl_.date), endDate))); keyPredicates.add(cb.or( //Restrict start of range by time as well cb.greaterThan(dd.get(DateDimensionImpl_.date), startDate), cb.greaterThanOrEqualTo(td.get(TimeDimensionImpl_.time), startTime))); keyPredicates.add(cb.or( //Restrict end of range by time as well cb.lessThan(dd.get(DateDimensionImpl_.date), endMinusOneDate), cb.lessThan(td.get(TimeDimensionImpl_.time), endTime))); keyPredicates.add(cb.equal(ba.get(BaseAggregationImpl_.interval), intervalParameter)); keyPredicates .add(ba.get(BaseAggregationImpl_.aggregatedGroup).in(aggregatedGroupsParameter)); addAggregationSpecificKeyPredicate(cb, ba, keyPredicates); criteriaQuery.select(ba); criteriaQuery.where(keyPredicates.toArray(new Predicate[keyPredicates.size()])); criteriaQuery.orderBy(cb.desc(dd.get(DateDimensionImpl_.date)), cb.desc(td.get(TimeDimensionImpl_.time))); return criteriaQuery; } }); /* * Similar to the previous query but only returns aggregates that also match the unclosed predicate generated * by the subclass. This is used for finding aggregates that missed having intervalComplete called due to * interval boundary placement. */ this.findUnclosedAggregationsByDateRangeQuery = this .createCriteriaQuery(new Function<CriteriaBuilder, CriteriaQuery<T>>() { @Override public CriteriaQuery<T> apply(CriteriaBuilder cb) { final CriteriaQuery<T> criteriaQuery = cb.createQuery(aggregationEntityType); final Root<T> ba = criteriaQuery.from(aggregationEntityType); final Join<T, DateDimensionImpl> dd = ba.join(BaseAggregationImpl_.dateDimension, JoinType.LEFT); final Join<T, TimeDimensionImpl> td = ba.join(BaseAggregationImpl_.timeDimension, JoinType.LEFT); addFetches(ba); final List<Predicate> keyPredicates = new ArrayList<Predicate>(); keyPredicates.add(cb.and( //Restrict results by outer date range cb.greaterThanOrEqualTo(dd.get(DateDimensionImpl_.date), startDate), cb.lessThan(dd.get(DateDimensionImpl_.date), endDate))); keyPredicates.add(cb.or( //Restrict start of range by time as well cb.greaterThan(dd.get(DateDimensionImpl_.date), startDate), cb.greaterThanOrEqualTo(td.get(TimeDimensionImpl_.time), startTime))); keyPredicates.add(cb.or( //Restrict end of range by time as well cb.lessThan(dd.get(DateDimensionImpl_.date), endMinusOneDate), cb.lessThan(td.get(TimeDimensionImpl_.time), endTime))); keyPredicates.add(cb.equal(ba.get(BaseAggregationImpl_.interval), intervalParameter)); //No aggregation specific key bits here, we only have start/end/interval parameters to work with addUnclosedPredicate(cb, ba, keyPredicates); criteriaQuery.select(ba); criteriaQuery.where(keyPredicates.toArray(new Predicate[keyPredicates.size()])); return criteriaQuery; } }); this.createCriteriaQueries(); }
From source file:org.jasig.portal.permission.dao.jpa.JpaPermissionOwnerDao.java
@Override public void afterPropertiesSet() throws Exception { this.fnameParameter = this.createParameterExpression(String.class, "fname"); this.findAllPermissionOwners = this .createCriteriaQuery(new Function<CriteriaBuilder, CriteriaQuery<PermissionOwnerImpl>>() { @Override// w ww .jav a 2 s . co m public CriteriaQuery<PermissionOwnerImpl> apply(CriteriaBuilder cb) { final CriteriaQuery<PermissionOwnerImpl> criteriaQuery = cb .createQuery(PermissionOwnerImpl.class); final Root<PermissionOwnerImpl> ownerRoot = criteriaQuery.from(PermissionOwnerImpl.class); criteriaQuery.select(ownerRoot); ownerRoot.fetch(PermissionOwnerImpl_.activities, JoinType.LEFT); return criteriaQuery; } }); this.findPermissionOwnerByFname = this .createCriteriaQuery(new Function<CriteriaBuilder, CriteriaQuery<PermissionOwnerImpl>>() { @Override public CriteriaQuery<PermissionOwnerImpl> apply(CriteriaBuilder cb) { final CriteriaQuery<PermissionOwnerImpl> criteriaQuery = cb .createQuery(PermissionOwnerImpl.class); final Root<PermissionOwnerImpl> ownerRoot = criteriaQuery.from(PermissionOwnerImpl.class); criteriaQuery.select(ownerRoot); ownerRoot.fetch(PermissionOwnerImpl_.activities, JoinType.LEFT); criteriaQuery.where(cb.equal(ownerRoot.get(PermissionOwnerImpl_.fname), fnameParameter)); return criteriaQuery; } }); }
From source file:org.niord.core.area.AreaService.java
/** * Searches for areas matching the given search params * * @param params the sesarch params/*from www.j a v a 2 s . com*/ * @return the search result */ @SuppressWarnings("all") public List<Area> searchAreas(AreaSearchParams params) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Area> areaQuery = cb.createQuery(Area.class); Root<Area> areaRoot = areaQuery.from(Area.class); // Build the predicate CriteriaHelper<Area> criteriaHelper = new CriteriaHelper<>(cb, areaQuery); // Match the name Join<Area, AreaDesc> descs = areaRoot.join("descs", JoinType.LEFT); if (params.isExact()) { criteriaHelper.equalsIgnoreCase(descs.get("name"), params.getName()); } else { criteriaHelper.like(descs.get("name"), params.getName()); } // Optionally, match the language if (StringUtils.isNotBlank(params.getLanguage())) { criteriaHelper.equals(descs.get("lang"), params.getLanguage()); } // Optionally, match the parent if (params.getParentId() != null) { areaRoot.join("parent", JoinType.LEFT); Path<Area> parent = areaRoot.get("parent"); criteriaHelper.equals(parent.get("id"), params.getParentId()); } // Assemple lineage filters from search domain and areas Set<String> lineages = new HashSet<>(); // Optionally, filter by the areas associated with the specified domain if (StringUtils.isNotBlank(params.getDomain())) { Domain d = domainService.findByDomainId(params.getDomain()); if (d != null && d.getAreas().size() > 0) { d.getAreas().forEach(a -> lineages.add(a.getLineage())); } } // Optionally, filter by area subtrees if (params.getAreaIds() != null && !params.getAreaIds().isEmpty()) { getAreaDetails(params.getAreaIds()).forEach(a -> lineages.add(a.getLineage())); } // If defined, apply the area lineage filter if (!lineages.isEmpty()) { Predicate[] areaMatch = lineages.stream() .map(lineage -> cb.like(areaRoot.get("lineage"), lineage + "%")).toArray(Predicate[]::new); criteriaHelper.add(cb.or(areaMatch)); } // Optionally, search by type if (params.getType() != null) { criteriaHelper.add(cb.equal(areaRoot.get("type"), params.getType())); } // Optionally, require that the area has an associated geometry if (params.isGeometry()) { criteriaHelper.add(cb.isNotNull(areaRoot.get("geometry"))); } // Optionally, require that the area has an messageSorting type if (params.isMessageSorting()) { criteriaHelper.add(cb.isNotNull(areaRoot.get("messageSorting"))); } // Unless the "inactive" search flag is set, only include active areas. if (!params.isInactive()) { criteriaHelper.add(cb.equal(areaRoot.get("active"), true)); } // Compute the sort order List<Order> sortOrders = new ArrayList<>(); if (TREE_SORT_ORDER.equals(params.getSortBy())) { Arrays.asList("treeSortOrder", "siblingSortOrder", "id").forEach(field -> { if (params.getSortOrder() == PagedSearchParamsVo.SortOrder.ASC) { sortOrders.add(cb.asc(areaRoot.get(field))); } else { sortOrders.add(cb.desc(areaRoot.get(field))); } }); } // Complete the query areaQuery.select(areaRoot).distinct(true).where(criteriaHelper.where()).orderBy(sortOrders); // Execute the query and update the search result return em.createQuery(areaQuery).setMaxResults(params.getMaxSize()).getResultList(); }
From source file:org.niord.core.category.CategoryService.java
/** * Searches for categories matching the given term in the given language * * @param params the sesarch params/*from w w w . j a v a2s .c o m*/ * @return the search result */ @SuppressWarnings("all") public List<Category> searchCategories(CategorySearchParams params) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Category> categoryQuery = cb.createQuery(Category.class); Root<Category> categoryRoot = categoryQuery.from(Category.class); // Build the predicate CriteriaHelper<Category> criteriaHelper = new CriteriaHelper<>(cb, categoryQuery); // Match the name Join<Category, CategoryDesc> descs = categoryRoot.join("descs", JoinType.LEFT); if (params.isExact()) { criteriaHelper.equalsIgnoreCase(descs.get("name"), params.getName()); } else { criteriaHelper.like(descs.get("name"), params.getName()); } // Optionally, match the language if (StringUtils.isNotBlank(params.getLanguage())) { criteriaHelper.equals(descs.get("lang"), params.getLanguage()); } // Optionally, match the parent if (params.getParentId() != null) { categoryRoot.join("parent", JoinType.LEFT); Path<Category> parent = categoryRoot.get("parent"); criteriaHelper.equals(parent.get("id"), params.getParentId()); } // Optionally, filter by the domains associated with the current domain if (StringUtils.isNotBlank(params.getDomain())) { Domain d = domainService.findByDomainId(params.getDomain()); if (d != null && d.getCategories().size() > 0) { Predicate[] categoryMatch = d.getCategories().stream() .map(c -> cb.like(categoryRoot.get("lineage"), c.getLineage() + "%")) .toArray(Predicate[]::new); criteriaHelper.add(cb.or(categoryMatch)); } } // Unless the "inactive" search flag is set, only include active categories. if (!params.isInactive()) { criteriaHelper.add(cb.equal(categoryRoot.get("active"), true)); } // Complete the query categoryQuery.select(categoryRoot).distinct(true).where(criteriaHelper.where()); //.orderBy(cb.asc(cb.locate(cb.lower(descs.get("name")), name.toLowerCase()))); // Execute the query and update the search result return em.createQuery(categoryQuery).setMaxResults(params.getMaxSize()).getResultList(); }
From source file:org.niord.core.mail.ScheduledMailService.java
/** Helper function that translates the search parameters into predicates */ private <T> Predicate[] buildQueryPredicates(CriteriaBuilder cb, CriteriaQuery<T> query, Root<ScheduledMail> mailRoot, ScheduledMailSearchParams params) { // Build the predicate CriteriaHelper<T> criteriaHelper = new CriteriaHelper<>(cb, query); // Match the recipient if (StringUtils.isNotBlank(params.getRecipient())) { Join<ScheduledMail, ScheduledMailRecipient> recipients = mailRoot.join("recipients", JoinType.LEFT); criteriaHelper.like(recipients.get("address"), params.getRecipient()); }//from w w w . ja v a 2 s. c o m // Match sender criteriaHelper.like(mailRoot.get("sender"), params.getSender()); // Match subject criteriaHelper.like(mailRoot.get("subject"), params.getSubject()); // Match status criteriaHelper = criteriaHelper.equals(mailRoot.get("status"), params.getStatus()); // Match date interval criteriaHelper.between(mailRoot.get("created"), params.getFrom(), params.getTo()); return criteriaHelper.where(); }