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


Java MongoIterable类代码示例

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


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

示例1: queryTables

import com.mongodb.client.MongoIterable; //导入依赖的package包/类
/**
 * @decription 查询数据库表名
 * @author yi.zhang
 * @time 2017年6月30日 下午2:16:02
 * @param table	表名
 * @return
 */
public List<String> queryTables(){
	try {
		if(session==null){
			init(servers, database, schema, username, password);
		}
		MongoIterable<String> collection = session.listCollectionNames();
		if (collection == null) {
			return null;
		}
		List<String> tables = new ArrayList<String>();
		MongoCursor<String> cursor = collection.iterator();
		while(cursor.hasNext()){
			String table = cursor.next();
			tables.add(table);
		}
		return tables;
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:dev-share,项目名称:database-transform-tool,代码行数:30,代码来源:MongoDBFactory.java

示例2: testVerifyDataAfterFeatureExecution

import com.mongodb.client.MongoIterable; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testVerifyDataAfterFeatureExecution() throws DbFeatureException {
    // GIVEN
    final MongoIterable<String> collectionIterable = mock(MongoIterable.class);
    final MongoCursor<String> iterator = mock(MongoCursor.class);
    when(expectedDataSets.strict()).thenReturn(Boolean.FALSE);
    when(expectedDataSets.value()).thenReturn(new String[] {});
    when(expectedDataSets.orderBy()).thenReturn(new String[] {});
    when(expectedDataSets.excludeColumns()).thenReturn(new String[] {});
    when(connection.listCollectionNames()).thenReturn(collectionIterable);
    when(collectionIterable.iterator()).thenReturn(iterator);
    when(iterator.hasNext()).thenReturn(Boolean.FALSE);

    // WHEN
    final DbFeature<MongoDatabase> feature = featureExecutor.createVerifyDataAfterFeature(expectedDataSets);
    assertThat(feature, notNullValue());
    feature.execute(connection);

    // THEN
    verify(connection).listCollectionNames();
    verifyNoMoreInteractions(connection);
}
 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:24,代码来源:MongoDbFeatureExecutorTest.java

示例3: existsTable

import com.mongodb.client.MongoIterable; //导入依赖的package包/类
/**
 * Checks if the main table exists in the database.
 * @param appid name of the {@link com.erudika.para.core.App}
 * @return true if the table exists
 */
public static boolean existsTable(String appid) {
	if (StringUtils.isBlank(appid)) {
		return false;
	}
	try {
		appid = getTableNameForAppid(appid);
		MongoIterable<String> collectionNames = getClient().listCollectionNames();
		for (final String name : collectionNames) {
			if (name.equalsIgnoreCase(appid)) {
				return true;
			}
		}
		return false;
	} catch (Exception e) {
		return false;
	}
}
 
开发者ID:Erudika,项目名称:para-dao-mongodb,代码行数:23,代码来源:MongoDBUtils.java

示例4: collectionExists

import com.mongodb.client.MongoIterable; //导入依赖的package包/类
public boolean collectionExists(String collectionName) {
    if (this.database == null) {
        return false;
    }

    final MongoIterable<String> iterable = database.listCollectionNames();
    try (final MongoCursor<String> it = iterable.iterator()) {
        while (it.hasNext()) {
            if (it.next().equalsIgnoreCase(collectionName)) {
                return true;
            }
        }
    }

    return false;
}
 
开发者ID:datafibers-community,项目名称:df_data_service,代码行数:17,代码来源:MongoAdminClient.java

示例5: connectsToTheCluster

import com.mongodb.client.MongoIterable; //导入依赖的package包/类
@Test
@IgnoreIf(condition = NoRunningMongoDbForTests.class)
public void connectsToTheCluster() throws Exception {

    MongoClient mongoClient = new MongoClient(new NoRunningMongoDbForTests().getHost(), 27017);
    MongoIterable<String> strings = mongoClient.listDatabaseNames();
    MongoCursor<String> iterator = strings.iterator();
    while (iterator.hasNext()) {
        LOG.info("Database: {}", iterator.next());
    }

    MongoDatabase db = mongoClient.getDatabase(strings.iterator().next());
    String name = db.getName();
    LOG.info("Got: {}", name);

    mongoClient.close();
}
 
开发者ID:Excelian,项目名称:Mache,代码行数:18,代码来源:MongoConnector.java

示例6: getIndexNames

import com.mongodb.client.MongoIterable; //导入依赖的package包/类
public List<String> getIndexNames() {
	globalLock.writeLock().lock();

	try {
		ArrayList<String> indexNames = new ArrayList<>();
		log.info("Searching database <" + mongoConfig.getDatabaseName() + "> for indexes");
		MongoDatabase db = mongo.getDatabase(mongoConfig.getDatabaseName());
		MongoIterable<String> allCollections = db.listCollectionNames();

		for (String collection : allCollections) {
			if (collection.endsWith(LumongoIndex.CONFIG_SUFFIX)) {
				String indexName = collection.substring(0, collection.length() - LumongoIndex.CONFIG_SUFFIX.length());
				indexNames.add(indexName);
			}

		}

		return indexNames;
	}
	finally {
		globalLock.writeLock().unlock();
	}
}
 
开发者ID:lumongo,项目名称:lumongo,代码行数:24,代码来源:LumongoIndexManager.java

示例7: applyPropertiesToCursor

import com.mongodb.client.MongoIterable; //导入依赖的package包/类
private void applyPropertiesToCursor( MongoIterable<Document> mongoIterable, QueryProperties queryProps, 
         boolean includeMetaDataSearchLimit, boolean includeSortExpr )
 {
     if( includeMetaDataSearchLimit )
     {
         Integer searchLimit = getModel().getEffectiveMDSearchLimit( queryProps ); 
         if( searchLimit > 0 )
{
             // Apply to FindIterable or MapReduceIterable
	if ( mongoIterable instanceof FindIterable )
	{
		FindIterable<Document> findIterable = (FindIterable<Document>) mongoIterable;
		findIterable.limit( searchLimit.intValue( ) );
	}
	else if ( mongoIterable instanceof MapReduceIterable )
	{
		MapReduceIterable<Document> mapReduceIterable = (MapReduceIterable<Document>) mongoIterable;
		mapReduceIterable.limit( searchLimit.intValue( ) );
	}       
}
     }
     
     applyPropertiesToCursor( mongoIterable, queryProps, includeSortExpr );
 }
 
开发者ID:eclipse,项目名称:birt,代码行数:25,代码来源:MDbOperation.java

示例8: collectionExists

import com.mongodb.client.MongoIterable; //导入依赖的package包/类
/**
 * Checks if the collection exists
 * 
 * @param db
 *        (MongoDatabase, mandatory)
 * @param collectionName
 *        (String, mandatory) name of the collection
 *        
 * @return (boolean)
 */
public static boolean collectionExists(MongoDatabase db, String collectionName)
{
    ArgumentCheck.checkMandatoryObject(db, "db");
    ArgumentCheck.checkMandatoryString(collectionName, "collectionName");

    MongoIterable<String> collectionNames = db.listCollectionNames();
    for (final String name : collectionNames)
    {
        if (name.equalsIgnoreCase(collectionName))
        {
            return true;
        }
    }

    return false;
}
 
开发者ID:AlfrescoBenchmark,项目名称:alfresco-benchmark,代码行数:27,代码来源:Mongo3Helper.java

示例9: mongoClient

import com.mongodb.client.MongoIterable; //导入依赖的package包/类
@Bean
@SuppressWarnings("unchecked")
public MongoClient mongoClient() {
    MongoClient result = Mockito.mock(MongoClient.class);
    MongoIterable<String> iterableMock = Mockito.mock(MongoIterable.class);
    MongoCursor<String> iteratorMock = Mockito.mock(MongoCursor.class);
    Mockito.when(iterableMock.iterator()).thenReturn(iteratorMock);
    Mockito.when(iteratorMock.hasNext()).thenReturn(true).thenReturn(false);
    Mockito.when(iteratorMock.next()).thenReturn("local");
    Mockito.when(result.listDatabaseNames()).thenReturn(iterableMock);
    return result;
}
 
开发者ID:cereebro,项目名称:cereebro,代码行数:13,代码来源:MongoDbRelationshipDetectorTest.java

示例10: listDatabaseNames

import com.mongodb.client.MongoIterable; //导入依赖的package包/类
private void listDatabaseNames() {
    MongoIterable<String> dbs = mongoClient.listDatabaseNames();
    System.out.println("\nDatabase names:");
    for (String db : dbs) {
        System.out.println(db);
    }
}
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_06,代码行数:8,代码来源:MongoMain.java

示例11: getEntriesFromGuild

import com.mongodb.client.MongoIterable; //导入依赖的package包/类
/**
 * Retrieves all entries associated with a guild
 * @param guildId snowflake ID of guild
 * @return all active entries
 */
public Collection<ScheduleEntry> getEntriesFromGuild(String guildId)
{
    MongoIterable<ScheduleEntry> entries = Main.getDBDriver().getEventCollection()
            .find(eq("guildId", guildId)).map(ScheduleEntry::new);

    return entries.into(new ArrayList<>());
}
 
开发者ID:notem,项目名称:Saber-Bot,代码行数:13,代码来源:EntryManager.java

示例12: getEntriesFromChannel

import com.mongodb.client.MongoIterable; //导入依赖的package包/类
/**
 * Retrieves all entries on a channel
 * @param channelId snowflake ID of channel
 * @return all active entries
 */
public Collection<ScheduleEntry> getEntriesFromChannel(String channelId)
{
    MongoIterable<ScheduleEntry> entries = Main.getDBDriver().getEventCollection()
            .find(eq("channelId", channelId)).map(ScheduleEntry::new);

    return entries.into(new ArrayList<>());
}
 
开发者ID:notem,项目名称:Saber-Bot,代码行数:13,代码来源:EntryManager.java

示例13: check

import com.mongodb.client.MongoIterable; //导入依赖的package包/类
@Override
protected Result check() throws Exception {
	MongoClient mongoClient = null;
	String databaseList = null;
	String databaseStats = null;

	try {
		mongoClient = createMongoClient();
		MongoIterable<String> dbList = mongoClient.listDatabaseNames();
		databaseList = StringUtils.join(dbList, ',');

		CommandResult resultSet = mongoClient.getDB(databaseName).getStats();
		databaseStats = resultSet.toString();
		logger.debug("connectionUrl={} databaseList={} stats={}", connectionUrl, databaseList, databaseStats);

		Integer nbrCollections = (Integer) resultSet.get("collections");
		if (nbrCollections == 0) {
			throw new RuntimeException("Database has nothing in it.");
		}
	} catch (Exception e) {
		ContextedRuntimeException wrappedException = wrapException(e);
		wrappedException.addContextValue("databaseList", databaseList);
		wrappedException.addContextValue("databaseStats", databaseStats);

		logger.error("MongoDB Healthcheck Failure", wrappedException);
		return Result.unhealthy(wrappedException);
	} finally {
		closeQuietly(mongoClient);
	}

	return Result.healthy();
}
 
开发者ID:BreakTheMonolith,项目名称:btm-DropwizardHealthChecks,代码行数:33,代码来源:MongoDbHealthCheck.java

示例14: getCollections

import com.mongodb.client.MongoIterable; //导入依赖的package包/类
public static Set<String> getCollections(String dbname) {
	MongoDatabase d = mongo.get(dbname);
	if (d != null) {

		MongoIterable<String> it = d.listCollectionNames();
		MongoCursor<String> ii = it.iterator();
		Set<String> r = new TreeSet<String>();
		while (ii.hasNext()) {
			r.add(ii.next());
		}
		return r;
	}
	return null;
}
 
开发者ID:giiwa,项目名称:giiwa,代码行数:15,代码来源:MongoHelper.java

示例15: ProfiledMapMongotIterable

import com.mongodb.client.MongoIterable; //导入依赖的package包/类
public ProfiledMapMongotIterable(MongoIterable<U> map, Function<TResult, U> mapper, ProfiledCursorCreator creator)
{
    super();
    this.mongoIterable = map;
    this.mapper = mapper;
    this.creator = creator;
}
 
开发者ID:dd00f,项目名称:ibm-performance-monitor,代码行数:8,代码来源:ProfiledMapMongotIterable.java


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