use of io.micronaut.data.annotation.Query in project micronaut-data by micronaut-projects.
the class RawQueryMethodMatcher method buildRawQuery.
/**
* Builds a raw query for the given match context. Should be called for methods annotated with {@link Query} explicitly.
*/
private void buildRawQuery(@NonNull MethodMatchContext matchContext, MethodMatchInfo methodMatchInfo, ParameterElement entityParameter, ParameterElement entitiesParameter, DataMethod.OperationType operationType) {
MethodElement methodElement = matchContext.getMethodElement();
String queryString = methodElement.stringValue(Query.class).orElseThrow(() -> new IllegalStateException("Should only be called if Query has value!"));
List<ParameterElement> parameters = Arrays.asList(matchContext.getParameters());
boolean namedParameters = matchContext.getRepositoryClass().booleanValue(RepositoryConfiguration.class, "namedParameters").orElse(true);
ParameterElement entityParam = null;
SourcePersistentEntity persistentEntity = null;
if (entityParameter != null) {
entityParam = entityParameter;
persistentEntity = matchContext.getEntity(entityParameter.getGenericType());
} else if (entitiesParameter != null) {
entityParam = entitiesParameter;
persistentEntity = matchContext.getEntity(entitiesParameter.getGenericType().getFirstTypeArgument().orElseThrow(IllegalStateException::new));
}
QueryResult queryResult = getQueryResult(matchContext, queryString, parameters, namedParameters, entityParam, persistentEntity);
String cq = matchContext.getAnnotationMetadata().stringValue(Query.class, "countQuery").orElse(null);
QueryResult countQueryResult = cq == null ? null : getQueryResult(matchContext, cq, parameters, namedParameters, entityParam, persistentEntity);
boolean encodeEntityParameters = persistentEntity != null || operationType == DataMethod.OperationType.INSERT;
methodMatchInfo.isRawQuery(true).encodeEntityParameters(encodeEntityParameters).queryResult(queryResult).countQueryResult(countQueryResult);
}
Aggregations