List of usage examples for com.mongodb DBObject get
Object get(String key);
From source file:com.edgytech.umongo.DocFieldObject.java
License:Apache License
@Override protected void structureComponentCustom(BoxPanel old) { Div fields = (Div) getBoundUnit(Item.fields); fields.removeAllChildren();//from w w w. j a va 2s . c o m DBObject doc = (DBObject) value; if (doc == null || doc.keySet().isEmpty()) { fields.addChild(new Text(null, null, "Empty")); } else { for (String key : doc.keySet()) { Object val = doc.get(key); if (val instanceof BasicDBObject) { fields.addChild(new DocFieldObject(key, key, val, this)); } else if (val instanceof BasicDBList) { fields.addChild(new DocFieldArray(key, key, val, this)); } else { fields.addChild(new DocFieldText(key, key, val, this)); } } } fields.structureComponent(); super.structureComponentCustom(old); }
From source file:com.edgytech.umongo.DocFieldObject.java
License:Apache License
void moveUp(String key) { DBObject doc = (DBObject) value; value = createDBObject();/* www .ja v a2s . com*/ Iterator<String> it = doc.keySet().iterator(); String prev = it.next(); while (it.hasNext()) { String cur = it.next(); if (cur.equals(key)) { addField(cur, doc.get(cur)); cur = prev; } else { addField(prev, doc.get(prev)); } prev = cur; } addField(prev, doc.get(prev)); structureComponent(); }
From source file:com.edgytech.umongo.DocFieldObject.java
License:Apache License
void moveDown(String key) { DBObject doc = (DBObject) value; value = createDBObject();/*w w w.j a va 2s.c om*/ Iterator<String> it = doc.keySet().iterator(); while (it.hasNext()) { String cur = it.next(); if (cur.equals(key) && it.hasNext()) { String next = it.next(); addField(next, doc.get(next)); } addField(cur, doc.get(cur)); } structureComponent(); }
From source file:com.edgytech.umongo.DocumentDeserializer.java
License:Apache License
private void fillInTemplate(DBObject obj, List<String> values) { for (String field : obj.keySet()) { Object val = obj.get(field); if (val instanceof BasicDBObject) { fillInTemplate((BasicDBObject) val, values); } else if (val instanceof BasicDBList) { fillInTemplate((BasicDBList) val, values); } else if (val instanceof String) { String str = (String) val; if (str.startsWith("$")) { str = str.substring(1);//from ww w .j a v a2 s .co m int slash = str.indexOf("/"); String ref = str; String type = null; if (slash > 0) { ref = str.substring(0, slash); type = str.substring(slash + 1); } // find field index int index = 0; while (index < filter.length && !filter[index].equals(ref)) { ++index; } if (index >= filter.length) { continue; } String value = values.get(index); try { if (type == null || "JSON".equals(type)) { // this is typically used for quoted Strings obj.put(field, JSON.parse(value)); } else if ("String".equals(type)) { obj.put(field, value); } else if ("Date".equals(type)) { Long time = Long.valueOf(value); obj.put(field, new Date(time)); } else if ("Boolean".equals(type)) { obj.put(field, Boolean.valueOf(value)); } else if ("Integer".equals(type)) { obj.put(field, Integer.valueOf(value)); } else if ("Long".equals(type)) { obj.put(field, Long.valueOf(value)); } else if ("Double".equals(type)) { obj.put(field, Double.valueOf(value)); } } catch (Exception ex) { Logger.getLogger(DocumentDeserializer.class.getName()).log(Level.WARNING, null, ex); } } else { // this is a static value obj.put(field, val); } } else { // this is a static value obj.put(field, val); } } }
From source file:com.edgytech.umongo.DocumentFieldMenu.java
License:Apache License
public void setValue(ButtonBase button) { final DocView dv = (DocView) (UMongo.instance.getTabbedResult().getSelectedUnit()); if (dv.getDBCursor() == null) { // local data new InfoDialog(null, null, null, "Cannot do in-place update on local data.").show(); return;/* ww w.j av a 2 s. com*/ } TreeNodeDocumentField field = (TreeNodeDocumentField) dv.getSelectedNode().getUserObject(); DBObject doc = dv.getSelectedDocument(); String path = dv.getSelectedDocumentPath(); Object newValue = UMongo.instance.getGlobalStore().editValue(field.getKey(), field.getValue()); if (newValue == null) { // new InfoDialog(null, null, null, "Cannot edit this type of data.").show(); return; } final DBObject query = doc.containsField("_id") ? new BasicDBObject("_id", doc.get("_id")) : doc; DBObject setValue = new BasicDBObject(path, newValue); final DBObject update = new BasicDBObject("$set", setValue); final DBCollection col = dv.getDBCursor().getCollection(); new DbJob() { @Override public Object doRun() { return col.update(query, update, false, false); } @Override public String getNS() { return col.getFullName(); } @Override public String getShortName() { return "Update"; } @Override public DBObject getRoot(Object result) { BasicDBObject obj = new BasicDBObject("query", query); obj.put("update", update); return obj; } @Override public void wrapUp(Object res) { super.wrapUp(res); dv.refresh(null); } }.addJob(); }
From source file:com.edgytech.umongo.DocumentFieldMenu.java
License:Apache License
public void unsetValue(ButtonBase button) { final DocView dv = (DocView) (UMongo.instance.getTabbedResult().getSelectedUnit()); DBObject doc = dv.getSelectedDocument(); String path = dv.getSelectedDocumentPath(); if (dv.getDBCursor() == null) { // local data new InfoDialog(null, null, null, "Cannot do in-place update on local data.").show(); return;/* w w w. j a v a 2s . co m*/ } if (!UMongo.instance.getGlobalStore().confirmDataLossOperation()) return; final DBObject query = doc.containsField("_id") ? new BasicDBObject("_id", doc.get("_id")) : doc; DBObject setValue = new BasicDBObject(path, 1); final DBObject update = new BasicDBObject("$unset", setValue); final DBCollection col = dv.getDBCursor().getCollection(); new DbJob() { @Override public Object doRun() { return col.update(query, update, false, false); } @Override public String getNS() { return col.getFullName(); } @Override public String getShortName() { return "Update"; } @Override public DBObject getRoot(Object result) { BasicDBObject obj = new BasicDBObject("query", query); obj.put("update", update); return obj; } @Override public void wrapUp(Object res) { super.wrapUp(res); dv.refresh(null); } }.addJob(); }
From source file:com.edgytech.umongo.DocumentMenu.java
License:Apache License
public void update(ButtonBase button) { final DocView dv = (DocView) (UMongo.instance.getTabbedResult().getSelectedUnit()); TreeNodeDocument node = (TreeNodeDocument) dv.getSelectedNode().getUserObject(); final DBObject doc = node.getDBObject(); ((DocBuilderField) getBoundUnit(Item.upUpdate)).setDBObject((BasicDBObject) doc); if (!((MenuItem) getBoundUnit(Item.update)).getDialog().show()) { return;//from w ww.ja va 2 s .c om } final DBObject query = doc.containsField("_id") ? new BasicDBObject("_id", doc.get("_id")) : doc; final DBObject update = ((DocBuilderField) getBoundUnit(Item.upUpdate)).getDBObject(); if (dv.getDBCursor() == null) { // local data Tree tree = dv.getTree(); tree.removeChild(node); dv.addDocument(update, null); tree.structureComponent(); tree.expandNode(tree.getTreeNode()); return; } final DBCollection col = dv.getDBCursor().getCollection(); new DbJob() { @Override public Object doRun() { return col.update(query, update, false, false); } @Override public String getNS() { return col.getFullName(); } @Override public String getShortName() { return "Update"; } @Override public DBObject getRoot(Object result) { BasicDBObject obj = new BasicDBObject("query", query); obj.put("update", update); return obj; } @Override public void wrapUp(Object res) { super.wrapUp(res); dv.refresh(null); } }.addJob(); }
From source file:com.edgytech.umongo.DocumentMenu.java
License:Apache License
public void remove(ButtonBase button) { final DocView dv = (DocView) (UMongo.instance.getTabbedResult().getSelectedUnit()); TreeNodeDocument node = (TreeNodeDocument) dv.getSelectedNode().getUserObject(); final DBObject doc = node.getDBObject(); if (dv.getDBCursor() == null) { // local data Tree tree = dv.getTree();//from w w w . j a va 2s.co m tree.removeChild(node); tree.structureComponent(); tree.expandNode(tree.getTreeNode()); return; } // go by _id if possible final DBObject query = doc.containsField("_id") ? new BasicDBObject("_id", doc.get("_id")) : doc; final DBCollection col = dv.getDBCursor().getCollection(); new DbJob() { @Override public Object doRun() { return col.remove(query); } @Override public String getNS() { return col.getFullName(); } @Override public String getShortName() { return "Remove"; } @Override public void wrapUp(Object res) { super.wrapUp(res); dv.refresh(null); } @Override public DBObject getRoot(Object result) { return query; } }.addJob(); }
From source file:com.edgytech.umongo.DocumentSerializer.java
License:Apache License
private Object getFieldValueRecursive(DBObject obj, String field) { if (field.indexOf(".") < 0) return obj.get(field); String[] tokens = field.split("\\."); for (int i = 0; i < tokens.length - 1; ++i) { String f = tokens[i];//from w w w.j ava 2 s .c o m if (!obj.containsField(f)) return null; Object o = obj.get(f); if (!DBObject.class.isInstance(o)) return null; obj = (DBObject) o; } return obj.get(tokens[tokens.length - 1]); }
From source file:com.edgytech.umongo.EditAggOpDialog.java
License:Apache License
public void setOperation(DBObject opObj) { setParameters(opObj.get(op)); }