List of usage examples for com.mongodb MongoException MongoException
public MongoException(final String msg, final Throwable t)
From source file:cc.acs.mongofs.gridfs.GridFSInputFile.java
License:Apache License
public void save(int chunkSize) { if (!_saved) { try {// ww w . ja v a2 s .co m saveChunks(chunkSize); } catch (IOException ioe) { throw new MongoException("couldn't save chunks", ioe); } } super.save(); }
From source file:com.github.nlloyd.hornofmongo.action.MongoScriptAction.java
License:Open Source License
public MongoScriptAction(MongoScope mongoScope, File script) { super(mongoScope); this.scriptName = script.getName(); try {/*from ww w . j ava 2s. c o m*/ this.scriptReader = new BufferedReader(new FileReader(script)); } catch (FileNotFoundException e) { throw new MongoException("Attempted to execute non-existent file " + script.getAbsolutePath(), e); } }
From source file:com.github.nlloyd.hornofmongo.action.MongoScriptAction.java
License:Open Source License
public MongoScriptAction(MongoScope mongoScope, String name, File script) { super(mongoScope); this.scriptName = name; try {/* ww w .j a v a 2s . c o m*/ this.scriptReader = new BufferedReader(new FileReader(script)); } catch (FileNotFoundException e) { throw new MongoException("Attempted to execute non-existent file " + script.getAbsolutePath(), e); } }
From source file:com.github.nlloyd.hornofmongo.action.MongoScriptAction.java
License:Open Source License
/** * Uses the provided context to execute either a String script, * /*from w w w . j a v a2s . co m*/ * @see org.mozilla.javascript.ContextAction#run(org.mozilla.javascript.Context) */ @Override public Object doRun(Context cx) { Object result = Undefined.instance; String script; if (StringUtils.isNotBlank(scriptString)) script = scriptString; else { try { script = readFully(scriptReader); } catch (IOException e) { throw new MongoException("IOException when executing a script in Reader form.", e); } } // this could be a command like "use", "show", or "help" which must be a // one-liner without a semi-colon line terminator boolean wasCmd = false; if (isOneLine(script)) { script = script.trim(); // special handling for: exit[;] and cls if (script.matches("^exit;?$")) { MongoScope.quit(cx, mongoScope, null, null); return result; } else if (script.equals("cls")) { MongoScope.clear(cx, mongoScope, null, null); return result; } String cmd = script; if (cmd.indexOf(' ') > 0) cmd = script.substring(0, cmd.indexOf(' ')); if (cmd.indexOf('"') == -1) { StringBuilder cmdCheck = new StringBuilder(); cmdCheck.append("__iscmd__ = shellHelper[\""); cmdCheck.append(cmd); cmdCheck.append("\"];"); cx.evaluateString(mongoScope, cmdCheck.toString(), "(shellhelp1)", 0, null); if (Context.toBoolean(ScriptableObject.getProperty(mongoScope, "__iscmd__"))) { StringBuilder cmdScript = new StringBuilder(); cmdScript.append("shellHelper( \""); cmdScript.append(cmd); cmdScript.append("\" , \""); cmdScript.append(script.substring(cmd.length())); cmdScript.append("\");"); try { cx.evaluateString(mongoScope, cmdScript.toString(), "(shellhelp2)", 0, null); } finally { wasCmd = true; } } } } if (!wasCmd) { result = cx.evaluateString(mongoScope, script, scriptName, 0, null); } return result; }
From source file:com.lowereast.guiceymongo.GuiceyCollection.java
License:Apache License
public Item findAndModify(DBObject query, DBObject update, DBObject sort, boolean returnNewValue, FieldSet fields, boolean upsert) { DBObject command = new BasicDBObject("findandmodify", _collection.getName()).append("update", update); if (query != null && !EMPTY.equals(query)) command.put("query", query); if (sort != null && !EMPTY.equals(sort)) command.put("sort", sort); if (returnNewValue) command.put("new", true); if (fields != null) command.put("fields", fields.build()); if (upsert)/* www . j av a 2 s. c o m*/ command.put("upsert", upsert); DBObject result = _collection.getDB().command(command); if (result.containsField("ok")) return _wrapper.wrap((DBObject) result.get("value")); throw new MongoException((Integer) result.get("code"), (String) result.get("errmsg")); }
From source file:com.lowereast.guiceymongo.GuiceyCollection.java
License:Apache License
public Item findAndRemove(DBObject query, DBObject sort) { DBObject command = new BasicDBObject("findandmodify", _collection.getName()).append("remove", true); if (query != null && !EMPTY.equals(query)) command.put("query", query); if (sort != null && !EMPTY.equals(sort)) command.put("sort", sort); DBObject result = _collection.getDB().command(command); if (1 == (Integer) result.get("ok")) return _wrapper.wrap((DBObject) result.get("value")); throw new MongoException((Integer) result.get("code"), (String) result.get("errmsg")); }
From source file:com.opengamma.util.mongo.MongoConnectorFactoryBean.java
License:Open Source License
/** * Creates the Mongo instance, using the host and port. * /*from w w w . java 2 s . co m*/ * @return the Mongo instance, not null */ protected MongoClient createMongo() { final MongoClient mongo = getMongo(); // store in variable to protect against change by subclass if (mongo != null) { return mongo; } final String host = getHost(); // store in variable to protect against change by subclass final int port = getPort(); // store in variable to protect against change by subclass ArgumentChecker.notNull(host, "host"); try { return new MongoClient(host, port); } catch (UnknownHostException ex) { throw new MongoException(ex.getMessage(), ex); } }
From source file:com.streamreduce.storm.MongoClient.java
License:Apache License
/** * Initializes the {@link Mongo} object. * * @param host the host MongoDB is expected to be running on * @param port the port MongoDB is expected to be listening on * @param username the username to authenticate as * @param password the password to the username above *//*from w ww . j a v a 2 s. c o m*/ private void init(String host, int port, String username, String password) { this.host = host; this.port = port; this.username = username; this.password = password; logger.info("Mongo Client Connecting to " + host + ":" + port); try { MongoOptions options = new MongoOptions(); options.autoConnectRetry = true; //options.connectionsPerHost = 50; options.connectTimeout = 1500; options.socketTimeout = 60000; options.threadsAllowedToBlockForConnectionMultiplier = 1000; //options.connectionsPerHost = 50; // * 5, so up to 250 can wait before it dies this.mongo = new Mongo(new ServerAddress(host, port), options); } catch (UnknownHostException e) { MongoException me = new MongoException("Unable to connect to Mongo at " + host + ":" + port, e); logger.error(me.getMessage(), me); throw me; } }
From source file:edu.umass.cs.gnsserver.database.MongoRecords.java
License:Apache License
private DBObject parseMongoQuery(String query, ColumnField valuesMapField) { // convert something like this: ~fred : ($gt: 0) into the queryable // format, namely this: {~nr_valuesMap.fred : ($gt: 0)} String edittedQuery = query;/*from ww w.ja v a 2s.com*/ edittedQuery = "{" + edittedQuery + "}"; edittedQuery = edittedQuery.replace("(", "{"); edittedQuery = edittedQuery.replace(")", "}"); edittedQuery = edittedQuery.replace("~", valuesMapField.getName() + "."); // Filter out HRN records String guidFilter = "{" + NameRecord.VALUES_MAP.getName() + "." + AccountAccess.GUID_INFO + ": { $exists: true}}"; edittedQuery = buildAndQuery(guidFilter, edittedQuery); try { DatabaseConfig.getLogger().log(Level.FINE, "{0} Edited query = {1}", new Object[] { dbName, edittedQuery }); DBObject parse = (DBObject) JSON.parse(edittedQuery); DatabaseConfig.getLogger().log(Level.FINE, "{0} Parse = {1}", new Object[] { dbName, parse.toString() }); return parse; } catch (Exception e) { throw new MongoException("Unable to parse query", e); } }
From source file:io.manasobi.commons.config.MongoDBConfig.java
@Bean public Jongo jongo() { DB db;/*from w ww .j av a 2 s . co m*/ try { //db = new MongoClient("127.0.0.1", 27017).getDB("manasobi"); db = new MongoClient(host, port).getDB(database); } catch (UnknownHostException e) { throw new MongoException("Connection error : ", e); } return new Jongo(db); }