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);
}
Aggregations