use of org.finra.herd.model.jpa.BusinessObjectDefinitionEntity in project herd by FINRAOS.
the class BusinessObjectDefinitionDaoImpl method getCountOfAllBusinessObjectDefinitions.
@Override
public long getCountOfAllBusinessObjectDefinitions() {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
Root<BusinessObjectDefinitionEntity> businessObjectDefinitionEntityRoot = criteria.from(BusinessObjectDefinitionEntity.class);
criteria.select(builder.count(businessObjectDefinitionEntityRoot));
return entityManager.createQuery(criteria).getSingleResult();
}
use of org.finra.herd.model.jpa.BusinessObjectDefinitionEntity in project herd by FINRAOS.
the class BusinessObjectDefinitionDaoImpl method getBusinessObjectDefinitionByKey.
@Override
public BusinessObjectDefinitionEntity getBusinessObjectDefinitionByKey(BusinessObjectDefinitionKey businessObjectDefinitionKey) {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<BusinessObjectDefinitionEntity> criteria = builder.createQuery(BusinessObjectDefinitionEntity.class);
// The criteria root is the business object definition.
Root<BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = criteria.from(BusinessObjectDefinitionEntity.class);
// Join to the other tables we can filter on.
Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntity = businessObjectDefinitionEntity.join(BusinessObjectDefinitionEntity_.namespace);
// Create the standard restrictions (i.e. the standard where clauses).
Predicate queryRestriction = builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)), businessObjectDefinitionKey.getNamespace().toUpperCase());
queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)), businessObjectDefinitionKey.getBusinessObjectDefinitionName().toUpperCase()));
criteria.select(businessObjectDefinitionEntity).where(queryRestriction);
return executeSingleResultQuery(criteria, String.format("Found more than one business object definition with parameters {namespace=\"%s\", businessObjectDefinitionName=\"%s\"}.", businessObjectDefinitionKey.getNamespace(), businessObjectDefinitionKey.getBusinessObjectDefinitionName()));
}
use of org.finra.herd.model.jpa.BusinessObjectDefinitionEntity in project herd by FINRAOS.
the class BusinessObjectDefinitionDaoImpl method getPercentageOfAllBusinessObjectDefinitions.
@Override
public List<BusinessObjectDefinitionEntity> getPercentageOfAllBusinessObjectDefinitions(double percentage) {
// Create the criteria builder and a tuple style criteria query.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Integer> criteria = builder.createQuery(Integer.class);
// The criteria root is the business object definition.
Root<BusinessObjectDefinitionEntity> businessObjectDefinitionEntityRoot = criteria.from(BusinessObjectDefinitionEntity.class);
// Get the columns.
Path<Integer> idColumn = businessObjectDefinitionEntityRoot.get(BusinessObjectDefinitionEntity_.id);
criteria.select(idColumn);
List<Integer> allBusinessObjectDefinitionIdsList = entityManager.createQuery(criteria).getResultList();
List<Integer> percentageOfBusinessObjectDefinitionIdsList = new ArrayList<>();
/*
* Gets a percentage of all business object definition entities.
* The percentage is randomly selected from all the business object definitions.
*
* For each business object id in the list of all business object definition ids, get a random double value between 0 and 1.
* If that value is below the percentage double value, also a number between 0 and 1 (inclusive),
* then add the business object id to the list of business object definition ids that will be used to return a random percentage
* of business object definition entities retrieved from the database.
*/
allBusinessObjectDefinitionIdsList.forEach(id -> {
if (ThreadLocalRandom.current().nextDouble() < percentage) {
percentageOfBusinessObjectDefinitionIdsList.add(id);
}
});
return getAllBusinessObjectDefinitionsByIds(percentageOfBusinessObjectDefinitionIdsList);
}
use of org.finra.herd.model.jpa.BusinessObjectDefinitionEntity in project herd by FINRAOS.
the class BusinessObjectDefinitionDaoImpl method getAllBusinessObjectDefinitionsByIds.
@Override
public List<BusinessObjectDefinitionEntity> getAllBusinessObjectDefinitionsByIds(List<Integer> ids) {
// Create the criteria builder and a tuple style criteria query.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<BusinessObjectDefinitionEntity> criteria = builder.createQuery(BusinessObjectDefinitionEntity.class);
// The criteria root is the business object definition.
Root<BusinessObjectDefinitionEntity> businessObjectDefinitionEntityRoot = criteria.from(BusinessObjectDefinitionEntity.class);
// Create the standard restrictions (i.e. the standard where clauses).
Expression<Integer> expression = businessObjectDefinitionEntityRoot.get(BusinessObjectDefinitionEntity_.id);
Predicate queryRestriction = expression.in(ids);
criteria.select(businessObjectDefinitionEntityRoot).where(queryRestriction);
return entityManager.createQuery(criteria).getResultList();
}
use of org.finra.herd.model.jpa.BusinessObjectDefinitionEntity in project herd by FINRAOS.
the class BusinessObjectFormatDaoImpl method getBusinessObjectFormatMaxVersion.
@Override
public Integer getBusinessObjectFormatMaxVersion(BusinessObjectFormatKey businessObjectFormatKey) {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Integer> criteria = builder.createQuery(Integer.class);
// The criteria root is the business object format.
Root<BusinessObjectFormatEntity> businessObjectFormatEntity = criteria.from(BusinessObjectFormatEntity.class);
// Join to the other tables we can filter on.
Join<BusinessObjectFormatEntity, FileTypeEntity> fileTypeEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.fileType);
Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.businessObjectDefinition);
// Create the standard restrictions (i.e. the standard where clauses).
// Business object format version should be ignored when building the query restriction.
Predicate queryRestriction = getQueryRestriction(builder, businessObjectFormatEntity, fileTypeEntity, businessObjectDefinitionEntity, businessObjectFormatKey, true);
// Create the path.
Expression<Integer> maxBusinessObjectFormatVersion = builder.max(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion));
criteria.select(maxBusinessObjectFormatVersion).where(queryRestriction);
return entityManager.createQuery(criteria).getSingleResult();
}
Aggregations