List of usage examples for com.mongodb BasicDBObjectBuilder push
public BasicDBObjectBuilder push(final String key)
From source file:org.alfresco.bm.test.mongo.MongoTestDAO.java
License:Open Source License
/** * @param test/*from www . j av a 2s. c o m*/ * only fetch runs for this test or <tt>null</tt> to get all test * runs * @param testRunStates * optional states that the test runs must be in or empty for all * @return a cursor onto the test runs for the given test */ public DBCursor getTestRuns(String test, int skip, int count, TestRunState... testRunStates) { BasicDBObjectBuilder queryObjBuilder = BasicDBObjectBuilder.start(); if (test != null) { ObjectId testObjId = getTestId(test); if (testObjId == null) { // The test no longer exists, so the run effectively doesn't // either logger.warn("Test not found: " + test); // Use a ficticious ID that will never match testObjId = new ObjectId(); } queryObjBuilder.add(FIELD_TEST, testObjId); } // Build query for the test run states if (testRunStates.length > 0) { List<String> stateStrs = new ArrayList<String>(testRunStates.length); for (int i = 0; i < testRunStates.length; i++) { stateStrs.add(testRunStates[i].toString()); } queryObjBuilder.push(FIELD_STATE); queryObjBuilder.add("$in", stateStrs); } DBObject queryObj = queryObjBuilder.get(); DBObject fieldsObj = BasicDBObjectBuilder.start().add(FIELD_NAME, true).add(FIELD_TEST, true) .add(FIELD_VERSION, true).add(FIELD_DESCRIPTION, true).add(FIELD_STATE, true) .add(FIELD_SCHEDULED, true).add(FIELD_STARTED, true).add(FIELD_STOPPED, true) .add(FIELD_COMPLETED, true).add(FIELD_DURATION, true).add(FIELD_PROGRESS, true) .add(FIELD_RESULTS_SUCCESS, true).add(FIELD_RESULTS_FAIL, true).add(FIELD_RESULTS_TOTAL, true) .add(FIELD_SUCCESS_RATE, true).get(); DBCursor dbCursor = testRuns.find(queryObj, fieldsObj).skip(skip).limit(count); // Done if (logger.isDebugEnabled()) { logger.debug( "Fetched test runs: \n" + " Test: " + test + "\n" + " Results: " + dbCursor.count()); } return dbCursor; }
From source file:org.alfresco.bm.user.UserDataServiceImpl.java
License:Open Source License
private Range getRandomizerRange(List<String> domains) { BasicDBObjectBuilder queryObjBuilder = BasicDBObjectBuilder.start().add(FIELD_CREATION_STATE, DataCreationState.Created.toString()); if (domains.size() > 0) { queryObjBuilder.push(FIELD_DOMAIN).add("$in", domains).pop(); }//w w w .jav a2s.com DBObject queryObj = queryObjBuilder.get(); DBObject fieldsObj = BasicDBObjectBuilder.start().add(FIELD_RANDOMIZER, Boolean.TRUE).get(); DBObject sortObj = BasicDBObjectBuilder.start().add(FIELD_RANDOMIZER, -1).get(); // Find max DBObject resultObj = collection.findOne(queryObj, fieldsObj, sortObj); int maxRandomizer = resultObj == null ? 0 : (Integer) resultObj.get(FIELD_RANDOMIZER); // Find min sortObj.put(FIELD_RANDOMIZER, +1); resultObj = collection.findOne(queryObj, fieldsObj, sortObj); int minRandomizer = resultObj == null ? 0 : (Integer) resultObj.get(FIELD_RANDOMIZER); return new Range(minRandomizer, maxRandomizer); }
From source file:org.alfresco.bm.user.UserDataServiceImpl.java
License:Open Source License
@Override public UserData getRandomUserFromDomains(List<String> domains) { Range range = getRandomizerRange(domains); int upper = range.getMax(); int lower = range.getMin(); int random = lower + (int) (Math.random() * (double) (upper - lower)); BasicDBObjectBuilder queryObjBuilder = BasicDBObjectBuilder.start() .add(FIELD_CREATION_STATE, DataCreationState.Created.toString()).push(FIELD_RANDOMIZER) .add("$gte", random).pop(); if (domains.size() > 0) { queryObjBuilder.push(FIELD_DOMAIN).add("$in", domains).pop(); }/* ww w . j ava2 s . co m*/ DBObject queryObj = queryObjBuilder.get(); DBObject userDataObj = collection.findOne(queryObj); return fromDBObject(userDataObj); }
From source file:org.apache.rya.mongodb.document.operators.aggregation.VariableOperators.java
License:Apache License
/** * Applies an expression to each item in an array and returns an array with * the applied results./* ww w . j av a 2 s. co m*/ * @param builder the {@link BasicDBObjectBuilder}. (not {@code null}) * @param input an expression that resolves to an array. * @param as the variable name for the items in the {@code input} array. * The {@code in} expression accesses each item in the {@code input} array * by this variable. * @param in the expression to apply to each item in the {@code input} * array. The expression accesses the item by its variable name. * @return the $map expression {@link BasicDBObjectBuilder}. */ public static BasicDBObjectBuilder map(final BasicDBObjectBuilder builder, final String input, final String as, final DBObject in) { checkNotNull(builder); builder.push("$map").add("input", input).add("as", as).add("in", in); return builder; }
From source file:org.envirocar.server.mongo.dao.MongoStatisticsDao.java
License:Open Source License
private DBObject matches(StatisticsFilter request) { BasicDBObjectBuilder b = new BasicDBObjectBuilder(); BasicDBObjectBuilder match = b.push(Ops.MATCH); if (request.hasTrack()) { DBRef track = mongoDB.ref(request.getTrack()); match.add(MongoMeasurement.TRACK, track); }//from w ww . j av a 2 s. c om if (request.hasUser()) { DBRef user = mongoDB.ref(request.getUser()); match.add(MongoMeasurement.USER, user); } if (request.hasSensor()) { MongoSensor sensor = (MongoSensor) request.getSensor(); match.add(SENSOR_ID_PATH, sensor.getId()); } return b.get(); }
From source file:org.teiid.translator.mongodb.MongoDBSelectVisitor.java
License:Open Source License
private DBObject buildGeoNearFunction(Function function) { List<Expression> args = function.getParameters(); // Column Name int paramIndex = 0; ColumnDetail column = getExpressionAlias(args.get(paramIndex++)); BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); builder.push(column.documentFieldName); builder.push(function.getName());/* w ww .j ava 2s . c o m*/ builder.push("$geometry");//$NON-NLS-1$ builder.add("type", SpatialType.Point.name());//$NON-NLS-1$ // walk the co-ordinates append(args.get(paramIndex++)); BasicDBList coordinates = new BasicDBList(); coordinates.add(this.onGoingExpression.pop()); builder.add("coordinates", coordinates); //$NON-NLS-1$ // maxdistance append(args.get(paramIndex++)); builder.pop().add("$maxDistance", this.onGoingExpression.pop()); //$NON-NLS-1$ return builder.get(); }
From source file:org.teiid.translator.mongodb.MongoDBSelectVisitor.java
License:Open Source License
private DBObject buildGeoFunction(Function function) { List<Expression> args = function.getParameters(); // Column Name int paramIndex = 0; ColumnDetail column = getExpressionAlias(args.get(paramIndex++)); // Type: Point, LineString, Polygon.. append(args.get(paramIndex++));/*ww w. jav a 2 s . co m*/ SpatialType type = SpatialType.valueOf((String) this.onGoingExpression.pop()); BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); builder.push(column.documentFieldName); builder.push(function.getName()); builder.push("$geometry");//$NON-NLS-1$ builder.add("type", type.name());//$NON-NLS-1$ // walk the co-ordinates append(args.get(paramIndex++)); BasicDBList coordinates = new BasicDBList(); coordinates.add(this.onGoingExpression.pop()); builder.add("coordinates", coordinates); //$NON-NLS-1$ return builder.get(); }