我正在尝试创建一个Oak的JCR存储库,以便使用“”存储内容。
(我完全不知道)这就是我一直在做的事情。
MongoClient connection = new MongoClient("127.0.0.1", 27017);
DB db = connection.getDB("test");
MongoMK.Builder m = new MongoMK.Builder();
MongoMK kernel = m.setMongoDB(db).open();
Repository repo = new Jcr().createRepository();
session = repo.login(); // Error javax.jcr.NoSuchWorkspaceException试图将“储存库”与"MongoMK“联系起来--这似乎是一场噩梦。
我试过
Repository repo = new Jcr(kernel).createRepository(); //Error我发现了类似的东西:[如何使用MicroKernel](https://stackoverflow.com/questions/25681933/how-to-create-repository-instance-in-jackrabbit-oak-using-microkernel)在JackRabbit Oak中创建存储库实例,这也没有帮助。
我的问题是,是否存在连接MongMK -仓库的问题??
试着用"NodeStore“。
发布于 2014-10-29 08:04:50
是的,这并没有很好的记录。下列措施应能发挥作用:
import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.Session;
import org.apache.jackrabbit.oak.Oak;
import org.apache.jackrabbit.oak.plugins.document.DocumentMK;
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
import com.mongodb.DB;
import com.mongodb.MongoClient;
public class Test {
public static void main(String... args) throws Exception {
DB db = new MongoClient("127.0.0.1", 27017).getDB("test2");
DocumentNodeStore ns = new DocumentMK.Builder().
setMongoDB(db).getNodeStore();
Repository repo = new Jcr(new Oak(ns))
.with(new OpenSecurityProvider())
.createRepository();
Session session = repo.login();
Node root = session.getRootNode();
if (root.hasNode("hello")) {
Node hello = root.getNode("hello");
long count = hello.getProperty("count").getLong();
hello.setProperty("count", count + 1);
System.out.println("found the hello node, count = " + count);
} else {
System.out.println("creating the hello node");
root.addNode("hello").setProperty("count", 1);
}
session.save();
session.logout();
ns.dispose();
}
}这现在也是记录在案了。
https://stackoverflow.com/questions/26286129
复制相似问题