Search in sources :

Example 16 with NodePropBundle

use of org.apache.jackrabbit.core.persistence.util.NodePropBundle in project jackrabbit by apache.

the class AbstractBundlePersistenceManager method load.

/**
 * {@inheritDoc}
 *
 * Loads the state via the appropriate NodePropBundle.
 */
public PropertyState load(PropertyId id) throws NoSuchItemStateException, ItemStateException {
    NodePropBundle bundle = getBundle(id.getParentId());
    if (bundle != null) {
        PropertyState state = createNew(id);
        PropertyEntry p = bundle.getPropertyEntry(id.getName());
        if (p != null) {
            state.setMultiValued(p.isMultiValued());
            state.setType(p.getType());
            state.setValues(p.getValues());
            state.setModCount(p.getModCount());
        } else if (id.getName().equals(JCR_UUID)) {
            state.setType(PropertyType.STRING);
            state.setMultiValued(false);
            state.setValues(new InternalValue[] { InternalValue.create(id.getParentId().toString()) });
        } else if (id.getName().equals(JCR_PRIMARYTYPE)) {
            state.setType(PropertyType.NAME);
            state.setMultiValued(false);
            state.setValues(new InternalValue[] { InternalValue.create(bundle.getNodeTypeName()) });
        } else if (id.getName().equals(JCR_MIXINTYPES)) {
            state.setType(PropertyType.NAME);
            state.setMultiValued(true);
            Set<Name> mixins = bundle.getMixinTypeNames();
            state.setValues(InternalValue.create(mixins.toArray(new Name[mixins.size()])));
        } else {
            throw new NoSuchItemStateException(id.toString());
        }
        return state;
    } else {
        throw new NoSuchItemStateException(id.toString());
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) PropertyEntry(org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry) NodePropBundle(org.apache.jackrabbit.core.persistence.util.NodePropBundle) InternalValue(org.apache.jackrabbit.core.value.InternalValue) PropertyState(org.apache.jackrabbit.core.state.PropertyState) Name(org.apache.jackrabbit.spi.Name)

Example 17 with NodePropBundle

use of org.apache.jackrabbit.core.persistence.util.NodePropBundle in project jackrabbit by apache.

the class ConsistencyCheckerImplTest method testDoubleCheckMissingNode.

public void testDoubleCheckMissingNode() throws RepositoryException {
    NodePropBundle bundle = new NodePropBundle(new NodeId(0, 0));
    final NodeId childNodeId = new NodeId(0, 1);
    bundle.addChildNodeEntry(nameFactory.create("", "test"), childNodeId);
    MockPersistenceManager pm = new MockPersistenceManager(Arrays.asList(bundle));
    ConsistencyCheckerImpl checker = new ConsistencyCheckerImpl(pm, null, null, null);
    checker.check(null, false);
    Set<ReportItem> reportItems = checker.getReport().getItems();
    assertEquals(1, reportItems.size());
    ReportItem reportItem = reportItems.iterator().next();
    assertEquals(ReportItem.Type.MISSING, reportItem.getType());
    assertEquals(bundle.getId().toString(), reportItem.getNodeId());
    checker.doubleCheckErrors();
    assertFalse("Double check removed valid error", checker.getReport().getItems().isEmpty());
    // fix the error
    NodePropBundle child = new NodePropBundle(childNodeId);
    pm.bundles.put(childNodeId, child);
    checker.doubleCheckErrors();
    assertTrue("Double check didn't remove invalid error", checker.getReport().getItems().isEmpty());
}
Also used : NodePropBundle(org.apache.jackrabbit.core.persistence.util.NodePropBundle) NodeId(org.apache.jackrabbit.core.id.NodeId) ConsistencyCheckerImpl(org.apache.jackrabbit.core.persistence.bundle.ConsistencyCheckerImpl) ReportItem(org.apache.jackrabbit.core.persistence.check.ReportItem)

Example 18 with NodePropBundle

use of org.apache.jackrabbit.core.persistence.util.NodePropBundle in project jackrabbit by apache.

the class ConsistencyCheckerImplTest method testFixDisconnectedNode.

// Disconnected nodes are those nodes for which there are nodes
// that have the node as its child, but the node itself does not
// have those nodes as its parent
public void testFixDisconnectedNode() throws RepositoryException, ClusterException {
    NodePropBundle bundle1 = new NodePropBundle(new NodeId(0, 0));
    NodePropBundle bundle2 = new NodePropBundle(new NodeId(0, 1));
    NodePropBundle bundle3 = new NodePropBundle(new NodeId(1, 0));
    // node1 has child node3
    bundle1.addChildNodeEntry(nameFactory.create("", "test"), bundle3.getId());
    // node2 also has child node3
    bundle2.addChildNodeEntry(nameFactory.create("", "test"), bundle3.getId());
    // node3 has node2 as parent
    bundle3.setParentId(bundle2.getId());
    MockPersistenceManager pm = new MockPersistenceManager(Arrays.asList(bundle1, bundle2, bundle3));
    ConsistencyCheckerImpl checker = new ConsistencyCheckerImpl(pm, null, null, master.createUpdateChannel("default"));
    // set up cluster event update listener
    final TestUpdateEventListener listener = new TestUpdateEventListener();
    final UpdateEventChannel slaveEventChannel = slave.createUpdateChannel("default");
    slaveEventChannel.setListener(listener);
    checker.check(null, false);
    Set<ReportItem> reportItems = checker.getReport().getItems();
    assertEquals(1, reportItems.size());
    ReportItem reportItem = reportItems.iterator().next();
    assertEquals(ReportItem.Type.DISCONNECTED, reportItem.getType());
    assertEquals(bundle1.getId().toString(), reportItem.getNodeId());
    checker.repair();
    bundle1 = pm.loadBundle(bundle1.getId());
    bundle2 = pm.loadBundle(bundle2.getId());
    bundle3 = pm.loadBundle(bundle3.getId());
    // node3 should have been removed as child node entry of node1
    assertEquals(0, bundle1.getChildNodeEntries().size());
    // node3 should still be a child of node2
    assertEquals(1, bundle2.getChildNodeEntries().size());
    assertEquals(bundle2.getId(), bundle3.getParentId());
    slave.sync();
    // verify events were correctly broadcast to cluster
    assertNotNull("Cluster node did not receive update event", listener.changes);
    assertTrue("Expected node1 to be modified", listener.changes.isModified(bundle1.getId()));
}
Also used : NodePropBundle(org.apache.jackrabbit.core.persistence.util.NodePropBundle) NodeId(org.apache.jackrabbit.core.id.NodeId) ConsistencyCheckerImpl(org.apache.jackrabbit.core.persistence.bundle.ConsistencyCheckerImpl) UpdateEventChannel(org.apache.jackrabbit.core.cluster.UpdateEventChannel) ReportItem(org.apache.jackrabbit.core.persistence.check.ReportItem)

Example 19 with NodePropBundle

use of org.apache.jackrabbit.core.persistence.util.NodePropBundle in project jackrabbit by apache.

the class ConsistencyCheckerImplTest method testFixAbandonedNode.

// Abandoned nodes are nodes that have a link to a parent but that
// parent does not have a link back to the child
public void testFixAbandonedNode() throws RepositoryException, ClusterException {
    NodePropBundle bundle1 = new NodePropBundle(new NodeId(0, 0));
    NodePropBundle bundle2 = new NodePropBundle(new NodeId(0, 1));
    // node2 has a reference to node 1 as its parent, but node 1 doesn't have
    // a corresponding child node entry
    bundle2.setParentId(bundle1.getId());
    MockPersistenceManager pm = new MockPersistenceManager(Arrays.asList(bundle1, bundle2));
    ConsistencyCheckerImpl checker = new ConsistencyCheckerImpl(pm, null, null, master.createUpdateChannel("default"));
    // set up cluster event update listener
    final TestUpdateEventListener listener = new TestUpdateEventListener();
    final UpdateEventChannel slaveEventChannel = slave.createUpdateChannel("default");
    slaveEventChannel.setListener(listener);
    checker.check(null, false);
    Set<ReportItem> reportItems = checker.getReport().getItems();
    assertEquals(1, reportItems.size());
    ReportItem reportItem = reportItems.iterator().next();
    assertEquals(ReportItem.Type.ABANDONED, reportItem.getType());
    assertEquals(bundle2.getId().toString(), reportItem.getNodeId());
    checker.repair();
    // node1 should now have a child node entry for node2
    bundle1 = pm.loadBundle(bundle1.getId());
    assertEquals(1, bundle1.getChildNodeEntries().size());
    assertEquals(bundle2.getId(), bundle1.getChildNodeEntries().get(0).getId());
    slave.sync();
    // verify events were correctly broadcast to cluster
    assertNotNull("Cluster node did not receive update event", listener.changes);
    assertTrue("Expected node1 to be modified", listener.changes.isModified(bundle1.getId()));
}
Also used : NodePropBundle(org.apache.jackrabbit.core.persistence.util.NodePropBundle) NodeId(org.apache.jackrabbit.core.id.NodeId) ConsistencyCheckerImpl(org.apache.jackrabbit.core.persistence.bundle.ConsistencyCheckerImpl) UpdateEventChannel(org.apache.jackrabbit.core.cluster.UpdateEventChannel) ReportItem(org.apache.jackrabbit.core.persistence.check.ReportItem)

Aggregations

NodePropBundle (org.apache.jackrabbit.core.persistence.util.NodePropBundle)19 NodeId (org.apache.jackrabbit.core.id.NodeId)14 ConsistencyCheckerImpl (org.apache.jackrabbit.core.persistence.bundle.ConsistencyCheckerImpl)9 ReportItem (org.apache.jackrabbit.core.persistence.check.ReportItem)8 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)5 UpdateEventChannel (org.apache.jackrabbit.core.cluster.UpdateEventChannel)4 RepositoryException (javax.jcr.RepositoryException)3 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 ClusterException (org.apache.jackrabbit.core.cluster.ClusterException)2 PropertyId (org.apache.jackrabbit.core.id.PropertyId)2 NodeInfo (org.apache.jackrabbit.core.persistence.util.NodeInfo)2 PropertyEntry (org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry)2 Name (org.apache.jackrabbit.spi.Name)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1