List of usage examples for com.mongodb BasicDBObject get
public Object get(final String key)
From source file:com.ebay.cloud.cms.metadata.mongo.UpdateOptionCommand.java
License:Apache License
@Override public void execute(MetadataContext context) { Collection<IndexInfo> updateIndex = targetOption.getIndexes(); BasicDBObject query = new BasicDBObject(); query.append(MetaClass.NAME, metaClass.getName()); BasicDBObject update = new BasicDBObject(); BasicDBObject ups = new BasicDBObject(); BasicDBObject versionObject = new BasicDBObject(); versionObject.put("version", 1); update.put(MongoOperand.inc, versionObject); BasicDBObject options = (BasicDBObject) converter.toBson(targetOption); BasicDBObject indexOptions = (BasicDBObject) options.get("indexes"); if (!updateIndex.isEmpty()) { for (IndexInfo index : updateIndex) { if (index.isInternal()) { continue; }// w ww .j a v a2 s. c o m appendCommand(query, ups, indexOptions, index, context); } } update.append(getOperand(context), ups); try { boolean updated = MongoUtils.wrapperUpdate(dbCollection, query, update); if (!updated) { StringBuilder sb = new StringBuilder(); for (IndexInfo f : updateIndex) { // sb.append(Objects.toStringHelper(f).toString()); sb.append(f.getClass().getName()); } throw new IndexOptionOperationException(sb.toString()); } } catch (MongoException e) { throw new MongoOperationException(e); } }
From source file:com.ebay.cloud.cms.metadata.mongo.UpdateOptionCommand.java
License:Apache License
protected void appendSetCommand(BasicDBObject query, BasicDBObject ups, BasicDBObject indexOptions, IndexInfo index, boolean update) { String fieldKey = "options.indexes." + index.getIndexName(); query.append(fieldKey, new BasicDBObject(MongoOperand.exists, update)); ups.append(fieldKey, indexOptions.get(index.getIndexName())); }
From source file:com.ebay.cloud.cms.query.metadata.AggregateMetaAttribute.java
License:Apache License
@JsonIgnore private Object getFieldValue(IEntity currentEntity) { BasicDBObject dbo = (BasicDBObject) currentEntity.getNode(); Object value = null;/*from w w w . j av a 2 s.co m*/ if (groupField != null) { value = ((DBObject) dbo.get("_id")).get(groupField.getFieldName()); } else { value = dbo.get(aggregationField.getFieldName()); } return value; }
From source file:com.ebay.cloud.cms.query.metadata.AggregateMetaAttribute.java
License:Apache License
@JsonIgnore private boolean hasFieldValue(IEntity currentEntity) { BasicDBObject dbo = (BasicDBObject) currentEntity.getNode(); if (groupField != null) { return ((DBObject) dbo.get("_id")).containsField(groupField.getFieldName()); } else {/*from ww w .jav a 2s. c o m*/ return dbo.containsField(aggregationField.getFieldName()); } }
From source file:com.edgytech.umongo.AggregateDialog.java
License:Apache License
@Override protected void updateComponentCustom(JDialog old) { BasicDBObject cmd = (BasicDBObject) JSON.parse(pipeline); if (cmd != null && cmd.containsField("pipeline")) { BasicDBList list = (BasicDBList) cmd.get("pipeline"); operationList.clear();//from w w w .j a va 2 s.c o m for (Object op : list) { operationList.add((BasicDBObject) op); } refreshAggList(); } }
From source file:com.edgytech.umongo.CollectionPanel.java
License:Apache License
public void mapReduce(final ButtonBase button) { final DBCollection col = getCollectionNode().getCollection(); String map = getStringFieldValue(Item.mrMap); String reduce = getStringFieldValue(Item.mrReduce); String finalize = getStringFieldValue(Item.mrFinalize); String stype = getStringFieldValue(Item.mrType); final OutputType type = OutputType.valueOf(stype.toUpperCase()); String out = getStringFieldValue(Item.mrOut); if (type != OutputType.INLINE && (out.isEmpty())) { new InfoDialog(id, null, null, "Output collection cannot be empty if type is not inline.").show(); return;// w ww.j av a 2 s. c om } String outDB = getStringFieldValue(Item.mrOutDB); DBObject query = ((DocBuilderField) getBoundUnit(Item.mrQuery)).getDBObject(); int limit = getIntFieldValue(Item.mrLimit); final MapReduceCommand cmd = new MapReduceCommand(col, map, reduce, out, type, query); DBObject sort = ((DocBuilderField) getBoundUnit(Item.mrSort)).getDBObject(); if (sort != null) { cmd.setSort(sort); } if (!outDB.isEmpty()) { cmd.setOutputDB(outDB); } if (!finalize.isEmpty()) { cmd.setFinalize(finalize); } if (limit > 0) { cmd.setLimit(limit); } if (getBooleanFieldValue(Item.mrJSMode)) { cmd.addExtraOption("jsMode", true); } final BasicDBObject cmdobj = (BasicDBObject) cmd.toDBObject(); if (getBooleanFieldValue(Item.mrOutSharded)) { ((BasicDBObject) cmdobj.get("out")).put("sharded", true); } if (getBooleanFieldValue(Item.mrNonAtomic)) { ((BasicDBObject) cmdobj.get("out")).put("nonAtomic", true); } new DbJob() { MapReduceOutput output; @Override public Object doRun() { // output = col.mapReduce(cmd); // if type in inline, then query options like slaveOk is fine CommandResult res = null; if (type == MapReduceCommand.OutputType.INLINE) { res = col.getDB().command(cmdobj, col.getOptions()); return res; } res = col.getDB().command(cmdobj); res.throwOnError(); output = new MapReduceOutput(col, cmdobj, res); return output; } @Override public void wrapUp(Object res) { if (output != null) { if (cmd.getOutputType() == OutputType.INLINE) { res = output.results(); } else { // spawn a find doFind(output.getOutputCollection(), null); res = output.getRaw(); } } super.wrapUp(res); } @Override public String getNS() { return col.getFullName(); } @Override public String getShortName() { return "MR"; } @Override public DBObject getRoot(Object result) { return cmdobj; } @Override public ButtonBase getButton() { return button; } @Override DBObject getCommand() { return cmdobj; } @Override DB getDB() { return col.getDB(); } }.addJob(); }
From source file:com.edgytech.umongo.CollectionPanel.java
License:Apache License
public void shardingDistribution(ButtonBase button) { final DB config = getCollectionNode().getCollection().getDB().getSisterDB("config"); new DbJob() { @Override/*w w w. j a va 2s . c om*/ public Object doRun() throws Exception { BasicDBObject result = new BasicDBObject(); BasicDBList shardList = new BasicDBList(); BasicDBObject stats = getStats(); BasicDBObject shards = (BasicDBObject) stats.get("shards"); if (shards == null || shards.isEmpty()) return null; long totalChunks = 0; long totalSize = stats.getLong("size"); long totalCount = stats.getLong("count"); for (Entry shard : shards.entrySet()) { String shardName = (String) shard.getKey(); BasicDBObject shardStats = (BasicDBObject) shard.getValue(); BasicDBObject query = new BasicDBObject("ns", getCollectionNode().getCollection().getFullName()); query.put("shard", shardName); long numChunks = config.getCollection("chunks").count(query); totalChunks += numChunks; double estChunkData = numChunks <= 0 ? 0 : shardStats.getLong("size") / numChunks; long estChunkCount = numChunks <= 0 ? 0 : (long) Math.floor(shardStats.getLong("count") / numChunks); BasicDBObject shardDetails = new BasicDBObject("shard", shardName); shardDetails.put("data", shardStats.getLong("size")); shardDetails.put("pctData", totalSize <= 0 ? 0 : (shardStats.getLong("size") * 100.0) / totalSize); shardDetails.put("docs", shardStats.getLong("count")); shardDetails.put("pctDocs", totalCount <= 0 ? 0 : (shardStats.getLong("count") * 100.0) / totalCount); shardDetails.put("chunks", numChunks); if (shardStats.containsField("avgObjSize")) shardDetails.put("avgDocSize", shardStats.getDouble("avgObjSize")); shardDetails.put("estimatedDataPerChunk", estChunkData); shardDetails.put("estimatedDocsPerChunk", estChunkCount); shardList.add(shardDetails); } result.put("shards", shardList); BasicDBObject total = new BasicDBObject(); total.put("data", totalSize); total.put("docs", totalCount); total.put("chunks", totalChunks); total.put("avgDocSize", stats.getDouble("avgObjSize")); result.put("total", total); return result; } @Override public String getNS() { return getCollectionNode().getCollection().getFullName(); } @Override public String getShortName() { return "Sharding Distribution"; } }.addJob(); }
From source file:com.edgytech.umongo.CollectionPanel.java
License:Apache License
public void removeTagRange(ButtonBase button) { final DB config = getCollectionNode().getCollection().getDB().getSisterDB("config"); final DBCollection col = config.getCollection("tags"); final String ns = getCollectionNode().getCollection().getFullName(); String value = getComponentStringFieldValue(Item.tagRangeList); BasicDBObject range = (BasicDBObject) JSON.parse(value); final DBObject min = (DBObject) range.get("min"); final DBObject doc = new BasicDBObject("_id", new BasicDBObject("ns", ns).append("min", min)); new DbJob() { @Override/* w w w . ja v a 2 s. c om*/ public Object doRun() { return col.remove(doc); } @Override public String getNS() { return ns; } @Override public String getShortName() { return "Remove Tag Range"; } @Override public DBObject getRoot(Object result) { BasicDBObject root = new BasicDBObject("doc", doc); return root; } @Override public void wrapUp(Object res) { super.wrapUp(res); refreshTagRangeList(); } }.addJob(); }
From source file:com.edgytech.umongo.EditAggGeoNearDialog.java
License:Apache License
@Override public void setParameters(Object value) { BasicDBObject cmd = (BasicDBObject) value; ((DocBuilderField) getBoundUnit(Item.near)).setDBObject((DBObject) cmd.get("near")); setStringFieldValue(Item.distanceField, cmd.getString("distanceField")); setDoubleFieldValue(Item.maxDistance, cmd.getDouble("maxDistance")); if (cmd.containsField("distanceMultiplier")) { setDoubleFieldValue(Item.distanceMultiplier, cmd.getDouble("distanceMultiplier")); }//from ww w .j a v a 2 s . c o m if (cmd.containsField("query")) { ((DocBuilderField) getBoundUnit(Item.query)).setDBObject((DBObject) cmd.get("query")); } if (cmd.containsField("spherical")) { setBooleanFieldValue(Item.spherical, cmd.getBoolean("spherical")); } if (cmd.containsField("query")) { ((DocBuilderField) getBoundUnit(Item.query)).setDBObject((DBObject) cmd.get("query")); } if (cmd.containsField("includeLocs")) { setStringFieldValue(Item.includeLocs, cmd.getString("includeLocs")); } if (cmd.containsField("uniqueDocs")) { setBooleanFieldValue(Item.uniqueDocs, cmd.getBoolean("uniqueDocs")); } }
From source file:com.edgytech.umongo.IndexPanel.java
License:Apache License
public void settings(ButtonBase button) { FormDialog dialog = (FormDialog) ((MenuItem) getBoundUnit(Item.settings)).getDialog(); BasicDBObject index = (BasicDBObject) getIndexInfo(); boolean isTTL = false; long ttl = 0; if (index.containsField("expireAfterSeconds")) { isTTL = true;/*from w w w . j a v a 2 s . c o m*/ ttl = index.getLong("expireAfterSeconds"); } setLongFieldValue(Item.expireAfterSeconds, ttl); if (!dialog.show()) return; long newTTL = getLongFieldValue(Item.expireAfterSeconds); if (newTTL != ttl) { BasicDBObject cmd = new BasicDBObject("collMod", getIndexNode().getCollectionNode().getCollection().getName()); BasicDBObject param = new BasicDBObject(); param.put("keyPattern", (DBObject) index.get("key")); param.put("expireAfterSeconds", newTTL); cmd.put("index", param); new DbJobCmd(getIndexNode().getCollectionNode().getCollection().getDB(), cmd).addJob(); } }