List of usage examples for com.mongodb DBCollection getOptions
@Deprecated public int getOptions()
From source file:com.edgytech.umongo.CollectionPanel.java
License:Apache License
@Override protected void updateComponentCustom(JPanel old) { try {//from w ww . j a v a 2s . c om DBCollection collection = getCollectionNode().getCollection(); setStringFieldValue(Item.name, collection.getName()); setStringFieldValue(Item.fullName, collection.getFullName()); setStringFieldValue(Item.queryOptions, MongoUtils.queryOptionsToString(collection.getOptions())); ((DocField) getBoundUnit(Item.writeConcern)).setDoc(collection.getWriteConcern().getCommand()); ((DocField) getBoundUnit(Item.readPreference)).setDoc(collection.getReadPreference().toDBObject()); ((CmdField) getBoundUnit(Item.stats)).updateFromCmd(collection); } catch (Exception e) { UMongo.instance.showError(this.getClass().getSimpleName() + " update", e); } }
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;/* ww w . j a v a 2 s.co m*/ } 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 readWriteOptions(ButtonBase button) { final DBCollection col = getCollectionNode().getCollection(); OptionDialog od = UMongo.instance.getGlobalStore().getOptionDialog(); od.update(col.getOptions(), col.getWriteConcern(), col.getReadPreference()); if (!od.show()) { return;//from w w w . j a v a 2s . co m } col.setOptions(od.getQueryOptions()); col.setWriteConcern(od.getWriteConcern()); col.setReadPreference(od.getReadPreference()); refresh(); }
From source file:com.github.nlloyd.hornofmongo.adaptor.Mongo.java
License:Open Source License
@SuppressWarnings({ "unchecked", "rawtypes" }) @JSFunction/*from www .j a v a 2s .co m*/ public void insert(final String ns, Object obj, int options) { Object rawObj = BSONizer.convertJStoBSON(obj, true); DBObject bsonObj = null; if (rawObj instanceof DBObject) bsonObj = (DBObject) rawObj; try { int dbSeparatorIdx = ns.indexOf('.'); com.mongodb.DB db = innerMongo.getDB(ns.substring(0, dbSeparatorIdx)); String collectionName = ns.substring(dbSeparatorIdx + 1); DBCollection collection = db.getCollection(collectionName); collection.setDBEncoderFactory(HornOfMongoBSONEncoder.FACTORY); collection.setDBDecoderFactory(HornOfMongoBSONDecoder.FACTORY); // unfortunately the Java driver does not expose the _allow_dot // argument in insert calls so we need to translate system.indexes // inserts into index creation calls through the java driver if (collectionName.endsWith("system.indexes")) { db.getCollection("system.indexes").insert(Arrays.asList(bsonObj)); } else { int oldOptions = collection.getOptions(); collection.setOptions(options); List insertObj = null; if (rawObj instanceof List) insertObj = (List) rawObj; else insertObj = Arrays.asList(rawObj); collection.insert(insertObj); collection.setOptions(oldOptions); } saveLastCalledDB(db); } catch (MongoException me) { handleMongoException(me); } }