use of dev.morphia.internal.PathTarget in project morphia by mongodb.
the class UpdateBase method toDocument.
/**
* @return the operations listed
*/
public Document toDocument() {
final Operations operations = new Operations(datastore, mapper.getEntityModel(type));
for (UpdateOperator update : updates) {
PathTarget pathTarget = new PathTarget(mapper, mapper.getEntityModel(type), update.field(), true);
operations.add(update.operator(), update.toTarget(pathTarget));
}
return operations.toDocument();
}
use of dev.morphia.internal.PathTarget in project morphia by mongodb.
the class PathTargetTest method arrays.
@Test
public void arrays() {
getMapper().map(EntityWithListsAndArrays.class, EmbeddedType.class, Another.class, Child.class);
Mapper mapper = getMapper();
EntityModel entityModel = mapper.getEntityModel(EntityWithListsAndArrays.class);
PathTarget pathTarget = new PathTarget(mapper, entityModel, "listEmbeddedType.1.anotherField");
Assert.assertEquals(pathTarget.translatedPath(), "listEmbeddedType.1.anotherField");
Assert.assertEquals(mapper.getEntityModel(Another.class).getProperty("anotherField"), pathTarget.getTarget());
Assert.assertEquals(new PathTarget(mapper, entityModel, "listEmbeddedType.$").translatedPath(), "listEmbeddedType.$");
Assert.assertEquals(new PathTarget(mapper, entityModel, "listEmbeddedType.1").translatedPath(), "listEmbeddedType.1");
}
use of dev.morphia.internal.PathTarget in project morphia by mongodb.
the class PathTargetTest method subClasses.
@Test
public void subClasses() {
getMapper().map(FatherEntity.class, ChildEntity.class, Another.class);
Mapper mapper = getMapper();
PathTarget pathTarget = new PathTarget(mapper, FatherEntity.class, "embedded.anotherField");
Assert.assertEquals(pathTarget.translatedPath(), "embedded.anotherField");
Assert.assertEquals(mapper.getEntityModel(Another.class).getProperty("anotherField"), pathTarget.getTarget());
}
use of dev.morphia.internal.PathTarget in project morphia by mongodb.
the class PathTargetTest method dottedPath.
@Test
public void dottedPath() {
getMapper().map(State.class, CityPopulation.class);
Mapper mapper = getMapper();
PathTarget pathTarget = new PathTarget(mapper, State.class, "biggestCity.population");
Assert.assertEquals(pathTarget.translatedPath(), "biggestCity.pop");
Assert.assertEquals(mapper.getEntityModel(CityPopulation.class).getProperty("population"), pathTarget.getTarget());
}
use of dev.morphia.internal.PathTarget in project morphia by mongodb.
the class PathTargetTest method interfaces.
@Test
public void interfaces() {
getMapper().map(HoldsAnInterface.class, MappedInterface.class, InterfaceTypeA.class, InterfaceTypeB.class);
Mapper mapper = getMapper();
EntityModel entityModel = mapper.getEntityModel(HoldsAnInterface.class);
PathTarget pathTarget = new PathTarget(mapper, entityModel, "mapped.value");
Assert.assertEquals(pathTarget.translatedPath(), "mapped.value");
Assert.assertEquals(mapper.getEntityModel(InterfaceTypeB.class).getProperty("value"), pathTarget.getTarget());
pathTarget = new PathTarget(mapper, entityModel, "mapped.field");
Assert.assertEquals(pathTarget.translatedPath(), "mapped.field");
Assert.assertEquals(mapper.getEntityModel(InterfaceTypeA.class).getProperty("field"), pathTarget.getTarget());
}
Aggregations