// --------------------------------------------------------------------------------
// Create and store an object graph in the repository
// --------------------------------------------------------------------------------
A a = new A();
a.setPath("/test");
a.setA1("a1");
a.setA2("a2");
B b = new B();
b.setB1("b1");
b.setB2("b2");
a.setB(b);
C c1 = new C();
c1.setId("first");
c1.setName("First Element");
C c2 = new C();
c2.setId("second");
c2.setName("Second Element");
C c3 = new C();
c3.setId("third");
c3.setName("Third Element");
Collection collection = new ArrayList();
collection.add(c1);
collection.add(c2);
collection.add(c3);
a.setCollection(collection);
ocm.insert(a);
ocm.save();
// --------------------------------------------------------------------------------
// Get the object
// --------------------------------------------------------------------------------
a = (A) ocm.getObject( "/test");
assertNotNull("a is null", a);
// --------------------------------------------------------------------------------
// Check if the object is locked
// --------------------------------------------------------------------------------
assertFalse("the object is locked", ocm.isLocked("/test"));
// --------------------------------------------------------------------------------
// Lock the object
// --------------------------------------------------------------------------------
Lock lock = ocm.lock("/test", true, false);
assertTrue("the Lock owner is not correct", lock.getLockOwner().equals("superuser"));
// --------------------------------------------------------------------------------
// Check if the object is locked
// --------------------------------------------------------------------------------
assertTrue("the object is not locked", ocm.isLocked("/test"));
// --------------------------------------------------------------------------------
// Unlock the object
// --------------------------------------------------------------------------------
ocm.unlock("/test", lock.getLockToken());
// --------------------------------------------------------------------------------
// Check if the object is locked
// --------------------------------------------------------------------------------
assertFalse("the object is locked", ocm.isLocked("/test"));
// --------------------------------------------------------------------------------
// Lock & update
// --------------------------------------------------------------------------------
lock = ocm.lock("/test", true, false);
a = (A) ocm.getObject("/test");
a.setA1("new a1 Value");
ocm.update(a);
ocm.save();
ocm.unlock("/test", lock.getLockToken());