Search in sources :

Example 6 with PathTarget

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();
}
Also used : UpdateOperator(dev.morphia.query.experimental.updates.UpdateOperator) PathTarget(dev.morphia.internal.PathTarget)

Example 7 with PathTarget

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");
}
Also used : Mapper(dev.morphia.mapping.Mapper) PathTarget(dev.morphia.internal.PathTarget) EntityModel(dev.morphia.mapping.codec.pojo.EntityModel) Test(org.testng.annotations.Test)

Example 8 with PathTarget

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());
}
Also used : Mapper(dev.morphia.mapping.Mapper) PathTarget(dev.morphia.internal.PathTarget) Test(org.testng.annotations.Test)

Example 9 with PathTarget

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());
}
Also used : Mapper(dev.morphia.mapping.Mapper) PathTarget(dev.morphia.internal.PathTarget) Test(org.testng.annotations.Test)

Example 10 with PathTarget

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());
}
Also used : Mapper(dev.morphia.mapping.Mapper) PathTarget(dev.morphia.internal.PathTarget) EntityModel(dev.morphia.mapping.codec.pojo.EntityModel) Test(org.testng.annotations.Test)

Aggregations

PathTarget (dev.morphia.internal.PathTarget)13 Mapper (dev.morphia.mapping.Mapper)8 Test (org.testng.annotations.Test)8 EntityModel (dev.morphia.mapping.codec.pojo.EntityModel)7 Document (org.bson.Document)3 Nullable (com.mongodb.lang.Nullable)2 PropertyModel (dev.morphia.mapping.codec.pojo.PropertyModel)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 StringJoiner (java.util.StringJoiner)2 DBObject (com.mongodb.DBObject)1 Datastore (dev.morphia.Datastore)1 Entity (dev.morphia.annotations.Entity)1 PropertyHandler (dev.morphia.mapping.codec.pojo.PropertyHandler)1 OperationTarget (dev.morphia.query.OperationTarget)1 UpdateOperator (dev.morphia.query.experimental.updates.UpdateOperator)1 Sofia (dev.morphia.sofia.Sofia)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1