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


Java FindIterable.forEach方法代码示例

本文整理汇总了Java中com.mongodb.client.FindIterable.forEach方法的典型用法代码示例。如果您正苦于以下问题:Java FindIterable.forEach方法的具体用法?Java FindIterable.forEach怎么用?Java FindIterable.forEach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mongodb.client.FindIterable的用法示例。


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

示例1: findReportsRaw

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
public static JSONObject findReportsRaw() {
    JSONArray reports = new JSONArray();
    FindIterable<Document> result = findReports();
    
    result.forEach(new Block<Document>() {
        @Override
        public void apply(final Document document) {
            JSONObject jsonReport = new JSONObject();
            jsonReport.put("id", document.getObjectId("_id").toString());
            jsonReport.put("comment", document.getString("comment"));
            jsonReport.put("city_item_id", document.getString("city_item_id"));
            jsonReport.put("priority", document.getInteger("priority"));
            jsonReport.put("resolved", document.getBoolean("resolved"));
            jsonReport.put("report_date", document.getLong("report_date"));
            reports.put(jsonReport);
        }
    });
    
    JSONObject jsonResults = new JSONObject();
    jsonResults.put("reports", reports);
    
    return jsonResults;
}
 
开发者ID:Labas-Vakaras,项目名称:Smart_City,代码行数:24,代码来源:ReportDAO.java

示例2: findReportsForView

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
/**
 * Returns all reports for view
 * 
 * @return List
 */
public static List<ReportViewObject> findReportsForView() {
    List<ReportViewObject> reports = new ArrayList<>();
    FindIterable<Document> result = findReports();
            
    result.forEach(new Block<Document>() {
        @Override
        public void apply(final Document document) {
            Report.Builder b = new Report.Builder();
            DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
            String reportDate = df.format(new Date(document.getLong("report_date")));

            reports.add(new ReportViewObject(
                    document.getObjectId("_id").toString(),
                    Integer.toString(document.getInteger("priority")),
                    document.getString("city_item_id"),
                    reportDate,
                    document.getBoolean("resolved") ? "YES" : "NO"));
        }
    });
    
    return reports;
}
 
开发者ID:Labas-Vakaras,项目名称:Smart_City,代码行数:28,代码来源:ReportDAO.java

示例3: run

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Override
public void run() {
	System.out.println("Reader started");
	MongoCollection<Document> collection = DBCacheManager.INSTANCE.getCachedMongoPool(mongoDbName, mongoUserName)
			.getDatabase(mongoDbName).getCollection(collectionName);
	FindIterable<Document> it = collection.find().batchSize(batchSize);
	it.forEach(new Block<Document>() {
		@Override
		public void apply(Document t) {
			System.out.println("Document read " + t);
			try {
				dataBuffer.put(t);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	});
}
 
开发者ID:gagoyal01,项目名称:mongodb-rdbms-sync,代码行数:20,代码来源:MngToOrclReader.java

示例4: findByCategory

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Override
public List<SurveyActivity> findByCategory(String categoryName) {
	ArrayList<SurveyActivity> activities = new ArrayList<>();

	FindIterable<Document> result = collection.find(eq("category.name", categoryName));

	result.forEach((Block<Document>) document -> activities.add(SurveyActivity.deserialize(document.toJson())));
	return activities;
}
 
开发者ID:ccem-dev,项目名称:otus-api,代码行数:10,代码来源:ActivityDaoBean.java

示例5: search

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Override
public synchronized List<Karma> search(String queryString) {
  int order = DESC;
  List<Karma> result = new ArrayList<>();
  BasicDBObject query = new BasicDBObject();
  queryString = queryString.toLowerCase();
  if (queryString.startsWith("!")) {
    queryString = queryString.substring(1);
    order = ASC;
  }
  if (queryString.contains("*")) {
    query.put("_id", new BasicDBObject("$regex", queryString.replace("*", ".*")).append("$options", "i"));
  } else {
    query.put("_id", queryString);
  }
  FindIterable<Document> documents = karmas.find(query).sort(new BasicDBObject().append("value", order)).limit(10);
  documents.forEach((Consumer<Document>) document -> result.add(gson.fromJson(document.toJson(), Karma.class)));
  return result;
}
 
开发者ID:devnull-tools,项目名称:boteco,代码行数:20,代码来源:MongoKarmaRepository.java

示例6: fireEvent

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
/**
 * Fires an event on all objects in the cache, which fulfill the query
 *
 * @param event
 * @param query
 */
public void fireEvent(final DataEvent event, BaseQuery query) {
    //query only ids
    FindIterable cursor = collection.find(query.getQuery());
    cursor.forEach(new Block() {

        @Override
        public void apply(Object t) {
            org.bson.Document dbObject = (org.bson.Document) t;
            String id = "" + dbObject.get("_id");
            synchronized (map) {
                Document o = map.get(id);
                if (o != null) {
                    o.fireChangedEvent(event);
                }
            }
        }
    });
}
 
开发者ID:KAOREND,项目名称:reactive-hamster,代码行数:25,代码来源:DocumentCollection.java

示例7: main

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
public static void main(String[] args) {
    // new client
    MongoClient client = new MongoClient();
    // get the data base
    MongoDatabase db = client.getDatabase("other");
    // here create a new collection
    //db.createCollection("filestore");
    // insert data into the collection
    db.getCollection("filestore").insertOne(
            new Document()
            .append("name", "smile")
            .append("age", 20));
    // retrive the data
    FindIterable<Document> iterable = db.getCollection("filestore").find();
    // show data
    iterable.forEach(new Block<Document>() {
        @Override
        public void apply(final Document document) {
            System.out.println(document);
        }
    });
}
 
开发者ID:smileboywtu,项目名称:CS-FileTransfer,代码行数:23,代码来源:UsingMongoSavaFile.java

示例8: main

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
public static void main(String[] args) {
    // new client
    MongoClient client = new MongoClient();
    // get the data base
    MongoDatabase db = client.getDatabase("other");
    // here create a new collection
    //db.createCollection("filestore");
    // insert data into the collection
    db.getCollection("filestore").insertOne(
            new Document()
                    .append("name", "smile")
                    .append("age", 20));
    // retrive the data
    FindIterable<Document> iterable = db.getCollection("filestore").find();
    // show data
    iterable.forEach(new Block<Document>() {
        @Override
        public void apply(final Document document) {
            System.out.println(document);
        }
    });
}
 
开发者ID:smileboywtu,项目名称:CS-FileTransfer,代码行数:23,代码来源:UsingMongoSavaFile.java

示例9: processEventLogFlow

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
private void processEventLogFlow() throws InterruptedException {
	FindIterable<O2MSyncEventLog> it = getCursor();
	retryCount = 0;
	it.forEach(new Block<O2MSyncEventLog>() {
		@Override
		public void apply(O2MSyncEventLog eventLog) {
			try {
				if (marker.isFailed()) {
					releaseReources();
					return;
				}
				logCollection.findOneAndUpdate(Filters.eq(SyncAttrs.ID, eventLog.getLogId()),
						Updates.set(O2MSyncEventLogCodec.STATUS, O2MSyncEventLogCodec.RUNNING));
				logger.info("Processing filter : "+eventLog.getEventFilters());
				if (eventLog.getOperation().equals(SyncConstants.DELETE)) {
					processDeletedDoc(eventLog);
				}else{
					processMongoObject(map.getMapObject(), true, null, map.getMapObject().getCollectionName(),
							eventLog);	
				}					
				logCollection.findOneAndUpdate(Filters.eq(SyncAttrs.ID, eventLog.getLogId()),
						Updates.set(O2MSyncEventLogCodec.STATUS, O2MSyncEventLogCodec.COMPLETE));
				logger.info("Processed filter : "+eventLog.getEventFilters());
			} catch (SyncError e) {
				logger.error("Error in O2M replication", e);
				Mailer.sendmail(eventId, null, e, Mailer.FAILURE);
			}
		}
	});
}
 
开发者ID:gagoyal01,项目名称:mongodb-rdbms-sync,代码行数:31,代码来源:OrclToMngSyncReader.java

示例10: find

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Override
public List<DataSource> find() {
	ArrayList<DataSource> dataSources = new ArrayList<DataSource>();

	FindIterable<Document> result = collection.find();
	result.forEach((Block<Document>) document -> {
		dataSources.add(DataSource.deserialize(document.toJson()));
	});

	return dataSources;
}
 
开发者ID:ccem-dev,项目名称:otus-api,代码行数:12,代码来源:DataSourceDaoBean.java

示例11: find

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
/**
 * Return activities considering that they were not discarded
 * @param rn
 * @return
 */
@Override
public List<SurveyActivity> find(long rn) {
	ArrayList<SurveyActivity> activities = new ArrayList<SurveyActivity>();

	FindIterable<Document> result = collection.find(and(eq("participantData.recruitmentNumber", rn), eq("isDiscarded", false)));
	result.forEach((Block<Document>) document -> {
		activities.add(SurveyActivity.deserialize(document.toJson()));
	});

	return activities;
}
 
开发者ID:ccem-dev,项目名称:otus-api,代码行数:17,代码来源:ActivityDaoBean.java

示例12: findNonDeleted

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Override
public List<ActivityCategory> findNonDeleted() {
    ArrayList<ActivityCategory> categories = new ArrayList<>();

    BasicDBObject query = new BasicDBObject();
    query.put("objectType", "ActivityCategory");
    query.put("disabled", false);

    FindIterable<Document> documents = collection.find(query);

    documents.forEach((Block<? super Document>) document -> categories.add(ActivityCategory.deserialize(document.toJson())));

    return categories;
}
 
开发者ID:ccem-dev,项目名称:otus-api,代码行数:15,代码来源:ActivityConfigurationDaoBean.java

示例13: find

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Override
public List<ExamLot> find() {
	ArrayList<ExamLot> ExamLots = new ArrayList<>();
	
	FindIterable<Document> result = collection.find();
	result.forEach((Block<Document>) document -> ExamLots.add(ExamLot.deserialize(document.toJson())));

	return ExamLots;
}
 
开发者ID:ccem-dev,项目名称:otus-api,代码行数:10,代码来源:ExamLotDaoBean.java

示例14: find

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Override
public List<TransportationLot> find() {
	ArrayList<TransportationLot> transportationLots = new ArrayList<>();

	FindIterable<Document> result = collection.find();
	result.forEach((Block<Document>) document -> transportationLots.add(TransportationLot.deserialize(document.toJson())));
	return transportationLots;
}
 
开发者ID:ccem-dev,项目名称:otus-api,代码行数:9,代码来源:TransportationLotDaoBean.java

示例15: getFullAliquotsList

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Override
public ArrayList<Aliquot> getFullAliquotsList() {
    ArrayList<Aliquot> fullList = new ArrayList<Aliquot>();

	FindIterable<Document> list = collection.find();
	list.forEach((Block<Document>) document ->{
           ParticipantLaboratory laboratory = ParticipantLaboratory.deserialize(document.toJson());
           fullList.addAll(laboratory.getAliquotsList());
       });

	return fullList;
}
 
开发者ID:ccem-dev,项目名称:otus-api,代码行数:13,代码来源:ParticipantLaboratoryDaoBean.java


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