Search in sources :

Example 6 with MongoConnection

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());
}
Also used : MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection) Before(org.junit.Before)

Example 7 with MongoConnection

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);
                }
            }
        }
    };
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) NodeStoreFixture(org.apache.jackrabbit.oak.fixture.NodeStoreFixture) Closeable(java.io.Closeable) IOException(java.io.IOException) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection) IOException(java.io.IOException) RepositoryException(javax.jcr.RepositoryException) DB(com.mongodb.DB)

Example 8 with MongoConnection

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);
}
Also used : MongoClientURI(com.mongodb.MongoClientURI) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection)

Example 9 with MongoConnection

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();
        }
    }
}
Also used : OptionSpec(joptsimple.OptionSpec) DocumentStoreException(org.apache.jackrabbit.oak.plugins.document.DocumentStoreException) MongoClientURI(com.mongodb.MongoClientURI) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) OptionParser(joptsimple.OptionParser) MongoDocumentStore(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore) DataSource(javax.sql.DataSource) DocumentStore(org.apache.jackrabbit.oak.plugins.document.DocumentStore) MongoDocumentStore(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore) RDBDocumentStore(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore) RDBDocumentStore(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore) OptionSet(joptsimple.OptionSet) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection)

Example 10 with MongoConnection

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;
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection)

Aggregations

MongoConnection (org.apache.jackrabbit.oak.plugins.document.util.MongoConnection)23 DocumentMK (org.apache.jackrabbit.oak.plugins.document.DocumentMK)8 Test (org.junit.Test)6 MongoClientURI (com.mongodb.MongoClientURI)5 DB (com.mongodb.DB)3 DBCollection (com.mongodb.DBCollection)3 DataSource (javax.sql.DataSource)3 DocumentStore (org.apache.jackrabbit.oak.plugins.document.DocumentStore)3 DBObject (com.mongodb.DBObject)2 MongoDocumentStore (org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Before (org.junit.Before)2 BasicDBObject (com.mongodb.BasicDBObject)1 MongoClientOptions (com.mongodb.MongoClientOptions)1 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 CheckForNull (javax.annotation.CheckForNull)1 Repository (javax.jcr.Repository)1 RepositoryException (javax.jcr.RepositoryException)1 Session (javax.jcr.Session)1