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


Java Block类代码示例

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


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

示例1: findReportsRaw

import com.mongodb.Block; //导入依赖的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: returnValueToURL

import com.mongodb.Block; //导入依赖的package包/类
public int returnValueToURL(String URL)
{
    Block<Document> printBlock = new Block<Document>() {
        @Override
        public void apply(final Document document) {
            System.out.println(document.toJson());
        }
    };
    MongoCollection<Document> collection = db.getCollection("ratings");

    collection.aggregate(
            Arrays.asList(
                    Aggregates.group("URL", Accumulators.avg("rating", 1))))
            .forEach(printBlock);
    System.out.println(printBlock.toString());
    return 0;
}
 
开发者ID:Sigma-News,项目名称:Backend,代码行数:18,代码来源:MongoDBManager.java

示例3: getDeviceEntitiesByName

import com.mongodb.Block; //导入依赖的package包/类
public List<DeviceEntity> getDeviceEntitiesByName(String name) {
  Document query = new Document("name", name);

  List<DeviceEntity> result = new ArrayList<>();

  collection.find(query).forEach((Block<? super Document>) document -> {
    Short devId = document.getInteger("dev_id").shortValue();
    String category = document.getString("category");
    String type = document.getString("type");
    boolean isTrusted = document.getBoolean("isTrusted");

    result.add(new DeviceEntity(devId, name, category, type, isTrusted));
  });

  return result;
}
 
开发者ID:daergoth,项目名称:HomeWire-Server,代码行数:17,代码来源:DeviceSetupRepository.java

示例4: loadRegionData

import com.mongodb.Block; //导入依赖的package包/类
public HashMap<UUID, ArrayList<LoadedRegion>> loadRegionData() {
	HashMap<UUID, ArrayList<LoadedRegion>> regions = new HashMap<>();

	MongoCollection<Document> collection = getDatabase().getCollection("chunks");
	collection.find().forEach((Block<Document>) document -> {
		UUID id = UUID.fromString(document.getString("_id"));
		UUID owner = UUID.fromString(document.getString("owner"));
		UUID world = UUID.fromString(document.getString("world"));
		LoadedRegion.ChunkType type = LoadedRegion.ChunkType.valueOf(document.getString("type"));
		int fromX = document.getInteger("fromX");
		int fromZ = document.getInteger("fromZ");
		int toX = document.getInteger("toX");
		int toZ = document.getInteger("toZ");
		Date date = (Date) document.getDate("created");

		Region region = new Region(new Coordinate(fromX, fromZ), new Coordinate(toX, toZ), world);

		if (regions.containsKey(id))
			regions.get(id).add(new LoadedRegion(owner, id, region, date, type));
		else
			regions.put(id, Lists.newArrayList(new LoadedRegion(owner, id, region, date, type)));

	});

	return regions;
}
 
开发者ID:DevOnTheRocks,项目名称:StickyChunk,代码行数:27,代码来源:MongodbDatabase.java

示例5: findReportsForView

import com.mongodb.Block; //导入依赖的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

示例6: run

import com.mongodb.Block; //导入依赖的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

示例7: findByCategory

import com.mongodb.Block; //导入依赖的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

示例8: getAllDevicesByCategory

import com.mongodb.Block; //导入依赖的package包/类
public List<DeviceEntity> getAllDevicesByCategory(String category) {
  List<DeviceEntity> result = new ArrayList<>();

  Document filter;
  if (category.isEmpty()) {
    filter = new Document();
  } else {
    filter = new Document("category", category);
  }

  collection.find(filter)
      .forEach((Block<? super Document>) document -> {
        Short devId = document.getInteger("dev_id").shortValue();
        String name = document.getString("name");
        String cat = document.getString("category");
        String type = document.getString("type");
        boolean isTrusted = document.getBoolean("isTrusted");

        result.add(new DeviceEntity(devId, name, cat, type, isTrusted));
      });

  return result;
}
 
开发者ID:daergoth,项目名称:HomeWire-Server,代码行数:24,代码来源:DeviceSetupRepository.java

示例9: getDeviceEntitiesByType

import com.mongodb.Block; //导入依赖的package包/类
public List<DeviceEntity> getDeviceEntitiesByType(String type) {
  Document query = new Document("type", type);

  List<DeviceEntity> result = new ArrayList<>();

  collection.find(query).forEach((Block<? super Document>) document -> {
    Short devId = document.getInteger("dev_id").shortValue();
    String category = document.getString("category");
    String name = document.getString("name");
    boolean isTrusted = document.getBoolean("isTrusted");

    result.add(new DeviceEntity(devId, name, category, type, isTrusted));
  });

  return result;
}
 
开发者ID:daergoth,项目名称:HomeWire-Server,代码行数:17,代码来源:DeviceSetupRepository.java

示例10: addPostings

import com.mongodb.Block; //导入依赖的package包/类
public List<Integer> addPostings(int topic) {
	
	List<Integer> postings  = new ArrayList<Integer>();

	BasicDBObject query = new BasicDBObject();
	query.put("topic_id", topic);
	BasicDBObject sortby = new BasicDBObject("post_number", 1);
	log.info("  Querying postings in topic " + topic);
	progress_counter = 0;
	List<Document> lbd = new ArrayList<>();
	mongoClient.getDatabase(mongoDbName).getCollection("postings").find(query).sort(sortby).forEach((Block<Document>) d -> { lbd.add(d); });
	for (int clump=0; clump<= lbd.size(); clump += 300) {
		log.info("  adding posts " + clump + " through " + Math.min(clump+300,lbd.size()));
		postings.addAll(helper.addPostingGroup(topic, lbd.subList(clump, Math.min(clump+300,lbd.size())),this));
	}
	log.info("done with adding posts to this topic");
	return postings;
}
 
开发者ID:DiscourseDB,项目名称:discoursedb-core,代码行数:19,代码来源:RavelryConverterService.java

示例11: migrateGeneralScriptFunctions

import com.mongodb.Block; //导入依赖的package包/类
private void migrateGeneralScriptFunctions(GlobalContext context) {
	logger.info("Searching for functions of type 'step.plugins.functions.types.GeneralScriptFunction' to be migrated...");
	com.mongodb.client.MongoCollection<Document> functions = MongoDBAccessorHelper.getMongoCollection_(context.getMongoClient(), "functions");
	
	AtomicInteger i = new AtomicInteger();
	Document filterCallFunction = new Document("type", "step.plugins.functions.types.GeneralScriptFunction");
	functions.find(filterCallFunction).forEach(new Block<Document>() {

		@Override
		public void apply(Document t) {
			t.replace("type", "step.plugins.java.GeneralScriptFunction");
			Document filter = new Document("_id", t.get("_id"));
			functions.replaceOne(filter, t);
			i.incrementAndGet();
		}
	});
	
	logger.info("Migrated "+i.get()+" functions of type 'step.plugins.functions.types.GeneralScriptFunction'");
}
 
开发者ID:denkbar,项目名称:step,代码行数:20,代码来源:InitializationPlugin.java

示例12: renameArtefactType

import com.mongodb.Block; //导入依赖的package包/类
private void renameArtefactType(GlobalContext context, String classFrom, String classTo) {
	logger.info("Searching for artefacts of type '"+classFrom+"' to be migrated...");
	com.mongodb.client.MongoCollection<Document> artefacts = MongoDBAccessorHelper.getMongoCollection_(context.getMongoClient(), "artefacts");
	
	AtomicInteger i = new AtomicInteger();
	Document filterCallFunction = new Document("_class", classFrom);
	artefacts.find(filterCallFunction).forEach(new Block<Document>() {

		@Override
		public void apply(Document t) {
			try {
				i.incrementAndGet();
				t.put("_class", classTo);
				
				Document filter = new Document("_id", t.get("_id"));
				
				artefacts.replaceOne(filter, t);
				logger.info("Migrating "+classFrom+ " to "+t.toJson());
			} catch(ClassCastException e) {
				// ignore
			}
		}
	});
	
	logger.info("Migrated "+i.get()+" artefacts of type '"+classFrom+"'");
}
 
开发者ID:denkbar,项目名称:step,代码行数:27,代码来源:InitializationPlugin.java

示例13: checkAndCleanup

import com.mongodb.Block; //导入依赖的package包/类
public boolean checkAndCleanup(String userId, String fileName) {
    List<Document> l = query(new Query().equals(USERID, userId).addSortCriteria(CREATION_TIME, false));
    if (l.size() >= maxPersistedPagesPerUser) {
        Document oldest = l.iterator().next();
        if ((System.currentTimeMillis() - oldest.get(CREATION_TIME).getTime()) < minimumDelay) {
            //there have been to many page persistences for this user in a short time, so don't persist
            return false;
        } else {
            //clean up oldest to free space for new persisted page
            gridFS.find(Filters.eq("filename", oldest.get(FILENAME))).forEach(new Block<GridFSFile>() {
                @Override
                public void apply(GridFSFile file) {
                    gridFS.delete(file.getObjectId());
                }
            });
            oldest.delete();
        }
    }
    //create new entry
    Document newOne = createNew();
    newOne.set(USERID, userId);
    newOne.set(FILENAME, fileName);
    newOne.set(CREATION_TIME, new Date());
    newOne.writeToDatabase(false);
    return true;
}
 
开发者ID:KAOREND,项目名称:reactive-hamster,代码行数:27,代码来源:PersistedPages.java

示例14: fireEvent

import com.mongodb.Block; //导入依赖的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

示例15: getDeployments

import com.mongodb.Block; //导入依赖的package包/类
public List<Deployment> getDeployments(String clusterId) {
    List<Deployment> deployments = new ArrayList<>();
    Block<Document> printBlock = new Block<Document>() {
        @Override
        public void apply(final Document document) {
            Deployment deployment = new Deployment();
            deployment.setUuid(document.getString("uuid"));
            deployment.setStatus(document.getString("status"));
            deployment.setHostCount(document.getInteger("hostCount"));
            deployment.setCompletedCount(document.getInteger("completedCount"));
            TarFile tarFile = new TarFile();
            tarFile.setUrl(document.getString("sourceTar"));
            deployment.setSourceTar(tarFile);
            deployment.setTimestamp(document.getDate("timestamp"));
            deployments.add(deployment);
        }
    };

    connection.getCollection(DEPLOYMENTS_COLLECTION_NAME).find(eq("clusterId", clusterId)).forEach(printBlock);
    return deployments;
}
 
开发者ID:Financial-Times,项目名称:paasport,代码行数:22,代码来源:DeploymentsDao.java


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