Search in sources :

Example 1 with ChangeLog

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

the class VersionItemStateManager method setNodeReferences.

/**
     * Sets the
     * @param references
     * @return
     */
public boolean setNodeReferences(ChangeLog references) {
    try {
        ChangeLog log = new ChangeLog();
        for (NodeReferences source : references.modifiedRefs()) {
            // filter out version storage intern ones
            NodeReferences target = new NodeReferences(source.getTargetId());
            for (PropertyId id : source.getReferences()) {
                if (!hasNonVirtualItemState(id.getParentId())) {
                    target.addReference(id);
                }
            }
            log.modified(target);
        }
        if (log.hasUpdates()) {
            pMgr.store(log);
        }
        return true;
    } catch (ItemStateException e) {
        log.error("Error while setting references: " + e.toString());
        return false;
    }
}
Also used : NodeReferences(org.apache.jackrabbit.core.state.NodeReferences) ChangeLog(org.apache.jackrabbit.core.state.ChangeLog) PropertyId(org.apache.jackrabbit.core.id.PropertyId) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 2 with ChangeLog

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

the class ConsistencyCheckerImpl method repair.

/**
     * Repair any errors found during a {@link #check}. Should be run after a {#check} and
     * (if needed) {@link #doubleCheckErrors}.
     *
     * @throws RepositoryException
     */
public void repair() throws RepositoryException {
    checkLostNFound();
    bundles = new HashMap<NodeId, NodePropBundle>();
    if (hasRepairableErrors()) {
        boolean successful = false;
        final CheckerUpdate update = new CheckerUpdate();
        try {
            eventChannel.updateCreated(update);
            for (ConsistencyCheckerError error : errors) {
                if (error.isRepairable()) {
                    try {
                        error.repair(update.getChanges());
                        info(null, "Repairing " + error);
                    } catch (ItemStateException e) {
                        error(null, "Failed to repair error: " + error, e);
                    }
                }
            }
            final ChangeLog changes = update.getChanges();
            if (changes.hasUpdates()) {
                eventChannel.updatePrepared(update);
                for (NodePropBundle bundle : bundles.values()) {
                    storeBundle(bundle);
                }
                update.setAttribute(ATTRIBUTE_UPDATE_SIZE, changes.getUpdateSize());
                successful = true;
            }
        } catch (ClusterException e) {
            throw new RepositoryException("Cannot create update", e);
        } finally {
            if (successful) {
                eventChannel.updateCommitted(update, "checker@");
            } else {
                eventChannel.updateCancelled(update);
            }
        }
    }
}
Also used : ClusterException(org.apache.jackrabbit.core.cluster.ClusterException) NodeId(org.apache.jackrabbit.core.id.NodeId) NodePropBundle(org.apache.jackrabbit.core.persistence.util.NodePropBundle) RepositoryException(javax.jcr.RepositoryException) ChangeLog(org.apache.jackrabbit.core.state.ChangeLog) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 3 with ChangeLog

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

the class UpdateEventFactory method createUpdateOperationWithNullUserId.

/**
     * Create an update operation.
     *
     * @return update operation
     */
public UpdateEvent createUpdateOperationWithNullUserId() {
    NodeState n1 = createNodeState();
    NodeState n2 = createNodeState();
    NodeState n3 = createNodeState();
    PropertyState p1 = createPropertyState(n1.getNodeId(), "{}a");
    PropertyState p2 = createPropertyState(n2.getNodeId(), "{}b");
    ChangeLog changes = new ChangeLog();
    changes.added(n1);
    changes.added(p1);
    changes.deleted(p2);
    changes.modified(n2);
    changes.deleted(n3);
    Session s = new ClusterSession(null);
    List events = new ArrayList();
    events.add(createEventState(n1, Event.NODE_ADDED, "{}n1", s));
    events.add(createEventState(p1, n1, Event.PROPERTY_ADDED, s));
    events.add(createEventState(p2, n2, Event.PROPERTY_REMOVED, s));
    events.add(createEventState(n3, Event.NODE_REMOVED, "{}n3", s));
    return new UpdateEvent(changes, events, System.currentTimeMillis(), "user-data");
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ChangeLog(org.apache.jackrabbit.core.state.ChangeLog) PropertyState(org.apache.jackrabbit.core.state.PropertyState) Session(javax.jcr.Session) UpdateEvent(org.apache.jackrabbit.core.cluster.SimpleEventListener.UpdateEvent)

Example 4 with ChangeLog

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

the class UpdateEventFactory method createUpdateOperation.

/**
     * Create an update operation.
     *
     * @return update operation
     */
public UpdateEvent createUpdateOperation() {
    NodeState n1 = createNodeState();
    NodeState n2 = createNodeState();
    NodeState n3 = createNodeState();
    PropertyState p1 = createPropertyState(n1.getNodeId(), "{}a");
    PropertyState p2 = createPropertyState(n2.getNodeId(), "{}b");
    ChangeLog changes = new ChangeLog();
    changes.added(n1);
    changes.added(p1);
    changes.deleted(p2);
    changes.modified(n2);
    changes.deleted(n3);
    List events = new ArrayList();
    events.add(createEventState(n1, Event.NODE_ADDED, "{}n1", session));
    events.add(createEventState(p1, n1, Event.PROPERTY_ADDED, session));
    events.add(createEventState(p2, n2, Event.PROPERTY_REMOVED, session));
    events.add(createEventState(n3, Event.NODE_REMOVED, "{}n3", session));
    return new UpdateEvent(changes, events, System.currentTimeMillis(), "user-data");
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ChangeLog(org.apache.jackrabbit.core.state.ChangeLog) PropertyState(org.apache.jackrabbit.core.state.PropertyState) UpdateEvent(org.apache.jackrabbit.core.cluster.SimpleEventListener.UpdateEvent)

Example 5 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