use of com.blazebit.persistence.criteria.BlazeCriteriaQuery in project blaze-persistence by Blazebit.
the class EntityViewMethodQueryBuilder method createJpaQuery.
private <V> Query createJpaQuery(EntityViewCdiQueryInvocationContext context) {
ExtendedParameters params = context.getExtendedParams();
EntityViewQueryRoot root = context.getRepositoryMethodMetadata().getEntityViewQueryRoot();
Pageable pageable = params.getPageable();
CriteriaBuilder<?> cb;
Specification<?> specification = params.getSpecification();
if (specification == null) {
cb = context.getCriteriaBuilderFactory().create(context.getEntityManager(), context.getEntityClass());
root.apply(cb);
} else {
BlazeCriteriaBuilder blazeCriteriaBuilder = BlazeCriteria.get(context.getCriteriaBuilderFactory());
BlazeCriteriaQuery<?> query = blazeCriteriaBuilder.createQuery(context.getEntityClass());
Root queryRoot = query.from(context.getEntityClass());
root.apply(queryRoot, query, blazeCriteriaBuilder);
Predicate predicate = specification.toPredicate(queryRoot, query, blazeCriteriaBuilder);
if (predicate != null) {
if (query.getRestriction() == null) {
query.where(predicate);
} else {
query.where(query.getRestriction(), predicate);
}
}
cb = query.createCriteriaBuilder(context.getEntityManager());
}
Class<V> entityViewClass = (Class<V>) context.getEntityViewClass();
// TODO: depending on return type we might need to do keyset extraction
boolean keysetExtraction = false;
FullQueryBuilder<?, ?> fullCb = QueryBuilderUtils.getFullQueryBuilder(cb, pageable, context.getEntityViewManager(), entityViewClass, keysetExtraction);
fullCb = context.applyCriteriaBuilderPostProcessors(fullCb);
Query q = params.applyTo(context.createQuery(fullCb));
return context.applyRestrictions(q);
}
Aggregations