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


Java DBCursor类代码示例

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


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

示例1: findAll

import com.mongodb.DBCursor; //导入依赖的package包/类
public List<AgentConfigurationDatabase> findAll(){
	ArrayList<AgentConfigurationDatabase> agents = null;
	logger.info("Getting all agent cfgs from database...");
       DBCursor cur = getAgentConfigurationTable().find();
       while (cur.hasNext()) {
       	if (agents == null) {
       		agents = new ArrayList<AgentConfigurationDatabase>();
       	}
       	agents.add(this.toAgentCfgDbObject(cur.next()));    	
       }
       if (agents != null){
       	logger.info("Retrieved " + agents.size() + " agent configurations from database");
       }
       else {
       	logger.info("Retrieved " + 0 + " agent configurations from database");
       }
	return agents;
}
 
开发者ID:elastest,项目名称:elastest-instrumentation-manager,代码行数:19,代码来源:AgentConfigurationRepository.java

示例2: getAgentByAgentId

import com.mongodb.DBCursor; //导入依赖的package包/类
public AgentFull getAgentByAgentId(String agentId){
	System.out.println("Searching host in DB with agentId = " + agentId);
	logger.info("Searching host in DB with agentId = " + agentId);
	AgentFull agent = null;
	BasicDBObject query = new BasicDBObject();
       query.put("agentId", agentId);

       DBCursor cursor = getAgentTable().find(query);
       if (cursor.hasNext()){
       	agent = new AgentFull();
       	agent.setAgentId((String) cursor.next().get("agentId"));
       	agent.setHost((String) cursor.curr().get("host"));
       	agent.setMonitored((boolean) cursor.curr().get("monitored"));
       	agent.setLogstashIp((String) cursor.curr().get("logstashIp"));
       	agent.setLogstashPort((String) cursor.curr().get("logstashPort"));
       	logger.info("Host finded in DB with agentId = " + agentId + " with ipAddress " + agent.getHost());
       	System.out.println("Host finded in DB with agentId = " + agentId + " with ipAddress " + agent.getHost());
       }
       else {
       	logger.info("Host doesn't exists in DB with agentId = " + agentId);
       	System.out.println("Host doesn't exists in DB with agentId = " + agentId);
       	return null;
       }		
	return agent;
}
 
开发者ID:elastest,项目名称:elastest-instrumentation-manager,代码行数:26,代码来源:AgentRepository.java

示例3: afterCreate

import com.mongodb.DBCursor; //导入依赖的package包/类
/** Read the occasions that are stored in the database and schedule them to run. */
@PostConstruct
public void afterCreate() {
  String method = "afterCreate";
  logger.entering(clazz, method);

  orchestrator.setOccasionResource(this);

  DBCollection occasions = getCollection();
  DBCursor cursor = occasions.find();
  while (cursor.hasNext()) {
    DBObject dbOccasion = cursor.next();
    Occasion occasion = new Occasion(dbOccasion);
    try {
      // TODO: There was a comment here about how we should mark the event as
      //       popped in the database, which will have different meaning for
      //       one-time or interval occasions.  Need to re-visit this.
      orchestrator.scheduleOccasion(occasion);
    } catch (Throwable t) {
      logger.log(Level.WARNING, "Could not schedule occasion at startup", t);
    }
  }

  logger.exiting(clazz, method);
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:26,代码来源:OccasionResource.java

示例4: generateFile

import com.mongodb.DBCursor; //导入依赖的package包/类
public void generateFile(String filename) {
    DB db = MongoHelper.mongoMerchantDB();

    DBCollection col = db.getCollection(COLLECTION_SYNONYMS);
    DBCursor cursor = col.find();
    try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(filename, true)))) {
        while (cursor.hasNext()) {
            DBObject doc = cursor.next();
            String word = doc.get(FIELD_KEY_WORLD) != null ? doc.get(FIELD_KEY_WORLD).toString() : null;
            String synonyms = doc.get(FIELD_KEY_WORLD) != null
                ? StringUtils.join((BasicDBList) doc.get(FIELD_KEY_SYNONYMS), ",") : null;
            if (word != null && synonyms != null) {
                out.println(createLine(word, synonyms));
            }
        }
    } catch (IOException e) {
        throw new RuntimeException("IOException: Current db cursor with id: " + cursor.curr().get("_id"), e);
    }
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:20,代码来源:SynonymsGenerator.java

示例5: testRetrieveAllAssetsPaginated

import com.mongodb.DBCursor; //导入依赖的package包/类
/**
 * Test that providing a PaginationOptions object results in the correct skip() and limit()
 * methods being called on the result cursor.
 */
@Test
public void testRetrieveAllAssetsPaginated(final @Mocked DBCollection collection, final @Injectable DBCursor cursor) {

    new Expectations() {
        {

            collection.find((DBObject) withNotNull(), (DBObject) withNull());
            result = cursor;
            cursor.skip(20);
            cursor.limit(10);
        }
    };

    List<AssetFilter> filters = new ArrayList<>();
    filters.add(new AssetFilter("key1", Arrays.asList(new Condition[] { new Condition(Operation.EQUALS, "value1") })));
    PaginationOptions pagination = new PaginationOptions(20, 10);
    createTestBean().retrieveAllAssets(filters, null, pagination, null);
}
 
开发者ID:WASdev,项目名称:tool.lars,代码行数:23,代码来源:PersistenceBeanBasicSearchTest.java

示例6: existConfiguration

import com.mongodb.DBCursor; //导入依赖的package包/类
public boolean existConfiguration(String agentId){		
	logger.info("Verifying if agent with agentId = " + agentId + " has a configuration stored in DB");
	System.out.println("Verifying if agent with agentId = " + agentId + " has a configuration stored in DB");
       BasicDBObject query = new BasicDBObject();
       query.put("agentId", agentId);

       DBCursor cursor = getAgentConfigurationTable().find(query);
       if (cursor.hasNext()){
       	logger.info("Configuration for agent with agentId = " + agentId + " exists");
       	System.out.println("Configuration for agent with agentId = " + agentId + " exists");
       	return true;
       }
       else {
       	logger.info("Not exists any configuration for an agent with agentId = " + agentId);
       	System.out.println("Not exists any configuration for an agent with agentId = " + agentId);
       	return false;
       }        
}
 
开发者ID:elastest,项目名称:elastest-instrumentation-manager,代码行数:19,代码来源:AgentConfigurationRepository.java

示例7: getAgentConfigurationByAgentId

import com.mongodb.DBCursor; //导入依赖的package包/类
public AgentConfigurationDatabase getAgentConfigurationByAgentId(String agentId){
	System.out.println("Searching agent cfg in DB with agentId = " + agentId);
	logger.info("Searching host in DB with agentId = " + agentId);
	BasicDBObject query = new BasicDBObject();
       query.put("agentId", agentId);

       DBCursor cursor = getAgentConfigurationTable().find(query);
       if (cursor.hasNext()){
       	logger.info("Agent cfg exists in DB with agentId = " + agentId);
       	return this.toAgentCfgDbObject(cursor.next());
       }
       else {
       	logger.info("Agent cfg doesn't exists in DB with agentId = " + agentId);
       	System.out.println("Agent cfg doesn't exists in DB with agentId = " + agentId);
       	return null;
       }		
}
 
开发者ID:elastest,项目名称:elastest-instrumentation-manager,代码行数:18,代码来源:AgentConfigurationRepository.java

示例8: existHost

import com.mongodb.DBCursor; //导入依赖的package包/类
public boolean existHost(String ipAddress){		
	logger.info("Verifying if host with ipAddress = " + ipAddress + " exists");
	System.out.println("Verifying if host with ipAddress = " + ipAddress + " exists");
       BasicDBObject query = new BasicDBObject();
       query.put("host", ipAddress);

       DBCursor cursor = getAgentTable().find(query);
       if (cursor.hasNext()){
       	logger.info("Host with ipAddress = " + ipAddress + " exists");
       	System.out.println("Host with ipAddress = " + ipAddress + " exists");
       	return true;
       }
       else {
       	logger.info("Not exists any host with ipAddress = " + ipAddress);
       	System.out.println("Not exists any host with ipAddress = " + ipAddress);
       	return false;
       }        
}
 
开发者ID:elastest,项目名称:elastest-instrumentation-manager,代码行数:19,代码来源:AgentRepository.java

示例9: findAll

import com.mongodb.DBCursor; //导入依赖的package包/类
public List<AgentFull> findAll(){
	ArrayList<AgentFull> agents = null;
	logger.info("Getting all agents from database...");
       DBCursor cur = getAgentTable().find();
       AgentFull agent = null;
       while (cur.hasNext()) {
       	if (agents == null) {
       		agents = new ArrayList<AgentFull>();
       	}
       	agent = new AgentFull();
       	agent.setAgentId((String) cur.next().get("agentId"));
       	agent.setHost((String) cur.curr().get("host") );
       	agent.setMonitored((boolean) cur.curr().get("monitored"));
       	agents.add(agent);    	
       }
       if (agents != null){
       	logger.info("Retrieved " + agents.size() + " agents from database");
       }
       else {
       	logger.info("Retrieved " + 0 + " agents from database");
       }
	return agents;
}
 
开发者ID:elastest,项目名称:elastest-instrumentation-manager,代码行数:24,代码来源:AgentRepository.java

示例10: findByFirstnameUsingMetaAttributes

import com.mongodb.DBCursor; //导入依赖的package包/类
/**
 * This test demonstrates usage of {@code $comment} {@link Meta} usage. One can also enable profiling using
 * {@code --profile=2} when starting {@literal mongod}.
 * <p>
 * <strong>NOTE</strong>: Requires MongoDB v. 2.6.4+
 */
@Test
public void findByFirstnameUsingMetaAttributes() {

	// execute derived finder method just to get the comment in the profile log
	repository.findByFirstname(dave.getFirstname());

	// execute another finder without meta attributes that should not be picked up
	repository.findByLastname(dave.getLastname(), new Sort("firstname"));

	DBCursor cursor = operations.getCollection(ApplicationConfiguration.SYSTEM_PROFILE_DB)
			.find(new BasicDBObject("query.$comment", AdvancedRepository.META_COMMENT));

	while (cursor.hasNext()) {

		DBObject dbo = cursor.next();
		DBObject query = (DBObject) dbo.get("query");

		assertThat(query.containsField("$comment"), is(true));
	}
}
 
开发者ID:Just-Fun,项目名称:spring-data-examples,代码行数:27,代码来源:AdvancedIntegrationTests.java

示例11: getAllIds

import com.mongodb.DBCursor; //导入依赖的package包/类
public List<String> getAllIds(final Map<String, Object> conditions) {
    DBObject query = new BasicDBObject(conditions);
    DBCursor cursor = coll.find(query);

    List<String> ids = new ArrayList<String>(cursor.count());
    for (DBObject o : cursor) {
        ids.add(o.get("_id").toString());
    }

    return ids;
}
 
开发者ID:HewlettPackard,项目名称:loom,代码行数:12,代码来源:MongoDbConnection.java

示例12: getCacheEntry

import com.mongodb.DBCursor; //导入依赖的package包/类
public CacheEntry getCacheEntry(String key, CacheEntry defaultValue) {
	DBCursor cur = null;
	DBCollection coll = getCollection();
	BasicDBObject query = new BasicDBObject("key", key.toLowerCase());

	// be sure to flush
	flushInvalid(coll,query);

	cur = coll.find(query);

	if (cur.count() > 0) {
		hits++;
		MongoDBCacheDocument doc = new MongoDBCacheDocument((BasicDBObject) cur.next());
		doc.addHit();
		//update the statistic and persist
		save(doc,0);
		return new MongoDBCacheEntry(doc);
	}
	misses++;
	return defaultValue;
}
 
开发者ID:lucee,项目名称:extension-mongodb,代码行数:22,代码来源:MongoDBCache.java

示例13: remove

import com.mongodb.DBCursor; //导入依赖的package包/类
@Override
public int remove(CacheKeyFilter filter) {
	DBCursor cur = qAll_Keys();
	int counter = 0;

	while (cur.hasNext()) {
		DBObject obj = cur.next();
		String key = (String) obj.get("key");
		if (filter.accept(key)) {
			doDelete((BasicDBObject) obj);
			counter++;
		}
	}

	return counter;
}
 
开发者ID:lucee,项目名称:extension-mongodb,代码行数:17,代码来源:MongoDBCache.java

示例14: values

import com.mongodb.DBCursor; //导入依赖的package包/类
@Override
public List<Object> values(CacheKeyFilter filter) {
	DBCursor cur = qAll_Keys_Values();
	List<Object> result = new ArrayList<Object>();

	while (cur.hasNext()) {
		BasicDBObject obj = (BasicDBObject) cur.next();
		MongoDBCacheDocument doc = new MongoDBCacheDocument(obj);

		if (filter.accept(doc.getKey())) {
			try {
				result.add(MongoDBCacheDocument.getValue(obj));
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}

	}

	return result;
}
 
开发者ID:lucee,项目名称:extension-mongodb,代码行数:22,代码来源:MongoDBCache.java

示例15: toDumpData

import com.mongodb.DBCursor; //导入依赖的package包/类
@Override
public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) {
	DBCursor cursor = coll.find();
	Iterator<DBObject> it = cursor.iterator();
	DumpTable table = new DumpTable("struct","#339933","#8e714e","#000000");
	table.setTitle("DBCollection");

	maxlevel--;
	DBObject obj;
	while(it.hasNext()) {
		obj = it.next();
		table.appendRow(0,
				__toDumpData(toCFML(obj), pageContext,maxlevel,dp)
			);
	}
	return table;
}
 
开发者ID:lucee,项目名称:extension-mongodb,代码行数:18,代码来源:DBCollectionImpl.java


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