Search in sources :

Example 1 with ExternalEntity

use of dev.morphia.annotations.experimental.ExternalEntity in project morphia by mongodb.

the class MorphiaDefaultsConvention method apply.

@Override
public void apply(Mapper mapper, EntityModelBuilder modelBuilder) {
    MapperOptions options = mapper.getOptions();
    final Entity entity = modelBuilder.getAnnotation(Entity.class);
    final Embedded embedded = modelBuilder.getAnnotation(Embedded.class);
    final ExternalEntity externalEntity = modelBuilder.getAnnotation(ExternalEntity.class);
    if (entity != null) {
        modelBuilder.enableDiscriminator(entity.useDiscriminator());
        modelBuilder.discriminatorKey(applyDefaults(entity.discriminatorKey(), options.getDiscriminatorKey()));
    } else if (externalEntity != null) {
        modelBuilder.enableDiscriminator(externalEntity.useDiscriminator());
        modelBuilder.discriminatorKey(applyDefaults(externalEntity.discriminatorKey(), options.getDiscriminatorKey()));
        modelBuilder.annotation(EntityBuilder.entityBuilder().cap(externalEntity.cap()).concern(externalEntity.concern()).discriminator(externalEntity.discriminator()).discriminatorKey(externalEntity.discriminatorKey()).value(externalEntity.value()).useDiscriminator(externalEntity.useDiscriminator()).build());
        modelBuilder.targetType(externalEntity.target());
    } else {
        modelBuilder.enableDiscriminator(embedded == null || embedded.useDiscriminator());
        modelBuilder.discriminatorKey(applyDefaults(embedded != null ? embedded.discriminatorKey() : Mapper.IGNORED_FIELDNAME, options.getDiscriminatorKey()));
    }
    options.getDiscriminator().apply(modelBuilder);
}
Also used : MapperOptions(dev.morphia.mapping.MapperOptions) ExternalEntity(dev.morphia.annotations.experimental.ExternalEntity) Entity(dev.morphia.annotations.Entity) ExternalEntity(dev.morphia.annotations.experimental.ExternalEntity) Embedded(dev.morphia.annotations.Embedded)

Aggregations

Embedded (dev.morphia.annotations.Embedded)1 Entity (dev.morphia.annotations.Entity)1 ExternalEntity (dev.morphia.annotations.experimental.ExternalEntity)1 MapperOptions (dev.morphia.mapping.MapperOptions)1