本文整理汇总了Java中com.mongodb.QueryBuilder.start方法的典型用法代码示例。如果您正苦于以下问题:Java QueryBuilder.start方法的具体用法?Java QueryBuilder.start怎么用?Java QueryBuilder.start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder.start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transformFieldFilter
import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
protected DBObject transformFieldFilter(
final SingleFieldValueFilter<K, T> fieldFilter,
final MongoStore<K, T> store) {
MongoMapping mapping = store.getMapping();
String dbFieldName = mapping.getDocumentField(fieldFilter.getFieldName());
FilterOp filterOp = fieldFilter.getFilterOp();
List<Object> operands = fieldFilter.getOperands();
QueryBuilder builder = QueryBuilder.start(dbFieldName);
builder = appendToBuilder(builder, filterOp, operands);
if (!fieldFilter.isFilterIfMissing()) {
// If false, the find query will pass if the column is not found.
DBObject notExist = QueryBuilder.start(dbFieldName).exists(false).get();
builder = QueryBuilder.start().or(notExist, builder.get());
}
return builder.get();
}
示例2: transformMapFilter
import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
protected DBObject transformMapFilter(
final MapFieldValueFilter<K, T> mapFilter, final MongoStore<K, T> store) {
MongoMapping mapping = store.getMapping();
String dbFieldName = mapping.getDocumentField(mapFilter.getFieldName())
+ "." + store.encodeFieldKey(mapFilter.getMapKey().toString());
FilterOp filterOp = mapFilter.getFilterOp();
List<Object> operands = mapFilter.getOperands();
QueryBuilder builder = QueryBuilder.start(dbFieldName);
builder = appendToBuilder(builder, filterOp, operands);
if (!mapFilter.isFilterIfMissing()) {
// If false, the find query will pass if the column is not found.
DBObject notExist = QueryBuilder.start(dbFieldName).exists(false).get();
builder = QueryBuilder.start().or(notExist, builder.get());
}
return builder.get();
}
示例3: getQuery
import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
public DBObject getQuery(final StatementConstraints contraints) {
final QueryBuilder queryBuilder = QueryBuilder.start();
if (contraints.hasSubject()){
queryBuilder.and(new BasicDBObject(SUBJECT, contraints.getSubject().toString()));
}
if (contraints.hasPredicates()){
final Set<URI> predicates = contraints.getPredicates();
if (predicates.size() > 1){
for (final URI pred : predicates){
final DBObject currentPred = new BasicDBObject(PREDICATE, pred.toString());
queryBuilder.or(currentPred);
}
}
else if (!predicates.isEmpty()){
queryBuilder.and(new BasicDBObject(PREDICATE, predicates.iterator().next().toString()));
}
}
if (contraints.hasContext()){
queryBuilder.and(new BasicDBObject(CONTEXT, contraints.getContext().toString()));
}
return queryBuilder.get();
}
示例4: createQueryPartition
import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
/**
* Create query partition.
*
* @param partition the partition
* @return the dB object
*/
private DBObject createQueryPartition(MongoPartition partition) {
QueryBuilder queryBuilderMin = QueryBuilder.start(partition.getKey());
DBObject bsonObjectMin = queryBuilderMin.greaterThanEquals(partition.splitWrapper().getStartToken()).get();
QueryBuilder queryBuilderMax = QueryBuilder.start(partition.getKey());
DBObject bsonObjectMax = queryBuilderMax.lessThan(partition.splitWrapper().getEndToken()).get();
QueryBuilder queryBuilder = QueryBuilder.start();
if (partition.splitWrapper().getStartToken() != null) {
queryBuilder.and(bsonObjectMin);
}
if (partition.splitWrapper().getEndToken() != null) {
queryBuilder.and(bsonObjectMax);
}
LOG.debug("mongodb query "+queryBuilder.get());
return queryBuilder.get();
}
示例5: getQueryBuilder
import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
public QueryBuilder getQueryBuilder() {
QueryBuilder query = QueryBuilder.start(this.projectedNames.get(0));
if (this.documentFieldName != null) {
query = QueryBuilder.start(this.documentFieldName);
}
return query;
}
示例6: filterQuery
import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
/**
* Filter query.
*
* @param filters the filters
* @return the mongo deep job config
*/
public MongoDeepJobConfig<T> filterQuery(Filter[] filters) {
if (filters.length > 0) {
List<BasicDBObject> list = new ArrayList<>();
QueryBuilder queryBuilder = QueryBuilder.start();
for (int i = 0; i < filters.length; i++) {
BasicDBObject bsonObject = new BasicDBObject();
Filter filter = filters[i];
if (filter.getFilterType().equals(FilterType.EQ)) {
bsonObject.put(filter.getField(), filter.getValue());
} else {
bsonObject.put(filter.getField(),
new BasicDBObject("$".concat(filter.getFilterType().getFilterTypeId().toLowerCase()),
filter.getValue()));
}
list.add(bsonObject);
}
queryBuilder.and(list.toArray(new BasicDBObject[list.size()]));
filterQuery(queryBuilder);
}
return this;
}
示例7: process
import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
@Override
public Pagination<GroupMember> process(MemberSearcher searcher) {
QueryBuilder builder = QueryBuilder.start();
if (StringUtils.isNotBlank(searcher.getExample().getGroupId())) {
builder.and(GroupMember.GROUP_ID).is(searcher.getExample().getGroupId());
}
if (StringUtils.isNotBlank(searcher.getExample().getUserId())) {
builder.and(GroupMember.USER_ID).is(searcher.getExample().getUserId());
}
String query = builder.get().toString();
Page page = searcher.getPage();
page.count = (int) members.count(query);
if (page.count == 0) {
return Pagination.empty();
}
@SuppressWarnings("rawtypes") Iterable<Map> iterable = members.find(query)
.skip(page.start)
.limit(page.limit)
.as(Map.class);
Pagination<GroupMember> pagination = new Pagination<>(new ArrayList<GroupMember>(page.limit), page);
for (Map<String, Object> _in : iterable) {
GroupMember member = new GroupMember();
member.fromMap(_in);
pagination.items.add(member);
}
return pagination;
}
示例8: process
import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
@Override
public Pagination<Message> process(MessageSearcher searcher) {
QueryBuilder builder = QueryBuilder.start();
if (StringUtils.isNotBlank(searcher.getExample().getGroupId())) {
builder.and(Message.GROUP_ID).is(searcher.getExample().getGroupId());
}
if (StringUtils.isNotBlank(searcher.getExample().getTitle())) {
builder.and(Message.TITLE).regex(Pattern.compile(searcher.getExample().getTitle()));
}
DBObject query = builder.get();
Page page = searcher.getPage();
page.count = (int) messages.getDBCollection().count(query);
if (page.count == 0) {
return Pagination.empty();
}
@SuppressWarnings("rawtypes") Iterable<Map> iterable = messages.find(query.toString())
.sort(CREATE_TIME_ORDER_DESC)
.skip(page.start)
.limit(page.limit)
.as(Map.class);
Pagination<Message> pagination = new Pagination<>(new ArrayList<Message>(page.limit), page);
for (Map<String, Object> _in : iterable) {
Message message = new Message();
message.fromMap(_in);
pagination.items.add(message);
}
return pagination;
}
示例9: process
import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
@Override
public Pagination<MessageACK> process(MessageACKSearcher searcher) {
QueryBuilder builder = QueryBuilder.start();
if (StringUtils.isNotBlank(searcher.getExample().getMessageId())) {
builder.and(MessageACK.MESSAGE_ID).is(searcher.getExample().getMessageId());
}
if (StringUtils.isNotBlank(searcher.getExample().getUserId())) {
builder.and(MessageACK.USER_ID).is(searcher.getExample().getUserId());
}
String query = builder.get().toString();
Page page = searcher.getPage();
page.count = (int) acks.count(query);
if (page.count == 0) {
return Pagination.empty();
}
@SuppressWarnings("rawtypes") Iterable<Map> iterable = acks.find(query)
.sort(CREATE_TIME_ORDER_DESC)
.skip(page.start)
.limit(page.limit)
.as(Map.class);
Pagination<MessageACK> pagination = new Pagination<>(new ArrayList<MessageACK>(page.limit), page);
for (Map<String, Object> _in : iterable) {
MessageACK line = new MessageACK();
line.fromMap(_in);
pagination.items.add(line);
}
return pagination;
}
示例10: iterateMessage
import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
@Override
public void iterateMessage(Message example, int limit, MessageClosure closure) {
QueryBuilder builder = QueryBuilder.start();
if (example.groupId != null) {
builder.and(Message.GROUP_ID).is(example.groupId);
}
if (example.appId != null) {
builder.and(Message.APP_ID).is(example.appId);
}
if (example.braodcast != null) {
builder.and(Message.BROADCAST).is(example.braodcast);
}
if (example.createTime != null) {
builder.and(Message.CREATE_TIME).lessThanEquals(example.createTime);
}
@SuppressWarnings("rawtypes")
Iterable<Map> iterable = messages.find(builder.get().toString())
.sort(CREATE_TIME_ORDER_DESC)
.limit(limit)
.as(Map.class);
for (Map<String, Object> in : iterable) {
Message message = new Message();
message.fromMap(in);
closure.execute(message);
}
}
示例11: getDrivers
import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
/**
* Get registered test drivers
*
* @param release
* the release name of the test or <tt>null</tt> for all releases
* @param schema
* the schema number of the driver or <tt>null</tt> for all schemas
* @param liveOnly
* <tt>true</tt> to retrieve only live instances
*/
public DBCursor getDrivers(String release, Integer schema, boolean active)
{
QueryBuilder queryBuilder = QueryBuilder.start();
if (release != null)
{
queryBuilder.and(FIELD_RELEASE).is(release);
}
if (schema != null)
{
queryBuilder.and(FIELD_SCHEMA).is(schema);
}
if (active)
{
queryBuilder.and(FIELD_PING + "." + FIELD_EXPIRES).greaterThan(new Date());
}
DBObject queryObj = queryBuilder.get();
DBObject sortObj = BasicDBObjectBuilder
.start()
.add(FIELD_RELEASE, 1)
.add(FIELD_SCHEMA, 1)
.get();
DBCursor cursor = testDrivers.find(queryObj).sort(sortObj);
// Done
if (logger.isDebugEnabled())
{
logger.debug(
"Retrieved test driver: \n" +
" Release: " + release + "\n" +
" Schema: " + schema + "\n" +
" active: " + active + "\n" +
" Results: " + cursor.count());
}
return cursor;
}
示例12: countDrivers
import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
/**
* Count registered drivers
*
* @param release
* the release name of the test or <tt>null</tt> for all releases
* @param schema
* the schema number of the driver or <tt>null</tt> for all schemas
* @param liveOnly
* <tt>true</tt> to retrieve only live instances
* @return a count of the number of drivers matching the criteria
*/
public long countDrivers(String release, Integer schema, boolean active)
{
QueryBuilder queryBuilder = QueryBuilder.start();
if (release != null)
{
queryBuilder.and(FIELD_RELEASE).is(release);
}
if (schema != null)
{
queryBuilder.and(FIELD_SCHEMA).is(schema);
}
if (active)
{
queryBuilder.and(FIELD_PING + "." + FIELD_EXPIRES).greaterThan(new Date());
}
DBObject queryObj = queryBuilder.get();
long count = testDrivers.count(queryObj);
// Done
if (logger.isDebugEnabled())
{
logger.debug(
"Retrieved test driver: \n" +
" Release: " + release + "\n" +
" Schema: " + schema + "\n" +
" active: " + active + "\n" +
" Results: " + count);
}
return count;
}
示例13: getPullQueryBuilder
import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
public QueryBuilder getPullQueryBuilder() {
if (this.documentFieldName != null) {
return QueryBuilder.start(this.documentFieldName.substring(this.documentFieldName.lastIndexOf('.')+1));
}
return QueryBuilder.start(this.projectedNames.get(0));
}
示例14: manyChildNodes
import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
@Test
@Ignore
public void manyChildNodes() {
DB db = MongoUtils.getConnection().getDB();
MongoUtils.dropCollections(db);
DBCollection nodes = db.getCollection(Collection.NODES.toString());
DBObject index = new BasicDBObject();
// modification time (descending)
index.put("_mod", -1L);
// and then id (ascending)
index.put("_id", 1L);
DBObject options = new BasicDBObject();
// options.put("unique", Boolean.TRUE);
nodes.ensureIndex(index, options);
// index on (_id, _mod):
// Query plan: { "cursor" : "BtreeCursor _id_1__mod_-1" ,
// "isMultiKey" : false , "n" : 2000 , "nscannedObjects" : 2000 ,
// "nscanned" : 954647 , "nscannedObjectsAllPlans" : 1907080 ,
// "nscannedAllPlans" : 2859727 , "scanAndOrder" : false ,
// "indexOnly" : true , "nYields" : 5 , "nChunkSkips" : 0 ,
// "millis" : 5112 ,...
// Time: 2229 ms
// Count: 2000
// index on (_mod, _id)
// Query plan: { "cursor" : "BtreeCursor _mod_-1__id_1" ,
// "isMultiKey" : false , "n" : 2000 , "nscannedObjects" : 2000 ,
// "nscanned" : 2000 , "nscannedObjectsAllPlans" : 2203 ,
// "nscannedAllPlans" : 2203 , "scanAndOrder" : false ,
// "indexOnly" : true , "nYields" : 0 , "nChunkSkips" : 0 ,
// "millis" : 3 ,...
// Time: 43 ms
// Count: 2000
int children = 1000000;
int perInsert = 1000;
int group = 0;
String parent = "/parent/node/abc";
for (int i = 0; i < children;) {
DBObject[] inserts = new DBObject[perInsert];
group++;
for (int j = 0; j < perInsert; j++, i++) {
BasicDBObject doc = new BasicDBObject();
inserts[j] = doc;
doc.put("_id", parent + "/node" + i);
doc.put("_mod", group);
}
nodes.insert(inserts, WriteConcern.SAFE);
log("inserted " + i + "/" + children);
}
QueryBuilder queryBuilder = QueryBuilder.start("_mod");
queryBuilder.greaterThanEquals(group - 1);
queryBuilder.and("_id").greaterThan(parent + "/");
queryBuilder.and("_id").lessThanEquals(parent + "0");
DBObject query = queryBuilder.get();
BasicDBObject keys = new BasicDBObject();
keys.put("_id", 1);
DBCursor cursor = nodes.find(query, keys);
int count = 0;
log("Query plan: " + cursor.explain());
long time = System.currentTimeMillis();
while (cursor.hasNext()) {
DBObject obj = cursor.next();
// dummy read operation (to ensure we did get the data)
obj.get("_id");
count++;
// log(" read " + obj);
}
time = System.currentTimeMillis() - time;
log("Time: " + time + " ms");
log("Count: " + count);
db.getMongo().close();
}
示例15: calculateSplits
import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
/**
* Calculate splits.
*
* @param collection the collection
* @return the deep partition [ ]
*/
private DeepPartition[] calculateSplits(DBCollection collection) {
BasicDBList splitData = getSplitData(collection);
List<ServerAddress> serverAddressList = collection.getDB().getMongo().getServerAddressList();
if (splitData == null) {
Pair<BasicDBList, List<ServerAddress>> pair = getSplitDataCollectionShardEnviroment(getShards(collection),
collection.getDB().getName(),
collection.getName());
splitData = pair.left;
serverAddressList = pair.right;
}
Object lastKey = null; // Lower boundary of the first min split
List<String> stringHosts = new ArrayList<>();
for (ServerAddress serverAddress : serverAddressList) {
stringHosts.add(serverAddress.toString());
}
int i = 0;
MongoPartition[] partitions = new MongoPartition[splitData.size() + 1];
for (Object aSplitData : splitData) {
BasicDBObject currentKey = (BasicDBObject) aSplitData;
Object currentO = currentKey.get(MONGO_DEFAULT_ID);
partitions[i] = new MongoPartition(mongoDeepJobConfig.getRddId(), i, new DeepTokenRange(lastKey,
currentO, stringHosts), MONGO_DEFAULT_ID);
lastKey = currentO;
i++;
}
QueryBuilder queryBuilder = QueryBuilder.start(MONGO_DEFAULT_ID);
queryBuilder.greaterThanEquals(lastKey);
partitions[i] = new MongoPartition(0, i, new DeepTokenRange(lastKey, null, stringHosts), MONGO_DEFAULT_ID);
return partitions;
}