本文整理汇总了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;
}
示例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);
}
示例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;
}
}
示例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;
}
示例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();
}
示例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();
}
}
示例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 );
}
示例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;
}
示例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;
}
示例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);
}
}
示例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<>());
}
示例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<>());
}
示例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();
}
示例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;
}
示例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;
}