use of com.mongodb.MongoClientURI in project jackrabbit-oak by apache.
the class NodeCollectionProvider method prepareClientForHostname.
private MongoClient prepareClientForHostname(String hostname) throws UnknownHostException {
ServerAddress address;
if (hostname.contains(":")) {
String[] hostSplit = hostname.split(":");
if (hostSplit.length != 2) {
throw new IllegalArgumentException("Not a valid hostname: " + hostname);
}
address = new ServerAddress(hostSplit[0], Integer.parseInt(hostSplit[1]));
} else {
address = new ServerAddress(hostname);
}
MongoClientURI originalUri = new MongoClientURI(originalMongoUri);
List<MongoCredential> credentialList = new ArrayList<MongoCredential>(1);
if (originalUri.getCredentials() != null) {
credentialList.add(originalUri.getCredentials());
}
return new MongoClient(address, credentialList, originalUri.getOptions());
}
use of com.mongodb.MongoClientURI in project jackrabbit-oak by apache.
the class NodeCollectionProvider method get.
@SuppressWarnings("deprecation")
public DBCollection get(String hostname) throws UnknownHostException {
if (collections.containsKey(hostname)) {
return collections.get(hostname);
}
MongoClient client;
if (originalMongoUri == null) {
MongoClientURI uri = new MongoClientURI("mongodb://" + hostname);
client = new MongoClient(uri);
} else {
client = prepareClientForHostname(hostname);
}
DB db = client.getDB(dbName);
db.getMongo().slaveOk();
DBCollection collection = db.getCollection(Collection.NODES.toString());
collections.put(hostname, collection);
return collection;
}
use of com.mongodb.MongoClientURI in project jackrabbit-oak by apache.
the class DocumentMongoFixture method getDb.
protected DB getDb(String suffix) throws UnknownHostException {
String dbName = new MongoClientURI(uri).getDatabase();
MongoConnection connection = new MongoConnection(uri);
return connection.getDB(dbName + "-" + suffix);
}
use of com.mongodb.MongoClientURI in project GeoGig by boundlessgeo.
the class MongoGraphDatabaseTest method createDatabase.
@Override
protected MongoGraphDatabase createDatabase(Platform platform) throws Exception {
final IniMongoProperties properties = new IniMongoProperties();
final String uri = properties.get("mongodb.uri", String.class).or("mongodb://localhost:27017/");
final String database = properties.get("mongodb.database", String.class).or("geogig");
MongoClient client = new MongoClient(new MongoClientURI(uri));
DB db = client.getDB(database);
db.dropDatabase();
MongoConnectionManager manager = new MongoConnectionManager();
ConfigDatabase config = new TestConfigDatabase(platform);
MongoGraphDatabase mongoGraphDatabase = new MongoGraphDatabase(manager, config);
return mongoGraphDatabase;
}
use of com.mongodb.MongoClientURI in project cas by apereo.
the class MongoDbConnectionFactory method mongoDbFactory.
private MongoDbFactory mongoDbFactory(final Mongo mongo, final BaseMongoDbProperties props) {
final String dbName;
final String authDbName;
if (StringUtils.isNotBlank(props.getClientUri())) {
final MongoClientURI uri = buildMongoClientURI(props.getClientUri(), buildMongoDbClientOptions(props));
authDbName = uri.getCredentials().getSource();
dbName = uri.getDatabase();
LOGGER.debug("Using database [{}] from the connection client URI", dbName);
} else {
authDbName = props.getAuthenticationDatabaseName();
dbName = props.getDatabaseName();
LOGGER.debug("Using database [{}] from individual settings", dbName);
}
if (StringUtils.isBlank(dbName)) {
LOGGER.error("Database name cannot be undefined. It must be specified as part of the client URI connection string if used, or " + "as an individual setting for the MongoDb connection");
}
return new SimpleMongoDbFactory(mongo, dbName, null, authDbName);
}
Aggregations