Search in sources :

Example 1 with Index

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);
    }
}
Also used : DataType(io.micronaut.data.model.DataType) MappedEntity(io.micronaut.data.annotation.MappedEntity) SourcePersistentProperty(io.micronaut.data.processor.model.SourcePersistentProperty) ClassElement(io.micronaut.inject.ast.ClassElement) HashMap(java.util.HashMap) TypeDef(io.micronaut.data.annotation.TypeDef) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Utils.getConfiguredDataTypes(io.micronaut.data.processor.visitors.Utils.getConfiguredDataTypes) Utils.getConfiguredDataConverters(io.micronaut.data.processor.visitors.Utils.getConfiguredDataConverters) TypeElementVisitor(io.micronaut.inject.visitor.TypeElementVisitor) MappedProperty(io.micronaut.data.annotation.MappedProperty) PropertyElement(io.micronaut.inject.ast.PropertyElement) InstantiationUtils(io.micronaut.core.reflect.InstantiationUtils) Map(java.util.Map) TypeUtils(io.micronaut.data.processor.visitors.finders.TypeUtils) AnnotationClassValue(io.micronaut.core.annotation.AnnotationClassValue) NamingStrategies(io.micronaut.data.model.naming.NamingStrategies) PersistentProperty(io.micronaut.data.model.PersistentProperty) Property(io.micronaut.context.annotation.Property) Index(io.micronaut.data.annotation.Index) NamingStrategy(io.micronaut.data.model.naming.NamingStrategy) SourcePersistentEntity(io.micronaut.data.processor.model.SourcePersistentEntity) Collectors(java.util.stream.Collectors) Indexes(io.micronaut.data.annotation.Indexes) Objects(java.util.Objects) NonNull(io.micronaut.core.annotation.NonNull) VisitorContext(io.micronaut.inject.visitor.VisitorContext) List(java.util.List) Association(io.micronaut.data.model.Association) Stream(java.util.stream.Stream) AnnotationValue(io.micronaut.core.annotation.AnnotationValue) Optional(java.util.Optional) AnnotationMetadata(io.micronaut.core.annotation.AnnotationMetadata) AttributeConverter(io.micronaut.data.model.runtime.convert.AttributeConverter) Relation(io.micronaut.data.annotation.Relation) SourcePersistentEntity(io.micronaut.data.processor.model.SourcePersistentEntity) Index(io.micronaut.data.annotation.Index) SourcePersistentProperty(io.micronaut.data.processor.model.SourcePersistentProperty) PersistentProperty(io.micronaut.data.model.PersistentProperty) Indexes(io.micronaut.data.annotation.Indexes) NamingStrategy(io.micronaut.data.model.naming.NamingStrategy) SourcePersistentProperty(io.micronaut.data.processor.model.SourcePersistentProperty) DataType(io.micronaut.data.model.DataType) AnnotationValue(io.micronaut.core.annotation.AnnotationValue) Stream(java.util.stream.Stream)

Aggregations

Property (io.micronaut.context.annotation.Property)1 AnnotationClassValue (io.micronaut.core.annotation.AnnotationClassValue)1 AnnotationMetadata (io.micronaut.core.annotation.AnnotationMetadata)1 AnnotationValue (io.micronaut.core.annotation.AnnotationValue)1 NonNull (io.micronaut.core.annotation.NonNull)1 InstantiationUtils (io.micronaut.core.reflect.InstantiationUtils)1 Index (io.micronaut.data.annotation.Index)1 Indexes (io.micronaut.data.annotation.Indexes)1 MappedEntity (io.micronaut.data.annotation.MappedEntity)1 MappedProperty (io.micronaut.data.annotation.MappedProperty)1 Relation (io.micronaut.data.annotation.Relation)1 TypeDef (io.micronaut.data.annotation.TypeDef)1 Association (io.micronaut.data.model.Association)1 DataType (io.micronaut.data.model.DataType)1 PersistentProperty (io.micronaut.data.model.PersistentProperty)1 NamingStrategies (io.micronaut.data.model.naming.NamingStrategies)1 NamingStrategy (io.micronaut.data.model.naming.NamingStrategy)1 AttributeConverter (io.micronaut.data.model.runtime.convert.AttributeConverter)1 SourcePersistentEntity (io.micronaut.data.processor.model.SourcePersistentEntity)1 SourcePersistentProperty (io.micronaut.data.processor.model.SourcePersistentProperty)1