本文整理汇总了Java中com.mongodb.DBCursor.skip方法的典型用法代码示例。如果您正苦于以下问题:Java DBCursor.skip方法的具体用法?Java DBCursor.skip怎么用?Java DBCursor.skip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.DBCursor
的用法示例。
在下文中一共展示了DBCursor.skip方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例3: 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);
}
示例4: 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);
}
示例5: 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;
}
示例6: 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());
}
}
示例7: 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);
}
}
示例8: 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;
}