Browse files

issue35: add support for query hints

  • Loading branch information...
1 parent 51f0fc6 commit 731b89376beac6d27e85278fa37a2bb593b51dcb @agirbal committed Nov 16, 2011
View
1 resource/xml/JMongoBrowser.xml
@@ -340,6 +340,7 @@
<IntSpinner id="findSkip" label="Skip" minValue="0" value="0" toolTipText="Number of documents to skip"/>
<IntSpinner id="findLimit" label="Limit" minValue="0" value="0" toolTipText="Maximum number of documents to return"/>
<IntSpinner id="findBatchSize" label="Batch Size" value="0" toolTipText="If positive, the ideal batch size to return from server. If negative, instructs the server to close the cursor after 1 batch of given size."/>
+ <org.mongo.jmongob.DocBuilderField id="findHint" label="Hint" toolTipText="Object with keys that represent the index to use. Use '$natural' to force full scan."/>
<CheckBox id="findExplain" label="Explain" toolTipText="Explain the find processing"/>
<CheckBox id="findExport" label="Export to File" toolTipText="Export to file, like mongoexport utility"/>
</FormDialog>
View
22 src/org/mongo/jmongob/CollectionPanel.java
@@ -4,14 +4,12 @@
*/
package org.mongo.jmongob;
-import com.edgytech.swingfast.CheckBox;
import com.edgytech.swingfast.ComboBox;
import com.edgytech.swingfast.ConfirmDialog;
import com.edgytech.swingfast.EnumListener;
import com.edgytech.swingfast.FormDialog;
import com.edgytech.swingfast.InfoDialog;
import com.edgytech.swingfast.MenuItem;
-import com.edgytech.swingfast.Showable;
import com.edgytech.swingfast.TreeNodeLabel;
import com.edgytech.swingfast.XmlComponentUnit;
import com.mongodb.BasicDBList;
@@ -34,7 +32,6 @@
import java.util.List;
import java.util.logging.Level;
import javax.swing.JPanel;
-import org.bson.BSONObject;
import org.mongo.jmongob.CollectionPanel.Item;
/**
@@ -68,6 +65,7 @@
findBatchSize,
findExplain,
findExport,
+ findHint,
findOne,
foQuery,
foFields,
@@ -194,6 +192,7 @@ public void find() {
DBObject query = ((DocBuilderField) getBoundUnit(Item.findQuery)).getDBObject();
DBObject fields = ((DocBuilderField) getBoundUnit(Item.findFields)).getDBObject();
DBObject sort = ((DocBuilderField) getBoundUnit(Item.findSort)).getDBObject();
+ DBObject hint = ((DocBuilderField) getBoundUnit(Item.findHint)).getDBObject();
int skip = getIntFieldValue(Item.findSkip);
int limit = getIntFieldValue(Item.findLimit);
int bs = getIntFieldValue(Item.findBatchSize);
@@ -202,7 +201,7 @@ public void find() {
if (export) {
exportToFile(col, query, fields, sort, skip, limit, bs);
} else {
- doFind(col, query, fields, sort, skip, limit, bs, explain);
+ doFind(col, query, fields, sort, skip, limit, bs, explain, hint);
}
}
@@ -355,7 +354,7 @@ public void wrapUp(Object res) {
res = output.results();
} else {
// spawn a find
- doFind(output.getOutputCollection(), null, null, null, 0, 0, 0, false);
+ doFind(output.getOutputCollection(), null);
res = output.getRaw();
}
}
@@ -379,7 +378,11 @@ public Object getRoot(Object result) {
}.addJob();
}
- static void doFind(final DBCollection col, final DBObject query, final DBObject fields, final DBObject sort, final int skip, final int limit, final int batchSize, final boolean explain) {
+ static void doFind(final DBCollection col, final DBObject query) {
+ doFind(col, query, null, null, 0, 0, 0, false, null);
+ }
+
+ static void doFind(final DBCollection col, final DBObject query, final DBObject fields, final DBObject sort, final int skip, final int limit, final int batchSize, final boolean explain, final DBObject hint) {
new DbJob() {
@Override
@@ -392,6 +395,9 @@ public Object doRun() {
if (limit > 0) {
cur.limit(limit);
}
+ if (hint != null) {
+ cur.hint(hint);
+ }
if (explain) {
return cur.explain();
}
@@ -949,13 +955,13 @@ public void reIndex() {
public void shardingInfo() {
final DB config = getCollectionNode().getCollection().getDB().getSisterDB("config");
final DBCollection col = config.getCollection("collections");
- CollectionPanel.doFind(col, new BasicDBObject("_id", getCollectionNode().getCollection().getFullName()), null, null, 0, 0, 0, false);
+ CollectionPanel.doFind(col, new BasicDBObject("_id", getCollectionNode().getCollection().getFullName()));
}
public void findChunks() {
final DB config = getCollectionNode().getCollection().getDB().getSisterDB("config");
final DBCollection col = config.getCollection("chunks");
- CollectionPanel.doFind(col, new BasicDBObject("ns", getCollectionNode().getCollection().getFullName()), null, null, 0, 0, 0, false);
+ CollectionPanel.doFind(col, new BasicDBObject("ns", getCollectionNode().getCollection().getFullName()));
}
public void moveChunk() {
View
1 src/org/mongo/jmongob/ConnectDialog.java
@@ -6,7 +6,6 @@
import com.edgytech.swingfast.FormDialog;
import com.mongodb.MongoOptions;
-import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
View
6 src/org/mongo/jmongob/DbPanel.java
@@ -473,7 +473,7 @@ public void shardingInfo() {
final DB db = getDbNode().getDb();
final DB config = db.getSisterDB("config");
final DBCollection col = config.getCollection("databases");
- CollectionPanel.doFind(col, new BasicDBObject("_id", db.getName()), null, null, 0, 0, 0, false);
+ CollectionPanel.doFind(col, new BasicDBObject("_id", db.getName()));
}
public void movePrimary() {
@@ -492,15 +492,15 @@ public void findJSFunction() {
DBObject query = new BasicDBObject();
if (name != null && !name.isEmpty())
query.put("_id", name);
- CollectionPanel.doFind(col, query, null, null, 0, 0, 0, false);
+ CollectionPanel.doFind(col, query);
}
public void addJSFunction() {
final DB db = getDbNode().getDb();
final DBCollection col = db.getCollection("system.js");
final String name = getStringFieldValue(Item.addJSFunctionName);
final String code = getStringFieldValue(Item.addJSFunctionCode);
- CollectionPanel.doFind(col, new BasicDBObject("_id", name), null, null, 0, 0, 0, false);
+ CollectionPanel.doFind(col, new BasicDBObject("_id", name));
new DbJob() {
View
4 src/org/mongo/jmongob/MongoPanel.java
@@ -257,14 +257,14 @@ public void cloneDB() {
public void currentOps() {
final Mongo mongo = getMongoNode().getMongo();
final DBObject query = ((DocBuilderField) getBoundUnit(Item.currentOpsQuery)).getDBObject();
- CollectionPanel.doFind(mongo.getDB("admin").getCollection("$cmd.sys.inprog"), query, null, null, 0, 0, 0, false);
+ CollectionPanel.doFind(mongo.getDB("admin").getCollection("$cmd.sys.inprog"), query);
}
public void killOp() {
final Mongo mongo = getMongoNode().getMongo();
final int opid = getIntFieldValue(Item.killOpId);
final DBObject query = new BasicDBObject("op", opid);
- CollectionPanel.doFind(mongo.getDB("admin").getCollection("$cmd.sys.killop"), query, null, null, 0, 0, 0, false);
+ CollectionPanel.doFind(mongo.getDB("admin").getCollection("$cmd.sys.killop"), query);
}
public void isMaster() {
View
4 src/org/mongo/jmongob/ServerPanel.java
@@ -133,14 +133,14 @@ public void setLogLevel() {
public void currentOps() {
final Mongo mongo = getServerNode().getServerMongo();
final DBObject query = ((DocBuilderField) getBoundUnit(Item.currentOpsQuery)).getDBObject();
- CollectionPanel.doFind(mongo.getDB("admin").getCollection("$cmd.sys.inprog"), query, null, null, 0, 0, 0, false);
+ CollectionPanel.doFind(mongo.getDB("admin").getCollection("$cmd.sys.inprog"), query);
}
public void killOp() {
final Mongo mongo = getServerNode().getServerMongo();
final int opid = getIntFieldValue(Item.killOpId);
final DBObject query = new BasicDBObject("op", opid);
- CollectionPanel.doFind(mongo.getDB("admin").getCollection("$cmd.sys.killop"), query, null, null, 0, 0, 0, false);
+ CollectionPanel.doFind(mongo.getDB("admin").getCollection("$cmd.sys.killop"), query);
}
}

0 comments on commit 731b893

Please sign in to comment.