Search in sources :

Example 6 with ChangeLog

use of org.apache.jackrabbit.core.state.ChangeLog in project jackrabbit by apache.

the class PersistenceManagerTest method assertCreateUpdateDelete.

private void assertCreateUpdateDelete(PersistenceManager manager) throws Exception {
    NodeState node = new NodeState(NODE_ID, TEST, RepositoryImpl.ROOT_NODE_ID, ItemState.STATUS_NEW, true);
    node.addChildNodeEntry(TEST, CHILD_ID);
    node.addPropertyName(NameConstants.JCR_PRIMARYTYPE);
    node.addPropertyName(TEST);
    NodeState child = new NodeState(CHILD_ID, TEST, NODE_ID, ItemState.STATUS_NEW, true);
    child.addPropertyName(NameConstants.JCR_PRIMARYTYPE);
    PropertyState property = new PropertyState(PROPERTY_ID, ItemState.STATUS_NEW, true);
    property.setType(PropertyType.REFERENCE);
    property.setValues(new InternalValue[] { InternalValue.create(CHILD_ID) });
    NodeReferences references = new NodeReferences(CHILD_ID);
    references.addReference(PROPERTY_ID);
    ChangeLog create = new ChangeLog();
    create.added(node);
    create.added(child);
    create.added(property);
    create.modified(references);
    manager.store(create);
    assertTrue(manager.exists(NODE_ID));
    assertTrue(manager.exists(CHILD_ID));
    assertTrue(manager.exists(PROPERTY_ID));
    assertTrue(manager.existsReferencesTo(CHILD_ID));
    assertEquals(node, manager.load(NODE_ID));
    assertEquals(child, manager.load(CHILD_ID));
    assertEquals(property, manager.load(PROPERTY_ID));
    assertEquals(references, manager.loadReferencesTo(CHILD_ID));
    references.removeReference(PROPERTY_ID);
    node.setStatus(ItemState.STATUS_EXISTING);
    ChangeLog update = new ChangeLog();
    update.modified(references);
    node.removePropertyName(TEST);
    update.deleted(property);
    update.modified(node);
    manager.store(update);
    assertTrue(manager.exists(NODE_ID));
    assertTrue(manager.exists(CHILD_ID));
    assertFalse(manager.exists(PROPERTY_ID));
    assertFalse(manager.existsReferencesTo(CHILD_ID));
    assertEquals(node, manager.load(NODE_ID));
    assertEquals(child, manager.load(CHILD_ID));
    ChangeLog delete = new ChangeLog();
    delete.deleted(child);
    delete.deleted(node);
    manager.store(delete);
    assertFalse(manager.exists(NODE_ID));
    assertFalse(manager.exists(CHILD_ID));
    assertFalse(manager.exists(PROPERTY_ID));
    assertFalse(manager.existsReferencesTo(CHILD_ID));
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) NodeReferences(org.apache.jackrabbit.core.state.NodeReferences) ChangeLog(org.apache.jackrabbit.core.state.ChangeLog) PropertyState(org.apache.jackrabbit.core.state.PropertyState)

Aggregations

ChangeLog (org.apache.jackrabbit.core.state.ChangeLog)6 NodeState (org.apache.jackrabbit.core.state.NodeState)4 PropertyState (org.apache.jackrabbit.core.state.PropertyState)4 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)3 NodeReferences (org.apache.jackrabbit.core.state.NodeReferences)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 RepositoryException (javax.jcr.RepositoryException)2 UpdateEvent (org.apache.jackrabbit.core.cluster.SimpleEventListener.UpdateEvent)2 PropertyId (org.apache.jackrabbit.core.id.PropertyId)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Session (javax.jcr.Session)1 ClusterException (org.apache.jackrabbit.core.cluster.ClusterException)1 NodeId (org.apache.jackrabbit.core.id.NodeId)1 NodePropBundle (org.apache.jackrabbit.core.persistence.util.NodePropBundle)1 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)1 InternalValue (org.apache.jackrabbit.core.value.InternalValue)1 Name (org.apache.jackrabbit.spi.Name)1