use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by mongodb.
the class AggregationImpl method execute.
@Override
public <R> MorphiaCursor<R> execute(Class<R> resultType) {
MongoCursor<R> cursor;
if (datastore.getMapper().isMappable(resultType) && !resultType.equals(this.collection.getDocumentClass())) {
MongoCollection<Document> collection = this.collection.withDocumentClass(Document.class);
MongoCursor<Document> results = collection.aggregate(getDocuments()).iterator();
EntityModel entityModel = datastore.getMapper().getEntityModel(this.collection.getDocumentClass());
cursor = new MappingCursor<>(results, datastore.getCodecRegistry().get(resultType), entityModel.getDiscriminatorKey());
} else {
cursor = collection.aggregate(getDocuments(), resultType).iterator();
}
return new MorphiaCursor<>(cursor);
}
use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by mongodb.
the class TestDocumentValidation method validationDocuments.
@Test
public void validationDocuments() {
Document validator = parse("{ \"jelly\" : { \"$ne\" : \"rhubarb\" } }");
getMapper().map(DocumentValidation.class);
EntityModel model = getMapper().getEntityModel(DocumentValidation.class);
for (ValidationLevel level : EnumSet.allOf(ValidationLevel.class)) {
for (ValidationAction action : EnumSet.allOf(ValidationAction.class)) {
checkValidation(validator, model, level, action);
}
}
}
use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by mongodb.
the class TestMapping method subTypes.
@Test
public void subTypes() {
getMapper().map(EmbeddedType.class, Another.class, Child.class);
Mapper mapper = getMapper();
List<EntityModel> subTypes = mapper.getEntityModel(EmbeddedType.class).getSubtypes();
Assert.assertTrue(subTypes.contains(mapper.getEntityModel(Another.class)));
Assert.assertTrue(subTypes.contains(mapper.getEntityModel(Child.class)));
}
use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by mongodb.
the class TestMapping method testMethodMapping.
@Test
public void testMethodMapping() {
Datastore datastore = createDatastore(getMongoClient(), TEST_DB_NAME, MapperOptions.builder().propertyDiscovery(PropertyDiscovery.METHODS).build());
EntityModel model = datastore.getMapper().map(MethodMappedUser.class).get(0);
assertTrue(model.getProperties().size() > 0);
assertNotNull(model.getVersionProperty(), model.getProperties().toString());
assertNotNull(model.getProperty("dateJoined"));
assertNotNull(model.getProperty("joined"));
assertNotNull(model.getProperty("friend_reference"));
assertNotNull(model.getProperty("morphia_reference"));
}
use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by mongodb.
the class TestVersioning method testCanMapAnEntityWithAnAbstractVersionedParent.
@Test
public void testCanMapAnEntityWithAnAbstractVersionedParent() {
Datastore datastore = Morphia.createDatastore(getMongoClient(), TEST_DB_NAME);
Mapper mapper = datastore.getMapper();
mapper.map(VersionedChildEntity.class);
List<EntityModel> mappedEntities = mapper.getMappedEntities();
assertEquals(mappedEntities.size(), 2, mappedEntities.toString());
List<Class<?>> list = new ArrayList<>();
for (EntityModel entityModel : mappedEntities) {
list.add(entityModel.getType());
}
assertTrue(list.contains(VersionedChildEntity.class));
assertTrue(list.contains(AbstractVersionedBase.class));
}
Aggregations