use of dev.morphia.mapping.MapperOptions 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);
}
use of dev.morphia.mapping.MapperOptions in project morphia by mongodb.
the class TestBase method withOptions.
protected void withOptions(MapperOptions options, Runnable block) {
MapperOptions previousOptions = mapperOptions;
try {
mapperOptions = options;
database = null;
datastore = null;
block.run();
} finally {
mapperOptions = previousOptions;
database = null;
datastore = null;
}
}
use of dev.morphia.mapping.MapperOptions in project morphia by mongodb.
the class TestMapping method collectionNaming.
@Test
public void collectionNaming() {
MapperOptions options = MapperOptions.builder().collectionNaming(NamingStrategy.lowerCase()).build();
Datastore datastore = createDatastore(TestBase.TEST_DB_NAME, options);
List<EntityModel> map = datastore.getMapper().map(ContainsMapWithEmbeddedInterface.class, ContainsIntegerList.class);
assertEquals(map.get(0).getCollectionName(), "containsmapwithembeddedinterface");
assertEquals(map.get(1).getCollectionName(), "cil");
options = MapperOptions.builder().collectionNaming(NamingStrategy.kebabCase()).build();
datastore = createDatastore(TestBase.TEST_DB_NAME, options);
map = datastore.getMapper().map(ContainsMapWithEmbeddedInterface.class, ContainsIntegerList.class);
assertEquals(map.get(0).getCollectionName(), "contains-map-with-embedded-interface");
assertEquals(map.get(1).getCollectionName(), "cil");
}
Aggregations