use of com.mongodb.MongoClient 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.MongoClient 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.MongoClient in project jackrabbit-oak by apache.
the class BlobThroughPutTest method performBenchMark.
@Ignore
@Test
public void performBenchMark() throws UnknownHostException, InterruptedException {
MongoClient local = new MongoClient(new DBAddress(localServer));
MongoClient remote = new MongoClient(new DBAddress(remoteServer));
run(local, false, false);
run(local, true, false);
run(remote, false, true);
run(remote, true, true);
dumpResult();
}
use of com.mongodb.MongoClient in project qi4j-sdk by Qi4j.
the class MongoMapEntityStoreMixin method activateService.
@Override
public void activateService() throws Exception {
loadConfiguration();
// Create Mongo driver and open the database
if (username.isEmpty()) {
mongo = new MongoClient(serverAddresses);
} else {
MongoCredential credential = MongoCredential.createMongoCRCredential(username, databaseName, password);
mongo = new MongoClient(serverAddresses, Arrays.asList(credential));
}
db = mongo.getDB(databaseName);
// Create index if needed
db.requestStart();
DBCollection entities = db.getCollection(collectionName);
if (entities.getIndexInfo().isEmpty()) {
entities.createIndex(new BasicDBObject(IDENTITY_COLUMN, 1));
}
db.requestDone();
}
use of com.mongodb.MongoClient in project sling by apache.
the class IndexCreationIT method setUp.
@Before
public void setUp() throws Exception {
String connectionString = System.getProperty("connectionString", "localhost:27017");
database = System.getProperty("database", "sling") + "_indextest";
collection = System.getProperty("collection", "resources");
mongoClient = new MongoClient(connectionString);
underTest = new MongoDBNoSqlAdapter(mongoClient, database, collection);
underTest.checkConnection();
underTest.createIndexDefinitions();
}
Aggregations