Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- issue39: add support for ReadPreference

  • Loading branch information...
commit 34bda750d3c9a03eab754969c4cb1cdf0330ad34 1 parent 83a442f
@agirbal authored
View
BIN  lib/SwingFast.jar
Binary file not shown
View
BIN  lib/bson.jar
Binary file not shown
View
BIN  lib/mongo.jar
Binary file not shown
View
2  package/version
@@ -1 +1 @@
-1-0-5
+1-0-6
View
3  resource/xml/JMongoBrowser.xml
@@ -29,6 +29,9 @@
<CheckBox id="fsync" value="false" toolTipText="Forces syncing of memory to disk on the server before acknowledgment of write operation success."/>
<CheckBox id="jsync" value="false" toolTipText="Waits that the data has been commited to the journal on disk."/>
</Div>
+ <Div id="readPreference">
+ <ComboBox id="rpPreference" label="Read Preference" items="None;Primary;Secondary" value="0" toolTipText="The read preference mode. Primary to read from master, Secondary to read from slaves."/>
+ </Div>
</TabbedDiv>
</org.mongo.jmongob.OptionDialog>
<org.mongo.jmongob.ErrorDialog id="errorDialog">
View
3  src/org/mongo/jmongob/CollectionPanel.java
@@ -521,12 +521,13 @@ public void wrapUp(Object res) {
public void options() {
final DBCollection col = getCollectionNode().getCollection();
OptionDialog od = JMongoBrowser.instance.getGlobalStore().getOptionDialog();
- od.update(col.getOptions(), col.getWriteConcern());
+ od.update(col.getOptions(), col.getWriteConcern(), col.getReadPreference());
if (!od.show()) {
return;
}
col.setOptions(od.getQueryOptions());
col.setWriteConcern(od.getWriteConcern());
+ col.setReadPreference(od.getReadPreference());
refresh();
}
View
3  src/org/mongo/jmongob/DbPanel.java
@@ -295,12 +295,13 @@ public void wrapUp(Object res) {
public void options() {
final DB db = getDbNode().getDb();
OptionDialog od = JMongoBrowser.instance.getGlobalStore().getOptionDialog();
- od.update(db.getOptions(), db.getWriteConcern());
+ od.update(db.getOptions(), db.getWriteConcern(), db.getReadPreference());
if (!od.show()) {
return;
}
db.setOptions(od.getQueryOptions());
db.setWriteConcern(od.getWriteConcern());
+ db.setReadPreference(od.getReadPreference());
refresh();
}
View
3  src/org/mongo/jmongob/MongoPanel.java
@@ -167,12 +167,13 @@ public void wrapUp(Object res) {
public void options() {
Mongo mongo = getMongoNode().getMongo();
OptionDialog od = JMongoBrowser.instance.getGlobalStore().getOptionDialog();
- od.update(mongo.getOptions(), mongo.getWriteConcern());
+ od.update(mongo.getOptions(), mongo.getWriteConcern(), mongo.getReadPreference());
if (!od.show()) {
return;
}
mongo.setOptions(od.getQueryOptions());
mongo.setWriteConcern(od.getWriteConcern());
+ mongo.setReadPreference(od.getReadPreference());
refresh();
}
View
26 src/org/mongo/jmongob/OptionDialog.java
@@ -5,10 +5,12 @@
package org.mongo.jmongob;
+import com.edgytech.swingfast.ComboBox;
import com.edgytech.swingfast.FormDialog;
import com.mongodb.Bytes;
import com.mongodb.MongoException;
import com.mongodb.MongoOptions;
+import com.mongodb.ReadPreference;
import com.mongodb.WriteConcern;
/**
@@ -27,14 +29,15 @@
writePolicy,
writeTimeout,
fsync,
- jsync
+ jsync,
+ rpPreference
}
public OptionDialog() {
setEnumBinding(Item.values(), null);
}
- void update(int options, WriteConcern wc) {
+ void update(int options, WriteConcern wc, ReadPreference rp) {
setBooleanFieldValue(Item.tailable, (options & Bytes.QUERYOPTION_TAILABLE) != 0);
setBooleanFieldValue(Item.slaveOk, (options & Bytes.QUERYOPTION_SLAVEOK) != 0);
setBooleanFieldValue(Item.opLogReplay, (options & Bytes.QUERYOPTION_OPLOGREPLAY) != 0);
@@ -49,6 +52,14 @@ void update(int options, WriteConcern wc) {
setStringFieldValue(Item.writePolicy, wStr);
setIntFieldValue(Item.writeTimeout, wc.getWtimeout());
setBooleanFieldValue(Item.fsync, wc.fsync());
+
+ ComboBox readBox = (ComboBox) getBoundUnit(Item.rpPreference);
+ if (rp == null)
+ readBox.value = 0;
+ else if (rp instanceof ReadPreference.PrimaryReadPreference)
+ readBox.value = 1;
+ else if (rp instanceof ReadPreference.SecondaryReadPreference)
+ readBox.value = 2;
}
int getQueryOptions() {
@@ -72,4 +83,15 @@ WriteConcern getWriteConcern() {
return new WriteConcern(wPolicy, wtimeout, fsync, jsync);
return new WriteConcern(w, wtimeout, fsync, jsync);
}
+
+ ReadPreference getReadPreference() {
+ ComboBox readBox = (ComboBox) getBoundUnit(Item.rpPreference);
+ if (readBox.value == 0)
+ return null;
+ if (readBox.value == 1)
+ return ReadPreference.PRIMARY;
+ if (readBox.value == 2)
+ return ReadPreference.SECONDARY;
+ return null;
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.