use of io.micronaut.data.operations.RepositoryOperations in project micronaut-data by micronaut-projects.
the class DataIntroductionAdvice method findInterceptor.
@NonNull
private DataInterceptor<Object, Object> findInterceptor(@Nullable String dataSourceName, @NonNull Class<?> operationsType, @NonNull Class<?> interceptorType) {
DataInterceptor interceptor;
if (!RepositoryOperations.class.isAssignableFrom(operationsType)) {
throw new IllegalArgumentException("Repository type must be an instance of RepositoryOperations!");
}
RepositoryOperations datastore;
try {
if (dataSourceName != null) {
Qualifier qualifier = Qualifiers.byName(dataSourceName);
datastore = (RepositoryOperations) beanLocator.getBean(operationsType, qualifier);
} else {
datastore = (RepositoryOperations) beanLocator.getBean(operationsType);
}
} catch (NoSuchBeanException e) {
throw new ConfigurationException("No backing RepositoryOperations configured for repository. Check your configuration and try again", e);
}
BeanIntrospection<Object> introspection = BeanIntrospector.SHARED.findIntrospections(ref -> ref.isPresent() && interceptorType.isAssignableFrom(ref.getBeanType())).stream().findFirst().orElseThrow(() -> new DataAccessException("No Data interceptor found for type: " + interceptorType));
if (introspection.getConstructorArguments().length == 0) {
interceptor = (DataInterceptor) introspection.instantiate();
} else {
interceptor = (DataInterceptor) introspection.instantiate(datastore);
}
return interceptor;
}
use of io.micronaut.data.operations.RepositoryOperations in project micronaut-coherence by micronaut-projects.
the class CoherenceDataIntroductionAdvice method findInterceptor.
@NonNull
private DataInterceptor<Object, Object> findInterceptor(@Nullable String dataSourceName, @NonNull Class<?> operationsType, @NonNull Class<?> interceptorType) {
DataInterceptor interceptor;
if (!RepositoryOperations.class.isAssignableFrom(operationsType)) {
throw new IllegalArgumentException("Repository type must be an instance of RepositoryOperations!");
}
Qualifier qualifier = Qualifiers.byName(dataSourceName);
RepositoryOperations datastore;
try {
datastore = (RepositoryOperations) beanLocator.getBean(operationsType, qualifier);
} catch (NoSuchBeanException e) {
// if there is no explicit configuration, use a DefaultCoherenceRepositoryOperations implementation
// using the default Coherence session
datastore = new DefaultCoherenceRepositoryOperations(dataSourceName, (ApplicationContext) beanLocator, (BeanContext) beanLocator);
((ApplicationContext) beanLocator).registerSingleton(RepositoryOperations.class, datastore, qualifier);
}
BeanIntrospection<Object> introspection = BeanIntrospector.SHARED.findIntrospections(ref -> interceptorType.isAssignableFrom(ref.getBeanType())).stream().findFirst().orElseThrow(() -> new DataAccessException("No Data interceptor found for type: " + interceptorType));
if (introspection.getConstructorArguments().length == 0) {
interceptor = (DataInterceptor) introspection.instantiate();
} else {
interceptor = (DataInterceptor) introspection.instantiate(datastore);
}
return interceptor;
}
Aggregations