Search in sources :

Example 1 with MorphiaCursor

use of dev.morphia.query.internal.MorphiaCursor 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);
}
Also used : EntityModel(dev.morphia.mapping.codec.pojo.EntityModel) Document(org.bson.Document) MorphiaCursor(dev.morphia.query.internal.MorphiaCursor)

Example 2 with MorphiaCursor

use of dev.morphia.query.internal.MorphiaCursor in project morphia by MorphiaOrg.

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);
}
Also used : EntityModel(dev.morphia.mapping.codec.pojo.EntityModel) Document(org.bson.Document) MorphiaCursor(dev.morphia.query.internal.MorphiaCursor)

Aggregations

EntityModel (dev.morphia.mapping.codec.pojo.EntityModel)2 MorphiaCursor (dev.morphia.query.internal.MorphiaCursor)2 Document (org.bson.Document)2