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


Java MongoClientURI.getDatabase方法代码示例

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


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

示例1: connect

import com.mongodb.MongoClientURI; //导入方法依赖的package包/类
private MongoDatabase connect(final PluginTask task) throws UnknownHostException, MongoException
{
    MongoClient mongoClient;
    String database;

    if (!task.getUri().isPresent() && !task.getHosts().isPresent()) {
        throw new ConfigException("'uri' or 'hosts' is required");
    }

    if (task.getUri().isPresent()) {
        MongoClientURI uri = new MongoClientURI(task.getUri().get());
        database = uri.getDatabase();
        mongoClient = new MongoClient(uri);
    }
    else {
        mongoClient = createClientFromParams(task);
        database = task.getDatabase().get();
    }

    MongoDatabase db = mongoClient.getDatabase(database);
    // Get collection count for throw Exception
    db.getCollection(task.getCollection()).count();
    return db;
}
 
开发者ID:hakobera,项目名称:embulk-input-mongodb,代码行数:25,代码来源:MongodbInputPlugin.java

示例2: MongoConnector

import com.mongodb.MongoClientURI; //导入方法依赖的package包/类
private MongoConnector(String connectURIStr) throws DiagnosticException {
  MongoClientURI clientURI = new MongoClientURI(connectURIStr);
  client = new MongoClient(clientURI);
  String dbName = clientURI.getDatabase() == null ? MONITOR_DB : clientURI.getDatabase();
  db = client.getDatabase(dbName);

}
 
开发者ID:YagelNasManit,项目名称:environment.monitor,代码行数:8,代码来源:MongoConnector.java

示例3: mongoDbFactory

import com.mongodb.MongoClientURI; //导入方法依赖的package包/类
@Bean
public MongoDbFactory mongoDbFactory() throws Exception {
  MongoClientURI uri = new MongoClientURI(mongoDbUrl);
  mongo = new MongoClient(uri);
  mongo.setReadPreference(ReadPreference.primary());
  mongo.setWriteConcern(WriteConcern.ACKNOWLEDGED);
  return new SimpleMongoDbFactory(mongo, uri.getDatabase());
}
 
开发者ID:ImmobilienScout24,项目名称:switchman,代码行数:9,代码来源:Persistence.java

示例4: connectMongoDb

import com.mongodb.MongoClientURI; //导入方法依赖的package包/类
public MongoDatabase connectMongoDb(MongoClientURI mongoClientURI, String dbName)
    throws MongobeeConfigurationException, MongobeeConnectionException {

  final MongoClient mongoClient = new MongoClient(mongoClientURI);
  final String database = (!hasText(dbName)) ? mongoClientURI.getDatabase() : dbName;
  return this.connectMongoDb(mongoClient, database);
}
 
开发者ID:mongobee,项目名称:mongobee,代码行数:8,代码来源:ChangeEntryDao.java

示例5: getDatabaseName

import com.mongodb.MongoClientURI; //导入方法依赖的package包/类
static String getDatabaseName( Properties connProps )
{
    MongoClientURI mongoURI = getMongoURI( connProps );
    if( mongoURI != null )
        return mongoURI.getDatabase();
    
    // no mongoURI specified, get from the individual property
    return getStringPropValue( connProps, DBNAME_PROP );
}
 
开发者ID:eclipse,项目名称:birt,代码行数:10,代码来源:MongoDBDriver.java

示例6: MongoConnection

import com.mongodb.MongoClientURI; //导入方法依赖的package包/类
public MongoConnection(MongoClientURI mcu, String url) throws UnknownHostException {
//	this.url = url;
	this._schema = mcu.getDatabase();		
	mc = new MongoClient(mcu);
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:6,代码来源:MongoConnection.java

示例7: createMongoDbFactory

import com.mongodb.MongoClientURI; //导入方法依赖的package包/类
private SimpleMongoDbFactory createMongoDbFactory(MongoServiceInfo serviceInfo, MongoClientOptions.Builder mongoOptionsToUse) throws UnknownHostException {
	MongoClientURI mongoClientURI = new MongoClientURI(serviceInfo.getUri(), mongoOptionsToUse);
	MongoClient mongo = new MongoClient(mongoClientURI);
	return new SimpleMongoDbFactory(mongo, mongoClientURI.getDatabase());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:6,代码来源:MongoDbFactoryCreator.java

示例8: forUri

import com.mongodb.MongoClientURI; //导入方法依赖的package包/类
/**
 * Create setup using MongoDB client uri.
 * <ul>
 * <li>URI should contain database path segment</li>
 * <li>New internal {@link MongoClient} will be created</li>
 * <li>New internal executor will be created (with shutdown on jvm exit)</li>
 * <li>New {@link Gson} instance will be created configured with type adapter factory
 * providers</li>
 * </ul>
 * <p>
 * Setup created by this factory methods should be reused to configure collection repositories for
 * the same MongoDB database.
 * <p>
 * This constructor designed for ease of use in sample scenarious. For more flexibility consider
 * using {@link #builder()} with custom constructed {@link ListeningExecutorService
 * executor} and {@link DB database} handle.
 * @param uri string that will be parsed as {@link MongoClientURI}.
 * @see MongoClientURI
 * @return repository setup instance.
 */
public static RepositorySetup forUri(String uri) {
  MongoClientURI clientUri = new MongoClientURI(uri);
  @Nullable String databaseName = clientUri.getDatabase();
  checkArgument(databaseName != null, "URI should contain database path segment");

  return builder()
      .database(newMongoClient(clientUri).getDatabase(databaseName))
      .executor(newExecutor())
      .gson(createGson())
      .build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:32,代码来源:RepositorySetup.java


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