本文整理汇总了Java中com.mongodb.DBCursor.limit方法的典型用法代码示例。如果您正苦于以下问题:Java DBCursor.limit方法的具体用法?Java DBCursor.limit怎么用?Java DBCursor.limit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.DBCursor
的用法示例。
在下文中一共展示了DBCursor.limit方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRetrieveAllAssetsPaginated
import com.mongodb.DBCursor; //导入方法依赖的package包/类
/**
* Test that providing a PaginationOptions object results in the correct skip() and limit()
* methods being called on the result cursor.
*/
@Test
public void testRetrieveAllAssetsPaginated(final @Mocked DBCollection collection, final @Injectable DBCursor cursor) {
new Expectations() {
{
collection.find((DBObject) withNotNull(), (DBObject) withNull());
result = cursor;
cursor.skip(20);
cursor.limit(10);
}
};
List<AssetFilter> filters = new ArrayList<>();
filters.add(new AssetFilter("key1", Arrays.asList(new Condition[] { new Condition(Operation.EQUALS, "value1") })));
PaginationOptions pagination = new PaginationOptions(20, 10);
createTestBean().retrieveAllAssets(filters, null, pagination, null);
}
示例2: getChatMessages
import com.mongodb.DBCursor; //导入方法依赖的package包/类
/**
* @param channelId The Unique ID of the channel.
* @param limit The Integer limit of ChatMessages to load.
* @return Returns a List of ChatMessages for the ChatChannel.
*/
private List<ChatMessage> getChatMessages(UUID channelId, int limit) {
List<ChatMessage> listChatMessages = new LinkedList<>();
// Grab all the messages with the channel_id set to the one provided.
DBObject query = new BasicDBObject("channel_id", channelId);
DBCursor cursor = collectionMessages.find(query);
// Sort the list by timestamp so that the last messages appear first.
cursor.sort(new BasicDBObject("timestamp", -1));
cursor.limit(limit);
if(cursor.size() > 0) {
List<DBObject> listObjects = cursor.toArray();
Collections.reverse(listObjects);
for(DBObject object : listObjects) {
// Create the MongoDocument.
MongoChatMessage mongoChatMessage = new MongoChatMessage(collectionMessages, object);
// Create the container for the document.
ChatMessage chatMessage = new ChatMessage(mongoChatMessage);
// Add this to the list to return.
listChatMessages.add(chatMessage);
}
}
// Close the cursor to release resources.
cursor.close();
// Return the result list of messages for the channel.
return listChatMessages;
}
示例3: getRecentBuildStatsForProduct
import com.mongodb.DBCursor; //导入方法依赖的package包/类
@GET
@Path("/recent-builds/{product}")
public DBObject getRecentBuildStatsForProduct(@BeanParam final Coordinates coordinates, @QueryParam("limit") final Integer limit) {
final BasicDBList returns = new BasicDBList();
final DB db = this.client.getDB("bdd");
final DBCollection collection = db.getCollection("reportStats");
final BasicDBObject example = coordinates.getQueryObject(Field.PRODUCT);
final DBCursor cursor = collection.find(example).sort(Coordinates.getFeatureSortingObject());
if (limit != null) {
cursor.limit(limit);
}
try {
while (cursor.hasNext()) {
final DBObject doc = cursor.next();
returns.add(doc);
}
} finally {
cursor.close();
}
return returns;
}
示例4: selectSet
import com.mongodb.DBCursor; //导入方法依赖的package包/类
public DBCursor selectSet(DBCollection collection) {
DBObject fields = getFields();
DBObject query = getQuery();
DBObject orderByObject = getOrderByObject();
DBCursor cursor = null;
// 日志
log(fields, query, orderByObject);
if (null != query && null == fields) {
cursor = collection.find(query);
} else if (null == query && null != fields) {
cursor = collection.find(new BasicDBObject(), fields);
} else if (null != fields && null != query) {
cursor = collection.find(query, fields);
} else {
cursor = collection.find();
}
if (null != orderByObject) {
cursor.sort(orderByObject);
}
if (null != this.limit) {
if (null == this.limit.getOffset()) {
cursor.limit(this.limit.getRowCount());
} else {
cursor.limit(this.limit.getRowCount());
cursor.skip(this.limit.getOffset());
}
}
return cursor;
}
示例5: find
import com.mongodb.DBCursor; //导入方法依赖的package包/类
private static ModulesContainer find(DBObject query, DBObject orderBy, Integer limit, Integer page) throws SinfonierException {
DBCollection collection = MongoFactory.getDB().getCollection(collectionName);
List<Module> list = new ArrayList<Module>();
DBCursor cursor;
if (limit != null) {
page = (page != null && page > 0) ? ((page-1)*limit) : 0;
} else {
page = null;
}
if (query == null) {
cursor = collection.find();
} else {
cursor = collection.find(query);
}
int totalModules = cursor.count();
if (orderBy != null) {
cursor = cursor.sort(orderBy);
}
if (page != null && page > 0) {
cursor.skip(page);
}
if (limit != null) {
cursor = cursor.limit(limit);
}
for (DBObject dbObject : cursor) {
list.add(new Module(dbObject));
}
return new ModulesContainer(list, totalModules);
}
示例6: find
import com.mongodb.DBCursor; //导入方法依赖的package包/类
private static TopologiesContainer find(DBObject query, DBObject orderBy, Integer limit, Integer page) throws SinfonierException {
DBCollection collection = MongoFactory.getDB().getCollection(getCollectionName());
List<Topology> list = new ArrayList<Topology>();
DBCursor cursor;
if (limit != null) {
page = (page != null && page > 0) ? ((page-1)*limit) : 0;
} else {
page = null;
}
if (query == null) {
cursor = collection.find();
} else {
cursor = collection.find(query);
}
int totalTopologies = cursor.count();
if (orderBy != null) {
cursor = cursor.sort(orderBy);
}
if (page != null && page > 0) {
cursor.skip(page);
}
if (limit != null) {
cursor = cursor.limit(limit);
}
for (DBObject dbObject : cursor) {
list.add(new Topology(dbObject));
}
return new TopologiesContainer(list, totalTopologies);
}
示例7: getFeatures
import com.mongodb.DBCursor; //导入方法依赖的package包/类
/**
*
* @param queryObject
* @param limit Limitation on the number of results returned. Setting to 0 is equivalent to unlimited
* @return
* @throws IOException
*/
private Collection<DBFeature.IGVFeat> getFeatures(DBObject queryObject, int limit) throws IOException{
DBCursor cursor = this.collection.find(queryObject);
cursor.limit(limit >= 0 ? limit : 0);
//Sort by increasing start value
//Only do this if we have an index, otherwise might be too memory intensive
if(hasLocusIndex){
cursor.sort(new BasicDBObject("Start", 1));
}
boolean isSorted = true;
int lastStart = -1;
List<DBFeature.IGVFeat> features = new ArrayList<DBFeature.IGVFeat>();
while (cursor.hasNext()) {
DBObject obj = cursor.next();
DBFeature feat = (DBFeature) obj;
features.add(feat.createIGVFeature());
isSorted &= feat.getStart() >= lastStart;
lastStart = feat.getStart();
}
if(!isSorted){
FeatureUtils.sortFeatureList(features);
}
return features;
}
示例8: getRecentVersionStatsForProduct
import com.mongodb.DBCursor; //导入方法依赖的package包/类
/**
* Go through the prior versions of this product; for each version, find the latest build and contribute the stats for that to the
* returned list.
*
* @param coordinates
* @param limit
* @return A list of report stats in reverse version order.
* @throws UnknownHostException
*/
@GET
@Path("/recent-versions/{product}")
public DBObject getRecentVersionStatsForProduct(@BeanParam final Coordinates coordinates, @QueryParam("limit") final Integer limit) {
final BasicDBList returns = new BasicDBList();
final DB db = this.client.getDB("bdd");
final DBCollection summaryCollection = db.getCollection("summary");
final DBCollection reportStatsCollection = db.getCollection("reportStats");
final DBCursor versions = summaryCollection.find(coordinates.getQueryObject(Field.PRODUCT)).sort(Coordinates.getFeatureSortingObject());
if (limit != null) {
versions.limit(limit);
}
try {
while (versions.hasNext()) { // go through each summary document
final DBObject version = versions.next(); // each represents the coordinates for a given version
final Coordinates c = new Coordinates((DBObject) version.get("coordinates"));
final BasicDBList builds = (BasicDBList) version.get("builds");
c.setBuild((String) builds.get(builds.size() - 1)); // we need to specify which build (the latest is last in the list)
final DBObject query = c.getQueryObject();
returns.add(reportStatsCollection.findOne(query));
}
} finally {
versions.close();
}
return returns;
}
示例9: getReportByProductVersionId
import com.mongodb.DBCursor; //导入方法依赖的package包/类
@GET
@Path("/{product}/{major}.{minor}.{servicePack}/{build}")
@Produces("application/json")
public DBObject getReportByProductVersionId(@BeanParam final Coordinates coordinates,
@QueryParam("searchText") final String searchText, @QueryParam("viewPassed") final Integer viewPassed,
@QueryParam("viewFailed") final Integer viewFailed,
@QueryParam("viewUndefined") final Integer viewUndefined, @QueryParam("viewSkipped") final Integer viewSkipped,
@QueryParam("start") final String start, @QueryParam("limit") final Integer limit) {
final BasicDBObject example = QueryBuilder.getInstance().buildFilterQuery(coordinates, searchText, viewPassed,
viewFailed, viewUndefined, viewSkipped, start);
final DB db = this.client.getDB("bdd");
final DBCollection collection = db.getCollection("features");
final DBCursor cursor = collection.find(example).sort(Coordinates.getFeatureSortingObject());
try {
if (limit != null) {
cursor.limit(limit);
}
final BasicDBList featuresToReturn = new BasicDBList();
while (cursor.hasNext()) {
featuresToReturn.add(cursor.next());
}
embedTestingTips(featuresToReturn, coordinates, db);
return featuresToReturn;
} finally {
cursor.close();
}
}
示例10: query
import com.mongodb.DBCursor; //导入方法依赖的package包/类
private AssetCursor query(DBObject filterObject, DBObject sortObject, DBObject projectionObject, PaginationOptions pagination) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("query: Querying database with query object " + filterObject);
logger.fine("query: sort object " + sortObject);
logger.fine("query: projection object " + projectionObject);
logger.fine("query: pagination object " + pagination);
}
DBCursor cursor = getAssetCollection().find(filterObject, projectionObject);
if (logger.isLoggable(Level.FINE)) {
logger.fine("query: found " + cursor.count() + " assets.");
}
if (pagination != null) {
cursor.skip(pagination.getOffset());
cursor.limit(pagination.getLimit());
}
if (sortObject != null) {
cursor.sort(sortObject);
}
AssetCursor result = new MongoAssetCursor(cursor);
result.addOperation(CONVERT_OID_TO_HEX);
return result;
}
示例11: addOptionsOn
import com.mongodb.DBCursor; //导入方法依赖的package包/类
private void addOptionsOn(DBCursor cursor) {
if (limit != null) {
cursor.limit(limit);
}
if (skip != null) {
cursor.skip(skip);
}
if (sort != null) {
cursor.sort(sort.toDBObject());
}
if (hint != null) {
cursor.hint(hint.toDBObject());
}
}
示例12: applyCursorConfigs
import com.mongodb.DBCursor; //导入方法依赖的package包/类
public void applyCursorConfigs(DBCursor dbCursor) {
if (skip!=null || limit!=null) {
log.debug("Applying page to cursor: skip="+skip+", limit="+limit);
if (skip!=null) {
dbCursor.skip(skip);
}
if (limit!=null) {
dbCursor.limit(limit);
}
}
if (orderBy!=null) {
log.debug("Applying sort to cursor: "+orderBy);
dbCursor.sort(orderBy);
}
}
示例13: createWorkflowDbCursor
import com.mongodb.DBCursor; //导入方法依赖的package包/类
public DBCursor createWorkflowDbCursor(WorkflowQuery query) {
BasicDBObject dbQuery = createDbQuery(query);
DBCursor dbCursor = workflowsCollection.find("find-workflows", dbQuery);
if (query.getLimit()!=null) {
dbCursor.limit(query.getLimit());
}
if (query.getOrderBy()!=null) {
dbCursor.sort(writeOrderBy(query.getOrderBy()));
}
return dbCursor;
}
示例14: findData
import com.mongodb.DBCursor; //导入方法依赖的package包/类
@Override
public <T extends Model> List<Map<String, Object>> findData(Class<T> modelClass, Map<String, Object> filter,
QueryOptions queryOptions, DBCollection collection) {
if (modelClass == null)
throw new DaoException("Model class cannot be empty");
if (filter == null)
filter = EMPTY_FILTER;
List<Map<String, Object>> docs = new ArrayList<>();
DBObject dbObject = buildQueryFilter(modelClass, filter, queryOptions);
// if (!modelClass.getName().startsWith("com.geecommerce.core"))
// System.out.println("filter: " + dbObject);
DBObject fields = buildFieldList(modelClass, queryOptions);
// System.out.println("fields: " + fields);
DBObject sortBy = buildSortBy(modelClass, queryOptions);
// System.out.println("sort: " + sortBy);
DBCollection col = collection == null ? collection(modelClass) : collection;
// ------------------------------------------------------------------
// Query with filter
// ------------------------------------------------------------------
DBCursor cursor = null;
try {
cursor = col.find(dbObject, fields);
cursor.sort(sortBy);
if (queryOptions != null && queryOptions.limit() != null) {
cursor.limit(queryOptions.limit());
} else {
// There is no reason to ever return more than 1500 results. //
// TODO: make configurable
cursor.limit(1500);
}
if (queryOptions != null && queryOptions.offset() != null) {
cursor.skip(queryOptions.offset().intValue());
}
// ------------------------------------------------------------------
// Iterate through results and add to results list docs
// ------------------------------------------------------------------
while (cursor.hasNext()) {
DBObject doc = cursor.next();
if (doc != null) {
try {
Map<String, Object> map = new LinkedHashMap<>();
convertToMongoDBValues(doc, map);
docs.add(map);
} catch (Throwable t) {
t.printStackTrace();
throw new DaoException(t);
}
}
}
} finally {
if (cursor != null)
cursor.close();
}
return docs;
}