Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- issue232: add usePowerOf2Sizes option to create collection

- issue233: make all create/drop consistent in behavior across entities
- issue234: make commandresult pop up window on exception, but still open a tab and log
  • Loading branch information...
commit 44dfa90603f41d3aac4b1c8e942d5fa93dc6b891 1 parent 645de38
@agirbal authored
View
BIN  lib/SwingFast.jar
Binary file not shown
View
5 resource/xml/umongo.xml
@@ -201,7 +201,8 @@
<CheckBox id="createCollCapped" label="Is Capped"/>
<IntField id="createCollSize" label="Max Size" toolTipText="If capped, maximum size in bytes"/>
<IntField id="createCollCount" label="Max Count" toolTipText="If capped, maximum number of documents"/>
- <CheckBox id="createCollAutoIndex" label="Auto Index Id" value="true" toolTipText="To automatically create an index on _id field, default is true"/>
+<!-- <CheckBox id="createCollAutoIndex" label="Auto Index Id" value="true" toolTipText="If true, automatically creates an index on _id field."/> -->
+ <CheckBox id="createCollUsePowerOf2Sizes" label="Use Power Of 2 Sizes" value="true" toolTipText="this options makes all document spaces a power of 2 which helps reduce fragmentation, but adds extra space for each document. Turn off if documents are static in nature."/>
</FormDialog>
</MenuItem>
<MenuSeparator/>
@@ -388,7 +389,7 @@
</MenuItem>
<MenuItem id="settings" call="settings" showDialog="false">
<FormDialog>
- <CheckBox id="usePowerOf2Sizes" label="Use Power Of 2 Sizes" value="false" toolTipText="usePowerOf2Sizes flags makes all document spaces a power of 2 which can help reduce fragmentation"/>
+ <CheckBox id="usePowerOf2Sizes" label="Use Power Of 2 Sizes" value="false" toolTipText="this options makes all document spaces a power of 2 which helps reduce fragmentation, but adds extra space for each document. Turn off if documents are static in nature."/>
</FormDialog>
</MenuItem>
<MenuSeparator/>
View
25 src/com/edgytech/umongo/CollectionPanel.java
@@ -620,29 +620,8 @@ public String getShortName() {
public void dropCollection(ButtonBase button) {
final CollectionNode colNode = getCollectionNode();
final DBCollection col = getCollectionNode().getCollection();
- new DbJob() {
- @Override
- public Object doRun() {
- col.drop();
- return null;
- }
-
- @Override
- public String getNS() {
- return col.getFullName();
- }
-
- @Override
- public String getShortName() {
- return "Drop";
- }
-
- @Override
- public void wrapUp(Object res) {
- super.wrapUp(res);
- colNode.removeNode();
- }
- }.addJob();
+ BasicDBObject cmd = new BasicDBObject( "drop" , col.getName() );
+ new DbJobCmd(col.getDB(), cmd, null, colNode.getDbNode(), null).addJob();
}
public void readWriteOptions(ButtonBase button) {
View
28 src/com/edgytech/umongo/DbJob.java
@@ -22,6 +22,7 @@
import java.util.Iterator;
import java.util.logging.Level;
import com.edgytech.umongo.DbJob.Item;
+import com.mongodb.CommandResult;
import com.mongodb.DB;
import com.mongodb.DBCursor;
import java.awt.Component;
@@ -182,6 +183,24 @@ public void wrapUp(Object res) {
if (logRes && res instanceof DBCursor) {
logObj.put("firstResult", ((DBCursor)res).curr());
}
+ } else if (res instanceof WriteResult) {
+ WriteResult wres = (WriteResult) res;
+ DBObject lasterr = wres.getCachedLastError();
+ if (lasterr != null) {
+ new DocView(null, title, this, sroot, lasterr).addToTabbedDiv();
+ }
+ if (logRes) {
+ logObj.put("firstResult", lasterr);
+ }
+ } else if (res instanceof CommandResult) {
+ CommandResult cres = (CommandResult) res;
+ if (!cres.ok()) {
+ UMongo.instance.showError(title, (Exception) cres.getException());
+ }
+ new DocView(null, title, this, sroot, (DBObject) res).addToTabbedDiv();
+ if (logRes) {
+ logObj.put("firstResult", res.toString());
+ }
} else if (res instanceof List) {
List list = (List) res;
new DocView(null, title, this, sroot, list.iterator()).addToTabbedDiv();
@@ -199,15 +218,6 @@ public void wrapUp(Object res) {
if (logRes) {
logObj.put("firstResult", MongoUtils.limitString((String)res, 0));
}
- } else if (res instanceof WriteResult) {
- WriteResult wres = (WriteResult) res;
- DBObject lasterr = wres.getCachedLastError();
- if (lasterr != null) {
- new DocView(null, title, this, sroot, lasterr).addToTabbedDiv();
- }
- if (logRes) {
- logObj.put("firstResult", lasterr);
- }
} else if (res instanceof Exception) {
UMongo.instance.showError(title, (Exception) res);
if (logRes) {
View
18 src/com/edgytech/umongo/DbJobCmd.java
@@ -27,8 +27,19 @@
DB db;
DBObject cmd;
BasePanel panel;
+ BaseTreeNode node;
ButtonBase button;
+ public DbJobCmd(DB db, DBObject cmd, BasePanel panel, BaseTreeNode node, ButtonBase button) {
+ this.id = null;
+ this.label = cmd.keySet().iterator().next();
+ this.db = db;
+ this.cmd = cmd;
+ this.panel = panel;
+ this.button = button;
+ this.node = node;
+ }
+
public DbJobCmd(DB db, DBObject cmd, BasePanel panel, ButtonBase button) {
this.id = null;
this.label = cmd.keySet().iterator().next();
@@ -53,7 +64,8 @@ public DbJobCmd(DBCollection col, String cmdStr) {
@Override
public Object doRun() {
CommandResult res = db.command(cmd);
- res.throwOnError();
+ // we want to pop up the exception, but still see the results...
+// res.throwOnError();
return res;
}
@@ -106,5 +118,9 @@ public void wrapUp(Object res) {
if (panel != null) {
panel.refresh();
}
+
+ if (node != null) {
+ node.structureComponent();
+ }
}
}
View
87 src/com/edgytech/umongo/DbPanel.java
@@ -91,7 +91,8 @@
createCollCapped,
createCollSize,
createCollCount,
- createCollAutoIndex,
+// createCollAutoIndex,
+ createCollUsePowerOf2Sizes,
enableSharding,
movePrimary,
mvpToShard,
@@ -349,31 +350,8 @@ public ButtonBase getButton() {
public void dropDatabase(ButtonBase button) {
final DbNode node = getDbNode();
final DB db = getDbNode().getDb();
- new DbJob() {
-
- @Override
- public Object doRun() {
- db.dropDatabase();
- return null;
- }
-
- @Override
- public String getNS() {
- return db.getName();
- }
-
- @Override
- public String getShortName() {
- return "Drop";
- }
-
- @Override
- public void wrapUp(Object res) {
- node.removeNode();
- node = null;
- super.wrapUp(res);
- }
- }.addJob();
+ BasicDBObject cmd = new BasicDBObject("dropDatabase", 1);
+ new DbJobCmd(db, cmd, null, node.getMongoNode(), null).addJob();
}
public void readWriteOptions(ButtonBase button) {
@@ -574,50 +552,29 @@ public void createCollection(final ButtonBase button) {
final boolean capped = getBooleanFieldValue(Item.createCollCapped);
final int size = getIntFieldValue(Item.createCollSize);
final int count = getIntFieldValue(Item.createCollCount);
- final boolean autoIndexId = getBooleanFieldValue(Item.createCollAutoIndex);
+// final boolean autoIndexId = getBooleanFieldValue(Item.createCollAutoIndex);
+ final boolean usePowerOf2Sizes = getBooleanFieldValue(Item.createCollUsePowerOf2Sizes);
- new DbJob() {
-
- @Override
- public Object doRun() throws IOException {
- DBObject opt = new BasicDBObject("capped", capped);
- if (capped) {
- if (size > 0) {
- opt.put("size", size);
- }
- if (count > 0) {
- opt.put("max", count);
- }
- }
- if (!autoIndexId) {
- opt.put("autoIndexId", false);
- }
- db.createCollection(name, opt);
- return null;
- }
-
- @Override
- public String getNS() {
- return db.getName();
+ DBObject createCmd = new BasicDBObject("create", name);
+ DBObject opt = new BasicDBObject("capped", capped);
+ if (capped) {
+ if (size > 0) {
+ opt.put("size", size);
}
-
- @Override
- public String getShortName() {
- return "Create Collection";
- }
-
- @Override
- public void wrapUp(Object res) {
- super.wrapUp(res);
- node.structureComponent();
+ if (count > 0) {
+ opt.put("max", count);
}
+ }
- @Override
- public ButtonBase getButton() {
- return button;
- }
- }.addJob();
+// // deprecated
+// if (!autoIndexId) {
+// opt.put("autoIndexId", false);
+// }
+ // usePowerOf2Sizes uses flags name :(
+ opt.put("flags", usePowerOf2Sizes ? 1 : 0);
+ createCmd.putAll(opt);
+ new DbJobCmd(db, createCmd, null, node, button).addJob();
}
public void getStats(ButtonBase button) {
View
32 src/com/edgytech/umongo/IndexPanel.java
@@ -79,35 +79,9 @@ public void actionPerformed(Item enm, XmlComponentUnit unit, Object src) {
public void drop(ButtonBase button) {
final IndexNode indexNode = getIndexNode();
- new DbJob() {
-
- @Override
- public Object doRun() throws IOException {
- indexNode.getCollectionNode().getCollection().dropIndex(indexNode.getName());
- return null;
- }
-
- @Override
- public String getNS() {
- return getIndexNode().getIndexedCollection().getFullName();
- }
-
- @Override
- public String getShortName() {
- return "Drop Index";
- }
-
- @Override
- public DBObject getRoot(Object result) {
- return indexNode.getIndex();
- }
-
- @Override
- public void wrapUp(Object res) {
- super.wrapUp(res);
- indexNode.removeNode();
- }
- }.addJob();
+ DBObject cmd = new BasicDBObject("deleteIndexes", indexNode.getCollectionNode().getCollection().getName());
+ cmd.put("index", indexNode.getName());
+ new DbJobCmd(indexNode.getCollectionNode().getDbNode().getDb(), cmd, null, indexNode.getCollectionNode(), null).addJob();
}
public void getStats(ButtonBase button) {
View
7 src/com/edgytech/umongo/MongoPanel.java
@@ -159,7 +159,7 @@ public void createDB(ButtonBase button) {
@Override
public Object doRun() throws IOException {
db.getStats();
- return null;
+ return new BasicDBObject("ok", 1);
}
@Override
@@ -173,6 +173,11 @@ public String getShortName() {
}
@Override
+ public DBObject getRoot(Object result) {
+ return new BasicDBObject("name", name);
+ }
+
+ @Override
public void wrapUp(Object res) {
super.wrapUp(res);
getMongoNode().structureComponent();

0 comments on commit 44dfa90

Please sign in to comment.
Something went wrong with that request. Please try again.