use of io.micronaut.data.annotation.TypeRole in project micronaut-data by micronaut-projects.
the class RepositoryTypeElementVisitor method visitClass.
@Override
public void visitClass(ClassElement element, VisitorContext context) {
String interfaceName = element.getName();
if (failing) {
return;
}
if (visitedRepositories.contains(interfaceName)) {
// prevent duplicate visits
currentRepository = null;
currentClass = null;
return;
}
this.currentClass = element;
entityResolver = new Function<ClassElement, SourcePersistentEntity>() {
MappedEntityVisitor mappedEntityVisitor = new MappedEntityVisitor();
MappedEntityVisitor embeddedMappedEntityVisitor = new MappedEntityVisitor(false);
@Override
public SourcePersistentEntity apply(ClassElement classElement) {
return entityMap.computeIfAbsent(classElement.getName(), s -> {
if (classElement.hasAnnotation("io.micronaut.data.annotation.Embeddable")) {
embeddedMappedEntityVisitor.visitClass(classElement, context);
} else {
mappedEntityVisitor.visitClass(classElement, context);
}
return new SourcePersistentEntity(classElement, this);
});
}
};
if (element.hasDeclaredStereotype(Repository.class)) {
visitedRepositories.add(interfaceName);
currentRepository = element;
queryEncoder = QueryBuilder.newQueryBuilder(element.getAnnotationMetadata());
this.dataTypes = Utils.getConfiguredDataTypes(currentRepository);
AnnotationMetadata annotationMetadata = element.getAnnotationMetadata();
List<AnnotationValue<TypeRole>> roleArray = annotationMetadata.findAnnotation(RepositoryConfiguration.class).map(av -> av.getAnnotations("typeRoles", TypeRole.class)).orElse(Collections.emptyList());
for (AnnotationValue<TypeRole> parameterRole : roleArray) {
String role = parameterRole.stringValue("role").orElse(null);
AnnotationClassValue cv = parameterRole.get("type", AnnotationClassValue.class).orElse(null);
if (StringUtils.isNotEmpty(role) && cv != null) {
context.getClassElement(cv.getName()).ifPresent(ce -> typeRoles.put(ce.getName(), role));
}
}
if (element.isAssignable(SPRING_REPO)) {
context.getClassElement("org.springframework.data.domain.Pageable").ifPresent(ce -> typeRoles.put(ce.getName(), TypeRole.PAGEABLE));
context.getClassElement("org.springframework.data.domain.Page").ifPresent(ce -> typeRoles.put(ce.getName(), TypeRole.PAGE));
context.getClassElement("org.springframework.data.domain.Slice").ifPresent(ce -> typeRoles.put(ce.getName(), TypeRole.SLICE));
context.getClassElement("org.springframework.data.domain.Sort").ifPresent(ce -> typeRoles.put(ce.getName(), TypeRole.SORT));
}
if (queryEncoder == null) {
context.fail("QueryEncoder not present on annotation processor path", element);
failing = true;
}
}
}
Aggregations