Search in sources :

Example 1 with SetPrimaryType

use of org.apache.jackrabbit.jcr2spi.operation.SetPrimaryType in project jackrabbit by apache.

the class ChangeLog method persisted.

//-----------------------------------------------< Inform the ChangeLog >---
/**
     * Call this method when this change log has been successfully persisted.
     * This implementation will call {@link Operation#persisted()} on the
     * individual operations followed by setting all remaining modified
     * states to EXISTING.
     */
public void persisted() throws RepositoryException {
    List<NodeState> changedMixins = new ArrayList<NodeState>();
    List<NodeState> changedPrimaryTypes = new ArrayList<NodeState>();
    Operation[] ops = operations.toArray(new Operation[operations.size()]);
    for (int i = 0; i < ops.length; i++) {
        ops[i].persisted();
        if (ops[i] instanceof SetMixin) {
            changedMixins.add(((SetMixin) ops[i]).getNodeState());
        } else if (ops[i] instanceof SetPrimaryType) {
            changedPrimaryTypes.add(((SetPrimaryType) ops[i]).getNodeState());
        }
    }
    // operation persistence.
    for (ItemState state : affectedStates) {
        HierarchyEntry he = state.getHierarchyEntry();
        switch(state.getStatus()) {
            case Status.EXISTING_MODIFIED:
                state.setStatus(Status.EXISTING);
                if (state.isNode()) {
                    if (changedPrimaryTypes.contains(state)) {
                        // primary type changed for a node -> force reloading upon next
                        // access in order to be aware of modified definition etc...
                        he.invalidate(true);
                    } else if (changedMixins.contains(state)) {
                        // mixin changed for a node -> force reloading upon next
                        // access in order to be aware of modified uniqueID.
                        he.invalidate(false);
                    }
                }
                break;
            case Status.EXISTING_REMOVED:
                he.remove();
                break;
            case Status.NEW:
                // illegal. should not get here.
                log.error("ChangeLog still contains NEW state: " + state.getName());
                state.setStatus(Status.EXISTING);
                break;
            case Status.MODIFIED:
            case Status._UNDEFINED_:
            case Status.STALE_DESTROYED:
            case Status.STALE_MODIFIED:
                // illegal.
                log.error("ChangeLog contains state (" + state.getName() + ") with illegal status " + Status.getName(state.getStatus()));
                break;
            case Status.EXISTING:
                if (state.isNode() && changedMixins.contains(state)) {
                    // mixin changed for a node -> force reloading upon next
                    // access in order to be aware of modified uniqueID.
                    he.invalidate(false);
                }
                // otherwise: ignore. operations already have been completed
                break;
            case Status.INVALIDATED:
            case Status.REMOVED:
                he.invalidate(false);
                break;
        }
    }
}
Also used : SetPrimaryType(org.apache.jackrabbit.jcr2spi.operation.SetPrimaryType) ArrayList(java.util.ArrayList) SetMixin(org.apache.jackrabbit.jcr2spi.operation.SetMixin) Operation(org.apache.jackrabbit.jcr2spi.operation.Operation) HierarchyEntry(org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry)

Aggregations

ArrayList (java.util.ArrayList)1 HierarchyEntry (org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry)1 Operation (org.apache.jackrabbit.jcr2spi.operation.Operation)1 SetMixin (org.apache.jackrabbit.jcr2spi.operation.SetMixin)1 SetPrimaryType (org.apache.jackrabbit.jcr2spi.operation.SetPrimaryType)1