List of usage examples for com.mongodb BasicDBList BasicDBList
BasicDBList
From source file:com.linuxbox.enkive.workspace.searchQuery.mongo.MongoSearchQueryBuilder.java
License:Open Source License
@Override public Collection<SearchQuery> getSearchQueries(Collection<String> searchQueryUUIDs) throws WorkspaceException { Collection<SearchQuery> queries = new HashSet<SearchQuery>(); BasicDBObject dbQuery = new BasicDBObject(); BasicDBList idList = new BasicDBList(); for (String searchQueryUUID : searchQueryUUIDs) idList.add(ObjectId.massageToObjectId(searchQueryUUID)); dbQuery.put("$in", idList); DBCursor searchQuery = searchQueryColl.find(new BasicDBObject(UUID, dbQuery)); while (searchQuery.hasNext()) { queries.add(extractQuery(searchQuery.next())); }//w ww .jav a 2 s .c o m return queries; }
From source file:com.linuxbox.enkive.workspace.searchResult.mongo.MongoSearchResultBuilder.java
License:Open Source License
@Override public Collection<SearchResult> getSearchResults(Collection<String> searchResultUUIDs) { Collection<SearchResult> results = new HashSet<SearchResult>(); BasicDBObject query = new BasicDBObject(); BasicDBList idList = new BasicDBList(); for (String searchResultUUID : searchResultUUIDs) idList.add(ObjectId.massageToObjectId(searchResultUUID)); query.put("$in", idList); DBCursor searchResult = searchResultsColl.find(new BasicDBObject(UUID, query)); while (searchResult.hasNext()) { MongoSearchResult result = extractResult(searchResult.next()); results.add(result);//from w w w . j a v a 2 s . c o m } return results; }
From source file:com.linuxbox.enkive.workspace.searchResult.mongo.MongoSearchResultUtils.java
License:Open Source License
protected List<String> sortMessages(Collection<String> messageIds, String sortField, int sortDirection, int pageNum, int pageSize) throws ResultPageException { ArrayList<String> sortedIds = new ArrayList<String>(); // Only want to return the ids BasicDBObject keys = new BasicDBObject(); keys.put("_id", 1); keys.put(sortField, 1);//from w w w . j a va 2 s. c o m BasicDBObject query = new BasicDBObject(); // Build object with IDs BasicDBList idList = new BasicDBList(); idList.addAll(messageIds); BasicDBObject idQuery = new BasicDBObject(); idQuery.put("$in", idList); query.put("_id", idQuery); // Add sort query DBCursor results = messageColl.find(query, keys); BasicDBObject orderBy = new BasicDBObject(); orderBy.put(sortField, sortDirection); try { results = results.sort(orderBy).skip((pageNum - 1) * pageSize).limit(pageSize); for (DBObject result : results) sortedIds.add((String) result.get("_id")); } catch (MongoException e) { // Mongo failed to get the page. Create an error message for the user. throw new ResultPageException("MongoDB failed to get the requested page of results", e); } return sortedIds; }
From source file:com.linuxbox.enkive.workspace.searchResult.mongo.MongoSearchResultUtils.java
License:Open Source License
public List<String> sortSearchResults(Collection<String> searchResultIds, String sortField, int sortDirection, int pageNum, int pageSize) { ArrayList<String> sortedIds = new ArrayList<String>(pageSize); // Only want to return the ids BasicDBObject keys = new BasicDBObject(); keys.put("_id", 1); keys.put(sortField, 1);//from w w w .j av a 2s .c o m BasicDBObject query = new BasicDBObject(); // Build object with IDs BasicDBList idList = new BasicDBList(); for (String Id : searchResultIds) idList.add(ObjectId.massageToObjectId(Id)); BasicDBObject idQuery = new BasicDBObject(); idQuery.put("$in", idList); query.put("_id", idQuery); // Add sort query DBCursor results = searchResultColl.find(query, keys); BasicDBObject orderBy = new BasicDBObject(); orderBy.put(sortField, sortDirection); results = results.sort(orderBy).skip((pageNum - 1) * pageSize).limit(pageSize); for (DBObject result : results.toArray()) sortedIds.add((String) result.get("_id")); return sortedIds; }
From source file:com.lowereast.guiceymongo.logging.MongoDbAppender.java
License:Open Source License
/** * Adds the ThrowableInformation object to an existing BSON object. * /* w w w .java2 s . c om*/ * @param bson The BSON object to add the throwable info to <i>(must not be null)</i>. * @param throwableInfo The ThrowableInformation object to add to the BSON object <i>(may be null)</i>. */ private void addThrowableInformation(DBObject bson, final ThrowableInformation throwableInfo) { if (throwableInfo != null) { Throwable currentThrowable = throwableInfo.getThrowable(); List throwables = new BasicDBList(); while (currentThrowable != null) { DBObject throwableBson = bsonifyThrowable(currentThrowable); if (throwableBson != null) { throwables.add(throwableBson); } currentThrowable = currentThrowable.getCause(); } if (throwables.size() > 0) { bson.put("throwables", throwables); } } }
From source file:com.lowereast.guiceymongo.logging.MongoDbAppender.java
License:Open Source License
/** * BSONifies the given stack trace./* w w w . j av a2 s .com*/ * * @param stackTrace The stack trace object to BSONify <i>(may be null)</i>. * @return The BSONified equivalent of the stack trace object <i>(may be null)</i>. */ private DBObject bsonifyStackTrace(final StackTraceElement[] stackTrace) { BasicDBList result = null; if (stackTrace != null && stackTrace.length > 0) { result = new BasicDBList(); for (StackTraceElement element : stackTrace) { DBObject bson = bsonifyStackTraceElement(element); if (bson != null) { result.add(bson); } } } return (result); }
From source file:com.lowereast.guiceymongo.logging.MongoDbAppender.java
License:Open Source License
/** * BSONifies the given class name.//from ww w. j av a 2 s . co m * * @param className The class name to BSONify <i>(may be null)</i>. * @return The BSONified equivalent of the class name <i>(may be null)</i>. */ private DBObject bsonifyClassName(final String className) { DBObject result = null; if (className != null && className.trim().length() > 0) { result = new BasicDBObject(); result.put("fullyQualifiedClassName", className); List packageComponents = new BasicDBList(); String[] packageAndClassName = className.split("\\."); packageComponents .addAll(Arrays.asList(Arrays.copyOf(packageAndClassName, packageAndClassName.length - 1))); if (packageComponents.size() > 0) { result.put("package", packageComponents); } result.put("className", packageAndClassName[packageAndClassName.length - 1]); } return (result); }
From source file:com.mastfrog.acteur.mongo.util.UpdateBuilder.java
License:Open Source License
public BasicDBObject build() { BasicDBObject result = new BasicDBObject(); if (!set.isEmpty()) { result.append("$set", new BasicDBObject(set)); }//from w ww .j a va 2s . co m if (!inc.isEmpty()) { result.append("$inc", new BasicDBObject(inc)); } if (!push.isEmpty()) { result.append("$push", new BasicDBObject(push)); } if (!pull.isEmpty()) { result.append("$pull", new BasicDBObject(push)); } if (!unset.isEmpty()) { BasicDBList list = new BasicDBList(); list.addAll(unset); result.append("$unset", list); } return result; }
From source file:com.mingo.convert.ConversionUtils.java
License:Apache License
/** * Convert aggregation output to BasicDBList. * * @param aggregationOutput aggregation output * @return BasicDBList/*w w w .j a v a 2 s . co m*/ */ public static BasicDBList getAsBasicDBList(AggregationOutput aggregationOutput) { Validate.notNull(aggregationOutput, "aggregation output cannot be null"); BasicDBList result = new BasicDBList(); result.addAll(Lists.newArrayList(aggregationOutput.results())); return result; }
From source file:com.mingo.convert.ConversionUtils.java
License:Apache License
/** * Converts the given source into the list of objects with specified type. * * @param type the type of target object * @param source {@link DBObject} interface. expected {@link com.mongodb.BasicDBList} implementation. * @param converter converter/*from ww w . j av a 2s .c om*/ * @param <T> the type of the class modeled by this {@code Class} object. * @return list of converted objects */ public static <T> List<T> convertList(Class<T> type, DBObject source, Converter<T> converter) { List<T> list = null; Validate.notNull(source, "source cannot be null"); if (source instanceof BasicDBList) { list = convertDBList(type, (BasicDBList) source, converter); } else if (source instanceof BasicDBObject) { BasicDBList listSource = new BasicDBList(); listSource.add(source); list = convertDBList(type, listSource, converter); } else { throw new RuntimeException("unsupported source. expected BasicDBList or BasicDBObject."); } return list; }