当前位置: 首页>>代码示例>>Java>>正文


Java FindIterable.skip方法代码示例

本文整理汇总了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;
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:27,代码来源:SimpleMongodbAccessor.java

示例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;
}
 
开发者ID:landawn,项目名称:AbacusUtil,代码行数:26,代码来源:MongoCollectionExecutor.java

示例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();
}
 
开发者ID:apache,项目名称:metamodel,代码行数:20,代码来源:MongoDbDataContext.java

示例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;
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:46,代码来源:MongodbDataAccess.java

示例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;
}
 
开发者ID:andyphillips404,项目名称:awplab-core,代码行数:13,代码来源:MongoDataProvider.java

示例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();
        }
    };
}
 
开发者ID:KAOREND,项目名称:reactive-hamster,代码行数:30,代码来源:DocumentCursor.java

示例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));
}
 
开发者ID:ralscha,项目名称:eds-starter6-mongodb,代码行数:28,代码来源:UserService.java

示例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));
    }
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:49,代码来源:MongoDbDataStore.java

示例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;
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:57,代码来源:MongoDbProducer.java

示例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;
	}
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:64,代码来源:MongoCollectionFind.java

示例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 );
}
 
开发者ID:cherimojava,项目名称:cherimodata,代码行数:49,代码来源:QueryInvocationHandler.java


注:本文中的com.mongodb.client.FindIterable.skip方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。