Java Code Examples for com.mongodb.MongoClientURI#getDatabase()
The following examples show how to use
com.mongodb.MongoClientURI#getDatabase() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChangeEntryDao.java From mongobee with Apache License 2.0 | 5 votes |
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); }
Example 2
Source File: MongoDBDriver.java From birt with Eclipse Public License 1.0 | 5 votes |
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 ); }
Example 3
Source File: MongoConfig.java From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License | 5 votes |
public MongoConfig(Properties p) { String uri = p.getProperty(URI_PROPERTY); if (uri == null) { throw new ConfigurationException("Please define a MongoDB URI for property: " + URI_PROPERTY); } MongoClientURI mongoUri = new MongoClientURI(uri); dbName = mongoUri.getDatabase(); client = new MongoClient(mongoUri); }
Example 4
Source File: MongoConnection.java From Mycat2 with GNU General Public License v3.0 | 4 votes |
public MongoConnection(MongoClientURI mcu, String url) throws UnknownHostException { // this.url = url; this._schema = mcu.getDatabase(); mc = new MongoClient(mcu); }
Example 5
Source File: MongoDataProxy.java From Knowage-Server with GNU Affero General Public License v3.0 | 4 votes |
private CommandResult loadData() { logger.debug("IN"); CommandResult result = null; String clientUrl = dataSource.getUrlConnection(); logger.debug("Getting the connection URL and db name"); if (dataSource.getUser() != null && dataSource.getPwd() != null && dataSource.getUser().length() > 0 && dataSource.getPwd().length() > 0) { String authPart = "mongodb://"+dataSource.getUser()+":"+dataSource.getPwd()+"@"; clientUrl = clientUrl.replace("mongodb://", authPart); } logger.debug("MongoDB connection URI:"+clientUrl); MongoClientURI mongoClientURI= new MongoClientURI(clientUrl); MongoClient mongoClient = new MongoClient(new MongoClientURI(clientUrl)); logger.debug("Connecting to mongodb"); String databaseName = mongoClientURI.getDatabase(); logger.debug("Database name: " + databaseName); try { logger.debug("Connecting to the db " + databaseName); DB database = mongoClient.getDB(databaseName); logger.debug("Executing the statement" + statement); result = database.doEval(getDecoredStatement()); } catch (Exception e) { logger.error("Exception executing the MongoDataset", e); throw new SpagoBIRuntimeException("Exception executing the MongoDataset", e); } finally { logger.debug("Closing connection"); mongoClient.close(); } logger.debug("OUT"); return result; }
Example 6
Source File: MongoConfiguration.java From hesperides with GNU General Public License v3.0 | 4 votes |
@Bean public MongoTemplate mongoTemplate(MongoClient mongoClient, MongoClientURI mongoClientURI) { return new MongoTemplate(mongoClient, mongoClientURI.getDatabase()); }
Example 7
Source File: MongoConfiguration.java From hesperides with GNU General Public License v3.0 | 4 votes |
@Bean @Primary public EventStorageEngine eventStorageEngine(MongoClient mongoClient, MongoClientURI mongoClientURI) { DefaultMongoTemplate axonMongoTemplate = new DefaultMongoTemplate(mongoClient, mongoClientURI.getDatabase()); return new MongoEventStorageEngine(axonMongoTemplate); }
Example 8
Source File: DatabasesForMongoDBCreator.java From bluemix-cloud-connectors with Apache License 2.0 | 4 votes |
private SimpleMongoDbFactory createMongoDbFactory(DatabasesForMongoDBServiceInfo serviceInfo, MongoClientOptions.Builder mongoOptionsToUse) throws UnknownHostException { MongoClientURI mongoClientURI = new MongoClientURI(buildUriString(serviceInfo), mongoOptionsToUse); MongoClient mongo = new MongoClient(mongoClientURI); return new SimpleMongoDbFactory(mongo, mongoClientURI.getDatabase()); }
Example 9
Source File: MongoDbFactoryCreator.java From spring-cloud-connectors with Apache License 2.0 | 4 votes |
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()); }
Example 10
Source File: RepositorySetup.java From immutables with Apache License 2.0 | 3 votes |
/** * 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(); }
Example 11
Source File: RoutingDBFactory.java From HA-DB with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Creates a new {@link SimpleMongoDbFactory} instance from the given * {@link MongoClientURI}. * * @param uri * must not be {@literal null}. * @throws UnknownHostException * @since 1.7 */ public RoutingDBFactory(MongoClientURI uri) { this(new MongoClient(uri), uri.getDatabase(), true); }