Skip to content

Commit 82d796d

Browse files
JAVA-352: fix hint(DBObject) to passthrough
1 parent 245b4d7 commit 82d796d

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/main/com/mongodb/DBCursor.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import java.util.*;
2222

23-
import com.mongodb.DBApiLayer.MyCollection;
2423
import com.mongodb.DBApiLayer.Result;
2524

2625

@@ -82,6 +81,7 @@ public DBCursor copy() {
8281
DBCursor c = new DBCursor(_collection, _query, _keysWanted);
8382
c._orderBy = _orderBy;
8483
c._hint = _hint;
84+
c._hintDBObj = _hintDBObj;
8585
c._limit = _limit;
8686
c._skip = _skip;
8787
c._options = _options;
@@ -137,17 +137,14 @@ public DBCursor addSpecial( String name , Object o ){
137137

138138
/**
139139
* Informs the database of indexed fields of the collection in order to improve performance.
140-
* @param indexKeys a <code>DBObject</code> with index names as keys
140+
* @param indexKeys a <code>DBObject</code> with fields and direction
141141
* @return same DBCursor for chaining operations
142142
*/
143143
public DBCursor hint( DBObject indexKeys ){
144144
if ( _it != null )
145145
throw new IllegalStateException( "can't hint after executing query" );
146146

147-
if ( indexKeys == null )
148-
_hint = null;
149-
else
150-
_hint = DBCollection.genIndexName( indexKeys );
147+
_hintDBObj = indexKeys;
151148
return this;
152149
}
153150

@@ -343,7 +340,10 @@ private void _check()
343340

344341
_addToQueryObject( foo , "query" , _query , true );
345342
_addToQueryObject( foo , "orderby" , _orderBy , false );
346-
_addToQueryObject( foo , "$hint" , _hint );
343+
if(_hint != null)
344+
_addToQueryObject( foo , "$hint" , _hint );
345+
if(_hintDBObj != null)
346+
_addToQueryObject( foo , "$hint" , _hintDBObj);
347347

348348
if ( _explain )
349349
foo.put( "$explain" , true );
@@ -392,7 +392,7 @@ boolean hasSpecialQueryFields(){
392392
if ( _orderBy != null && _orderBy.keySet().size() > 0 )
393393
return true;
394394

395-
if ( _hint != null || _snapshot )
395+
if ( _hint != null || _hintDBObj != null || _snapshot )
396396
return true;
397397

398398
return _explain;
@@ -700,6 +700,7 @@ public String toString() {
700700

701701
private DBObject _orderBy = null;
702702
private String _hint = null;
703+
private DBObject _hintDBObj = null;
703704
private boolean _explain = false;
704705
private int _limit = 0;
705706
private int _batchSize = 0;

0 commit comments

Comments
 (0)