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


Java QueryBuilder类代码示例

本文整理汇总了Java中com.mongodb.QueryBuilder的典型用法代码示例。如果您正苦于以下问题:Java QueryBuilder类的具体用法?Java QueryBuilder怎么用?Java QueryBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


QueryBuilder类属于com.mongodb包,在下文中一共展示了QueryBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateDownloadLogs

import com.mongodb.QueryBuilder; //导入依赖的package包/类
@Override
public void updateDownloadLogs(final String id, final UserInfos user, final Handler<JsonObject> handler) {
	final QueryBuilder query = QueryBuilder.start("_id").is(id);

	final JsonObject logElem = new JsonObject().putString("userDisplayName", user.getUsername()).putObject("downloadDate", MongoDb.now());
	final MongoUpdateBuilder modifier = new MongoUpdateBuilder();
	modifier.addToSet("downloadLogs", logElem);
	mongo.update(ShareBigFiles.SHARE_BIG_FILE_COLLECTION, MongoQueryBuilder.build(query),
			modifier.build(), new Handler<Message<JsonObject>>() {
				@Override
				public void handle(Message<JsonObject> event) {
					if ("ok".equals(event.body().getString("status"))) {
						handler.handle(new JsonObject().putString("status", "ok"));
					} else {
						handler.handle(new JsonObject().putString("status", "error")
								.putString("message", event.body().getString("message")));
					}
				}
			});
}
 
开发者ID:OPEN-ENT-NG,项目名称:share-big-files,代码行数:21,代码来源:ShareBigFilesServiceImpl.java

示例2: authorize

import com.mongodb.QueryBuilder; //导入依赖的package包/类
@Override
public void authorize(final HttpServerRequest request, final Binding binding, final UserInfos user, final Handler<Boolean> handler) {
	RequestUtils.bodyToJson(request, Server.getPathPrefix(Config.getInstance().getConfig()) + "deletes", new Handler<JsonObject>() {
		public void handle(JsonObject data) {
			final List<String> ids = data.getArray("ids").toList();
			if (ids != null && !ids.isEmpty()) {
				List<DBObject> groups = new ArrayList<>();
				String sharedMethod = binding.getServiceMethod().replaceAll("\\.", "-");
				groups.add(QueryBuilder.start("userId").is(user.getUserId())
						.put(sharedMethod).is(true).get());
				for (String gpId: user.getGroupsIds()) {
					groups.add(QueryBuilder.start("groupId").is(gpId)
							.put(sharedMethod).is(true).get());
				}
				QueryBuilder query = QueryBuilder.start("_id").in(new HashSet<String>(ids)).or(
						QueryBuilder.start("owner.userId").is(user.getUserId()).get(),
						QueryBuilder.start("shared").elemMatch(
								new QueryBuilder().or(groups.toArray(new DBObject[groups.size()])).get()).get()
				);
				MongoAppFilter.executeCountQuery(request, conf.getCollection(), MongoQueryBuilder.build(query), ids.size(), handler);
			} else {
				handler.handle(false);
			}
		}
	});
}
 
开发者ID:OPEN-ENT-NG,项目名称:share-big-files,代码行数:27,代码来源:MassJsonShareAndOwner.java

示例3: 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();
}
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:19,代码来源:DefaultFactory.java

示例4: 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();
}
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:19,代码来源:DefaultFactory.java

示例5: getAllByDefinitionId

import com.mongodb.QueryBuilder; //导入依赖的package包/类
@Override
@Authorization( scope = PermissionScope.PIPELINE, type = PermissionType.VIEWER )
public ServiceResult getAllByDefinitionId(String pipelineDefinitionId) {
    ServiceResult result = null;

    switch (super.DATABASE_TYPE) {
        case REDIS:
            result = this.getAll();
            List<Pipeline> pipelines = (List<Pipeline>) result.getEntity();

            List<Pipeline> filteredPipelines = pipelines
                    .stream()
                    .filter(p -> p.getPipelineDefinitionId().equals(pipelineDefinitionId))
                    .collect(Collectors.toList());

            result.setEntity(filteredPipelines);
            break;
        case MONGODB:
            BasicDBObject query = (BasicDBObject) QueryBuilder.start().put("pipelineDefinitionId").is(pipelineDefinitionId).get();
            result = this.getPipelineMongoService().QueryExecutor(query);
            break;
    }

    return result;
}
 
开发者ID:rndsolutions,项目名称:hawkcd,代码行数:26,代码来源:PipelineService.java

示例6: updateShare

import com.mongodb.QueryBuilder; //导入依赖的package包/类
@Override
public void updateShare(String pageId, String userId, JsonObject value, Handler<Either<String, JsonObject>> handler) {
	JsonArray shared = new JsonArray();
	shared.add(new JsonObject().putString("groupId", value.getString("read")).
			putBoolean("net-atos-entng-community-controllers-PagesController|get", true));
	shared.add(new JsonObject().putString("groupId", value.getString("contrib")).
			putBoolean("net-atos-entng-community-controllers-PagesController|get", true).
			putBoolean("net-atos-entng-community-controllers-PagesController|update", true));
	shared.add(new JsonObject().putString("groupId", value.getString("manager")).
			putBoolean("net-atos-entng-community-controllers-PagesController|get", true).
			putBoolean("net-atos-entng-community-controllers-PagesController|update", true).
			putBoolean("net-atos-entng-community-controllers-PagesController|delete", true));

	MongoUpdateBuilder updateQuery = new MongoUpdateBuilder().set("shared", shared);
	QueryBuilder query = QueryBuilder.start("_id").is(pageId);
	mongo.update(conf.getCollection(), MongoQueryBuilder.build(query), updateQuery.build(), MongoDbResult.validActionResultHandler(handler));
}
 
开发者ID:OPEN-ENT-NG,项目名称:community,代码行数:18,代码来源:DefaultCommunityService.java

示例7: authorize

import com.mongodb.QueryBuilder; //导入依赖的package包/类
@Override
public void authorize(HttpServerRequest request, Binding binding, UserInfos user, Handler<Boolean> handler) {
	String sharedMethod = binding.getServiceMethod().replaceAll("\\.", "-");
	String id = request.params().get(conf.getResourceIdLabel());
	if (id != null && !id.trim().isEmpty()) {
		List<DBObject> groups = new ArrayList<>();
		groups.add(QueryBuilder.start("userId").is(user.getUserId())
				.put(sharedMethod).is(true).get());
		for (String gpId: user.getGroupsIds()) {
			groups.add(QueryBuilder.start("groupId").is(gpId)
					.put(sharedMethod).is(true).get());
		}
		QueryBuilder query = QueryBuilder.start("_id").is(id).or(
				QueryBuilder.start("owner.userId").is(user.getUserId()).get(),
				QueryBuilder.start("visibility").is(VisibilityFilter.PUBLIC.name()).get(),
				QueryBuilder.start("visibility").is(VisibilityFilter.PROTECTED.name()).get(),
				QueryBuilder.start("shared").elemMatch(
						new QueryBuilder().or(groups.toArray(new DBObject[groups.size()])).get()).get()
		);
		MongoAppFilter.executeCountQuery(request, conf.getCollection(),
				MongoQueryBuilder.build(query), 1, handler);
	} else {
		handler.handle(false);
	}
}
 
开发者ID:OPEN-ENT-NG,项目名称:community,代码行数:26,代码来源:PageReadFilter.java

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

示例9: getTemporalObject

import com.mongodb.QueryBuilder; //导入依赖的package包/类
private DBObject getTemporalObject(final TemporalInstant instant, final TemporalPolicy policy) {
    final DBObject temporalObj;
    switch(policy) {
        case INSTANT_AFTER_INSTANT:
            temporalObj = QueryBuilder.start(INSTANT)
                   .greaterThan(instant.getAsDateTime().toDate())
                   .get();
            break;
        case INSTANT_BEFORE_INSTANT:
            temporalObj = QueryBuilder.start(INSTANT)
                   .lessThan(instant.getAsDateTime().toDate())
                   .get();
            break;
        case INSTANT_EQUALS_INSTANT:
            temporalObj = QueryBuilder.start(INSTANT)
                   .is(instant.getAsDateTime().toDate())
                   .get();
            break;
         default:
             temporalObj = new BasicDBObject();
    }
    return temporalObj;
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:24,代码来源:GeoTemporalMongoDBStorageStrategy.java

示例10: testShellDirect

import com.mongodb.QueryBuilder; //导入依赖的package包/类
@Test
public void testShellDirect() throws Exception {
    Command cmd = this.utility.parseCommand("SELECT * FROM Customers");
    MongoDBConnection connection = Mockito.mock(MongoDBConnection.class);
    ExecutionContext context = Mockito.mock(ExecutionContext.class);
    DBCollection dbCollection = Mockito.mock(DBCollection.class);
    DB db = Mockito.mock(DB.class);
    Mockito.stub(db.getCollection("MyTable")).toReturn(dbCollection);
    
    Mockito.stub(db.collectionExists(Mockito.anyString())).toReturn(true);
    Mockito.stub(connection.getDatabase()).toReturn(db);
    
    Argument arg = new Argument(Direction.IN, null, String.class, null);
    arg.setArgumentValue(new Literal("$ShellCmd;MyTable;remove;{ qty: { $gt: 20 }}", String.class));

    ResultSetExecution execution = this.translator.createDirectExecution(Arrays.asList(arg), cmd, context, this.utility.createRuntimeMetadata(), connection);
    execution.execute();
    Mockito.verify(dbCollection).remove(QueryBuilder.start("qty").greaterThan(20).get());
}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:20,代码来源:TestMongoDBDirectQueryExecution.java

示例11: deleteChunks

import com.mongodb.QueryBuilder; //导入依赖的package包/类
@Override
public boolean deleteChunks(List<String> chunkIds, long maxLastModifiedTime) throws Exception {
    DBCollection collection = getBlobCollection();
    QueryBuilder queryBuilder = new QueryBuilder();
    if (chunkIds != null) {
        queryBuilder = queryBuilder.and(MongoBlob.KEY_ID).in(chunkIds.toArray(new String[0]));
        if (maxLastModifiedTime > 0) {
            queryBuilder = queryBuilder.and(MongoBlob.KEY_LAST_MOD)
                                .lessThan(maxLastModifiedTime);
        }
    }

    WriteResult result = collection.remove(queryBuilder.get());
    if (result.getN() == chunkIds.size()) {
        return true;
    }

    return false;
}
 
开发者ID:denismo,项目名称:jackrabbit-dynamodb-store,代码行数:20,代码来源:MongoBlobStore.java

示例12: acquireRecoveryLock

import com.mongodb.QueryBuilder; //导入依赖的package包/类
@Override
public boolean acquireRecoveryLock(int clusterId) {
    QueryBuilder query =
            start().and(
                    start(Document.ID).is(Integer.toString(clusterId)).get(),
                    start(ClusterNodeInfo.REV_RECOVERY_LOCK).notEquals(RecoverLockState.ACQUIRED.name()).get()
            );

    DBObject returnFields = new BasicDBObject();
    returnFields.put("_id", 1);

    BasicDBObject setUpdates = new BasicDBObject();
    setUpdates.append(ClusterNodeInfo.REV_RECOVERY_LOCK, RecoverLockState.ACQUIRED.name());

    BasicDBObject update = new BasicDBObject();
    update.append("$set", setUpdates);

    DBObject oldNode = getClusterNodeCollection().findAndModify(query.get(), returnFields,
            null /*sort*/, false /*remove*/, update, false /*returnNew*/,
            false /*upsert*/);

    return oldNode != null;
}
 
开发者ID:denismo,项目名称:jackrabbit-dynamodb-store,代码行数:24,代码来源:MongoMissingLastRevSeeker.java

示例13: createQueryForUpdate

import com.mongodb.QueryBuilder; //导入依赖的package包/类
@Nonnull
private static QueryBuilder createQueryForUpdate(UpdateOp updateOp,
                                          boolean checkConditions) {
    QueryBuilder query = getByKeyQuery(updateOp.getId());

    for (Entry<Key, Operation> entry : updateOp.getChanges().entrySet()) {
        Key k = entry.getKey();
        Operation op = entry.getValue();
        switch (op.type) {
            case CONTAINS_MAP_ENTRY: {
                if (checkConditions) {
                    query.and(k.toString()).exists(op.value);
                }
                break;
            }
        }
    }
    return query;
}
 
开发者ID:denismo,项目名称:jackrabbit-dynamodb-store,代码行数:20,代码来源:MongoDocumentStore.java

示例14: 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();
}
 
开发者ID:Stratio,项目名称:deep-spark,代码行数:28,代码来源:MongoReader.java

示例15: getLastRecord

import com.mongodb.QueryBuilder; //导入依赖的package包/类
public static DBObject getLastRecord(DBCollection collection, Date startDate, Date endDate) {
	DBObject lastone = null;
	try {
		BasicDBObject searchQuery = new BasicDBObject();
		QueryBuilder qb = new QueryBuilder();
		qb.put("Date").greaterThanEquals(startDate).lessThanEquals(endDate);
		searchQuery.putAll(qb.get());
		DBCursor cursor = collection.find(searchQuery);
		
		while (cursor.hasNext()) {

			lastone = cursor.next();
		}
		

	} catch (MongoException e) {
		e.printStackTrace();

	}
	return lastone;
}
 
开发者ID:eBay,项目名称:mTracker,代码行数:22,代码来源:Connector.java


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