List of usage examples for com.mongodb QueryBuilder get
public DBObject get()
From source file:com.stratio.deep.mongodb.reader.MongoReader.java
License:Apache License
/** * Generate filter query.//from w w w . ja va 2 s .c om * * @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), mongoDeepJobConfig.getQuery()); LOG.debug("mongodb query " + queryBuilder.get()); return queryBuilder.get(); } return createQueryPartition(partition); }
From source file:com.streamreduce.storm.MongoClient.java
License:Apache License
/** * Returns the list of events in the Nodeable datastore between the Dates specified by the since and before * parameters./* www .ja v a 2 s . com*/ * * @param since the date (exclusive) to get the events after. A null means this parameter is ignored. * @param until the date (inclusive) to get the events before. A null means this parameter is ignored. * @return the list of events or an empty list if there are none */ public List<BasicDBObject> getEvents(Date since, Date until) { DB connectionsDb = getDB("nodeablemsgdb"); QueryBuilder queryBuilder = QueryBuilder.start(); if (since != null) { queryBuilder.and("timestamp").greaterThan(since.getTime()); } if (until != null) { queryBuilder.and("timestamp").lessThanEquals(until.getTime()); } DBObject query = queryBuilder.get(); return asList(connectionsDb.getCollection("eventStream").find(query)); }
From source file:com.vaushell.gfmongodb.MongoDbUserRealm.java
License:Open Source License
@Override public Enumeration getGroupNames(final String username) { final QueryBuilder builder = QueryBuilder.start(getProperty(PARAM_USERNAME)).is(username); final DBObject user = usersCollection.findOne(builder.get()); if (user == null) { return null; }/*from ww w. j a v a2 s. co m*/ return Collections.enumeration(getGroups(user)); }
From source file:com.vaushell.gfmongodb.MongoDbUserRealm.java
License:Open Source License
/** * Authenticate user./* ww w . jav a2s . co m*/ * * @param username Username. * @param givenPassword Password * @return List of groups. * @throws LoginException */ String[] authenticate(final String username, final char[] givenPassword) throws LoginException { if (username == null || username.length() <= 0 || givenPassword == null || givenPassword.length <= 0) { throw new LoginException("username or password is empty"); } final QueryBuilder builder = QueryBuilder.start(getProperty(PARAM_USERNAME)).is(username); final DBObject user = usersCollection.findOne(builder.get()); if (user == null) { throw new LoginException("cannot find user with username '" + username + "'"); } final String databasePassword = (String) user.get(getProperty(PARAM_PASSWORD)); if (databasePassword == null || databasePassword.length() <= 0) { throw new LoginException("cannot find nonempty password for username '" + username + "'"); } final String transformedPassword = DigestUtils.sha256Hex(new String(givenPassword)); if (!databasePassword.equals(transformedPassword)) { throw new LoginException("password is wrong for username '" + username + "'"); } final List<String> groups = getGroups(user); return groups.toArray(new String[groups.size()]); }
From source file:fr.wseduc.mongodb.MongoQueryBuilder.java
License:Apache License
public static JsonObject build(QueryBuilder queryBuilder) { DBObject dbo = queryBuilder.get(); return new JsonObject(JSON.serialize(dbo)); }
From source file:homework.week2.course.UserDAO.java
License:Apache License
public DBObject validateLogin(String username, String password) { DBObject user = null;//from ww w . ja va 2 s. co m // XXX look in the user collection for a user that has this username // assign the result to the user variable. QueryBuilder userQuery = QueryBuilder.start("_id").is(username); DBCursor cursor = usersCollection.find(userQuery.get()); user = cursor.hasNext() ? cursor.next() : null; cursor.close(); 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:homework.week3.course.BlogPostDAO.java
License:Apache License
public DBObject findByPermalink(String permalink) { DBObject post = null;/*ww w. j a v a2 s .c o m*/ // XXX HW 3.2, Work Here QueryBuilder findQuery = QueryBuilder.start("permalink").is(permalink); DBCursor cur = postsCollection.find(findQuery.get()); post = cur.hasNext() ? cur.next() : null; return post; }
From source file:homework.week3.course.BlogPostDAO.java
License:Apache License
public List<DBObject> findByDateDescending(int limit) { List<DBObject> posts = null; // XXX HW 3.2, Work Here // Return a list of DBObjects, each one a post from the posts collection QueryBuilder sortQuery = QueryBuilder.start("date").is(-1); DBCursor cursor = postsCollection.find().sort(sortQuery.get()).limit(limit); posts = cursor.toArray();/*from w w w. j a va 2 s . c o m*/ return posts; }
From source file:it.sayservice.platform.smartplanner.otp.OTPManager.java
License:Apache License
private SymbolicRouteDayInfoHashCalendar findDayInfo(String router, String agencyId, String routeId, String date, boolean symbolic) { if (symbolic) { QueryBuilder qb = QueryBuilder.start(); qb.and("routeId").is(routeId); qb.and("agencyId").is(agencyId); List<SymbolicRouteDayInfoHashCalendar> symbolicInfos = (List) storage.getObjectsByQuery( mongoRouterMapper.getMongoTemplateMap().get(router), qb.get(), Constants.AGENCY_INFO, SymbolicRouteDayInfoHashCalendar.class, null); SymbolicRouteDayInfoHashCalendar si = symbolicInfos.get(0); return si; } else {/*from w w w . j a v a 2 s . com*/ return null; } }
From source file:it.sayservice.platform.smartplanner.otp.OTPManager.java
License:Apache License
private List<AlertDelay> getAlertDelay(String router, String routeId, String tripId, boolean now) { QueryBuilder qb = new QueryBuilder(); qb = qb.start("transport.routeId").is(routeId).and("transport.tripId").is(tripId); if (now) {//from w w w . j ava2 s .c om long time = System.currentTimeMillis(); qb = qb.and("from").lessThanEquals(time); qb = qb.and("to").greaterThanEquals(time); } List<AlertDelay> delays = (List) storage.getObjectsByQuery( mongoRouterMapper.getMongoTemplateMap().get(router), qb.get(), Constants.ALERT_DELAYS, AlertDelay.class, "delay"); return delays; }