Skip to content

Commit

Permalink
- issue232: add usePowerOf2Sizes option to create collection
Browse files Browse the repository at this point in the history
- 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
agirbal committed Jun 19, 2014
1 parent 645de38 commit 44dfa90
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 130 deletions.
Binary file modified lib/SwingFast.jar
Binary file not shown.
5 changes: 3 additions & 2 deletions resource/xml/umongo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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/>
Expand Down Expand Up @@ -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/>
Expand Down
25 changes: 2 additions & 23 deletions src/com/edgytech/umongo/CollectionPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
28 changes: 19 additions & 9 deletions src/com/edgytech/umongo/DbJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand Down
18 changes: 17 additions & 1 deletion src/com/edgytech/umongo/DbJobCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,19 @@ public class DbJobCmd extends DbJob {
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();
Expand All @@ -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;
}

Expand Down Expand Up @@ -106,5 +118,9 @@ public void wrapUp(Object res) {
if (panel != null) {
panel.refresh();
}

if (node != null) {
node.structureComponent();
}
}
}
87 changes: 22 additions & 65 deletions src/com/edgytech/umongo/DbPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ enum Item {
createCollCapped,
createCollSize,
createCollCount,
createCollAutoIndex,
// createCollAutoIndex,
createCollUsePowerOf2Sizes,
enableSharding,
movePrimary,
mvpToShard,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
32 changes: 3 additions & 29 deletions src/com/edgytech/umongo/IndexPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion src/com/edgytech/umongo/MongoPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -172,6 +172,11 @@ public String getShortName() {
return "Create DB";
}

@Override
public DBObject getRoot(Object result) {
return new BasicDBObject("name", name);
}

@Override
public void wrapUp(Object res) {
super.wrapUp(res);
Expand Down

0 comments on commit 44dfa90

Please sign in to comment.