List of usage examples for com.mongodb QueryBuilder get
public DBObject get()
From source file:com.bosscs.spark.mongodb.config.MongoDeepJobConfig.java
License:Apache License
/** * {@inheritDoc}//from www .jav a 2 s . c o m */ @Override public MongoDeepJobConfig<T> filterQuery(QueryBuilder query) { this.query = query.get(); return this; }
From source file:com.bosscs.spark.mongodb.reader.MongoReader.java
License:Apache License
/** * Create query partition./* w w w . j ava 2 s .c o m*/ * * @param partition the partition * @return the dB object */ private DBObject createQueryPartition(MongoPartition partition) { QueryBuilder queryBuilderMin = QueryBuilder.start(partition.getKey()); DBObject bsonObjectMin = queryBuilderMin.greaterThanEquals(partition.splitWrapper().getStartToken()).get(); QueryBuilder queryBuilderMax = QueryBuilder.start(partition.getKey()); DBObject bsonObjectMax = queryBuilderMax.lessThan(partition.splitWrapper().getEndToken()).get(); QueryBuilder queryBuilder = QueryBuilder.start(); if (partition.splitWrapper().getStartToken() != null) { queryBuilder.and(bsonObjectMin.toString()); } if (partition.splitWrapper().getEndToken() != null) { queryBuilder.and(bsonObjectMax.toString()); } LOG.debug("mongodb query " + queryBuilder.get()); return queryBuilder.get(); }
From source file:com.bosscs.spark.mongodb.reader.MongoReader.java
License:Apache License
/** * Generate filter query.//from ww w .j a v a2 s.com * * @param partition the partition * @return the dB object */ private DBObject generateFilterQuery(MongoPartition partition) { if (mongoDeepJobConfig.getQuery() != null) { QueryBuilder queryBuilder = QueryBuilder.start(); queryBuilder.and(createQueryPartition(partition).toString() + mongoDeepJobConfig.getQuery()); LOG.debug("mongodb query " + queryBuilder.get()); return queryBuilder.get(); } return createQueryPartition(partition); }
From source file:com.ccoe.build.alerts.connector.Connector.java
License:Apache License
public static DBObject getLastRecord(DBCollection collection, Date startDate, Date endDate) { DBObject lastone = null;/*w ww . j a v a2 s .c om*/ try { BasicDBObject searchQuery = new BasicDBObject(); QueryBuilder qb = new QueryBuilder(); qb.put("Date").greaterThanEquals(startDate).lessThanEquals(endDate); searchQuery.putAll(qb.get()); DBCursor cursor = collection.find(searchQuery); while (cursor.hasNext()) { lastone = cursor.next(); } } catch (MongoException e) { e.printStackTrace(); } return lastone; }
From source file:com.ccoe.build.alerts.connector.Connector.java
License:Apache License
public static double getMovingAverage(DBCollection collection, String field, Date startDate, Date endDate) { double weekSum = 0; DBObject record = null;/*from w w w .j av a 2 s. c o m*/ int count = 0; try { BasicDBObject searchQuery = new BasicDBObject(); QueryBuilder qb = new QueryBuilder(); qb.put("Date").greaterThanEquals(startDate).lessThanEquals(endDate); searchQuery.putAll(qb.get()); DBCursor cursor = collection.find(searchQuery); while (cursor.hasNext()) { record = cursor.next(); DBObject dbo = (DBObject) record.get("Data"); Set<String> keySet = dbo.keySet(); for (String keyName : keySet) { if (field.equals(keyName)) { count++; Object keyValue = dbo.get(keyName); double keyValueNum = 0; if (keyValue instanceof Integer) { int intValue = (Integer) keyValue; keyValueNum = Double.parseDouble("" + intValue); } else if (keyValue instanceof Double) { keyValueNum = (Double) keyValue; } weekSum += keyValueNum; } } } } catch (MongoException e) { e.printStackTrace(); } DAYS = count; return weekSum * 1.0 / count; }
From source file:com.gederin.blog.dao.BlogPostDAO.java
License:Apache License
public DBObject findByPermalink(String permalink) { DBObject post = null;//from w ww . jav a 2 s . c o m QueryBuilder queryBuilder = QueryBuilder.start("permalink").is(permalink); post = this.postsCollection.findOne(queryBuilder.get()); // XXX HW 3.2, Work Here return post; }
From source file:com.gederin.blog.dao.UserDAO.java
License:Apache License
public DBObject validateLogin(String username, String password) { DBObject user = null;//www . j a v a2 s . c o m QueryBuilder queryBuilder = QueryBuilder.start("_id").is(username); user = this.usersCollection.findOne(queryBuilder.get()); if (user == null) { System.out.println("User not in database"); return null; } String hashedAndSalted = user.get("password").toString(); String salt = hashedAndSalted.split(",")[1]; if (!hashedAndSalted.equals(makePasswordHash(password, salt))) { System.out.println("Submitted password is not a match"); return null; } return user; }
From source file:com.gigaspaces.persistency.parser.SQL2MongoBaseVisitor.java
License:Open Source License
public T visitOr(SQL2MongoParser.OrContext ctx) { T r = visitChildren(ctx);//from w w w .j a va 2s . c o m if (IsLogic(ctx, "OR")) { QueryBuilder q = QueryBuilder.start(); for (DBObject at : ands) q.or(at); Set<String> keys = atom.get().keySet(); for (String key : keys) { q.or(new BasicDBObject(key, atom.get().get(key))); } ands.clear(); atom = QueryBuilder.start(); ors.add(q.get()); } return r; }
From source file:com.ikanow.aleph2.shared.crud.mongodb.utils.MongoDbUtils.java
License:Apache License
/** Creates the MongoDB clause from the QueryComponent inner object * @param field - the field used in the clause * @param operator_args - an operator enum and a pair of objects whose context depends on the operator * @return the MongoDB clause//from w w w . j a v a 2 s.com */ protected static BasicDBObject operatorToMongoKey(final String field, final Tuple2<Operator, Tuple2<Object, Object>> operator_args) { return Patterns.match(operator_args).<BasicDBObject>andReturn() .when(op_args -> Operator.exists == op_args._1(), op_args -> new BasicDBObject(field, new BasicDBObject("$exists", op_args._2()._1()))) .when(op_args -> (Operator.any_of == op_args._1()), op_args -> new BasicDBObject(field, new BasicDBObject("$in", op_args._2()._1()))) .when(op_args -> (Operator.all_of == op_args._1()), op_args -> new BasicDBObject(field, new BasicDBObject("$all", op_args._2()._1()))) .when(op_args -> (Operator.equals == op_args._1()) && (null != op_args._2()._2()), op_args -> new BasicDBObject(field, new BasicDBObject("$ne", op_args._2()._2()))) .when(op_args -> (Operator.equals == op_args._1()), op_args -> new BasicDBObject(field, op_args._2()._1())) .when(op_args -> Operator.range_open_open == op_args._1(), op_args -> { QueryBuilder qb = QueryBuilder.start(field); if (null != op_args._2()._1()) qb = qb.greaterThan(op_args._2()._1()); if (null != op_args._2()._2()) qb = qb.lessThan(op_args._2()._2()); return (BasicDBObject) qb.get(); }).when(op_args -> Operator.range_open_closed == op_args._1(), op_args -> { QueryBuilder qb = QueryBuilder.start(field); if (null != op_args._2()._1()) qb = qb.greaterThan(op_args._2()._1()); if (null != op_args._2()._2()) qb = qb.lessThanEquals(op_args._2()._2()); return (BasicDBObject) qb.get(); }).when(op_args -> Operator.range_closed_closed == op_args._1(), op_args -> { QueryBuilder qb = QueryBuilder.start(field); if (null != op_args._2()._1()) qb = qb.greaterThanEquals(op_args._2()._1()); if (null != op_args._2()._2()) qb = qb.lessThanEquals(op_args._2()._2()); return (BasicDBObject) qb.get(); }).when(op_args -> Operator.range_closed_open == op_args._1(), op_args -> { QueryBuilder qb = QueryBuilder.start(field); if (null != op_args._2()._1()) qb = qb.greaterThanEquals(op_args._2()._1()); if (null != op_args._2()._2()) qb = qb.lessThan(op_args._2()._2()); return (BasicDBObject) qb.get(); }).otherwise(op_args -> new BasicDBObject()); }
From source file:com.linuxbox.enkive.audit.mongodb.MongoAuditService.java
License:Open Source License
@Override public AuditEntry getEvent(String identifier) throws AuditServiceException { final ObjectId idObject = ObjectId.massageToObjectId(identifier); final QueryBuilder queryBuilder = QueryBuilder.start(MongoDbConstants.OBJECT_ID_KEY).is(idObject); final DBObject resultObject = auditCollection.findOne(queryBuilder.get()); return dbObjectToAuditEntry(resultObject); }