Java Code Examples for org.springframework.data.mongodb.core.query.Query#skip()

The following examples show how to use org.springframework.data.mongodb.core.query.Query#skip() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongoAccessor.java    From jstarcraft-core with Apache License 2.0 6 votes vote down vote up
@Override
public <K extends Comparable, T extends IdentityObject<K>> List<T> queryIntersection(Class<T> clazz, Map<String, Object> condition, StoragePagination pagination) {
	MongoMetadata metadata = metadatas.get(clazz);
	final Iterator<Entry<String, Object>> conditionIterator = condition.entrySet().iterator();
	Criteria criteria = Criteria.where(MongoMetadata.mongoId).exists(true);
	Criteria[] andCriterias = new Criteria[condition.size()];
	int index = 0;
	while (conditionIterator.hasNext()) {
		Entry<String, Object> keyValue = conditionIterator.next();
		String key = keyValue.getKey();
		Object value = keyValue.getValue();
		if (metadata.getPrimaryName().equals(key)) {
			key = MongoMetadata.mongoId;
		}
		andCriterias[index++] = Criteria.where(key).is(value);
	}
	Query query = Query.query(criteria.andOperator(andCriterias));
	if (pagination != null) {
		query.skip(pagination.getFirst());
		query.limit(pagination.getSize());
	}
	return template.find(query, clazz, metadata.getOrmName());
}
 
Example 2
Source File: MongoAccessor.java    From jstarcraft-core with Apache License 2.0 6 votes vote down vote up
@Override
public <K extends Comparable, T extends IdentityObject<K>> List<T> queryUnion(Class<T> clazz, Map<String, Object> condition, StoragePagination pagination) {
	MongoMetadata metadata = metadatas.get(clazz);
	final Iterator<Entry<String, Object>> conditionIterator = condition.entrySet().iterator();
	Criteria criteria = Criteria.where(MongoMetadata.mongoId).exists(true);
	Criteria[] orCriterias = new Criteria[condition.size()];
	int index = 0;
	while (conditionIterator.hasNext()) {
		Entry<String, Object> keyValue = conditionIterator.next();
		String key = keyValue.getKey();
		Object value = keyValue.getValue();
		if (metadata.getPrimaryName().equals(key)) {
			key = MongoMetadata.mongoId;
		}
		orCriterias[index++] = Criteria.where(key).is(value);
	}
	Query query = Query.query(criteria.orOperator(orCriterias));
	if (pagination != null) {
		query.skip(pagination.getFirst());
		query.limit(pagination.getSize());
	}
	return template.find(query, clazz, metadata.getOrmName());
}
 
Example 3
Source File: MongoAccessor.java    From jstarcraft-core with Apache License 2.0 6 votes vote down vote up
@Override
public <K extends Comparable, T extends IdentityObject<K>> void iterate(StorageIterator<T> iterator, Class<T> clazz, StoragePagination pagination) {
	MongoMetadata metadata = metadatas.get(clazz);
	Query query = new Query(Criteria.where(MongoMetadata.mongoId).exists(true));
	if (pagination != null) {
		query.skip(pagination.getFirst());
		query.limit(pagination.getSize());
	}
	try (CloseableIterator<T> stream = template.stream(query, clazz, metadata.getOrmName())) {
		while (stream.hasNext()) {
			try {
				// TODO 需要考虑中断
				final T object = stream.next();
				iterator.iterate(object);
			} catch (Throwable throwable) {
				throw new StorageQueryException(throwable);
			}
		}
	}
}
 
Example 4
Source File: MongoDataPointRepositoryImpl.java    From omh-dsu-ri with Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<DataPoint> findBySearchCriteria(DataPointSearchCriteria searchCriteria, @Nullable Integer offset,
        @Nullable Integer limit) {

    checkNotNull(searchCriteria);
    checkArgument(offset == null || offset >= 0);
    checkArgument(limit == null || limit >= 0);

    Query query = newQuery(searchCriteria);

    if (offset != null) {
        query.skip(offset);
    }

    if (limit != null) {
        query.limit(limit);
    }

    return mongoOperations.find(query, DataPoint.class);
}
 
Example 5
Source File: IngestionBatchJobDAOImpl.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
public List<IngestionBatchJob> find(String tenantId, Integer limit, Integer offset, String sortOn, Order order) {
	Query query = new Query();

	// Tenant Id is required.
	query.addCriteria(Criteria.where("tenantId").is(tenantId));
	/*
	 * We are going to allow for null for multiple items, so we'll do a null check on each.
	 */
	if (limit != null) {
		query.limit(limit);
	}
	
	if (offset != null) {
		query.skip(offset);
	}

	if (sortOn != null && !"".equals(sortOn)) {
		if (order != null) {
			query.sort().on(sortOn, order);
		} else {
			query.sort().on(sortOn, Order.ASCENDING);
		}
	}
	return ingestionBatchJobMongoTemplate.find(query, IngestionBatchJob.class);
}
 
Example 6
Source File: DataTablesCriteria.java    From spring-data-mongodb-datatables with Apache License 2.0 5 votes vote down vote up
private void addSort(Query query, DataTablesInput input) {
    query.skip(input.getStart());
    query.limit(input.getLength());

    if (isEmpty(input.getOrder())) return;

    List<Sort.Order> orders = input.getOrder().stream()
            .filter(order -> isOrderable(input, order))
            .map(order -> toOrder(input, order)).collect(toList());
    query.with(by(orders));
}
 
Example 7
Source File: MongoAccessor.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@Override
public <K extends Comparable, T extends IdentityObject<K>> List<T> queryInstances(Class<T> clazz, StoragePagination pagination) {
	MongoMetadata metadata = metadatas.get(clazz);
	Query query = new Query(Criteria.where(MongoMetadata.mongoId).exists(true));
	if (pagination != null) {
		query.skip(pagination.getFirst());
		query.limit(pagination.getSize());
	}
	return template.find(query, clazz, metadata.getOrmName());
}
 
Example 8
Source File: MongoAccessor.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@Override
public <K extends Comparable, T extends IdentityObject<K>> void iterateIntersection(StorageIterator<T> iterator, Class<T> clazz, Map<String, Object> condition, StoragePagination pagination) {
	MongoMetadata metadata = metadatas.get(clazz);
	final Iterator<Entry<String, Object>> conditionIterator = condition.entrySet().iterator();
	Criteria criteria = Criteria.where(MongoMetadata.mongoId).exists(true);
	Criteria[] andCriterias = new Criteria[condition.size()];
	int index = 0;
	while (conditionIterator.hasNext()) {
		Entry<String, Object> keyValue = conditionIterator.next();
		String key = keyValue.getKey();
		Object value = keyValue.getValue();
		if (metadata.getPrimaryName().equals(key)) {
			key = MongoMetadata.mongoId;
		}
		andCriterias[index++] = Criteria.where(key).is(value);
	}
	Query query = Query.query(criteria.andOperator(andCriterias));
	if (pagination != null) {
		query.skip(pagination.getFirst());
		query.limit(pagination.getSize());
	}
	try (CloseableIterator<T> stream = template.stream(query, clazz, metadata.getOrmName())) {
		while (stream.hasNext()) {
			try {
				// TODO 需要考虑中断
				final T object = stream.next();
				iterator.iterate(object);
			} catch (Throwable throwable) {
				throw new StorageQueryException(throwable);
			}
		}
	}
}
 
Example 9
Source File: MongoAccessor.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@Override
public <K extends Comparable, T extends IdentityObject<K>> void iterateUnion(StorageIterator<T> iterator, Class<T> clazz, Map<String, Object> condition, StoragePagination pagination) {
	MongoMetadata metadata = metadatas.get(clazz);
	final Iterator<Entry<String, Object>> conditionIterator = condition.entrySet().iterator();
	Criteria criteria = Criteria.where(MongoMetadata.mongoId).exists(true);
	Criteria[] orCriterias = new Criteria[condition.size()];
	int index = 0;
	while (conditionIterator.hasNext()) {
		Entry<String, Object> keyValue = conditionIterator.next();
		String key = keyValue.getKey();
		Object value = keyValue.getValue();
		if (metadata.getPrimaryName().equals(key)) {
			key = MongoMetadata.mongoId;
		}
		orCriterias[index++] = Criteria.where(key).is(value);
	}
	Query query = Query.query(criteria.orOperator(orCriterias));
	if (pagination != null) {
		query.skip(pagination.getFirst());
		query.limit(pagination.getSize());
	}
	try (CloseableIterator<T> stream = template.stream(query, clazz, metadata.getOrmName())) {
		while (stream.hasNext()) {
			try {
				// TODO 需要考虑中断
				final T object = stream.next();
				iterator.iterate(object);
			} catch (Throwable throwable) {
				throw new StorageQueryException(throwable);
			}
		}
	}
}
 
Example 10
Source File: ProxyDaoImpl.java    From ProxyPool with Apache License 2.0 5 votes vote down vote up
@Override
public List<ProxyData> findProxyByCond(QueryProxyDTO queryProxyDTO, boolean isGetAll) {
    Query query = new Query();
    if(Preconditions.isNotBlank(queryProxyDTO.getType()) && !"all".equals(queryProxyDTO.getType())) {
        query.addCriteria(Criteria.where("proxyType").is(queryProxyDTO.getType()));
    }
    if(Preconditions.isNotBlank(queryProxyDTO.getIp()) && !"all".equals(queryProxyDTO.getIp())) {
        query.addCriteria(Criteria.where("proxyAddress").regex(".*?"+queryProxyDTO.getIp()+".*"));
    }
    if(queryProxyDTO.getMinPort() != null) {
        query.addCriteria(Criteria.where("proxyPort").gte(queryProxyDTO.getMinPort()).lte(queryProxyDTO.getMaxPort()));
    }
    if(!isGetAll) {
        if(Preconditions.isNotBlank(queryProxyDTO.getSort())) {
            if("asc".equals(queryProxyDTO.getOrder())) {
                query.with(new Sort(Sort.Direction.ASC, queryProxyDTO.getSort()));
            } else {
                query.with(new Sort(Sort.Direction.DESC, queryProxyDTO.getSort()));
            }
        } else {
            query.with(new Sort(Sort.Direction.DESC, "lastSuccessfulTime"));
            query.with(new Sort(Sort.Direction.ASC, "proxyPort"));
        }
        int skip = (queryProxyDTO.getPage() - 1) * queryProxyDTO.getRows();
        query.skip(skip);
        query.limit(queryProxyDTO.getRows());
    }
    return mongoTemplate.find(query, ProxyData.class, Constant.COL_NAME_PROXY);
}
 
Example 11
Source File: OrderRepositoryImpl.java    From the-app with Apache License 2.0 5 votes vote down vote up
private Query applySortAndPagination(Query query, int limit, int offset, Sort sort) {
    if (offset != 0) {
        query.skip(offset);
    }
    if (limit != 0) {
        query.limit(limit);
    }
    if (sort != null) {
        query.with(sort);
    }
    return query;
}
 
Example 12
Source File: EventRepositoryImpl.java    From jsflight with Apache License 2.0 5 votes vote down vote up
@Override
public Event getEventToReplay(ObjectId recordingId, int offset)
{
    Query query = new Query();
    query.addCriteria(Criteria.where("recordingId").is(recordingId));
    query.with(new Sort(Sort.Direction.ASC, "timestamp"));
    query.skip(offset);
    return mongoTemplate.findOne(query, Event.class);
}
 
Example 13
Source File: OrderRepositoryImpl.java    From AppStash with Apache License 2.0 5 votes vote down vote up
private Query applySortAndPagination(Query query, int limit, int offset, Sort sort) {
    if (offset != 0) {
        query.skip(offset);
    }
    if (limit != 0) {
        query.limit(limit);
    }
    if (sort != null) {
        query.with(sort);
    }
    return query;
}