List of usage examples for com.mongodb CommandResult get
public Object get(final String key)
From source file:com.hangum.tadpole.mongodb.core.editors.dbInfos.comosites.InstanceInformationComposite.java
License:Open Source License
/** * Show connection Information/* w ww. j a v a 2 s . co m*/ */ private void createCursorsChart(Composite cmpConnections, CommandResult commandResult) { Group compositeCursor = new Group(cmpConnections, SWT.NONE); compositeCursor.setLayout(new GridLayout(1, false)); compositeCursor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); compositeCursor.setText("Cursors"); ColorStream colors = Colors.cat20Colors(compositeCursor.getDisplay()).loop(); pieChartCursors = new PieChart(compositeCursor, SWT.NONE); GridLayout gl_grpConnectionInfo = new GridLayout(1, false); gl_grpConnectionInfo.verticalSpacing = 0; gl_grpConnectionInfo.horizontalSpacing = 0; gl_grpConnectionInfo.marginHeight = 0; gl_grpConnectionInfo.marginWidth = 0; pieChartCursors.setLayout(gl_grpConnectionInfo); pieChartCursors.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); pieChartCursors.setInnerRadius(0.1f); DBObject cursorCursors = (DBObject) commandResult.get("cursors"); int totalOpen = cursorCursors == null ? 0 : ENumberUtils.toInt(cursorCursors.get("totalOpen")); int clientCursors_size = cursorCursors == null ? 0 : ENumberUtils.toInt(cursorCursors.get("clientCursors_size")); int timedOut = cursorCursors == null ? 0 : ENumberUtils.toInt(cursorCursors.get("timedOut")); ChartItem itemTotalOpen = new ChartItem(pieChartCursors); itemTotalOpen.setText("Total Open (" + totalOpen + ")"); itemTotalOpen.setColor(colors.next()); itemTotalOpen.setValue(totalOpen); ChartItem itemClientCursors_size = new ChartItem(pieChartCursors); itemClientCursors_size.setText("Client cursors size (" + clientCursors_size + ")"); itemClientCursors_size.setColor(colors.next()); itemClientCursors_size.setValue(clientCursors_size); ChartItem itemTimedOut = new ChartItem(pieChartCursors); itemTimedOut.setText("Timed Out (" + timedOut + ")"); itemTimedOut.setColor(colors.next()); itemTimedOut.setValue(timedOut); }
From source file:com.hangum.tadpole.mongodb.core.editors.dbInfos.comosites.ShardingComposite.java
License:Open Source License
/** * Create the composite.//w w w . j a v a2 s . c o m * @param parent * @param style */ public ShardingComposite(Composite parent, int style, UserDBDAO userDB) { super(parent, style); GridLayout gridLayout = new GridLayout(1, false); gridLayout.verticalSpacing = 1; gridLayout.horizontalSpacing = 1; gridLayout.marginHeight = 1; gridLayout.marginWidth = 1; setLayout(gridLayout); this.userDB = userDB; Composite compositeServerStatus = new Composite(this, SWT.NONE); compositeServerStatus.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); GridLayout gl_compositeServerStatus = new GridLayout(1, false); gl_compositeServerStatus.verticalSpacing = 1; gl_compositeServerStatus.horizontalSpacing = 1; gl_compositeServerStatus.marginHeight = 1; gl_compositeServerStatus.marginWidth = 1; compositeServerStatus.setLayout(gl_compositeServerStatus); Composite composite = new Composite(compositeServerStatus, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); GridLayout gl_composite = new GridLayout(1, false); gl_composite.verticalSpacing = 1; gl_composite.horizontalSpacing = 1; gl_composite.marginHeight = 1; gl_composite.marginWidth = 1; composite.setLayout(gl_composite); ToolBar toolBar = new ToolBar(composite, SWT.FLAT | SWT.RIGHT); toolBar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); toolBar.setBounds(0, 0, 87, 20); ToolItem tltmRefresh = new ToolItem(toolBar, SWT.NONE); tltmRefresh.setImage(ImageUtils.getRefresh()); tltmRefresh.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { initData(); } }); tltmRefresh.setToolTipText(Messages.CollectionInformationComposite_tltmRefresh_text); Group grpReplicaSet = new Group(compositeServerStatus, SWT.NONE); GridLayout gl_grpReplicaSet = new GridLayout(1, false); gl_grpReplicaSet.verticalSpacing = 0; gl_grpReplicaSet.horizontalSpacing = 0; gl_grpReplicaSet.marginHeight = 0; gl_grpReplicaSet.marginWidth = 0; grpReplicaSet.setLayout(gl_grpReplicaSet); grpReplicaSet.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); grpReplicaSet.setText(Messages.ShardingComposite_0); try { CommandResult res = MongoDBQuery.getAdminMongoDB(userDB).command("listShards"); //$NON-NLS-1$ shards = (BasicDBList) res.get("shards"); //$NON-NLS-1$ } catch (Exception e) { logger.error("listShards", e); //$NON-NLS-1$ } compositeShardList = new FindOneDetailComposite(grpReplicaSet, Messages.ShardingComposite_4, shards, false); compositeShardList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); GridLayout gl_compositeLocalLocks = new GridLayout(1, false); gl_compositeLocalLocks.verticalSpacing = 2; gl_compositeLocalLocks.horizontalSpacing = 2; gl_compositeLocalLocks.marginHeight = 2; gl_compositeLocalLocks.marginWidth = 2; compositeShardList.setLayout(gl_compositeLocalLocks); }
From source file:com.hangum.tadpole.mongodb.core.editors.dbInfos.comosites.ShardingComposite.java
License:Open Source License
/** * data refresh/* w w w . jav a 2s . com*/ */ private void initData() { try { CommandResult res = MongoDBQuery.getAdminMongoDB(userDB).command("listShards"); //$NON-NLS-1$ shards = (BasicDBList) res.get("shards"); //$NON-NLS-1$ } catch (Exception e) { logger.error("listShards", e); //$NON-NLS-1$ } compositeShardList.refresh(Messages.ShardingComposite_4, shards, false); }
From source file:com.icoin.trading.tradeengine.query.tradeexecuted.repositories.TradeExecutedQueryRepositoryImpl.java
License:Apache License
@Override public List<OpenHighLowCloseVolume> ohlc(String orderBookIdentifier, Date start, Date end, Pageable pageable) { hasLength(orderBookIdentifier);// ww w. jav a2 s .c o m notNull(pageable); DBObject command = BasicDBObjectBuilder.start("aggregate", TRADE_EXECUTED_ENTRY_COLLECTION).get(); final DBObject criteriaObject = Criteria.where("orderBookIdentifier").is(orderBookIdentifier) .and("tradeTime").gte(start).lt(end).getCriteriaObject(); DBObject match = BasicDBObjectBuilder.start("$match", criteriaObject).get(); DBObject projection = BasicDBObjectBuilder .start("year", BasicDBObjectBuilder.start("$year", "$tradeTime").get()) .append("month", BasicDBObjectBuilder.start("$month", "$tradeTime").get()) .append("day", BasicDBObjectBuilder.start("$dayOfMonth", "$tradeTime").get()) .append("hour", BasicDBObjectBuilder.start("$hour", "$tradeTime").get()) .append("minute", BasicDBObjectBuilder.start("$minute", "$tradeTime").get()) .append("tradedPrice", 1).append("tradedAmount", 1).append("_id", 0).get(); DBObject project = BasicDBObjectBuilder.start("$project", projection).get(); //{ "aggregate" : "tradeExecutedEntry" , // "pipeline" : [ { "$match" : { "orderBookIdentifier" : "f830f7e3-9f99-4688-92e7-6dbafc7220a8" , // "tradeTime" : { "$gte" : { "$date" : "2007-12-12T04:12:12.120Z"} , // "$lt" : { "$date" : "2012-12-12T04:12:04.120Z"}}}} , // { "$project" : { "tradeTime" : 1 , "tradedPrice.amount" : 1 , "tradedAmount.amount" : 1 , "year" : // { "$year" : [ "$tradeTime"]} , "month" : { "$month" : [ "$tradeTime"]} , "week" : { "$week" : [ "$tradeTime"]}}} , // { "$group" : { "_id" : "$year" , "open" : { "$first" : "$tradedPrice"} , "high" : { "$max" : "$tradedPrice"} , // "low" : { "$min" : "$tradedPrice"} , "close" : { "$last" : "$tradedPrice"} , "volume" : { "$sum" : "$tradedAmount"}}} , // { "$skip" : 0} , { "$limit" : 100}]} // {"$project": { // "year": {"$year": "$dt"}, // "month": {"$month": "$dt"}, // "day": {"$dayOfMonth": "$dt"}, // "hour": {"$hour": "$dt"}, // "minute": {"$minute": "$dt"}, // "second": {"$second": "$dt"}, // "dt": 1, // "p": 1 }}, // {"_id" : {"year": "$year", "month": "$month", "day": "$day", "hour": "$hour", "minute": "$minute" }, // "open": {"$first": "$p"}, // "high": {"$max": "$p"}, // "low": {"$min": "$p"}, // "close": {"$last": "$p"} }} ] ) // 02:41:22.649 [main] DEBUG c.i.t.t.q.t.r.TradeExecutedQueryRepositoryImpl - aggregation { "aggregate" : "tradeExecutedEntry" , "pipeline" : [ { "$match" : { "orderBookIdentifier" : "c623022b-9baa-437a-a70f-b59adead3ecf" , "tradeTime" : { "$gte" : { "$date" : "2007-12-12T04:12:12.120Z"} , "$lt" : { "$date" : "2012-12-12T04:12:04.120Z"}}}} , { "$project" : { "year" : { "$year" : "$tradeTime"} , "month" : { "$month" : "$tradeTime"} , "day" : { "$dayOfMonth" : "$tradeTime"} , "hour" : { "$hour" : "$tradeTime"} , "minute" : { "$minute" : "$tradeTime"} , "tradedPrice" : 1 , "tradedAmount" : 1 , "_id" : 0}} , { "$group" : { "_id" : { "year" : "$year" , "priceCcy" : "$tradedPrice.currency" , "amountCcy" : "$tradedAmount.currency"} , "open" : { "$first" : "$tradedPrice.amount"} , "high" : { "$max" : "$tradedPrice.amount"} , "low" : { "$min" : "$tradedPrice.amount"} , "close" : { "$last" : "$tradedPrice.amount"} , "volume" : { "$sum" : "$tradedAmount.amount"}}}]} found :[ { "_id" : { "year" : 2012 , "priceCcy" : "CNY" , "amountCcy" : "BTC"} , "open" : 10500 , "high" : 10500 , "low" : 10500 , "close" : 10500 , "volume" : 11550000000} , { "_id" : { "year" : 2010 , "priceCcy" : "CNY" , "amountCcy" : "BTC"} , "open" : 10500 , "high" : 10500 , "low" : 10500 , "close" : 10500 , "volume" : 2100000000} , { "_id" : { "year" : 2011 , "priceCcy" : "CNY" , "amountCcy" : "BTC"} , "open" : 10500 , "high" : 10500 , "low" : 10500 , "close" : 10500 , "volume" : 1050000000}] // 02:46:45.023 [main] DEBUG c.i.t.t.q.t.r.TradeExecutedQueryRepositoryImpl - aggregation { "aggregate" : "tradeExecutedEntry" , "pipeline" : [ { "$match" : { "orderBookIdentifier" : "04527652-b53b-47bf-967d-2001fbe18c13" , "tradeTime" : { "$gte" : { "$date" : "2007-12-12T04:12:12.120Z"} , "$lt" : { "$date" : "2012-12-12T04:12:04.120Z"}}}} , { "$project" : { "year" : { "$year" : "$tradeTime"} , "month" : { "$month" : "$tradeTime"} , "day" : { "$dayOfMonth" : "$tradeTime"} , "hour" : { "$hour" : "$tradeTime"} , "minute" : { "$minute" : "$tradeTime"} , "tradedPrice" : 1 , "tradedAmount" : 1 , "_id" : 0}} , { "$group" : { "_id" : { "year" : "$year" , "priceCcy" : "$tradedPrice.currency" , "amountCcy" : "$tradedAmount.currency"} , "open" : { "$first" : "$tradedPrice.amount"} , "high" : { "$max" : "$tradedPrice.amount"} , "low" : { "$min" : "$tradedPrice.amount"} , "close" : { "$last" : "$tradedPrice.amount"} , "volume" : { "$sum" : "$tradedAmount.amount"}}}]} found :[ { "_id" : { "year" : 2012 , "priceCcy" : "CNY" , "amountCcy" : "BTC"} , "open" : 10500 , "high" : 10500 , "low" : 10500 , "close" : 10500 , "volume" : 11550000000} , { "_id" : { "year" : 2010 , "priceCcy" : "CNY" , "amountCcy" : "BTC"} , "open" : 10500 , "high" : 10500 , "low" : 10500 , "close" : 10500 , "volume" : 2100000000} , { "_id" : { "year" : 2011 , "priceCcy" : "CNY" , "amountCcy" : "BTC"} , "open" : 10500 , "high" : 10500 , "low" : 10500 , "close" : 10500 , "volume" : 1050000000}] final DBObject groupId = BasicDBObjectBuilder.start("year", "$year") // .append("month", "$month") // .append("day", "$dayOfMonth") // .append("hour", "$hour") // .append("minute", "$minute") .append("priceCcy", "$tradedPrice.currency").append("amountCcy", "$tradedAmount.currency").get(); DBObject groupOp = BasicDBObjectBuilder.start("_id", groupId) .append("open", BasicDBObjectBuilder.start("$first", "$tradedPrice.amount").get()) .append("high", BasicDBObjectBuilder.start("$max", "$tradedPrice.amount").get()) .append("low", BasicDBObjectBuilder.start("$min", "$tradedPrice.amount").get()) .append("close", BasicDBObjectBuilder.start("$last", "$tradedPrice.amount").get()) .append("volume", BasicDBObjectBuilder.start("$sum", "$tradedAmount.amount").get()).get(); DBObject group = BasicDBObjectBuilder.start("$group", groupOp).get(); final BasicDBList pipeline = new BasicDBList(); pipeline.add(match); pipeline.add(project); pipeline.add(group); command.put("pipeline", pipeline); CommandResult commandResult = mongoTemplate.executeCommand(command); handleCommandError(commandResult, command); // map results @SuppressWarnings("unchecked") Iterable<DBObject> resultSet = (Iterable<DBObject>) commandResult.get("result"); List<OpenHighLowCloseVolume> mappedResults = Lists.newLinkedList(); if (logger.isDebugEnabled()) { logger.debug("aggregation {} found :{}", command, resultSet); } System.err.println(Long.MAX_VALUE / 100000000); return null; }
From source file:com.ikanow.infinit.e.api.knowledge.SearchHandler.java
License:Open Source License
/** * Sends a geonear command to the feature.geo database. Returns back * a list of the nearest 10 locations/* w w w. ja va 2s .c o m*/ * * @param lat * @param lon * @return */ private BasicDBList runGeoNear(Double lat, Double lon) { String location = null; BasicDBObject command = new BasicDBObject("geoNear", "geo"); Double[] coordinates = { lat, lon }; command.put("near", coordinates); command.put("maxDistance", MAXIMUM_DISTANCE_IN_METERS); CommandResult commandResult = MongoDbManager.getDB("feature").command(command); if (commandResult.ok() && commandResult.containsField("results")) { BasicDBList results = (BasicDBList) commandResult.get("results"); return results; } return null; }
From source file:com.imaginea.mongodb.requestdispatchers.Graphs.java
License:Apache License
/** * Process <opcounters> query request made after each second by Front end * //from w ww . j a v a2 s. co m * @param db * : Db Name to egt Server Stats <admin> * @return Server stats of <opcounters> key * @throws IOException * @throws JSONException */ private JSONArray processQuery(DB db) throws IOException, JSONException { CommandResult cr = db.command("serverStatus"); BasicDBObject obj = (BasicDBObject) cr.get("opcounters"); int currentValue; JSONObject temp = new JSONObject(); num = num + jump; temp.put("TimeStamp", num); currentValue = (Integer) obj.get("query"); temp.put("QueryValue", currentValue - lastNoOfQueries); lastNoOfQueries = currentValue; currentValue = (Integer) obj.get("insert"); temp.put("InsertValue", currentValue - lastNoOfInserts); lastNoOfInserts = currentValue; currentValue = (Integer) obj.get("update"); temp.put("UpdateValue", currentValue - lastNoOfUpdates); lastNoOfUpdates = currentValue; currentValue = (Integer) obj.get("delete"); temp.put("DeleteValue", currentValue - lastNoOfDeletes); lastNoOfDeletes = currentValue; if (array.length() == maxLen) { JSONArray tempArray = new JSONArray(); for (int i = 1; i < maxLen; i++) { tempArray.put(array.get(i)); } array = tempArray; } array.put(temp); return array; }
From source file:com.imaginea.mongodb.requestdispatchers.Graphs.java
License:Apache License
/** * //from w w w . j a v a 2 s . co m * Initialize by previous <opcounter> value. * * @param db * : Name of Database * @return : Status of Initialization * @throws RuntimeException */ private JSONObject processInitiate(DB db) throws RuntimeException, JSONException { JSONObject respObj = new JSONObject(); array = new JSONArray(); num = 0; try { CommandResult cr = db.command("serverStatus"); BasicDBObject obj = (BasicDBObject) cr.get("opcounters"); lastNoOfQueries = (Integer) obj.get("query"); lastNoOfInserts = (Integer) obj.get("insert"); lastNoOfUpdates = (Integer) obj.get("update"); lastNoOfDeletes = (Integer) obj.get("delete"); respObj.put("result", "Initiated"); } catch (Exception e) { // Invalid User JSONObject error = new JSONObject(); error.put("message", e.getMessage()); error.put("code", ErrorCodes.ERROR_INITIATING_GRAPH); respObj.put("error", error); logger.info(respObj); } return respObj; }
From source file:com.imaginea.mongodb.services.CollectionServiceImpl.java
License:Apache License
/** * Get Statistics of a collection inside a database in mongo to which user * is connected to.// www .j av a2s . co m * * @param dbName * Name of Database in which to insert a collection * @param collectionName * Name of Collection to be inserted * @return Array of JSON Objects each containing a key value pair in * Collection Stats. * @exception EmptyDatabaseNameException * if dbName is null * @exception EmptyCollectionNameException * if collectionName is null * @exception UndefinedDatabaseException * if database is not present * @exception UndefinedCollectionException * if collection is not present * @exception DatabaseException * throw super type of UndefinedDatabaseException * @exception ValidationException * throw super type of * EmptyDatabaseNameException,EmptyCollectionNameException * @exception CollectionException * throw super type of UndefinedCollectionException * @exception JSONException * JSON Exception */ public JSONArray getCollStats(String dbName, String collectionName) throws DatabaseException, CollectionException, ValidationException, JSONException { mongoInstance = mongoInstanceProvider.getMongoInstance(); if (dbName == null) { throw new EmptyDatabaseNameException("Database name is null"); } if (dbName.equals("")) { throw new EmptyDatabaseNameException("Database Name Empty"); } if (collectionName == null) { throw new EmptyCollectionNameException("Collection name is null"); } if (collectionName.equals("")) { throw new EmptyCollectionNameException("Collection Name Empty"); } JSONArray collStats = new JSONArray(); try { if (!mongoInstance.getDatabaseNames().contains(dbName)) { throw new UndefinedDatabaseException("DB with name [" + dbName + "]DOES_NOT_EXIST"); } if (!mongoInstance.getDB(dbName).getCollectionNames().contains(collectionName)) { throw new UndefinedCollectionException( "Collection with name [" + collectionName + "] DOES NOT EXIST in Database [" + dbName + "]"); } CommandResult stats = mongoInstance.getDB(dbName).getCollection(collectionName).getStats(); Set<String> keys = stats.keySet(); Iterator<String> keyIterator = keys.iterator(); JSONObject temp = new JSONObject(); while (keyIterator.hasNext()) { temp = new JSONObject(); String key = keyIterator.next().toString(); temp.put("Key", key); String value = stats.get(key).toString(); temp.put("Value", value); String type = stats.get(key).getClass().toString(); temp.put("Type", type.substring(type.lastIndexOf('.') + 1)); collStats.put(temp); } } catch (JSONException e) { throw e; } catch (MongoException m) { CollectionException e = new CollectionException(ErrorCodes.GET_COLL_STATS_EXCEPTION, "GET_COLL_STATS_EXCEPTION", m.getCause()); throw e; } return collStats; }
From source file:com.imaginea.mongodb.services.DatabaseServiceImpl.java
License:Apache License
/** * Return Stats of a particular Database in mongo to which user is connected * to.//from w w w. j a va2 s .c om * * @param dbName * Name of Database * @return Array of JSON Objects each containing a key value pair in Db * Stats. * @exception EmptyDatabaseNameException * DbName is empty * @exception UndefinedDatabaseException * Db not present * @exception JSONException * While parsing JSON * @exception DatabaseException * Error while performing this operation * @exception ValidationException * throw super type of EmptyDatabaseNameException */ public JSONArray getDbStats(String dbName) throws DatabaseException, ValidationException, JSONException { mongoInstance = mongoInstanceProvider.getMongoInstance(); if (dbName == null) { throw new EmptyDatabaseNameException("Database name is null"); } if (dbName.equals("")) { throw new EmptyDatabaseNameException("Database Name Empty"); } JSONArray dbStats = new JSONArray(); try { boolean dbPresent = mongoInstance.getDatabaseNames().contains(dbName); if (!dbPresent) { throw new UndefinedDatabaseException("DB with name [" + dbName + "] DOES NOT EXIST"); } DB db = mongoInstance.getDB(dbName); CommandResult stats = db.getStats(); Set<String> keys = stats.keySet(); Iterator<String> keyIterator = keys.iterator(); JSONObject temp = new JSONObject(); while (keyIterator.hasNext()) { temp = new JSONObject(); String key = keyIterator.next().toString(); temp.put("Key", key); String value = stats.get(key).toString(); temp.put("Value", value); String type = stats.get(key).getClass().toString(); temp.put("Type", type.substring(type.lastIndexOf('.') + 1)); dbStats.put(temp); } } catch (JSONException e) { throw e; } catch (MongoException m) { throw new DatabaseException(ErrorCodes.GET_DB_STATS_EXCEPTION, "GET_DB_STATS_EXCEPTION"); } return dbStats; }
From source file:com.jaspersoft.mongodb.query.MongoDbQueryWrapper.java
License:Open Source License
private void runCommand(Object commandValue) throws JRException { if (!(commandValue instanceof DBObject)) { throw new JRException("Command must be a valid BSON object"); }/*from w w w. j a v a 2 s . c o m*/ DBObject commandObject = (DBObject) commandValue; if (logger.isDebugEnabled()) { logger.debug("Command object: " + commandObject); } CommandResult commandResult = connection.getMongoDatabase().command(commandObject); if (!commandResult.ok()) { throw new JRException(commandResult.getErrorMessage()); } Object resultObject = commandResult.get(RESULT_KEY); if (resultObject == null) { throw new JRException("No results"); } commandResults = (List<?>) resultObject; }