Skip to content

Commit 40743ca

Browse files
author
Brendan W. McAdams
committed
JAVA-428 - Support new ReadPreference semantics, deprecate SlaveOK
* Cull exceess overloaded methods specifically the ones with ReadPreference
1 parent c715a13 commit 40743ca

File tree

2 files changed

+6
-98
lines changed

2 files changed

+6
-98
lines changed

src/main/com/mongodb/DBCollection.java

Lines changed: 5 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -315,21 +315,9 @@ public final DBCursor find( DBObject query , DBObject fields , int numToSkip , i
315315
*/
316316
public final DBObject findOne( Object obj )
317317
throws MongoException {
318-
return findOne(obj, null, _readPref);
318+
return findOne(obj, null);
319319
}
320320

321-
/**
322-
* Finds an object by its id.
323-
* This compares the passed in value to the _id field of the document
324-
*
325-
* @param obj any valid object
326-
* @return the object, if found, otherwise <code>null</code>
327-
* @throws MongoException
328-
*/
329-
public final DBObject findOne( Object obj , ReadPreference readPref )
330-
throws MongoException {
331-
return findOne(obj, null, readPref);
332-
}
333321

334322
/**
335323
* Finds an object by its id.
@@ -341,20 +329,7 @@ public final DBObject findOne( Object obj , ReadPreference readPref )
341329
* @dochub find
342330
*/
343331
public final DBObject findOne( Object obj, DBObject fields ) {
344-
return findOne( obj, fields, _readPref );
345-
}
346-
347-
/**
348-
* Finds an object by its id.
349-
* This compares the passed in value to the _id field of the document
350-
*
351-
* @param obj any valid object
352-
* @param fields fields to return
353-
* @return the object, if found, otherwise <code>null</code>
354-
* @dochub find
355-
*/
356-
public final DBObject findOne( Object obj, DBObject fields, ReadPreference readPref ) {
357-
Iterator<DBObject> iterator = __find(new BasicDBObject("_id", obj), fields, 0, -1, 0, getOptions(), readPref, _decoderFactory.create() );
332+
Iterator<DBObject> iterator = __find(new BasicDBObject("_id", obj), fields, 0, -1, 0, getOptions(), _readPref, _decoderFactory.create() );
358333
return (iterator != null ? iterator.next() : null);
359334
}
360335

@@ -590,18 +565,7 @@ public void setHintFields( List<DBObject> lst ){
590565
* @dochub find
591566
*/
592567
public final DBCursor find( DBObject ref ){
593-
return find( ref, _readPref );
594-
}
595-
596-
/**
597-
* Queries for an object in this collection.
598-
* @param ref object for which to search
599-
* @param preference Read Preference for this write
600-
* @return an iterator over the results
601-
* @dochub find
602-
*/
603-
public final DBCursor find( DBObject ref, ReadPreference preference ){
604-
return new DBCursor( this, ref, null, preference );
568+
return new DBCursor( this, ref, null, _readPref );
605569
}
606570

607571
/**
@@ -628,52 +592,17 @@ public final DBCursor find( DBObject ref, ReadPreference preference ){
628592
* @dochub find
629593
*/
630594
public final DBCursor find( DBObject ref , DBObject keys ){
631-
return find( ref, keys, _readPref );
595+
return new DBCursor( this, ref, keys, _readPref );
632596
}
633597

634-
/**
635-
* Queries for an object in this collection.
636-
*
637-
* <p>
638-
* An empty DBObject will match every document in the collection.
639-
* Regardless of fields specified, the _id fields are always returned.
640-
* </p>
641-
* <p>
642-
* An example that returns the "x" and "_id" fields for every document
643-
* in the collection that has an "x" field:
644-
* </p>
645-
* <blockquote><pre>
646-
* BasicDBObject keys = new BasicDBObject();
647-
* keys.put("x", 1);
648-
*
649-
* DBCursor cursor = collection.find(new BasicDBObject(), keys);
650-
* </pre></blockquote>
651-
*
652-
* @param ref object for which to search
653-
* @param keys fields to return
654-
* @return a cursor to iterate over results
655-
* @dochub find
656-
*/
657-
public final DBCursor find( DBObject ref , DBObject keys, ReadPreference readPref ){
658-
return new DBCursor( this, ref, keys, readPref );
659-
}
660598

661599
/**
662600
* Queries for all objects in this collection.
663601
* @return a cursor which will iterate over every object
664602
* @dochub find
665603
*/
666604
public final DBCursor find(){
667-
return find( _readPref );
668-
}
669-
670-
/**
671-
* Queries for all objects in this collection.
672-
* @return a cursor which will iterate over every object
673-
* @dochub find
674-
*/
675-
public final DBCursor find( ReadPreference readPref ){
676-
return new DBCursor( this, new BasicDBObject(), null, readPref );
605+
return new DBCursor( this, null, null, _readPref );
677606
}
678607

679608
/**
@@ -686,16 +615,6 @@ public final DBObject findOne()
686615
return findOne( new BasicDBObject() );
687616
}
688617

689-
/**
690-
* Returns a single object from this collection.
691-
* @return the object found, or <code>null</code> if the collection is empty
692-
* @throws MongoException
693-
*/
694-
public final DBObject findOne( ReadPreference readPref )
695-
throws MongoException {
696-
return findOne( new BasicDBObject(), readPref );
697-
}
698-
699618
/**
700619
* Returns a single object from this collection matching the query.
701620
* @param o the query object
@@ -707,17 +626,6 @@ public final DBObject findOne( DBObject o )
707626
return findOne( o, null, _readPref );
708627
}
709628

710-
/**
711-
* Returns a single object from this collection matching the query.
712-
* @param o the query object
713-
* @return the object found, or <code>null</code> if no such object exists
714-
* @throws MongoException
715-
*/
716-
public final DBObject findOne( DBObject o, ReadPreference readPref )
717-
throws MongoException {
718-
return findOne( o, null, readPref );
719-
}
720-
721629
/**
722630
* Returns a single object from this collection matching the query.
723631
* @param o the query object

src/test/com/mongodb/ReplSetTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public static void main( String args[] )
8585
while ( true ){
8686
_sleep();
8787
try {
88-
DBObject x = c.findOne(new BasicDBObject( "_id", 17 ),
88+
DBObject x = c.findOne(new BasicDBObject( "_id", 17 ), null,
8989
ReadPreference.withTags( new BasicDBObject("dc", "proximacentauri") ));
9090
System.out.println( x );
9191
Integer n = (Integer) x.get( "x" );

0 commit comments

Comments
 (0)