Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include an AdvancedDatastore-specific method for aggregation #979

Merged
merged 2 commits into from
Aug 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions morphia/src/main/java/org/mongodb/morphia/AdvancedDatastore.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.mongodb.morphia;

import org.mongodb.morphia.aggregation.AggregationPipeline;
import org.mongodb.morphia.query.Query;
import org.mongodb.morphia.query.UpdateOperations;

import com.mongodb.DBDecoderFactory;
import com.mongodb.DBObject;
import com.mongodb.DBRef;
import com.mongodb.ReadPreference;
import com.mongodb.WriteConcern;
import com.mongodb.WriteResult;
import org.mongodb.morphia.query.Query;
import org.mongodb.morphia.query.UpdateOperations;

/**
* This interface exposes advanced {@link Datastore} features, like interacting with DBObject and low-level options. It implements matching
Expand All @@ -17,6 +19,15 @@
*/
public interface AdvancedDatastore extends Datastore {

/**
* Returns an {@link AggregationPipeline} bound to the given collection and class.
*
* @param collection the collection to query
* @param clazz The class to create aggregation against
* @return the aggregation pipeline
*/
AggregationPipeline createAggregation(String collection, Class<?> clazz);

/**
* @param <T> The type of the entity
* @param collection the collection to query
Expand Down
8 changes: 7 additions & 1 deletion morphia/src/main/java/org/mongodb/morphia/DatastoreImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.mongodb.ReadPreference;
import com.mongodb.WriteConcern;
import com.mongodb.WriteResult;

import org.mongodb.morphia.aggregation.AggregationPipeline;
import org.mongodb.morphia.aggregation.AggregationPipelineImpl;
import org.mongodb.morphia.annotations.CappedAt;
Expand Down Expand Up @@ -138,7 +139,12 @@ public DatastoreImpl copy(final String database) {
*/
@Override
public AggregationPipeline createAggregation(final Class source) {
return new AggregationPipelineImpl(this, source);
return new AggregationPipelineImpl(this, getCollection(source), source);
}

@Override
public AggregationPipeline createAggregation(final String collection, final Class<?> clazz) {
return new AggregationPipelineImpl(this, db.getCollection(collection), clazz);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ public class AggregationPipelineImpl implements AggregationPipeline {
* Creates an AggregationPipeline
*
* @param datastore the datastore to use
* @param collection the database collection on which to operate
* @param source the source type to aggregate
*/
public AggregationPipelineImpl(final DatastoreImpl datastore, final Class source) {
public AggregationPipelineImpl(final DatastoreImpl datastore, final DBCollection collection, final Class source) {
this.datastore = datastore;
this.collection = datastore.getCollection(source);
this.collection = collection;
mapper = datastore.getMapper();
this.source = source;
}
Expand Down