You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by th...@apache.org on 2014/10/29 09:36:28 UTC

svn commit: r1635066 - /jackrabbit/oak/trunk/oak-doc/src/site/markdown/construct.md

Author: thomasm
Date: Wed Oct 29 08:36:28 2014
New Revision: 1635066

URL: http://svn.apache.org/r1635066
Log:
OAK-301 Document Oak

Modified:
    jackrabbit/oak/trunk/oak-doc/src/site/markdown/construct.md

Modified: jackrabbit/oak/trunk/oak-doc/src/site/markdown/construct.md
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-doc/src/site/markdown/construct.md?rev=1635066&r1=1635065&r2=1635066&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-doc/src/site/markdown/construct.md (original)
+++ jackrabbit/oak/trunk/oak-doc/src/site/markdown/construct.md Wed Oct 29 08:36:28 2014
@@ -15,62 +15,48 @@
    limitations under the License.
   -->
 
-# Repository construction
+# Repository Construction
 
-Oak comes with a simple mechanism for constructing content repositories
+Oak comes with a simple and flexible mechanism for constructing content repositories
 for use in embedded deployments and test cases. This article describes this
 mechanism. Deployments in managed environments like OSGi should use the native
 construction/configuration mechanism of the environment.
 
-The core class to use is called `Oak` and can be found in the
-`org.apache.jackrabbit.oak` package inside `oak-core`. It takes a
-`MicroKernel` instance and wraps it into a `ContentRepository`:
-
-    MicroKernel kernel = ...;
-    ContentRepository repository = new Oak(kernel).createContentRepository();
-
-For test purposes you can use the default constructor that
-automatically instantiates an in-memory `MicroKernel` for use with the
-repository. And if you're only using the test repository for a single
-`ContentSession` or just a singe `Root`, then you can shortcut the login
-steps by using either of the last two statements below:
-
-    ContentRepository repository = new Oak().createContentRepository();
-    ContentSession session = new Oak().createContentSession();
-    Root root = new Oak().createRoot();
-
-By default no pluggable components are associated with the created
-repository, so all login attempts will work and result in full write
-access. 
-
-To add extra functionality like type validation or indexing support,
-use the `with()` method. The method takes all kinds of Oak plugins and
-adds them to the repository to be created. The method returns the Oak
-instance being used, so you can chain method calls like this:
-
-    ContentRepository repository = new Oak(kernel)
-        .with(new InitialContent())        // add initial content
-        .with(new DefaultTypeEditor())     // automatically set default types
-        .with(new NameValidatorProvider()) // allow only valid JCR names
-        .with(new SecurityProviderImpl())  // use the default security
-        .with(new PropertyIndexHook())     // simple indexing support
-        .with(new PropertyIndexProvider()) // search support for the indexes
-        .createContentRepository();
-
-As you can see, constructing a fully featured JCR repository like this
-will require quite a few plugins. To avoid having to specify them all
-whenever constructing a new repository, we also have a class called
-`Jcr` in the `org.apache.jackrabbit.oak.jcr` package in `oak-jcr`. That
-class works much like the `Oak` class, but it constructs
-`javax.jcr.Repository` instances instead of `ContentRepositories` and
-automatically includes all the plugin components needed for proper JCR
-functionality:
-
-    MicroKernel kernel = ...;
-    Repository repository = new Jcr(kernel).createRepository();
-
-The `Jcr` class supports all the same `with()` methods as the `Oak` class
-does, so you can easily extend the constructed JCR repository with custom
-functionality if you like. For test purposes the `Jcr` class also has an
-empty default constructor that works like the one in the `Oak` class.
-
+First, we construct a Repository instance.
+Both the `Oak` and the `Jcr` classes support `with()` methods, 
+so you can easily extend the repository with custom functionality if you like.
+The `OpenSecurityProvider` will cause all login attempts will work.
+To construct an in-memory repository, use:
+
+        Repository repo = new Jcr(new Oak())
+                .with(new OpenSecurityProvider())
+                .createRepository();
+
+To use a MongoDB backend, use:
+
+        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();
+
+To login to the repository and do some work:
+                
+        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();
+        
+To logout and close the backend store:
+        
+        session.logout();
+        ns.dispose();