use of org.apache.deltaspike.data.impl.param.Parameters in project deltaspike by apache.
the class MethodQueryBuilder method createJpaQuery.
private Query createJpaQuery(CdiQueryInvocationContext context) {
Parameters params = context.getParams();
QueryRoot root = context.getRepositoryMethodMetadata().getQueryRoot();
String jpqlQuery = context.applyQueryStringPostProcessors(root.getJpqlQuery());
context.setQueryString(jpqlQuery);
params.updateValues(root.getParameterUpdates());
Query result = params.applyTo(context.getEntityManager().createQuery(jpqlQuery));
return context.applyRestrictions(result);
}
use of org.apache.deltaspike.data.impl.param.Parameters in project deltaspike by apache.
the class AnnotatedQueryBuilder method createJpaQuery.
private javax.persistence.Query createJpaQuery(Query query, CdiQueryInvocationContext context) {
EntityManager entityManager = context.getEntityManager();
Parameters params = context.getParams();
javax.persistence.Query result = null;
if (isNotEmpty(query.named())) {
if (!context.hasQueryStringPostProcessors()) {
result = params.applyTo(entityManager.createNamedQuery(query.named()));
} else {
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 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 org.apache.deltaspike.data.impl.param.Parameters in project deltaspike by apache.
the class CdiQueryInvocationContext method applyRestrictions.
public Query applyRestrictions(Query query) {
Parameters params = getParams();
Method method = getMethod();
if (params.hasSizeRestriction()) {
query.setMaxResults(params.getSizeRestriciton());
}
if (params.hasFirstResult()) {
query.setFirstResult(params.getFirstResult());
}
LockModeType lockMode = extractLockMode();
if (lockMode != null) {
query.setLockMode(lockMode);
}
QueryHint[] hints = extractQueryHints();
if (hints != null) {
for (QueryHint hint : hints) {
query.setHint(hint.name(), hint.value());
}
}
applyEntityGraph(query, method);
query = applyJpaQueryPostProcessors(query);
return query;
}
use of org.apache.deltaspike.data.impl.param.Parameters in project deltaspike by apache.
the class CountQueryPostProcessor method postProcess.
@Override
public Query postProcess(CdiQueryInvocationContext context, Query query) {
String queryString = getQueryString(context, query);
QueryExtraction extract = new 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);
Parameters params = context.getParams();
params.applyTo(result);
return result;
}
Aggregations