Java 类com.mongodb.client.model.Projections 实例源码

项目:mongodb-rdbms-sync    文件:SyncEventDao.java   
public O2MSyncDataLoader getPendingDataLoader() {
    O2MSyncDataLoader loader = null;
    Document document = syncEventDoc.findOneAndUpdate(
            Filters.and(Filters.eq(SyncAttrs.STATUS, SyncStatus.PENDING),
                    Filters.eq(SyncAttrs.EVENT_TYPE, String.valueOf(EventType.System))),
            Updates.set(SyncAttrs.STATUS, SyncStatus.IN_PROGRESS),
            new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER)
                    .projection(Projections.include(SyncAttrs.SOURCE_DB_NAME, SyncAttrs.SOURCE_USER_NAME)));
    if (document != null && !document.isEmpty()) {
        Object interval = document.get(SyncAttrs.INTERVAL);
        String appName = document.getString(SyncAttrs.APPLICATION_NAME);
        if(interval!=null && interval instanceof Long){
            loader = new O2MSyncDataLoader((Long)interval, appName);
        }else{
            loader = new O2MSyncDataLoader(120000, appName);
        }
        loader.setEventId(document.getObjectId(SyncAttrs.ID));
        loader.setDbName(document.getString(SyncAttrs.SOURCE_DB_NAME));
        loader.setDbUserName(document.getString(SyncAttrs.SOURCE_USER_NAME));
        loader.setStatus(document.getString(SyncAttrs.STATUS));
    }
    return loader;
}
项目:sam    文件:ServerResource.java   
@GET
@Path("services/server/{environment}/{hostname}/deployment/{applicationId}")
@ApiOperation(value = "Get a deployed application on the server", response = Deployment.class)
public Deployment getServerDeployment(
  @ApiParam("Server hostname") @PathParam("hostname") String hostname,
  @ApiParam("Environment") @PathParam("environment") String environment,
  @ApiParam("Application id") @PathParam("applicationId") String applicationId
) {
  final Document document = database.getCollection(Collections.SERVERS)
    .find(Filters.and(
      Filters.eq("environment", environment),
      Filters.eq("hostname", hostname)
    )).projection(Projections.elemMatch("deployments",
      Filters.eq("applicationId", applicationId)
    )).first();
  if (document == null) {
    throw new WebApplicationException(Status.NOT_FOUND);
  }

  final Deployment deployment = Mapper.mapObject(document, "deployments", Deployment::fromDeploymentBson);
  if (deployment == null) {
    throw new WebApplicationException(Status.NOT_FOUND);
  }
  return deployment;
}
项目:verbum-domini    文件:VerseDaoImpl.java   
@Override
public Pagination<VerseBean> list(VerseBean filter, Integer firstResult, Integer maxResults) {
    MongoCollection<VerseBeanImpl> coll = this.persistenceManager.fetchCollection(VerseBeanImpl.class);
    Pagination<VerseBean> pagination = new Pagination<VerseBean>();

    pagination.setSize(this.countQueryResult(coll, this.createBasicFilter(filter)));
    FindIterable<VerseBeanImpl> iterable = coll.find(this.createBasicFilter(filter))
            .skip(firstResult - 1)
            .limit(maxResults)
            .projection(Projections.include("_id", "number", "chapter_id"));

    Iterator<VerseBeanImpl> iterator = iterable.iterator();
    List<VerseBean> verses = new ArrayList<>();
    while (iterator.hasNext()) {
        verses.add(iterator.next());
    }

    pagination.setElements(verses);

    return pagination;
}
项目:verbum-domini    文件:BibleDaoImpl.java   
@Override
public Pagination<BibleBean> list(BibleBean filter, Integer firstResult, Integer maxResults) {
    MongoCollection<BibleBeanImpl> coll = this.persistenceManager.fetchCollection(BibleBeanImpl.class);
    Pagination<BibleBean> pagination = new Pagination<BibleBean>();

    pagination.setSize(this.countQueryResult(coll, this.createBasicFilter(filter)));
    FindIterable<BibleBeanImpl> iterable = coll.find(this.createBasicFilter(filter))
            .skip(firstResult - 1)
            .limit(maxResults)
            .projection(Projections.include("_id", "name", "language"));

    Iterator<BibleBeanImpl> iterator = iterable.iterator();
    List<BibleBean> bibles = new ArrayList<>();
    while (iterator.hasNext()) {
        bibles.add(iterator.next());
    }

    pagination.setElements(bibles);

    return pagination;
}
项目:bsoncodec-apt    文件:CharacterPojoTest.java   
@Test
public void testInsertAndFind() {
    MongoDatabase db = connect();
    CharacterPojo pojo = insert(db);

    MongoCollection<CharacterPojo> coll = db.getCollection(COLL_NAME,
            CharacterPojo.class);
    CharacterPojo read = coll.find().first();
    assertThat(read).isEqualToComparingFieldByField(pojo);

    CharacterPojo empty = coll.find().projection(Projections.include("id")).first();
    assertThat(empty.getScalarPrimitive()).isEqualTo((char) 0);
    assertThat(empty.getScalar()).isNull();
    assertThat(empty.getArray()).isNull();
    assertThat(empty.getArrayPrimitive()).isNull();
    assertThat(empty.getArray2()).isNull();
    assertThat(empty.getArray2Primitive()).isNull();
    assertThat(empty.getList()).isNull();
    assertThat(empty.getSet()).isNull();
    assertThat(empty.getMap()).isNull();
}
项目:bsoncodec-apt    文件:StringPojoTest.java   
@Test
public void testInsertAndFind() {
    MongoDatabase db = connect();
    StringPojo pojo = insert(db);

    MongoCollection<StringPojo> coll = db.getCollection(COLL_NAME, StringPojo.class);
    StringPojo read = coll.find().first();
    assertThat(read).isEqualToComparingFieldByField(pojo);

    StringPojo empty = coll.find().projection(Projections.include("id")).first();
    assertThat(empty.getScalar()).isNull();
    assertThat(empty.getArray()).isNull();
    assertThat(empty.getArray2()).isNull();
    assertThat(empty.getList()).isNull();
    assertThat(empty.getSet()).isNull();
    assertThat(empty.getMap()).isNull();
}
项目:bsoncodec-apt    文件:ShortPojoTest.java   
@Test
public void testInsertAndFind() {
    MongoDatabase db = connect();
    ShortPojo pojo = insert(db);

    MongoCollection<ShortPojo> coll = db.getCollection(COLL_NAME, ShortPojo.class);
    ShortPojo read = coll.find().first();
    assertThat(read).isEqualToComparingFieldByField(pojo);

    ShortPojo empty = coll.find().projection(Projections.include("id")).first();
    assertThat(empty.getScalarPrimitive()).isEqualTo((short) 0);
    assertThat(empty.getScalar()).isNull();
    assertThat(empty.getArray()).isNull();
    assertThat(empty.getArrayPrimitive()).isNull();
    assertThat(empty.getArray2()).isNull();
    assertThat(empty.getArray2Primitive()).isNull();
    assertThat(empty.getList()).isNull();
    assertThat(empty.getSet()).isNull();
    assertThat(empty.getMap()).isNull();
}
项目:bsoncodec-apt    文件:LongPojoTest.java   
@Test
public void testInsertAndFind() {
    MongoDatabase db = connect();
    LongPojo pojo = insert(db);

    MongoCollection<LongPojo> coll = db.getCollection(COLL_NAME, LongPojo.class);
    LongPojo read = coll.find().first();
    assertThat(read).isEqualToComparingFieldByField(pojo);

    LongPojo empty = coll.find().projection(Projections.include("id")).first();
    assertThat(empty.getScalarPrimitive()).isEqualTo(0L);
    assertThat(empty.getScalar()).isNull();
    assertThat(empty.getArray()).isNull();
    assertThat(empty.getArrayPrimitive()).isNull();
    assertThat(empty.getArray2()).isNull();
    assertThat(empty.getArray2Primitive()).isNull();
    assertThat(empty.getList()).isNull();
    assertThat(empty.getSet()).isNull();
    assertThat(empty.getMap()).isNull();
}
项目:bsoncodec-apt    文件:MonthPojoTest.java   
@Test
public void testInsertAndFind() {
    MongoDatabase db = connect();
    MonthPojo pojo = insert(db);

    MongoCollection<MonthPojo> coll = db.getCollection(COLL_NAME, MonthPojo.class);
    MonthPojo read = coll.find().first();
    assertThat(read).isEqualToComparingFieldByField(pojo);

    MonthPojo empty = coll.find().projection(Projections.include("id")).first();
    assertThat(empty.getScalar()).isNull();
    assertThat(empty.getArray()).isNull();
    assertThat(empty.getArray2()).isNull();
    assertThat(empty.getList()).isNull();
    assertThat(empty.getSet()).isNull();
    assertThat(empty.getMap()).isNull();
}
项目:bsoncodec-apt    文件:DatePojoTest.java   
@Test
public void testInsertAndFind() {
    MongoDatabase db = connect();
    DatePojo pojo = insert(db);

    MongoCollection<DatePojo> coll = db.getCollection(COLL_NAME, DatePojo.class);
    DatePojo read = coll.find().first();
    assertThat(read).isEqualToComparingFieldByField(pojo);

    DatePojo empty = coll.find().projection(Projections.include("id")).first();
    assertThat(empty.getScalar()).isNull();
    assertThat(empty.getArray()).isNull();
    assertThat(empty.getArray2()).isNull();
    assertThat(empty.getList()).isNull();
    assertThat(empty.getSet()).isNull();
    assertThat(empty.getMap()).isNull();
}
项目:bsoncodec-apt    文件:BooleanPojoTest.java   
@Test
public void testInsertAndFind() {
    MongoDatabase db = connect();
    BooleanPojo pojo = insert(db);

    MongoCollection<BooleanPojo> coll = db.getCollection(COLL_NAME,
            BooleanPojo.class);
    BooleanPojo read = coll.find().first();
    assertThat(read).isEqualToComparingFieldByField(pojo);

    BooleanPojo empty = coll.find().projection(Projections.include("id")).first();
    assertThat(empty.getScalarPrimitive()).isEqualTo(false);
    assertThat(empty.getScalar()).isNull();
    assertThat(empty.getArray()).isNull();
    assertThat(empty.getArrayPrimitive()).isNull();
    assertThat(empty.getArray2()).isNull();
    assertThat(empty.getArray2Primitive()).isNull();
    assertThat(empty.getList()).isNull();
    assertThat(empty.getSet()).isNull();
    assertThat(empty.getMap()).isNull();
}
项目:bsoncodec-apt    文件:Decimal128PojoTest.java   
@Test
public void testInsertAndFind() {
    MongoDatabase db = connect();
    Decimal128Pojo pojo = insert(db);

    MongoCollection<Decimal128Pojo> coll = db.getCollection(COLL_NAME,
            Decimal128Pojo.class);
    Decimal128Pojo read = coll.find().first();
    assertThat(read).isEqualToComparingFieldByField(pojo);

    Decimal128Pojo empty = coll.find().projection(Projections.include("id")).first();
    assertThat(empty.getScalar()).isNull();
    assertThat(empty.getArray()).isNull();
    assertThat(empty.getArray2()).isNull();
    assertThat(empty.getList()).isNull();
    assertThat(empty.getSet()).isNull();
    assertThat(empty.getMap()).isNull();
}
项目:bsoncodec-apt    文件:YearPojoTest.java   
@Test
public void testInsertAndFind() {
    MongoDatabase db = connect();
    YearPojo pojo = insert(db);

    MongoCollection<YearPojo> coll = db.getCollection(COLL_NAME, YearPojo.class);
    YearPojo read = coll.find().first();
    assertThat(read).isEqualToComparingFieldByField(pojo);

    YearPojo empty = coll.find().projection(Projections.include("id")).first();
    assertThat(empty.getScalar()).isNull();
    assertThat(empty.getArray()).isNull();
    assertThat(empty.getArray2()).isNull();
    assertThat(empty.getList()).isNull();
    assertThat(empty.getSet()).isNull();
    assertThat(empty.getMap()).isNull();
}
项目:bsoncodec-apt    文件:DoublePojoTest.java   
@Test
public void testInsertAndFind() {
    MongoDatabase db = connect();
    DoublePojo pojo = insert(db);

    MongoCollection<DoublePojo> coll = db.getCollection(COLL_NAME, DoublePojo.class);
    DoublePojo read = coll.find().first();
    assertThat(read).isEqualToComparingFieldByField(pojo);

    DoublePojo empty = coll.find().projection(Projections.include("id")).first();
    assertThat(empty.getScalarPrimitive()).isEqualTo(0.0f);
    assertThat(empty.getScalar()).isNull();
    assertThat(empty.getArray()).isNull();
    assertThat(empty.getArrayPrimitive()).isNull();
    assertThat(empty.getArray2()).isNull();
    assertThat(empty.getArray2Primitive()).isNull();
    assertThat(empty.getList()).isNull();
    assertThat(empty.getSet()).isNull();
    assertThat(empty.getMap()).isNull();
}
项目:bsoncodec-apt    文件:FloatPojoTest.java   
@Test
public void testInsertAndFind() {
    MongoDatabase db = connect();
    FloatPojo pojo = insert(db);

    MongoCollection<FloatPojo> coll = db.getCollection(COLL_NAME, FloatPojo.class);
    FloatPojo read = coll.find().first();
    assertThat(read).isEqualToComparingFieldByField(pojo);

    FloatPojo empty = coll.find().projection(Projections.include("id")).first();
    assertThat(empty.getScalarPrimitive()).isEqualTo(0.0f);
    assertThat(empty.getScalar()).isNull();
    assertThat(empty.getArray()).isNull();
    assertThat(empty.getArrayPrimitive()).isNull();
    assertThat(empty.getArray2()).isNull();
    assertThat(empty.getArray2Primitive()).isNull();
    assertThat(empty.getList()).isNull();
    assertThat(empty.getSet()).isNull();
    assertThat(empty.getMap()).isNull();
}
项目:bsoncodec-apt    文件:EnumPojoTest.java   
@Test
public void testInsertAndFind() {
    MongoDatabase db = connect();
    EnumPojo pojo = insert(db);

    MongoCollection<EnumPojo> coll = db.getCollection(COLL_NAME, EnumPojo.class);
    EnumPojo read = coll.find().first();

    assertThat(read).isEqualToIgnoringGivenFields(pojo, "enumSet3");
    assertThat(read.getEnumSet3()).isNull();

    EnumPojo empty = coll.find().projection(Projections.include("id")).first();
    assertThat(empty.getScalar()).isNull();
    assertThat(empty.getArray()).isNull();
    assertThat(empty.getArray2()).isNull();
    assertThat(empty.getList()).isNull();
    assertThat(empty.getSet()).isNull();
    assertThat(empty.getEnumSet1()).isNull();
    assertThat(empty.getEnumSet2()).isNull();
    assertThat(empty.getEnumSet3()).isNull();
    assertThat(empty.getMap()).isNull();
    assertThat(empty.getEnumMap()).isNull();
}
项目:bsoncodec-apt    文件:BytePojoTest.java   
@Test
public void testInsertAndFind() {
    MongoDatabase db = connect();
    BytePojo pojo = insert(db);

    MongoCollection<BytePojo> coll = db.getCollection(COLL_NAME, BytePojo.class);
    BytePojo read = coll.find().first();
    assertThat(read).isEqualToComparingFieldByField(pojo);

    BytePojo empty = coll.find().projection(Projections.include("id")).first();
    assertThat(empty.getScalarPrimitive()).isEqualTo((byte) 0);
    assertThat(empty.getScalar()).isNull();
    assertThat(empty.getArray()).isNull();
    assertThat(empty.getArrayPrimitive()).isNull();
    assertThat(empty.getList()).isNull();
    assertThat(empty.getSet()).isNull();
    assertThat(empty.getMap()).isNull();
}
项目:bsoncodec-apt    文件:InstantPojoTest.java   
@Test
public void testInsertAndFind() {
    MongoDatabase db = connect();
    InstantPojo pojo = insert(db);

    MongoCollection<InstantPojo> coll = db.getCollection(COLL_NAME,
            InstantPojo.class);
    InstantPojo read = coll.find().first();
    assertThat(read).isEqualToComparingFieldByField(pojo);

    InstantPojo empty = coll.find().projection(Projections.include("id")).first();
    assertThat(empty.getScalar()).isNull();
    assertThat(empty.getArray()).isNull();
    assertThat(empty.getArray2()).isNull();
    assertThat(empty.getList()).isNull();
    assertThat(empty.getSet()).isNull();
    assertThat(empty.getMap()).isNull();
}
项目:bsoncodec-apt    文件:IntegerPojoTest.java   
@Test
public void testInsertAndFind() {
    MongoDatabase db = connect();
    IntegerPojo pojo = insert(db);

    MongoCollection<IntegerPojo> coll = db.getCollection(COLL_NAME,
            IntegerPojo.class);
    IntegerPojo read = coll.find().first();
    assertThat(read).isEqualToComparingFieldByField(pojo);

    IntegerPojo empty = coll.find().projection(Projections.include("id")).first();
    assertThat(empty.getScalarPrimitive()).isEqualTo(0);
    assertThat(empty.getScalar()).isNull();
    assertThat(empty.getArray()).isNull();
    assertThat(empty.getArrayPrimitive()).isNull();
    assertThat(empty.getArray2()).isNull();
    assertThat(empty.getArray2Primitive()).isNull();
    assertThat(empty.getList()).isNull();
    assertThat(empty.getSet()).isNull();
    assertThat(empty.getMap()).isNull();
}
项目:mandrel    文件:MongoMetadataStoreTest.java   
@Test
public void test() {

    Job job = new Job().setId(30);
    TaskContext taskContext = new TaskContext();
    taskContext.setDefinition(job);

    MongoMetadataStoreDefinition definition = new MongoMetadataStoreDefinition();
    MongoMetadataStore store = definition.build(taskContext);

    System.err.println(Sets.newHashSet(store.getCollection().find().projection(Projections.include("_id")).map(doc -> Uri.create(doc.getString("_id")))
            .iterator()));

    Uri uri = new Uri("http", null, "test", 80, "/pouet", null);
    store.delete(uri);
    store.addMetadata(uri, new BlobMetadata());

    Set<Uri> deduplicate = store.deduplicate(Sets.newHashSet(uri));

    Assertions.assertThat(deduplicate).isEmpty();
}
项目:repositoryminer    文件:TDFinder.java   
@SuppressWarnings("unchecked")
private void findBugs(String commit) {
    FindBugsDAO dao = new FindBugsDAO();
    List<Document> analysisDoc = dao.findByCommit(commit, Projections.include("filename", "bugs.category"));

    for (Document fileDoc : analysisDoc) {
        TDItem tdItem = searchFile(fileDoc.getString("filename"));
        List<Document> bugs = (List<Document>) fileDoc.get("bugs");

        int specificBugs = 0;
        for (Document bug : bugs) {
            String category = bug.getString("category");
            if (category.equals("MT_CORRECTNESS")) {
                addTDIndicator(tdItem, TDIndicator.MULTITHREAD_CORRECTNESS, 1);
                specificBugs++;
            } else if (category.equals("PERFORMANCE")) {
                addTDIndicator(tdItem, TDIndicator.SLOW_ALGORITHM, 1);
                specificBugs++;
            }
        }

        if ((bugs.size() - specificBugs) > 0) {
            addTDIndicator(tdItem, TDIndicator.AUTOMATIC_STATIC_ANALYSIS_ISSUES, bugs.size() - specificBugs);
        }
    }
}
项目:testcontainers-hazelcast    文件:MongoMapStore.java   
@Override
public Iterable<String> loadAllKeys() {
    log.info("LoadAllKeys");
    List<String> keys = new LinkedList<String>();
    FindIterable<Document> ids = collection.find().projection(Projections.include("_id"));
    for (Document document : ids) {
        keys.add(document.get("_id").toString());
    }
    return keys;
}
项目:mongodb-rdbms-sync    文件:SyncEventDao.java   
public SyncMarker getEventStats(ObjectId eventId) {
    Document group = new Document("$group",
            new Document(SyncAttrs.ID, null).append(SyncAttrs.TOTAL_ROWS, new Document("$sum", "$marker.totalRows"))
                    .append(SyncAttrs.ROWS_READ, new Document("$sum", "$marker.rowsRead"))
                    .append(SyncAttrs.ROWS_DUMPED, new Document("$sum", "$marker.rowsDumped"))
                    .append(SyncAttrs.START_TIME, new Document("$min", "$marker.startTime"))
                    .append(SyncAttrs.END_TIME, new Document("$max", "$marker.endTime")));
    return syncEvents.aggregate(Arrays.asList(Aggregates.match(Filters.eq(SyncAttrs.PARENT_EVENT_ID, eventId)),
            Aggregates.project(Projections.include(SyncAttrs.MARKER)), group), SyncMarker.class).first();
}
项目:mongodb-rdbms-sync    文件:SyncEventDao.java   
public List<SyncError> getEventErrors(ObjectId eventId) {
    Document group = new Document("$group",
            new Document(SyncAttrs.ID, null).append(SyncAttrs.ERRORS, new Document("$addToSet", "$errors")));
    return syncEvents.aggregate(
            Arrays.asList(Aggregates.match(Filters.eq(SyncAttrs.PARENT_EVENT_ID, eventId)),
                    Aggregates.unwind("$errors"),
                    Aggregates
                            .project(Projections.include(SyncAttrs.ERRORS)),
                    group, Aggregates.unwind("$errors"),
                    Aggregates.project(new Document(SyncAttrs.ERROR_MESSAGE, "$errors.errorMessage")
                            .append(SyncAttrs.TRACE, "$errors.trace")
                            .append(SyncAttrs.THREAD_NAME, "$errors.threadName"))),
            SyncError.class).allowDiskUse(true).into(new ArrayList<SyncError>());
}
项目:mongodb-rdbms-sync    文件:SyncEventDao.java   
public List<ObjectId> checkCancelledEvents(final Set<ObjectId> activeEventList) {
    final List<ObjectId> cancelledEvents = new ArrayList<ObjectId>();
    syncEvents
            .find(Filters.and(Filters.in(SyncAttrs.ID, activeEventList),
                    Filters.eq(SyncAttrs.STATUS, SyncStatus.CANCELLED)), Document.class)
            .projection(Projections.include(SyncAttrs.ID)).forEach(new Block<Document>() {
                @Override
                public void apply(Document arg0) {
                    cancelledEvents.add(arg0.getObjectId(SyncAttrs.ID));
                }
            });
    return cancelledEvents;
}
项目:sam    文件:ApplicationResource.java   
private Iterable<ServerDeployment> findApplicationDeployments(String applicationId) {
  return database.getCollection(Collections.SERVERS)
    .find(
      Filters.eq("deployments.applicationId", applicationId)
    ).projection(Projections.fields(
      Projections.include("hostname", "environment"),
      Projections.elemMatch("deployments")
    )).map(ServerDeployment::fromBson);
}
项目:sam    文件:SearchResource.java   
private <T> PaginatedCollection<T> textSearch(String query, String collection, Function<Document,T> mapper) {
  return RestHelper.paginatedList(
    database.getCollection(collection)
      .find(Filters.text(query))
      .projection(Projections.metaTextScore("score"))
      .sort(Sorts.metaTextScore("score"))
      .map(mapper)
  );
}
项目:sam    文件:GroupResource.java   
private PaginatedCollection<String> getIds() {
  return RestHelper.paginatedList(database
    .getCollection(Collections.GROUPS)
    .find()
    .projection(Projections.include("id"))
    .map(t->t.getString("id"))
  );
}
项目:kafka-connect-mongodb    文件:DatabaseReader.java   
private FindIterable<Document> find(int page){
    final FindIterable<Document> documents = oplog
            .find(query)
            .sort(new Document("$natural", 1))
            .skip(page * batchSize)
            .limit(batchSize)
            .projection(Projections.include("ts", "op", "ns", "o"))
            .cursorType(CursorType.TailableAwait);
    return documents;
}
项目:Rapture    文件:MongoNotificationHandler.java   
@Override
public NotificationResult findNotificationsAfterEpoch(final CallingContext context, Long lastEpochSeen) {
    // Find all records where the recordtype is NOTIFICATION and
    // the epoch is gt lastEpochSeen, returning just the ids
    // Return the current epoch and these ids.

    final Document queryObject = new Document();
    queryObject.put(RECORDTYPE, NOTIFICATION);
    final Document greaterEpochObject = new Document();
    greaterEpochObject.put("$gt", lastEpochSeen);
    queryObject.put("epoch", greaterEpochObject);

    MongoRetryWrapper<NotificationResult> wrapper = new MongoRetryWrapper<NotificationResult>() {
        public FindIterable<Document> makeCursor() {
            return getNotificationCollection().find(queryObject).projection(Projections.include("id", "kernelId"));
        }

        public NotificationResult action(FindIterable<Document> cursor) {
            NotificationResult res = new NotificationResult(getLatestNotificationEpoch());
            for (Document dobj : cursor) {
                String kernelId = (String) dobj.get("kernelId");
                // ignore any notifications that came from this same kernel,
                // which can cause race conditions
                if (kernelId != null && kernelId.equals(context.getContext())) {
                    continue;
                }
                res.addId((String) dobj.get("id"));
            }
            return res;
        }
    };
    return wrapper.doAction();
}
项目:AbacusUtil    文件:MongoCollectionExecutor.java   
private FindIterable<Document> query(final Collection<String> selectPropNames, final Bson filter, final Bson sort, final int offset, final int count) {
    if (N.isNullOrEmpty(selectPropNames)) {
        return this.query(filter, sort, null, offset, count);
    } else if (selectPropNames instanceof List) {
        return this.query(filter, sort, Projections.include((List<String>) selectPropNames), offset, count);
    } else {
        return this.query(filter, sort, Projections.include(selectPropNames.toArray(new String[selectPropNames.size()])), offset, count);
    }
}
项目:verbum-domini    文件:DaoHelper.java   
public static Integer lastId(MongoCollection<?> coll) {
    FindIterable<Document> it = (FindIterable<Document>) coll.find()
        .projection(Projections.include("_id")).sort(new BasicDBObject("_id", -1)).limit(1);
    Document res = it.first();

    if (res == null) {
        return 0;
    }

    return res.getInteger("_id");
}
项目:bsoncodec-apt    文件:AtomicBooleanPojoTest.java   
@Test
public void testInsertAndFind() {
    MongoDatabase db = connect();
    insert(db);

    MongoCollection<AtomicBooleanPojo> coll = db.getCollection(COLL_NAME,
            AtomicBooleanPojo.class);
    AtomicBooleanPojo read = coll.find().first();

    assertThat(read.getScalar().get()).isEqualTo(true);
    assertThat(read.getArray()).hasSize(2);
    assertThat(read.getArray()[0].get()).isEqualTo(true);
    assertThat(read.getArray()[1].get()).isEqualTo(false);

    assertThat(read.getArray2()).hasSize(2);
    assertThat(read.getArray2()[0][0].get()).isEqualTo(false);
    assertThat(read.getArray2()[1][0].get()).isEqualTo(true);

    assertThat(read.getList()).hasSize(1);
    assertThat(read.getSet()).hasSize(1);
    assertThat(read.getList().iterator().next().get()).isEqualTo(true);
    assertThat(read.getSet().iterator().next().get()).isEqualTo(false);

    AtomicBooleanPojo empty = coll.find().projection(Projections.include("id"))
            .first();
    assertThat(empty.getScalar()).isNull();
    assertThat(empty.getArray()).isNull();
    assertThat(empty.getArray2()).isNull();
    assertThat(empty.getList()).isNull();
    assertThat(empty.getSet()).isNull();
    assertThat(empty.getMap()).isNull();
}
项目:bsoncodec-apt    文件:AtomicIntegerPojoTest.java   
@Test
public void testInsertAndFind() {
    MongoDatabase db = connect();
    insert(db);

    MongoCollection<AtomicIntegerPojo> coll = db.getCollection(COLL_NAME,
            AtomicIntegerPojo.class);
    AtomicIntegerPojo read = coll.find().first();

    assertThat(read.getScalar().get()).isEqualTo(1);
    assertThat(read.getArray()).hasSize(2);
    assertThat(read.getArray()[0].get()).isEqualTo(2);
    assertThat(read.getArray()[1].get()).isEqualTo(3);

    assertThat(read.getArray2()).hasSize(2);
    assertThat(read.getArray2()[0][0].get()).isEqualTo(4);
    assertThat(read.getArray2()[1][0].get()).isEqualTo(5);

    assertThat(read.getList()).hasSize(1);
    assertThat(read.getSet()).hasSize(1);
    assertThat(read.getList().iterator().next().get()).isEqualTo(6);
    assertThat(read.getSet().iterator().next().get()).isEqualTo(7);

    AtomicIntegerPojo empty = coll.find().projection(Projections.include("id"))
            .first();
    assertThat(empty.getScalar()).isNull();
    assertThat(empty.getArray()).isNull();
    assertThat(empty.getArray2()).isNull();
    assertThat(empty.getList()).isNull();
    assertThat(empty.getSet()).isNull();
    assertThat(empty.getMap()).isNull();
}
项目:bsoncodec-apt    文件:AtomicLongPojoTest.java   
@Test
public void testInsertAndFind() {
    MongoDatabase db = connect();
    insert(db);

    MongoCollection<AtomicLongPojo> coll = db.getCollection(COLL_NAME,
            AtomicLongPojo.class);
    AtomicLongPojo read = coll.find().first();

    assertThat(read.getScalar().get()).isEqualTo(1);
    assertThat(read.getArray()).hasSize(2);
    assertThat(read.getArray()[0].get()).isEqualTo(2);
    assertThat(read.getArray()[1].get()).isEqualTo(3);

    assertThat(read.getArray2()).hasSize(2);
    assertThat(read.getArray2()[0][0].get()).isEqualTo(4);
    assertThat(read.getArray2()[1][0].get()).isEqualTo(5);

    assertThat(read.getList()).hasSize(1);
    assertThat(read.getSet()).hasSize(1);
    assertThat(read.getList().iterator().next().get()).isEqualTo(6);
    assertThat(read.getSet().iterator().next().get()).isEqualTo(7);

    AtomicLongPojo empty = coll.find().projection(Projections.include("id")).first();
    assertThat(empty.getScalar()).isNull();
    assertThat(empty.getArray()).isNull();
    assertThat(empty.getArray2()).isNull();
    assertThat(empty.getList()).isNull();
    assertThat(empty.getSet()).isNull();
    assertThat(empty.getMap()).isNull();
}
项目:mandrel    文件:MongoMetadataStore.java   
@Override
public Set<Uri> deduplicate(Collection<Uri> uris) {
    Set<Uri> temp = Sets.newHashSet(uris);

    Set<Uri> founds = Sets.newHashSet(collection.find(Filters.in("_id", uris)).projection(Projections.include("_id"))
            .map(doc -> Uri.create(doc.getString("_id"))).iterator());
    temp.removeAll(founds);

    return temp;
}
项目:repositoryminer    文件:RepositoryMinerExComment.java   
@Override
public void init(String repositoryKey) throws IOException {
    super.init(repositoryKey);

    RepositoryDAO repoHandler = new RepositoryDAO();
    Repository repository = Repository
            .parseDocument(repoHandler.findById(repositoryId, Projections.include("path")));

    this.repositoryPath = repository.getPath();
}
项目:repositoryminer    文件:SnapshotAnalysisPlugin.java   
public void init(String repositoryKey) throws IOException {
    Document repoDoc = new RepositoryDAO().findByKey(repositoryKey, Projections.include("_id", "path", "scm"));
    if (repoDoc == null) {
        throw new RepositoryMinerException("Repository with the key " + repositoryKey + " does not exists");
    }

    scm = SCMFactory.getSCM(SCMType.valueOf(repoDoc.getString("scm")));
    repositoryId = repoDoc.getObjectId("_id");
    tmpRepository = RMFileUtils.copyFolderToTmp(repoDoc.getString("path"),
            StringUtils.encodeToSHA1(repositoryId.toHexString()));

    scm.open(tmpRepository);
}
项目:repositoryminer    文件:MiningPlugin.java   
public MiningPlugin(String repositoryKey) {
    RepositoryDAO dao = new RepositoryDAO();
    repositoryId = dao.findByKey(repositoryKey, Projections.include("_id")).getObjectId("_id");

    if (repositoryId == null) {
        throw new RepositoryMinerException("Repository not found.");
    }
}
项目:repositoryminer    文件:RepositoryMinerMetrics.java   
private void checkDuplicatedAnalysis(String hash) {
    CodeAnalysisReportDAO configDao = new CodeAnalysisReportDAO();
    Document doc = configDao.findByCommitHash(hash, Projections.include("_id"));
    if (doc != null) {
        configDao.deleteById(doc.getObjectId("_id"));
        new CodeAnalysisDAO().deleteByReport(doc.getObjectId("_id"));
    }
}