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