use of org.apache.jackrabbit.oak.plugins.document.util.MongoConnection in project jackrabbit-oak by apache.
the class MongoStatusTest method createStatus.
@Before
public void createStatus() {
MongoConnection c = connectionFactory.getConnection();
status = new MongoStatus(c.getDB());
}
use of org.apache.jackrabbit.oak.plugins.document.util.MongoConnection in project jackrabbit-oak by apache.
the class RandomOpCompare method getMongo.
private static NodeStoreFixture getMongo() {
return new NodeStoreFixture() {
@Override
public NodeStore createNodeStore() {
MongoConnection connection;
try {
connection = new MongoConnection("mongodb://localhost:27017/oak");
} catch (Exception e) {
throw new RuntimeException(e);
}
DB mongoDB = connection.getDB();
return new DocumentMK.Builder().memoryCacheSize(0).setMongoDB(mongoDB, 16).setPersistentCache("target/persistentCache,time").getNodeStore();
}
@Override
public NodeStore createNodeStore(int clusterNodeId) {
return null;
}
@Override
public void dispose(NodeStore nodeStore) {
if (nodeStore instanceof Closeable) {
try {
((Closeable) nodeStore).close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
};
}
use of org.apache.jackrabbit.oak.plugins.document.util.MongoConnection in project jackrabbit-oak by apache.
the class TextExtractorMain method bootStrapNodeStore.
private static NodeStore bootStrapNodeStore(String src, BlobStore blobStore, Closer closer) throws IOException {
if (src.startsWith(MongoURI.MONGODB_PREFIX)) {
MongoClientURI uri = new MongoClientURI(src);
if (uri.getDatabase() == null) {
System.err.println("Database missing in MongoDB URI: " + uri.getURI());
System.exit(1);
}
MongoConnection mongo = new MongoConnection(uri.getURI());
closer.register(asCloseable(mongo));
DocumentNodeStore store = new DocumentMK.Builder().setBlobStore(blobStore).setMongoDB(mongo.getDB()).getNodeStore();
closer.register(asCloseable(store));
return store;
}
return SegmentTarUtils.bootstrap(src, blobStore, closer);
}
use of org.apache.jackrabbit.oak.plugins.document.util.MongoConnection in project jackrabbit-oak by apache.
the class UnlockUpgradeCommand method execute.
@Override
public void execute(String... args) throws Exception {
OptionParser parser = new OptionParser();
// RDB specific options
OptionSpec<String> rdbjdbcuser = parser.accepts("rdbjdbcuser", "RDB JDBC user").withOptionalArg().defaultsTo("");
OptionSpec<String> rdbjdbcpasswd = parser.accepts("rdbjdbcpasswd", "RDB JDBC password").withOptionalArg().defaultsTo("");
OptionSpec<String> nonOption = parser.nonOptions("unlockUpgrade {<jdbc-uri> | <mongodb-uri>}");
OptionSpec help = parser.acceptsAll(asList("h", "?", "help"), "show help").forHelp();
OptionSet options = parser.parse(args);
List<String> nonOptions = nonOption.values(options);
if (options.has(help)) {
parser.printHelpOn(System.out);
return;
}
if (nonOptions.isEmpty()) {
parser.printHelpOn(System.err);
return;
}
DocumentStore store = null;
try {
String uri = nonOptions.get(0);
if (uri.startsWith(MONGODB_PREFIX)) {
MongoClientURI clientURI = new MongoClientURI(uri);
if (clientURI.getDatabase() == null) {
System.err.println("Database missing in MongoDB URI: " + clientURI.getURI());
} else {
MongoConnection mongo = new MongoConnection(clientURI.getURI());
store = new MongoDocumentStore(mongo.getDB(), new DocumentMK.Builder());
}
} else if (uri.startsWith("jdbc")) {
DataSource ds = RDBDataSourceFactory.forJdbcUrl(uri, rdbjdbcuser.value(options), rdbjdbcpasswd.value(options));
store = new RDBDocumentStore(ds, new DocumentMK.Builder());
} else {
System.err.println("Unrecognized URI: " + uri);
}
if (store != null && VERSION.writeTo(store)) {
System.out.println("Format version set to " + VERSION);
}
} catch (DocumentStoreException e) {
System.err.println(e.getMessage());
} finally {
if (store != null) {
store.dispose();
}
}
}
use of org.apache.jackrabbit.oak.plugins.document.util.MongoConnection in project jackrabbit-oak by apache.
the class MongoUtils method getConnectionByURL.
//----------------------------< internal >----------------------------------
/**
* Get a connection if available. If not available, null is returned.
*
* @param url the mongodb url
* @return the connection or null
*/
private static MongoConnection getConnectionByURL(String url) {
if (exception != null) {
return null;
}
MongoConnection mongoConnection;
try {
mongoConnection = new MongoConnection(url);
mongoConnection.getDB().command(new BasicDBObject("ping", 1));
// dropCollections(mongoConnection.getDB());
} catch (Exception e) {
exception = e;
mongoConnection = null;
}
return mongoConnection;
}
Aggregations