當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。