當前位置: 首頁>>代碼示例>>Java>>正文


Java DBCursor.skip方法代碼示例

本文整理匯總了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);
}
 
開發者ID:WASdev,項目名稱:tool.lars,代碼行數:23,代碼來源:PersistenceBeanBasicSearchTest.java

示例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;
}
 
開發者ID:xsonorg,項目名稱:tangyuan2,代碼行數:33,代碼來源:SelectVo.java

示例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);
}
 
開發者ID:telefonicaid,項目名稱:fiware-sinfonier,代碼行數:38,代碼來源:Module.java

示例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);
}
 
開發者ID:telefonicaid,項目名稱:fiware-sinfonier,代碼行數:38,代碼來源:Topology.java

示例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;
    }
 
開發者ID:WASdev,項目名稱:tool.lars,代碼行數:29,代碼來源:PersistenceBean.java

示例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());
    }
}
 
開發者ID:CIDARLAB,項目名稱:clotho3crud,代碼行數:15,代碼來源:RefFind.java

示例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);
  }
}
 
開發者ID:effektif,項目名稱:effektif,代碼行數:16,代碼來源:Query.java

示例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;
}
 
開發者ID:geetools,項目名稱:geeCommerce-Java-Shop-Software-and-PIM,代碼行數:72,代碼來源:AbstractMongoDao.java


注:本文中的com.mongodb.DBCursor.skip方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。