io.micronaut.data.runtime.query.DefaultStoredQueryResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of micronaut-data-runtime Show documentation
Show all versions of micronaut-data-runtime Show documentation
Data Repository Support for Micronaut
/*
* Copyright 2017-2022 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.data.runtime.query;
import io.micronaut.aop.MethodInvocationContext;
import io.micronaut.core.annotation.AnnotationMetadata;
import io.micronaut.core.annotation.Internal;
import io.micronaut.core.type.Argument;
import io.micronaut.data.annotation.DataAnnotationUtils;
import io.micronaut.data.annotation.Query;
import io.micronaut.data.annotation.RepositoryConfiguration;
import io.micronaut.data.intercept.annotation.DataMethod;
import io.micronaut.data.model.DataType;
import io.micronaut.data.model.query.builder.sql.SqlQueryBuilder;
import io.micronaut.data.model.runtime.QueryParameterBinding;
import io.micronaut.data.model.runtime.StoredQuery;
import io.micronaut.data.operations.HintsCapableRepository;
import io.micronaut.data.runtime.query.internal.DefaultStoredQuery;
import io.micronaut.inject.ExecutableMethod;
import java.util.List;
import static io.micronaut.data.model.runtime.StoredQuery.*;
/**
* Default stored query resolver.
*
* @author Denis Stepanov
* @since 3.3
*/
@Internal
public abstract class DefaultStoredQueryResolver implements StoredQueryResolver {
@Override
public StoredQuery resolveQuery(MethodInvocationContext, ?> context, Class entityClass, Class resultType, boolean isCount) {
if (resultType == null) {
//noinspection unchecked
resultType = (Class) context.classValue(DataMethod.NAME, DataMethod.META_MEMBER_RESULT_TYPE)
.orElse(entityClass);
}
String query = context.stringValue(Query.class).orElseThrow(() ->
new IllegalStateException("No query present in method")
);
return new DefaultStoredQuery<>(
context.getExecutableMethod(),
resultType,
entityClass,
query,
isCount,
getHintsCapableRepository()
);
}
@Override
public StoredQuery resolveCountQuery(MethodInvocationContext, ?> context, Class entityClass, Class resultType) {
String query = context.stringValue(Query.class, DataMethod.META_MEMBER_COUNT_QUERY)
.orElseGet(() -> context.stringValue(Query.class)
.orElseThrow(() -> new IllegalStateException("No query present in method")));
return new DefaultStoredQuery<>(
context.getExecutableMethod(),
resultType,
entityClass,
query,
true,
getHintsCapableRepository()
);
}
@Override
public StoredQuery createStoredQuery(ExecutableMethod, ?> executableMethod,
OperationType operationType,
String name,
AnnotationMetadata annotationMetadata,
Class
© 2015 - 2025 Weber Informatics LLC | Privacy Policy