Skip to content

Commit 2979ae8

Browse files
committed
JAVA-970: Rename MongoCursor to Cursor, override close to not throw IOException, and make DBCursor implement Cursor.
1 parent 88b4640 commit 2979ae8

7 files changed

Lines changed: 17 additions & 66 deletions

File tree

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
import java.util.Iterator;
2323

2424

25-
public interface MongoCursor extends Iterator<DBObject>, Closeable {
25+
public interface Cursor extends Iterator<DBObject>, Closeable {
2626
long getCursorId();
2727

2828
ServerAddress getServerAddress();
29+
30+
void close();
2931
}

src/main/com/mongodb/DBCollection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,7 @@ public AggregationOutput aggregate(final List<DBObject> pipeline, ReadPreference
15541554
* @return the aggregation operation's result set
15551555
* @mongodb.driver.manual core/aggregation-pipeline/ Aggregation
15561556
*/
1557-
public MongoCursor aggregate(final List<DBObject> pipeline, AggregationOptions options) {
1557+
public Cursor aggregate(final List<DBObject> pipeline, AggregationOptions options) {
15581558
return aggregate(pipeline, options, getReadPreference());
15591559
}
15601560

@@ -1567,7 +1567,7 @@ public MongoCursor aggregate(final List<DBObject> pipeline, AggregationOptions o
15671567
* @return the aggregation operation's result set
15681568
* @mongodb.driver.manual core/aggregation-pipeline/ Aggregation
15691569
*/
1570-
public abstract MongoCursor aggregate(final List<DBObject> pipeline, final AggregationOptions options,
1570+
public abstract Cursor aggregate(final List<DBObject> pipeline, final AggregationOptions options,
15711571
final ReadPreference readPreference);
15721572

15731573
/**

src/main/com/mongodb/DBCollectionImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ QueryResultIterator find(DBObject ref, DBObject fields, int numToSkip, int batch
7878
return new QueryResultIterator(db, this, res, batchSize, limit, options, decoder);
7979
}
8080

81-
public MongoCursor aggregate(final List<DBObject> pipeline, final AggregationOptions options,
82-
final ReadPreference readPreference) {
81+
public Cursor aggregate(final List<DBObject> pipeline, final AggregationOptions options,
82+
final ReadPreference readPreference) {
8383

8484
if(options == null) {
8585
throw new IllegalArgumentException("options can not be null");
@@ -94,7 +94,7 @@ public MongoCursor aggregate(final List<DBObject> pipeline, final AggregationOpt
9494
String outCollection = (String) last.get("$out");
9595
if (outCollection != null) {
9696
DBCollection collection = _db.getCollection(outCollection);
97-
return new DBCursorAdapter(new DBCursor(collection, new BasicDBObject(), null, ReadPreference.primary()));
97+
return new DBCursor(collection, new BasicDBObject(), null, ReadPreference.primary());
9898
} else {
9999
Integer batchSize = options.getBatchSize();
100100
return new QueryResultIterator(res, db, this, batchSize == null ? 0 : batchSize, getDecoder());

src/main/com/mongodb/DBCursor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import org.bson.util.annotations.NotThreadSafe;
2020

21-
import java.io.Closeable;
2221
import java.util.ArrayList;
2322
import java.util.Collections;
2423
import java.util.Iterator;
@@ -56,7 +55,7 @@
5655
* @dochub cursors
5756
*/
5857
@NotThreadSafe
59-
public class DBCursor implements Iterator<DBObject> , Iterable<DBObject>, Closeable {
58+
public class DBCursor implements Cursor, Iterable<DBObject> {
6059

6160
/**
6261
* Initializes a new database cursor

src/main/com/mongodb/DBCursorAdapter.java

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/main/com/mongodb/QueryResultIterator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import static com.mongodb.DBApiLayer.DeadCursor;
2929
import static java.util.Arrays.asList;
3030

31-
class QueryResultIterator implements MongoCursor {
31+
class QueryResultIterator implements Cursor {
3232

3333
private final DBApiLayer _db;
3434
private final DBDecoder _decoder;
@@ -61,7 +61,7 @@ class QueryResultIterator implements MongoCursor {
6161
_options = options;
6262
_host = res._host;
6363
_decoder = decoder;
64-
init( res );
64+
initFromQueryResponse(res);
6565
_optionalFinalizer = getOptionalFinalizer(collection);
6666
}
6767

@@ -137,7 +137,7 @@ private void getMore(){
137137
OutMessage.getMore(_collection, _cursorId, getGetMoreBatchSize()),
138138
_host, _decoder);
139139
_numGetMores++;
140-
init( res );
140+
initFromQueryResponse(res);
141141
}
142142

143143
private int getGetMoreBatchSize() {
@@ -171,7 +171,7 @@ public void close(){
171171
}
172172
}
173173

174-
private void init(final Response response) {
174+
private void initFromQueryResponse(final Response response) {
175175
init(response._flags, response.cursor(), response.size(), response.iterator());
176176
}
177177

src/test/com/mongodb/AggregationTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public void testDollarOutOnSecondary() throws UnknownHostException {
199199
AggregationOptions options = AggregationOptions.builder()
200200
.outputMode(OutputMode.CURSOR)
201201
.build();
202-
MongoCursor cursor = verify(pipeline, options, ReadPreference.secondary(), aggCollection);
202+
Cursor cursor = verify(pipeline, options, ReadPreference.secondary(), aggCollection);
203203
assertEquals(2, rsDatabase.getCollection("aggCollection").count());
204204
assertEquals(primary, cursor.getServerAddress());
205205
}
@@ -222,7 +222,7 @@ public void testAggregateOnSecondary() throws UnknownHostException {
222222
AggregationOptions options = AggregationOptions.builder()
223223
.outputMode(OutputMode.INLINE)
224224
.build();
225-
MongoCursor cursor = verify(pipeline, options, ReadPreference.secondary(), aggCollection);
225+
Cursor cursor = verify(pipeline, options, ReadPreference.secondary(), aggCollection);
226226
assertNotEquals(primary, cursor.getServerAddress());
227227
}
228228

@@ -266,9 +266,9 @@ private void verify(final List<DBObject> pipeline, final AggregationOptions opti
266266
verify(pipeline, options, readPreference, collection);
267267
}
268268

269-
private MongoCursor verify(final List<DBObject> pipeline, final AggregationOptions options, final ReadPreference readPreference,
269+
private Cursor verify(final List<DBObject> pipeline, final AggregationOptions options, final ReadPreference readPreference,
270270
final DBCollection collection) {
271-
final MongoCursor cursor = collection.aggregate(pipeline, options, readPreference);
271+
final Cursor cursor = collection.aggregate(pipeline, options, readPreference);
272272

273273
final Map<String, DBObject> results = new HashMap<String, DBObject>();
274274
while (cursor.hasNext()) {

0 commit comments

Comments
 (0)