]> git.argeo.org Git - lgpl/argeo-commons.git/blob - java/SecondHop.java
Prepare next development cycle
[lgpl/argeo-commons.git] / java / SecondHop.java
1 import javax.jcr.Repository;
2 import javax.jcr.Session;
3 import javax.jcr.SimpleCredentials;
4 import javax.jcr.Node;
5 import org.apache.jackrabbit.core.TransientRepository;
6
7 /**
8 * Second hop example. Stores, retrieves, and removes example content.
9 */
10 public class SecondHop {
11
12 /**
13 * The main entry point of the example application.
14 *
15 * @param args command line arguments (ignored)
16 * @throws Exception if an error occurs
17 */
18 public static void main(String[] args) throws Exception {
19 Repository repository = new TransientRepository();
20 Session session = repository.login(
21 new SimpleCredentials("username", "password".toCharArray()));
22 try {
23 Node root = session.getRootNode();
24
25 // Store content
26 Node hello = root.addNode("hello");
27 Node world = hello.addNode("world");
28 world.setProperty("message", "Hello, World!");
29 session.save();
30
31 // Retrieve content
32 Node node = root.getNode("hello/world");
33 System.out.println(node.getPath());
34 System.out.println(node.getProperty("message").getString());
35
36 // Remove content
37 root.getNode("hello").remove();
38 session.save();
39 } finally {
40 session.logout();
41 }
42 }
43
44 }