use of io.micronaut.data.annotation.Index in project micronaut-data by micronaut-projects.
the class MappedEntityVisitor method visitClass.
@Override
public void visitClass(ClassElement element, VisitorContext context) {
NamingStrategy namingStrategy = resolveNamingStrategy(element);
Optional<String> targetName = element.stringValue(MappedEntity.class);
SourcePersistentEntity entity = entityResolver.apply(element);
if (isMappedEntity() && !targetName.isPresent()) {
element.annotate(MappedEntity.class, builder -> {
String mappedName = namingStrategy.mappedName(entity);
builder.value(mappedName);
});
}
Map<String, DataType> dataTypes = getConfiguredDataTypes(element);
Map<String, String> dataConverters = getConfiguredDataConverters(element);
List<SourcePersistentProperty> properties = entity.getPersistentProperties();
final List<AnnotationValue<Index>> indexes = properties.stream().filter(x -> ((PersistentProperty) x).findAnnotation(Indexes.class).isPresent()).map(prop -> prop.findAnnotation(Index.class)).flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty)).collect(Collectors.toList());
if (!indexes.isEmpty()) {
element.annotate(Indexes.class, builder -> builder.values(indexes.toArray(new AnnotationValue[] {})));
}
for (PersistentProperty property : properties) {
computeMappingDefaults(namingStrategy, property, dataTypes, dataConverters, context);
}
SourcePersistentProperty identity = entity.getIdentity();
if (identity != null) {
computeMappingDefaults(namingStrategy, identity, dataTypes, dataConverters, context);
}
SourcePersistentProperty[] compositeIdentities = entity.getCompositeIdentity();
if (compositeIdentities != null) {
for (SourcePersistentProperty compositeIdentity : compositeIdentities) {
computeMappingDefaults(namingStrategy, compositeIdentity, dataTypes, dataConverters, context);
}
}
SourcePersistentProperty version = entity.getVersion();
if (version != null) {
computeMappingDefaults(namingStrategy, version, dataTypes, dataConverters, context);
}
}
Aggregations