List of usage examples for javax.persistence.criteria Root join
<Y> Join<X, Y> join(SingularAttribute<? super X, Y> attribute);
From source file:org.finra.herd.dao.impl.StorageFileDaoImpl.java
@Override public StorageFileEntity getStorageFileByStorageNameAndFilePath(String storageName, String filePath) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<StorageFileEntity> criteria = builder.createQuery(StorageFileEntity.class); // The criteria root is the storage files. Root<StorageFileEntity> storageFileEntity = criteria.from(StorageFileEntity.class); // Join to the other tables we can filter on. Join<StorageFileEntity, StorageUnitEntity> storageUnitEntity = storageFileEntity .join(StorageFileEntity_.storageUnit); Join<StorageUnitEntity, StorageEntity> storageEntity = storageUnitEntity.join(StorageUnitEntity_.storage); // Create the standard restrictions (i.e. the standard where clauses). Predicate filePathRestriction = builder.equal(storageFileEntity.get(StorageFileEntity_.path), filePath); Predicate storageNameRestriction = builder.equal(builder.upper(storageEntity.get(StorageEntity_.name)), storageName.toUpperCase());//www . jav a 2 s.com criteria.select(storageFileEntity).where(builder.and(filePathRestriction, storageNameRestriction)); return executeSingleResultQuery(criteria, String.format( "Found more than one storage file with parameters {storageName=\"%s\"," + " filePath=\"%s\"}.", storageName, filePath)); }
From source file:org.finra.herd.dao.impl.StorageFileDaoImpl.java
@Override public Long getStorageFileCount(String storageName, String filePathPrefix) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<Long> criteria = builder.createQuery(Long.class); // The criteria root is the storage files. Root<StorageFileEntity> storageFileEntity = criteria.from(StorageFileEntity.class); // Join to the other tables we can filter on. Join<StorageFileEntity, StorageUnitEntity> storageUnitEntity = storageFileEntity .join(StorageFileEntity_.storageUnit); Join<StorageUnitEntity, StorageEntity> storageEntity = storageUnitEntity.join(StorageUnitEntity_.storage); // Create path. Expression<Long> storageFileCount = builder.count(storageFileEntity.get(StorageFileEntity_.id)); // Create the standard restrictions (i.e. the standard where clauses). Predicate storageNameRestriction = builder.equal(builder.upper(storageEntity.get(StorageEntity_.name)), storageName.toUpperCase());/*from www . j a va 2s. c o m*/ Predicate filePathRestriction = builder.like(storageFileEntity.get(StorageFileEntity_.path), String.format("%s%%", filePathPrefix)); // Add the clauses for the query. criteria.select(storageFileCount).where(builder.and(storageNameRestriction, filePathRestriction)); return entityManager.createQuery(criteria).getSingleResult(); }
From source file:org.finra.herd.dao.impl.StorageFileDaoImpl.java
@Override public List<String> getStorageFilesByStorageAndFilePathPrefix(String storageName, String filePathPrefix) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<StorageFileEntity> criteria = builder.createQuery(StorageFileEntity.class); // The criteria root is the storage files. Root<StorageFileEntity> storageFileEntity = criteria.from(StorageFileEntity.class); // Join to the other tables we can filter on. Join<StorageFileEntity, StorageUnitEntity> storageUnitEntity = storageFileEntity .join(StorageFileEntity_.storageUnit); Join<StorageUnitEntity, StorageEntity> storageEntity = storageUnitEntity.join(StorageUnitEntity_.storage); // Create the standard restrictions (i.e. the standard where clauses). Predicate filePathRestriction = builder.like(storageFileEntity.get(StorageFileEntity_.path), String.format("%s%%", filePathPrefix)); Predicate storageNameRestriction = builder.equal(builder.upper(storageEntity.get(StorageEntity_.name)), storageName.toUpperCase());//from w ww.j ava 2 s . co m // Order the results by file path. Order orderByFilePath = builder.asc(storageFileEntity.get(StorageFileEntity_.path)); criteria.select(storageFileEntity).where(builder.and(filePathRestriction, storageNameRestriction)) .orderBy(orderByFilePath); // Retrieve the storage files. List<StorageFileEntity> storageFileEntities = entityManager.createQuery(criteria).getResultList(); // Build the result list. List<String> storageFilePaths = new ArrayList<>(); for (StorageFileEntity storageFile : storageFileEntities) { storageFilePaths.add(storageFile.getPath()); } return storageFilePaths; }
From source file:org.finra.herd.dao.impl.StorageUnitDaoImpl.java
@Override public List<StorageUnitEntity> getLatestVersionStorageUnitsByStoragePlatformAndFileType(String storagePlatform, String businessObjectFormatFileType) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<StorageUnitEntity> criteria = builder.createQuery(StorageUnitEntity.class); // The criteria root is the storage unit. Root<StorageUnitEntity> storageUnitEntityRoot = criteria.from(StorageUnitEntity.class); // Join to the other tables we can filter on. Join<StorageUnitEntity, StorageEntity> storageEntityJoin = storageUnitEntityRoot .join(StorageUnitEntity_.storage); Join<StorageEntity, StoragePlatformEntity> storagePlatformEntityJoin = storageEntityJoin .join(StorageEntity_.storagePlatform); Join<StorageUnitEntity, BusinessObjectDataEntity> businessObjectDataEntityJoin = storageUnitEntityRoot .join(StorageUnitEntity_.businessObjectData); Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> businessObjectFormatEntityJoin = businessObjectDataEntityJoin .join(BusinessObjectDataEntity_.businessObjectFormat); Join<BusinessObjectFormatEntity, FileTypeEntity> fileTypeEntityJoin = businessObjectFormatEntityJoin .join(BusinessObjectFormatEntity_.fileType); // Create the standard restrictions (i.e. the standard where clauses). List<Predicate> predicates = new ArrayList<>(); predicates.add(builder.equal(builder.upper(storagePlatformEntityJoin.get(StoragePlatformEntity_.name)), storagePlatform.toUpperCase())); predicates.add(builder.equal(builder.upper(fileTypeEntityJoin.get(FileTypeEntity_.code)), businessObjectFormatFileType.toUpperCase())); predicates//from ww w . j a v a 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(); }
From source file:org.finra.herd.dao.impl.StorageUnitDaoImpl.java
@Override public List<StorageUnitEntity> getS3StorageUnitsToCleanup(int maxResult) { // 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, StorageUnitStatusEntity> storageUnitStatusEntityJoin = storageUnitEntityRoot .join(StorageUnitEntity_.status); Join<StorageUnitEntity, BusinessObjectDataEntity> businessObjectDataEntityJoin = storageUnitEntityRoot .join(StorageUnitEntity_.businessObjectData); Join<BusinessObjectDataEntity, BusinessObjectDataStatusEntity> businessObjectDataStatusEntity = businessObjectDataEntityJoin .join(BusinessObjectDataEntity_.status); // Get the current time. Timestamp currentTime = new Timestamp(System.currentTimeMillis()); // Create the standard restrictions (i.e. the standard where clauses). // Restrictions include: // - Storage platform is set to S3 storage // - Storage unit status is DISABLED // - Associated BData has a DELETED status // - Final destroy on timestamp < current time List<Predicate> predicates = new ArrayList<>(); predicates.add(builder.equal(storagePlatformEntityJoin.get(StoragePlatformEntity_.name), StoragePlatformEntity.S3));/* www. ja v a 2 s.co m*/ predicates.add(builder.equal(storageUnitStatusEntityJoin.get(StorageUnitStatusEntity_.code), StorageUnitStatusEntity.DISABLED)); predicates.add(builder.equal(businessObjectDataStatusEntity.get(BusinessObjectDataStatusEntity_.code), BusinessObjectDataStatusEntity.DELETED)); predicates.add(builder.lessThan(storageUnitEntityRoot.get(StorageUnitEntity_.finalDestroyOn), currentTime)); // Order the results. Order orderBy = builder.asc(storageUnitEntityRoot.get(StorageUnitEntity_.finalDestroyOn)); // 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).setMaxResults(maxResult).getResultList(); }
From source file:org.finra.herd.dao.impl.StorageUnitDaoImpl.java
@Override public List<StorageUnitEntity> getS3StorageUnitsToExpire(int maxResult) { // 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, StorageUnitStatusEntity> storageUnitStatusEntityJoin = storageUnitEntityRoot .join(StorageUnitEntity_.status); // Get the current time. Timestamp currentTime = new Timestamp(System.currentTimeMillis()); // Create the standard restrictions (i.e. the standard where clauses). List<Predicate> predicates = new ArrayList<>(); predicates.add(builder.equal(storagePlatformEntityJoin.get(StoragePlatformEntity_.name), StoragePlatformEntity.S3));/*from ww w .ja va2 s. co m*/ predicates.add(builder.equal(storageUnitStatusEntityJoin.get(StorageUnitStatusEntity_.code), StorageUnitStatusEntity.RESTORED)); predicates.add( builder.lessThan(storageUnitEntityRoot.get(StorageUnitEntity_.restoreExpirationOn), currentTime)); // Order the results. Order orderBy = builder.asc(storageUnitEntityRoot.get(StorageUnitEntity_.restoreExpirationOn)); // 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).setMaxResults(maxResult).getResultList(); }
From source file:org.finra.herd.dao.impl.StorageUnitDaoImpl.java
@Override public List<StorageUnitEntity> getS3StorageUnitsToRestore(int maxResult) { // 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, StorageUnitStatusEntity> storageUnitStatusEntityJoin = storageUnitEntityRoot .join(StorageUnitEntity_.status); // Create the standard restrictions (i.e. the standard where clauses). List<Predicate> predicates = new ArrayList<>(); predicates.add(builder.equal(storagePlatformEntityJoin.get(StoragePlatformEntity_.name), StoragePlatformEntity.S3));/*from w ww . j a v a 2 s . c om*/ predicates.add(builder.equal(storageUnitStatusEntityJoin.get(StorageUnitStatusEntity_.code), StorageUnitStatusEntity.RESTORING)); // Order the results by storage unit updated on timestamp. Order orderBy = builder.asc(storageUnitEntityRoot.get(StorageUnitEntity_.updatedOn)); // 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).setMaxResults(maxResult).getResultList(); }
From source file:org.finra.herd.dao.impl.StorageUnitDaoImpl.java
@Override public StorageUnitEntity getStorageUnitByBusinessObjectDataAndStorageName( BusinessObjectDataEntity businessObjectDataEntity, String storageName) { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<StorageUnitEntity> criteria = builder.createQuery(StorageUnitEntity.class); Root<StorageUnitEntity> storageUnitEntity = criteria.from(StorageUnitEntity.class); // join storage unit to storage to retrieve name Join<StorageUnitEntity, StorageEntity> storageEntity = storageUnitEntity.join(StorageUnitEntity_.storage); // where business object data equals Predicate businessObjectDataRestriction = builder .equal(storageUnitEntity.get(StorageUnitEntity_.businessObjectData), businessObjectDataEntity); // where storage name equals, ignoring case Predicate storageNameRestriction = builder.equal(builder.upper(storageEntity.get(StorageEntity_.name)), storageName.toUpperCase());/*from w w w .ja v a 2 s . c om*/ criteria.select(storageUnitEntity) .where(builder.and(businessObjectDataRestriction, storageNameRestriction)); List<StorageUnitEntity> resultList = entityManager.createQuery(criteria).getResultList(); // return single result or null return resultList.size() >= 1 ? resultList.get(0) : null; }
From source file:org.finra.herd.dao.impl.StorageUnitDaoImpl.java
@Override public StorageUnitEntity getStorageUnitByKey( BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<StorageUnitEntity> criteria = builder.createQuery(StorageUnitEntity.class); // The criteria root is the storage unit. Root<StorageUnitEntity> storageUnitEntityRoot = criteria.from(StorageUnitEntity.class); // Join to the other tables we can filter on. Join<StorageUnitEntity, BusinessObjectDataEntity> businessObjectDataEntityJoin = storageUnitEntityRoot .join(StorageUnitEntity_.businessObjectData); Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> businessObjectFormatEntityJoin = businessObjectDataEntityJoin .join(BusinessObjectDataEntity_.businessObjectFormat); Join<BusinessObjectFormatEntity, FileTypeEntity> fileTypeEntityJoin = businessObjectFormatEntityJoin .join(BusinessObjectFormatEntity_.fileType); Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntityJoin = businessObjectFormatEntityJoin .join(BusinessObjectFormatEntity_.businessObjectDefinition); Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntityJoin = businessObjectDefinitionEntityJoin .join(BusinessObjectDefinitionEntity_.namespace); Join<StorageUnitEntity, StorageEntity> storageEntityJoin = storageUnitEntityRoot .join(StorageUnitEntity_.storage); // Create the standard restrictions (i.e. the standard where clauses). List<Predicate> predicates = new ArrayList<>(); predicates.add(builder.equal(builder.upper(namespaceEntityJoin.get(NamespaceEntity_.code)), businessObjectDataStorageUnitKey.getNamespace().toUpperCase())); predicates.add(builder.equal(//www . ja v a 2s .c om builder.upper(businessObjectDefinitionEntityJoin.get(BusinessObjectDefinitionEntity_.name)), businessObjectDataStorageUnitKey.getBusinessObjectDefinitionName().toUpperCase())); predicates.add(builder.equal( builder.upper(businessObjectDefinitionEntityJoin.get(BusinessObjectDefinitionEntity_.name)), businessObjectDataStorageUnitKey.getBusinessObjectDefinitionName().toUpperCase())); predicates.add( builder.equal(builder.upper(businessObjectFormatEntityJoin.get(BusinessObjectFormatEntity_.usage)), businessObjectDataStorageUnitKey.getBusinessObjectFormatUsage().toUpperCase())); predicates.add(builder.equal(builder.upper(fileTypeEntityJoin.get(FileTypeEntity_.code)), businessObjectDataStorageUnitKey.getBusinessObjectFormatFileType().toUpperCase())); predicates.add(builder.equal( businessObjectFormatEntityJoin.get(BusinessObjectFormatEntity_.businessObjectFormatVersion), businessObjectDataStorageUnitKey.getBusinessObjectFormatVersion())); predicates.add(getQueryRestrictionOnPartitionValues(builder, businessObjectDataEntityJoin, businessObjectDataStorageUnitKey.getPartitionValue(), businessObjectDataStorageUnitKey.getSubPartitionValues())); predicates.add(builder.equal(businessObjectDataEntityJoin.get(BusinessObjectDataEntity_.version), businessObjectDataStorageUnitKey.getBusinessObjectDataVersion())); predicates.add(builder.equal(builder.upper(storageEntityJoin.get(StorageEntity_.name)), businessObjectDataStorageUnitKey.getStorageName().toUpperCase())); // Add the clauses for the query. criteria.select(storageUnitEntityRoot) .where(builder.and(predicates.toArray(new Predicate[predicates.size()]))); // Execute the query and return the result. return executeSingleResultQuery(criteria, String.format( "Found more than one business object data storage unit instance with parameters {namespace=\"%s\", businessObjectDefinitionName=\"%s\"," + " businessObjectFormatUsage=\"%s\", businessObjectFormatFileType=\"%s\", businessObjectFormatVersion=\"%d\"," + " businessObjectDataPartitionValue=\"%s\", businessObjectDataSubPartitionValues=\"%s\", businessObjectDataVersion=\"%d\"," + " storageName=\"%s\"}.", businessObjectDataStorageUnitKey.getNamespace(), businessObjectDataStorageUnitKey.getBusinessObjectDefinitionName(), businessObjectDataStorageUnitKey.getBusinessObjectFormatUsage(), businessObjectDataStorageUnitKey.getBusinessObjectFormatFileType(), businessObjectDataStorageUnitKey.getBusinessObjectFormatVersion(), businessObjectDataStorageUnitKey.getPartitionValue(), CollectionUtils.isEmpty(businessObjectDataStorageUnitKey.getSubPartitionValues()) ? "" : StringUtils.join(businessObjectDataStorageUnitKey.getSubPartitionValues(), ","), businessObjectDataStorageUnitKey.getBusinessObjectDataVersion(), businessObjectDataStorageUnitKey.getStorageName())); }
From source file:org.finra.herd.dao.impl.StorageUnitDaoImpl.java
@Override public List<StorageUnitEntity> getStorageUnitsByStoragePlatformAndBusinessObjectData(String storagePlatform, BusinessObjectDataEntity businessObjectDataEntity) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<StorageUnitEntity> criteria = builder.createQuery(StorageUnitEntity.class); // The criteria root is the storage unit. Root<StorageUnitEntity> storageUnitEntity = criteria.from(StorageUnitEntity.class); // Join to the other tables we can filter on. Join<StorageUnitEntity, StorageEntity> storageEntity = storageUnitEntity.join(StorageUnitEntity_.storage); Join<StorageEntity, StoragePlatformEntity> storagePlatformEntity = storageEntity .join(StorageEntity_.storagePlatform); // Create the standard restrictions (i.e. the standard where clauses). List<Predicate> predicates = new ArrayList<>(); predicates.add(builder.equal(builder.upper(storagePlatformEntity.get(StoragePlatformEntity_.name)), storagePlatform.toUpperCase())); predicates.add(builder.equal(storageUnitEntity.get(StorageUnitEntity_.businessObjectData), businessObjectDataEntity));//from w w w . j av a 2s . com // Order by storage name. Order orderBy = builder.asc(storageEntity.get(StorageEntity_.name)); // Add the clauses for the query. criteria.select(storageUnitEntity).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))) .orderBy(orderBy); // Execute the query and return the results. return entityManager.createQuery(criteria).getResultList(); }