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