]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - sandbox/runtime/org.argeo.sandbox.jackrabbit/src/main/java/SecondHop.java
Introduce Jackrabbit sandbox
[lgpl/argeo-commons.git] / sandbox / runtime / org.argeo.sandbox.jackrabbit / src / main / java / SecondHop.java
diff --git a/sandbox/runtime/org.argeo.sandbox.jackrabbit/src/main/java/SecondHop.java b/sandbox/runtime/org.argeo.sandbox.jackrabbit/src/main/java/SecondHop.java
new file mode 100644 (file)
index 0000000..6d2bd9f
--- /dev/null
@@ -0,0 +1,44 @@
+import javax.jcr.Repository;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.Node;
+import org.apache.jackrabbit.core.TransientRepository;
+
+/**
+ * Second hop example. Stores, retrieves, and removes example content.
+ */
+public class SecondHop {
+
+    /**
+     * The main entry point of the example application.
+     *
+     * @param args command line arguments (ignored)
+     * @throws Exception if an error occurs
+     */
+    public static void main(String[] args) throws Exception {
+        Repository repository = new TransientRepository();
+        Session session = repository.login(
+                new SimpleCredentials("username", "password".toCharArray()));
+        try {
+            Node root = session.getRootNode();
+
+            // Store content
+            Node hello = root.addNode("hello");
+            Node world = hello.addNode("world");
+            world.setProperty("message", "Hello, World!");
+            session.save();
+
+            // Retrieve content
+            Node node = root.getNode("hello/world");
+            System.out.println(node.getPath());
+            System.out.println(node.getProperty("message").getString());
+
+            // Remove content
+            root.getNode("hello").remove();
+            session.save();
+        } finally {
+            session.logout();
+        }
+    }
+
+}