com.mongodb.DBCursor#limit ( )源码实例Demo

下面列出了com.mongodb.DBCursor#limit ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private void toPrivateStorageList(String collectionName,
                                  List<PrivateStorage> privatesStorage,
                                  DBCursor cursor,
                                  int pageNumber,
                                  int pageSize) throws JsonProcessingException {
    try {
        cursor.skip(pageNumber);
        cursor.limit(pageSize);
        while (cursor.hasNext()) {
            cursor.next();

            String content = jsonParsingService.toJsonString(cursor.curr().toMap());

            privatesStorage.add(PrivateStorage.builder()
                    .collectionName(collectionName)
                    .collectionContent(content)
                    .build());
        }
    } finally {
        cursor.close();
    }
}
 
源代码2 项目: XBDD   文件: AutomationStatistics.java
@GET
@Path("/recent-builds/{product}")
public Response getRecentBuildStatsForProduct(@BeanParam final Coordinates coordinates, @QueryParam("limit") final Integer limit) {
	final BasicDBList returns = new BasicDBList();
	final DBCollection collection = this.mongoLegacyDb.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 Response.ok(SerializerUtil.serialise(returns)).build();
}
 
源代码3 项目: tangyuan2   文件: SelectVo.java
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;
}
 
源代码4 项目: XBDD   文件: AutomationStatistics.java
/**
 * 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.
 */
@GET
@Path("/recent-versions/{product}")
@Produces(MediaType.APPLICATION_JSON)
public Response getRecentVersionStatsForProduct(@BeanParam final Coordinates coordinates, @QueryParam("limit") final Integer limit) {
	final BasicDBList returns = new BasicDBList();

	final DBCollection summaryCollection = this.mongoLegacyDb.getCollection("summary");
	final DBCollection reportStatsCollection = this.mongoLegacyDb.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 Response.ok(SerializerUtil.serialise(returns)).build();
}
 
源代码5 项目: hvdf   文件: MongoDBQueryHelpers.java
public static void getSamplesFromCursor(DBCursor cursor, int limit, List<Sample> outList){
    try{
        // exhaust the cursor adding each sample
		cursor.batchSize(limit);
		cursor.limit(limit);
        while(cursor.hasNext()) {
        	outList.add(new Sample(cursor.next()));
        }
    } finally {
        // ensure cursor is closed
        cursor.close();
    }
}
 
源代码6 项目: BLELocalization   文件: DataServlet.java
/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
 *      response)
 * 
 *      Get resource
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	if (mDS != MongoService.getInstance()) {
		System.out.println("MongoService db name is changed");
		mDS = MongoService.getInstance();
		mCollRef = mDS.getCollection("refpoints");
		mCollSamp = mDS.getCollection("samplings");
		mCollMap = mDS.getCollection("maps");
	}
	
	String type = request.getParameter("type");
	String id = request.getParameter("id");
	System.out.println("doGet: type=" + type + " id=" + id);

	if ("file".equals(type)) {
		if (id == null) {
			// Get list of files
			mDS.sendJSON(mDS.getFileList(), request, response);
			return;
		}
		try {
			mDS.sendFile(id, response);
		} catch (Exception e) {
			System.err.println("Send error: " + id);
		}
		return;
	}

	// Get document(s)
	String distinct = request.getParameter("distinct");
	String pipeline = request.getParameter("pipeline");
	String query = request.getParameter("query");
	String keys = request.getParameter("keys");
	String format = request.getParameter("format");
	DBObject queryObj = query != null ? (DBObject) JSON.parse(query) : null;
	DBObject keysObj = keys != null ? (DBObject) JSON.parse(keys) : null;

	Object result = null;
	DBCollection collection = mDS.getCollection(type);
	if (id != null) {
		result = collection.findOne(new ObjectId(id), keysObj);
	} else if (distinct != null) {
		result = collection.distinct(distinct, queryObj);
	} else if (pipeline != null) {
		DBObject pipelineObj = (DBObject) JSON.parse(pipeline);
		if (pipelineObj instanceof List<?>) {
			result = collection.aggregate((List<DBObject>) pipelineObj).results();
		} else {
			result = collection.aggregate(pipelineObj).results();
		}
	} else {
		DBCursor cursor = collection.find(queryObj, keysObj);
		String sort = request.getParameter("sort");
		String skip = request.getParameter("skip");
		String limit = request.getParameter("limit");
		String count = request.getParameter("count");
		if (sort != null) {
			cursor = cursor.sort((DBObject) JSON.parse(sort));
		}
		if (skip != null) {
			cursor = cursor.skip(Integer.parseInt(skip));
		}
		if (limit != null) {
			cursor = cursor.limit(Integer.parseInt(limit));
		}
		result = "true".equals(count) ? cursor.count() : cursor;
	}
	if (id != null && result == null) {
		response.sendError(HttpServletResponse.SC_BAD_REQUEST, String.format("Document %s does not exist", id));
		return;
	}
	if ("csv".equals(format)) {
		mDS.sendCSV(result, request, response);
		return;
	}
	mDS.sendJSON(result, request, response);
}