use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by MorphiaOrg.
the class EntityModelTest method testInheritedTypes.
@Test
public void testInheritedTypes() {
EntityModel model = getDs().getMapper().map(MoreSpecificEntity.class).get(0);
MoreSpecificEntity beforeDB = new MoreSpecificEntity();
beforeDB.setId(UUID.randomUUID());
beforeDB.setTest("a string");
beforeDB.setTest2(UUID.randomUUID());
beforeDB.setNumber(13);
beforeDB.setNumber2(14);
getDs().save(beforeDB);
assertEquals(model.getProperty("id").getType(), UUID.class);
assertEquals(model.getProperty("test").getType(), String.class);
assertEquals(model.getProperty("test2").getType(), UUID.class);
getDs().getDatabase().getCollection("specificEntity").deleteMany(new Document());
}
use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by MorphiaOrg.
the class Operations method versionUpdate.
protected void versionUpdate() {
PropertyModel versionField = entityModel.getVersionProperty();
if (versionField != null) {
List<OperationTarget> operationTargets = ops.get("$inc");
String version = versionField.getMappedName();
boolean already = operationTargets != null && operationTargets.stream().anyMatch(tv -> {
PathTarget target = tv.getTarget();
return target != null && target.translatedPath().equals(version);
});
if (!already) {
add("$inc", new OperationTarget(new PathTarget(datastore.getMapper(), entityModel, versionField.getName()), 1L));
}
}
}
use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by MorphiaOrg.
the class Projection method project.
private Document project(Mapper mapper, Class<?> clazz) {
Document projection = new Document();
iterate(mapper, projection, clazz, includes, 1);
iterate(mapper, projection, clazz, excludes, 0);
final EntityModel model = mapper.getEntityModel(clazz);
Entity entityAnnotation = model.getEntityAnnotation();
if (isIncluding() && entityAnnotation != null && entityAnnotation.useDiscriminator()) {
projection.put(mapper.getOptions().getDiscriminatorKey(), 1);
}
return projection;
}
use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by MorphiaOrg.
the class SingleReference method decode.
/**
* Decodes a document in to an entity
*
* @param datastore the datastore
* @param mapper the mapper
* @param mappedField the MappedField
* @param paramType the type of the underlying entity
* @param document the Document to decode
* @return the entity
*/
public static MorphiaReference<?> decode(Datastore datastore, Mapper mapper, PropertyModel mappedField, Class<?> paramType, Document document) {
final EntityModel entityModel = mapper.getEntityModel(paramType);
Object id = document.get(mappedField.getMappedName());
return new SingleReference<>(datastore, mapper, entityModel, id);
}
Aggregations