本文整理匯總了Java中com.mongodb.client.FindIterable.skip方法的典型用法代碼示例。如果您正苦於以下問題:Java FindIterable.skip方法的具體用法?Java FindIterable.skip怎麽用?Java FindIterable.skip使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.mongodb.client.FindIterable
的用法示例。
在下文中一共展示了FindIterable.skip方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: find
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
/**
* 查找指定條數的數據
*/
public <T> List<T> find(String collectionName, Integer pageNumber, Integer pageSize, Class<T> clazz) {
MongoCollection collection = mongoDatabase.getCollection(collectionName);
List<T> list = new ArrayList<>();
if (collection == null) {
return list;
}
FindIterable findIterable = collection.find();
if (pageSize != null && pageSize >= 0) {
if (pageNumber != null && pageNumber >= 1) {
findIterable = findIterable.skip((pageNumber - 1) * pageSize);
}
findIterable = findIterable.limit(pageSize);
}
Iterator<Document> iterator = findIterable.iterator();
while (iterator.hasNext()) {
Document document = iterator.next();
document.remove("_id");
T t = JSON.parseObject(document.toJson(), clazz);
list.add(t);
}
return list;
}
示例2: query
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
private FindIterable<Document> query(final Bson filter, final Bson sort, final Bson projection, final int offset, final int count) {
if (offset < 0 || count < 0) {
throw new IllegalArgumentException("offset (" + offset + ") and count(" + count + ") can't be negative");
}
FindIterable<Document> findIterable = coll.find(filter);
if (projection != null) {
findIterable = findIterable.projection(projection);
}
if (sort != null) {
findIterable = findIterable.sort(sort);
}
if (offset > 0) {
findIterable = findIterable.skip(offset);
}
if (count < Integer.MAX_VALUE) {
findIterable = findIterable.limit(count);
}
return findIterable;
}
示例3: getDocumentMongoCursor
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
private MongoCursor<Document> getDocumentMongoCursor(Table table, List<FilterItem> whereItems, int firstRow,
int maxRows, Consumer<FilterItem> filterItemsToPostProcessConsumer) {
final MongoCollection<Document> collection = _mongoDb.getCollection(table.getName());
final Document query = createMongoDbQuery(table, whereItems, filterItemsToPostProcessConsumer);
logger.info("Executing MongoDB 'find' query: {}", query);
FindIterable<Document> iterable = collection.find(query);
if (maxRows > 0) {
iterable = iterable.limit(maxRows);
}
if (firstRow > 1) {
final int skip = firstRow - 1;
iterable = iterable.skip(skip);
}
return iterable.iterator();
}
示例4: find
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
/**
* 查詢
*
* @param collectionName 集合名
* @param query 查詢條件
* @param fields 返回字段或者排除字段
* @param sort 排序方式
* @param pageInfo 分頁
* @return
*/
public List<Map<String, Object>> find(
String collectionName,
MongodbQuery query, MongodbFields fields,
MongodbSort sort, MongodbPageInfo pageInfo) {
List<Map<String, Object>> resultMapList = new ArrayList<Map<String, Object>>();
MongoCollection<Document> collection = sMongoDatabase.getCollection(collectionName);
FindIterable<Document> findIterable = collection.find(query == null ? new Document() : query.getQuery());
if (fields == null) {
findIterable.projection(new MongodbFields().getDbObject());
} else {
findIterable.projection(fields.getDbObject());
}
if (sort != null) {
findIterable.sort(sort.getDbObject());
}
if (pageInfo != null) {
int startPos = pageInfo.getPageIndex() * pageInfo.getPageSize();
int rows = pageInfo.getPageSize();
if (startPos > 0) {
findIterable.skip(startPos - 1);
}
findIterable.limit(rows);
}
MongoCursor<Document> cursor = findIterable.iterator();
try {
while (cursor.hasNext()) {
Map<String, Object> document = cursor.next();
resultMapList.add(document);
}
} finally {
cursor.close();
}
return resultMapList;
}
示例5: fetchDataFromBackEnd
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
protected List<T> fetchDataFromBackEnd(Query<T, Bson> query) {
Bson filter = getFilter(query);
FindIterable<T> findIterable = mongoCollection.find();
if (filter != null) findIterable = findIterable.filter(filter);
findIterable = findIterable.skip(query.getOffset());
findIterable = findIterable.limit(query.getLimit());
findIterable = findIterable.sort(getSorts(query.getSortOrders()));
final List<T> data = new ArrayList<T>();
findIterable.iterator().forEachRemaining(data::add);
return data;
}
示例6: iterator
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
@Override
public Iterator<Document> iterator() {
FindIterable fi = dc.getCollection().find(query.getQuery()).sort(query.getSort());
if (limit != -1) {
fi = fi.limit(limit);
}
if (skip != -1) {
fi = fi.skip(skip);
}
cursor = fi.iterator();
return new Iterator<Document>() {
@Override
public boolean hasNext() {
return cursor.hasNext();
}
@Override
public Document next() {
org.bson.Document dbObject = (org.bson.Document) cursor.next();
return dc.getDocumentForBSON(dbObject);
}
@Override
public void remove() {
cursor.remove();
}
};
}
示例7: read
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
@ExtDirectMethod(STORE_READ)
public ExtDirectStoreResult<User> read(ExtDirectStoreReadRequest request) {
List<Bson> andFilters = new ArrayList<>();
StringFilter filter = request.getFirstFilterForField("filter");
if (filter != null) {
List<Bson> orFilters = new ArrayList<>();
orFilters.add(Filters.regex(CUser.loginName, filter.getValue(), "i"));
orFilters.add(Filters.regex(CUser.lastName, filter.getValue(), "i"));
orFilters.add(Filters.regex(CUser.firstName, filter.getValue(), "i"));
orFilters.add(Filters.regex(CUser.email, filter.getValue(), "i"));
andFilters.add(Filters.or(orFilters));
}
andFilters.add(Filters.eq(CUser.deleted, false));
long total = this.mongoDb.getCollection(User.class)
.count(Filters.and(andFilters));
FindIterable<User> find = this.mongoDb.getCollection(User.class)
.find(Filters.and(andFilters));
find.sort(Sorts.orderBy(QueryUtil.getSorts(request)));
find.skip(request.getStart());
find.limit(request.getLimit());
return new ExtDirectStoreResult<>(total, QueryUtil.toList(find));
}
示例8: runNativeQuery
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
@Override
public RaptureQueryResult runNativeQuery(final String repoType, final List<String> queryParams) {
if (repoType.toUpperCase().equals(MONGODB)) {
MongoRetryWrapper<RaptureQueryResult> wrapper = new MongoRetryWrapper<RaptureQueryResult>() {
@Override
public FindIterable<Document> makeCursor() {
// Here we go, the queryParams are basically
// (1) the searchCriteria
Document queryObj = getQueryObjFromQueryParams(queryParams);
// Document fieldObj =
// getFieldObjFromQueryParams(queryParams);
MongoCollection<Document> collection = MongoDBFactory.getCollection(instanceName, tableName);
FindIterable<Document> find = collection.find(queryObj).batchSize(100);
if (queryParams.size() > 2) {
Map<String, Object> options = JacksonUtil.getMapFromJson(queryParams.get(2));
if (options.containsKey(SKIP)) {
find.skip((Integer) options.get(SKIP));
}
if (options.containsKey(LIMIT)) {
find.limit((Integer) options.get(LIMIT));
}
if (options.containsKey(SORT)) {
Map<String, Object> sortInfo = JacksonUtil.getMapFromJson(options.get(SORT).toString());
Document sortInfoObject = new Document();
sortInfoObject.putAll(sortInfo);
find.sort(sortInfoObject);
}
}
return find;
}
@Override
public RaptureQueryResult action(FindIterable<Document> iterable) {
RaptureQueryResult res = new RaptureQueryResult();
for (Document d : iterable) {
res.addRowContent(new JsonContent(d.toString()));
}
return res;
}
};
return wrapper.doAction();
} else {
throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, mongoMsgCatalog.getMessage("Mismatch", repoType));
}
}
示例9: createDoFindAll
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
private Function<Exchange, Object> createDoFindAll() {
return exchange1 -> {
Iterable<BasicDBObject> result;
MongoCollection<BasicDBObject> dbCol = calculateCollection(exchange1);
// do not use getMandatoryBody, because if the body is empty we want to retrieve all objects in the collection
BasicDBObject query = null;
// do not run around looking for a type converter unless there is a need for it
if (exchange1.getIn().getBody() != null) {
query = exchange1.getIn().getBody(BasicDBObject.class);
}
BasicDBObject fieldFilter = exchange1.getIn().getHeader(MongoDbConstants.FIELDS_FILTER, BasicDBObject.class);
// get the batch size and number to skip
Integer batchSize = exchange1.getIn().getHeader(MongoDbConstants.BATCH_SIZE, Integer.class);
Integer numToSkip = exchange1.getIn().getHeader(MongoDbConstants.NUM_TO_SKIP, Integer.class);
Integer limit = exchange1.getIn().getHeader(MongoDbConstants.LIMIT, Integer.class);
BasicDBObject sortBy = exchange1.getIn().getHeader(MongoDbConstants.SORT_BY, BasicDBObject.class);
FindIterable<BasicDBObject> ret;
if (query == null && fieldFilter == null) {
ret = dbCol.find(new BasicDBObject());
} else if (fieldFilter == null) {
ret = dbCol.find(query);
} else {
ret = dbCol.find(new BasicDBObject()).projection(fieldFilter);
}
if (sortBy != null) {
ret.sort(sortBy);
}
if (batchSize != null) {
ret.batchSize(batchSize);
}
if (numToSkip != null) {
ret.skip(numToSkip);
}
if (limit != null) {
ret.limit(limit);
}
if (!MongoDbOutputType.DBCursor.equals(endpoint.getOutputType())) {
try {
result = new ArrayList<>();
ret.iterator().forEachRemaining(((List<BasicDBObject>) result)::add);
exchange1.getOut().setHeader(MongoDbConstants.RESULT_PAGE_SIZE, ((List<BasicDBObject>) result).size());
} finally {
ret.iterator().close();
}
} else {
result = ret;
}
return result;
};
}
示例10: execute
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
public cfData execute(cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException {
MongoDatabase db = getMongoDatabase( _session, argStruct );
String collection = getNamedStringParam(argStruct, "collection", null);
if ( collection == null )
throwException(_session, "please specify a collection");
cfData query = getNamedParam(argStruct, "query", null );
if ( query == null )
throwException(_session, "please specify query");
int size = getNamedIntParam(argStruct, "size", -1 );
int skip = getNamedIntParam(argStruct, "skip", -1 );
cfData sort = getNamedParam(argStruct, "sort", null );
cfData fields = getNamedParam(argStruct, "fields", null );
try{
MongoCollection<Document> col = db.getCollection(collection);
// Get the initial cursor
FindIterable<Document> cursor;
long start = System.currentTimeMillis();
Document qry = getDocument(query);
cursor = col.find( qry );
if ( fields != null )
cursor = cursor.projection( getDocument(fields) );
// Are we sorting?
if ( sort != null )
cursor = cursor.sort( getDocument(sort) );
// Are we limiting
if ( skip != -1 )
cursor = cursor.skip(skip);
// How many we bringing back
if ( size != -1 )
cursor = cursor.limit(size);
// Now we can run the query
cfArrayData results = cfArrayData.createArray(1);
cursor.forEach( new Block<Document>() {
@SuppressWarnings( "rawtypes" )
@Override
public void apply( final Document st ) {
try {
results.addElement( tagUtils.convertToCfData( (Map)st ) );
} catch ( cfmRunTimeException e ) {}
}
} );
_session.getDebugRecorder().execMongo(col, "find", qry, System.currentTimeMillis()-start);
return results;
} catch (MongoException me){
throwException(_session, me.getMessage());
return null;
}
}
示例11: invoke
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
@Override
public Object invoke( Object proxy, Method method, Object[] args )
throws Throwable
{
String methodName = method.getName();
switch ( methodName )
{
case "e":
// this is just a handout for the entity to get knowledge of what to check
return this.entityProxy.get();
case "where":/* fallthrough */
case "and":
return this.specifier.get();
case "iterator":
FindIterable it = coll.find( Filters.and( filters.toArray( new Bson[] {} ) ) );
if ( limit != null )
{
it.limit( limit );
}
if ( skip != null )
{
it.skip( skip );
}
if ( sorts.size() > 0 )
{
it.sort( Sorts.orderBy( sorts ) );
}
return it.iterator();
case "count":
return coll.count( Filters.and( filters.toArray( new Bson[] {} ) ) );
case "limit":
limit = (Integer) args[0];
return queryEnd.get();
case "skip":
skip = (Integer) args[0];
return queryEnd.get();
case "sort":
checkState( !sortSet, "Sorting can be specified only once" );
sortSet = true;
return querySort.get();
case "desc":/* fallthrough */
case "asc":
return addSortInformation( "asc".equals( methodName ) );
case "by":
return addSortInformation( args[0] == QuerySort.Sort.ASC );
}
throw new IllegalStateException( "Unknown method found: " + methodName );
}