use of com.blazebit.persistence.deltaspike.data.impl.param.ExtendedParameters in project blaze-persistence by Blazebit.
the class CountQueryPostProcessor method postProcess.
@Override
public Query postProcess(EntityViewCdiQueryInvocationContext context, Query query) {
String queryString = getQueryString(context, query);
CountQueryPostProcessor.QueryExtraction extract = new CountQueryPostProcessor.QueryExtraction(queryString);
String count = extract.rewriteToCount();
LOG.log(Level.FINER, "Rewrote query {0} to {1}", new Object[] { queryString, count });
Query result = context.getEntityManager().createQuery(count);
ExtendedParameters params = context.getParams();
params.applyTo(result);
return result;
}
use of com.blazebit.persistence.deltaspike.data.impl.param.ExtendedParameters in project blaze-persistence by Blazebit.
the class EntityViewAnnotatedQueryBuilder method createJpaQuery.
private javax.persistence.Query createJpaQuery(Query query, EntityViewCdiQueryInvocationContext context) {
EntityManager entityManager = context.getEntityManager();
ExtendedParameters params = context.getParams();
javax.persistence.Query result = null;
if (isNotEmpty(query.named())) {
if (context.hasQueryStringPostProcessors()) {
javax.persistence.Query namedQuery = entityManager.createNamedQuery(query.named());
String named = factory.extract(namedQuery);
String jpqlQuery = context.applyQueryStringPostProcessors(named);
result = params.applyTo(entityManager.createQuery(jpqlQuery));
} else {
result = params.applyTo(entityManager.createNamedQuery(query.named()));
}
} else if (query.isNative()) {
String jpqlQuery = context.applyQueryStringPostProcessors(query.value());
Class<?> resultType = getQueryResultType(context.getMethod());
if (isEntityType(resultType)) {
result = params.applyTo(entityManager.createNativeQuery(jpqlQuery, resultType));
} else {
result = params.applyTo(entityManager.createNativeQuery(jpqlQuery));
}
} else {
String jpqlQuery = context.applyQueryStringPostProcessors(query.value());
context.setQueryString(jpqlQuery);
result = params.applyTo(entityManager.createQuery(jpqlQuery));
}
return context.applyRestrictions(result);
}
use of com.blazebit.persistence.deltaspike.data.impl.param.ExtendedParameters 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