use of dev.morphia.mapping.MapperOptions in project morphia by mongodb.
the class TestEnumMapping method testCustomerWithArrayList.
@Test
public void testCustomerWithArrayList() {
MapperOptions options = MapperOptions.builder(getMapper().getOptions()).storeEmpties(true).storeNulls(true).build();
final Datastore datastore = Morphia.createDatastore(getMongoClient(), getDatabase().getName(), options);
Mapper mapper = datastore.getMapper();
mapper.map(CustomerWithArrayList.class);
CustomerWithArrayList customer = new CustomerWithArrayList();
List<WebTemplate> templates1 = new ArrayList<>();
templates1.add(new WebTemplate("template #1.1"));
templates1.add(new WebTemplate("template #1.2"));
customer.add(WebTemplateType.CrewContract, templates1);
List<WebTemplate> templates2 = new ArrayList<>();
templates1.add(new WebTemplate("template #2.1"));
templates1.add(new WebTemplate("template #2.2"));
customer.add(WebTemplateType.CrewContractHeader, templates2);
getDs().save(customer);
final Datastore datastore1 = getDs();
CustomerWithArrayList loaded = datastore1.find(CustomerWithArrayList.class).filter(eq("_id", customer.id)).first();
assertEquals(customer.mapWithArrayList, loaded.mapWithArrayList);
}
use of dev.morphia.mapping.MapperOptions in project morphia by mongodb.
the class TestClassLoader method recreateCollection.
private MongoCollection<BasicEntity> recreateCollection(ClassLoader classLoader) {
MapperOptions options = MapperOptions.builder().discriminator(DiscriminatorFunction.className()).classLoader(classLoader).build();
Datastore datastore = Morphia.createDatastore(getMongoClient(), TEST_DB_NAME, options);
return datastore.getCollection(BasicEntity.class);
}
use of dev.morphia.mapping.MapperOptions in project morphia by mongodb.
the class TestEnumMapping method testCustomerWithList.
@Test
public void testCustomerWithList() {
MapperOptions options = MapperOptions.builder(getMapper().getOptions()).storeEmpties(true).storeNulls(true).build();
final Datastore datastore = Morphia.createDatastore(getMongoClient(), getDatabase().getName(), options);
Mapper mapper = datastore.getMapper();
mapper.map(CustomerWithArrayList.class);
CustomerWithList customer = new CustomerWithList();
List<WebTemplate> templates1 = new ArrayList<>();
templates1.add(new WebTemplate("template #1.1"));
templates1.add(new WebTemplate("template #1.2"));
customer.add(WebTemplateType.CrewContract, templates1);
List<WebTemplate> templates2 = new ArrayList<>();
templates1.add(new WebTemplate("template #2.1"));
templates1.add(new WebTemplate("template #2.2"));
customer.add(WebTemplateType.CrewContractHeader, templates2);
getDs().save(customer);
final Datastore datastore1 = getDs();
CustomerWithList loaded = datastore1.find(CustomerWithList.class).filter(eq("_id", customer.id)).first();
assertEquals(customer.mapWithList, loaded.mapWithList);
}
use of dev.morphia.mapping.MapperOptions in project morphia by mongodb.
the class PropertyModelBuilder method discoverMappedName.
public PropertyModelBuilder discoverMappedName() {
MapperOptions options = mapper.getOptions();
Property property = getAnnotation(Property.class);
Reference reference = getAnnotation(Reference.class);
Version version = getAnnotation(Version.class);
if (hasAnnotation(Id.class)) {
mappedName("_id");
} else if (property != null && !property.value().equals(Mapper.IGNORED_FIELDNAME)) {
mappedName(property.value());
} else if (reference != null && !reference.value().equals(Mapper.IGNORED_FIELDNAME)) {
mappedName(reference.value());
} else if (version != null && !version.value().equals(Mapper.IGNORED_FIELDNAME)) {
mappedName(version.value());
} else {
mappedName(options.getFieldNaming().apply(name()));
}
return this;
}
use of dev.morphia.mapping.MapperOptions in project morphia by mongodb.
the class ConfigureProperties method apply.
@Override
public void apply(Mapper mapper, EntityModelBuilder modelBuilder) {
MapperOptions options = mapper.getOptions();
processProperties(modelBuilder, options);
if (modelBuilder.idPropertyName() == null) {
IdField idProperty = modelBuilder.getAnnotation(IdField.class);
if (idProperty != null) {
modelBuilder.idPropertyName(idProperty.value());
PropertyModelBuilder propertyModelBuilder = modelBuilder.propertyModelByName(idProperty.value());
propertyModelBuilder.mappedName("_id");
}
}
}
Aggregations