use of dev.morphia.mapping.codec.pojo.PropertyModel in project morphia by mongodb.
the class PathTarget method resolve.
private void resolve() {
context = this.root;
position = 0;
PropertyModel property = null;
while (hasNext()) {
String segment = next();
// array operator
if ("$".equals(segment) || (segment.startsWith("$[") && segment.endsWith("]")) || segment.matches("[0-9]+")) {
if (!hasNext()) {
break;
}
segment = next();
}
property = resolveProperty(segment);
if (property != null) {
if (hasNext() && property.isReference()) {
failValidation(segment);
}
translate(property.getMappedName());
if (property.isMap() && hasNext()) {
// consume the map key segment
next();
}
} else {
if (validateNames) {
failValidation(segment);
}
}
}
target = property;
resolved = true;
}
use of dev.morphia.mapping.codec.pojo.PropertyModel in project morphia by mongodb.
the class TestPropertyModel method basicFieldMapping.
@Test
public void basicFieldMapping() {
final PropertyModel property = getMappedField("name");
Assert.assertTrue(property.isScalarValue());
Assert.assertSame(property.getType(), String.class);
Assert.assertEquals(property.getName(), "name");
Assert.assertEquals(property.getMappedName(), "n");
}
use of dev.morphia.mapping.codec.pojo.PropertyModel in project morphia by mongodb.
the class TestPropertyModel method collectionFieldMapping.
@Test
public void collectionFieldMapping() {
final PropertyModel property = getMappedField("listOfString");
Assert.assertFalse(property.isScalarValue());
Assert.assertTrue(property.isMultipleValues());
Assert.assertFalse(property.isArray());
Assert.assertSame(property.getType(), List.class);
Assert.assertSame(property.getNormalizedType(), String.class);
Assert.assertEquals(property.getName(), "listOfString");
Assert.assertEquals(property.getMappedName(), "listOfString");
}
use of dev.morphia.mapping.codec.pojo.PropertyModel in project morphia by mongodb.
the class TestPropertyModel method nestedCollectionsMapping.
@Test
public void nestedCollectionsMapping() {
final PropertyModel property = getMappedField("listOfListOfString");
Assert.assertFalse(property.isScalarValue());
Assert.assertTrue(property.isMultipleValues());
Assert.assertFalse(property.isArray());
Assert.assertSame(property.getType(), List.class);
final TypeData<?> typeData = property.getTypeData();
Assert.assertSame(typeData.getType(), List.class);
Assert.assertEquals(typeData.getTypeParameters().get(0).getTypeParameters().get(0).getType(), String.class);
Assert.assertEquals(property.getName(), "listOfListOfString");
Assert.assertEquals(property.getMappedName(), "listOfListOfString");
final List<List<String>> list = new ArrayList<>();
list.add(dbList("a", "b", "c"));
list.add(dbList("d", "e", "f"));
TestEntity testEntity = new TestEntity();
testEntity.listOfListOfString = list;
getDs().save(testEntity);
Assert.assertEquals(list, getDs().find(TestEntity.class).filter(eq("_id", testEntity.id)).first().listOfListOfString);
}
use of dev.morphia.mapping.codec.pojo.PropertyModel in project morphia by mongodb.
the class TestPropertyModel method idFieldMapping.
@Test
public void idFieldMapping() {
final PropertyModel property = getMappedField("id");
Assert.assertTrue(property.isScalarValue());
Assert.assertSame(property.getType(), ObjectId.class);
Assert.assertEquals(property.getName(), "id");
Assert.assertEquals(property.getMappedName(), "_id");
}
Aggregations