List of usage examples for javax.persistence.criteria CriteriaQuery select
CriteriaQuery<T> select(Selection<? extends T> selection);
From source file:org.finra.dm.dao.impl.DmDaoImpl.java
/** * {@inheritDoc}//from w ww . j a v a 2 s.co m */ @Override public List<FileTypeKey> getFileTypes() { // Create the criteria builder and a tuple style criteria query. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<String> criteria = builder.createQuery(String.class); // The criteria root is the file type. Root<FileTypeEntity> fileTypeEntity = criteria.from(FileTypeEntity.class); // Get the columns. Path<String> fileTypeCodeColumn = fileTypeEntity.get(FileTypeEntity_.code); // Add the select clause. criteria.select(fileTypeCodeColumn); // Add the order by clause. criteria.orderBy(builder.asc(fileTypeCodeColumn)); // Run the query to get a list of file type codes back. List<String> fileTypeCodes = entityManager.createQuery(criteria).getResultList(); // Populate the "keys" objects from the returned file type codes. List<FileTypeKey> fileTypeKeys = new ArrayList<>(); for (String fileTypeCode : fileTypeCodes) { fileTypeKeys.add(new FileTypeKey(fileTypeCode)); } return fileTypeKeys; }
From source file:org.finra.dm.dao.impl.DmDaoImpl.java
/** * {@inheritDoc}/* www.j a v a2s. c om*/ */ @Override public List<NamespaceKey> getNamespaces() { // Create the criteria builder and a tuple style criteria query. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<String> criteria = builder.createQuery(String.class); // The criteria root is the business object definition. Root<NamespaceEntity> namespaceEntity = criteria.from(NamespaceEntity.class); // Get the columns. Path<String> namespaceCodeColumn = namespaceEntity.get(NamespaceEntity_.code); // Add the select clause. criteria.select(namespaceCodeColumn); // Add the order by clause. criteria.orderBy(builder.asc(namespaceCodeColumn)); // Run the query to get a list of namespace codes back. List<String> namespaceCodes = entityManager.createQuery(criteria).getResultList(); // Populate the "keys" objects from the returned namespace codes. List<NamespaceKey> namespaceKeys = new ArrayList<>(); for (String namespaceCode : namespaceCodes) { namespaceKeys.add(new NamespaceKey(namespaceCode)); } return namespaceKeys; }
From source file:org.finra.dm.dao.impl.DmDaoImpl.java
/** * {@inheritDoc}// ww w. j a v a 2 s . co m */ @Override @Cacheable(DaoSpringModuleConfig.DM_CACHE_NAME) public List<String> getSecurityFunctions() { // Create the criteria builder and a tuple style criteria query. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<String> criteria = builder.createQuery(String.class); // The criteria root is the business object definition. Root<SecurityFunctionEntity> securityFunctionEntity = criteria.from(SecurityFunctionEntity.class); // Get the columns. Path<String> functionCodeColumn = securityFunctionEntity.get(SecurityFunctionEntity_.code); // Add the select clause. criteria.select(functionCodeColumn); // Add the order by clause. criteria.orderBy(builder.asc(functionCodeColumn)); // Run the query to get a list of tuples back. return entityManager.createQuery(criteria).getResultList(); }
From source file:org.finra.dm.dao.impl.DmDaoImpl.java
/** * {@inheritDoc}//from w w w . ja v a2s . 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}//from w w w. j a va 2s . c o m */ @Override public StorageEntity getStorageByName(String storageName) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<StorageEntity> criteria = builder.createQuery(StorageEntity.class); // The criteria root is the namespace. Root<StorageEntity> storageEntity = criteria.from(StorageEntity.class); // Create the standard restrictions (i.e. the standard where clauses). Predicate queryRestriction = builder.equal(builder.upper(storageEntity.get(StorageEntity_.name)), storageName.toUpperCase()); criteria.select(storageEntity).where(queryRestriction); return executeSingleResultQuery(criteria, String.format("Found more than one storage with \"%s\" name.", storageName)); }
From source file:org.finra.dm.dao.impl.DmDaoImpl.java
/** * {@inheritDoc}/*from w w w . ja v a2 s. c o m*/ */ @Override public NamespaceEntity getNamespaceByCd(String namespaceCode) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<NamespaceEntity> criteria = builder.createQuery(NamespaceEntity.class); // The criteria root is the namespace. Root<NamespaceEntity> namespaceEntity = criteria.from(NamespaceEntity.class); // Create the standard restrictions (i.e. the standard where clauses). Predicate queryRestriction = builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)), namespaceCode.toUpperCase()); criteria.select(namespaceEntity).where(queryRestriction); return executeSingleResultQuery(criteria, String.format("Found more than one namespace with namespaceCode=\"%s\".", namespaceCode)); }
From source file:org.finra.dm.dao.impl.DmDaoImpl.java
/** * {@inheritDoc}/*from w w w. j ava2s . com*/ * <p/> * This implementation uses JPA criteria, and throws exception when more than 1 on-demand price is found for the specified parameters. */ @Override public OnDemandPriceEntity getOnDemandPrice(String region, String instanceType) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<OnDemandPriceEntity> criteriaQuery = criteriaBuilder.createQuery(OnDemandPriceEntity.class); Root<OnDemandPriceEntity> onDemandPrice = criteriaQuery.from(OnDemandPriceEntity.class); Path<String> regionPath = onDemandPrice.get(OnDemandPriceEntity_.region); Path<String> instanceTypePath = onDemandPrice.get(OnDemandPriceEntity_.instanceType); Predicate regionEquals = criteriaBuilder.equal(regionPath, region); Predicate instanceTypeEquals = criteriaBuilder.equal(instanceTypePath, instanceType); criteriaQuery.select(onDemandPrice).where(regionEquals, instanceTypeEquals); return executeSingleResultQuery(criteriaQuery, "More than 1 on-demand price found with given region '" + region + "' and instance type '" + instanceType + "'."); }
From source file:org.finra.dm.dao.impl.DmDaoImpl.java
/** * {@inheritDoc}/*from w w w .j a v a 2s . com*/ */ @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}/* www . j a v a 2 s .co m*/ */ @Override public NotificationEventTypeEntity getNotificationEventTypeByCode(String code) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<NotificationEventTypeEntity> criteria = builder .createQuery(NotificationEventTypeEntity.class); // The criteria root is the notification event type. Root<NotificationEventTypeEntity> notificationEventTypeEntity = criteria .from(NotificationEventTypeEntity.class); // Create the standard restrictions (i.e. the standard where clauses). Predicate queryRestriction = builder.equal( builder.upper(notificationEventTypeEntity.get(NotificationEventTypeEntity_.code)), code.toUpperCase()); criteria.select(notificationEventTypeEntity).where(queryRestriction); return executeSingleResultQuery(criteria, String.format("Found more than one notification event type with code \"%s\".", code)); }
From source file:org.finra.dm.dao.impl.DmDaoImpl.java
/** * {@inheritDoc}//from w w w .j av a 2 s . co m */ @Override public BusinessObjectDataStatusEntity getBusinessObjectDataStatusByCode(String code) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<BusinessObjectDataStatusEntity> criteria = builder .createQuery(BusinessObjectDataStatusEntity.class); // The criteria root is the business object data statuses. Root<BusinessObjectDataStatusEntity> businessObjectDataStatus = criteria .from(BusinessObjectDataStatusEntity.class); // Create the standard restrictions (i.e. the standard where clauses). Predicate businessObjectDataStatusCodeRestriction = builder.equal( builder.upper(businessObjectDataStatus.get(BusinessObjectDataStatusEntity_.code)), code.toUpperCase()); criteria.select(businessObjectDataStatus).where(businessObjectDataStatusCodeRestriction); return executeSingleResultQuery(criteria, String.format("Found more than one business object data status with code \"%s\".", code)); }