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