use of io.micronaut.data.intercept.RepositoryMethodKey in project micronaut-coherence by micronaut-projects.
the class CoherenceDataIntroductionAdvice method intercept.
@Override
public Object intercept(MethodInvocationContext<Object, Object> context) {
RepositoryMethodKey key = new RepositoryMethodKey(context.getTarget(), context.getExecutableMethod());
DataInterceptor<Object, Object> dataInterceptor = interceptorMap.get(key);
if (dataInterceptor == null) {
String dataSourceName = context.stringValue(Repository.class).orElse(null);
Class<?> operationsType = context.classValue(RepositoryConfiguration.class, "operations").orElse(PrimaryRepositoryOperations.class);
Class<?> interceptorType = context.classValue(DataMethod.class, DataMethod.META_MEMBER_INTERCEPTOR).orElse(null);
if (interceptorType != null && DataInterceptor.class.isAssignableFrom(interceptorType)) {
DataInterceptor<Object, Object> childInterceptor = findInterceptor(dataSourceName, operationsType, interceptorType);
interceptorMap.put(key, childInterceptor);
return childInterceptor.intercept(key, context);
} else {
final AnnotationValue<DataMethod> declaredAnnotation = context.getDeclaredAnnotation(DataMethod.class);
if (declaredAnnotation != null) {
interceptorType = declaredAnnotation.classValue(DataMethod.META_MEMBER_INTERCEPTOR).orElse(null);
if (interceptorType != null && DataInterceptor.class.isAssignableFrom(interceptorType)) {
DataInterceptor<Object, Object> childInterceptor = findInterceptor(dataSourceName, operationsType, interceptorType);
interceptorMap.put(key, childInterceptor);
return childInterceptor.intercept(key, context);
}
}
final String interceptorName = context.getAnnotationMetadata().stringValue(DataMethod.class, DataMethod.META_MEMBER_INTERCEPTOR).orElse(null);
if (interceptorName != null) {
throw new IllegalStateException("Micronaut Data Interceptor [" + interceptorName + "] is not on" + " the classpath but required by the method: " + context.getExecutableMethod());
}
throw new IllegalStateException("Micronaut Data method is missing compilation time query " + "information. Ensure that the Micronaut Data annotation processors are declared in your" + " build and try again with a clean re-build.");
}
} else {
return dataInterceptor.intercept(key, context);
}
}
Aggregations