Search in sources :

Example 6 with SessionItemStateManager

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

the class ItemManager method stateDiscarded.

/**
     * {@inheritDoc}
     */
public void stateDiscarded(ItemState discarded) {
    ItemData data = retrieveItem(discarded.getId());
    if (data != null && data.getState() == discarded) {
        if (discarded.isTransient()) {
            switch(discarded.getStatus()) {
                /**
                 * persistent item that has been transiently removed
                 */
                case ItemState.STATUS_EXISTING_REMOVED:
                case ItemState.STATUS_EXISTING_MODIFIED:
                    ItemState persistentState = discarded.getOverlayedState();
                    // the state is a transient wrapper for the underlying
                    // persistent state, therefore restore the persistent state
                    // and resurrect this item instance if necessary
                    SessionItemStateManager stateMgr = sessionContext.getItemStateManager();
                    stateMgr.disconnectTransientItemState(discarded);
                    data.setState(persistentState);
                    return;
                /**
                     * persistent item that has been transiently modified or
                     * removed and the underlying persistent state has been
                     * externally destroyed since the transient
                     * modification/removal.
                     */
                case ItemState.STATUS_STALE_DESTROYED:
                    /**
                     * first notify the listeners that this instance has been
                     * permanently invalidated
                     */
                    itemDestroyed(discarded.getId(), data);
                    // now set state of this instance to 'destroyed'
                    data.setStatus(ItemImpl.STATUS_DESTROYED);
                    data.setState(null);
                    return;
                /**
                     * new item that has been transiently added
                     */
                case ItemState.STATUS_NEW:
                    /**
                     * first notify the listeners that this instance has been
                     * permanently invalidated
                     */
                    itemDestroyed(discarded.getId(), data);
                    // now set state of this instance to 'destroyed'
                    // finally dispose state
                    data.setStatus(ItemImpl.STATUS_DESTROYED);
                    data.setState(null);
                    return;
            }
        }
        /**
             * first notify the listeners that this instance has been
             * invalidated
             */
        itemInvalidated(discarded.getId(), data);
        // now render this instance 'invalid'
        data.setStatus(ItemImpl.STATUS_INVALIDATED);
    }
}
Also used : ItemState(org.apache.jackrabbit.core.state.ItemState) SessionItemStateManager(org.apache.jackrabbit.core.state.SessionItemStateManager)

Example 7 with SessionItemStateManager

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

the class ItemSaveOperation method restoreTransientItems.

/**
     * walk through list of transient states and re-apply transient changes
     */
private void restoreTransientItems(SessionContext context, Iterable<ItemState> items) {
    ItemManager itemMgr = context.getItemManager();
    SessionItemStateManager stateMgr = context.getItemStateManager();
    for (ItemState itemState : items) {
        ItemId id = itemState.getId();
        ItemImpl item;
        try {
            if (stateMgr.isItemStateInAttic(id)) {
                // If an item has been removed and then again created, the
                // item is lost after persistTransientItems() and the
                // TransientItemStateManager will bark because of a deleted
                // state in its attic. We therefore have to forge a new item
                // instance ourself.
                item = itemMgr.createItemInstance(itemState);
                itemState.setStatus(ItemState.STATUS_NEW);
            } else {
                try {
                    item = itemMgr.getItem(id, false);
                } catch (ItemNotFoundException infe) {
                    // itemState probably represents a 'new' item and the
                    // ItemImpl instance wrapping it has already been gc'ed;
                    // we have to re-create the ItemImpl instance
                    item = itemMgr.createItemInstance(itemState);
                    itemState.setStatus(ItemState.STATUS_NEW);
                }
            }
            // for persistent nodes undo effect of item.makePersistent()
            if (item.isNode()) {
                NodeImpl node = (NodeImpl) item;
                node.restoreTransient((NodeState) itemState);
            } else {
                PropertyImpl prop = (PropertyImpl) item;
                prop.restoreTransient((PropertyState) itemState);
            }
        } catch (RepositoryException re) {
            // something went wrong, log exception and carry on
            String msg = itemMgr.safeGetJCRPath(id) + ": failed to restore transient state";
            if (log.isDebugEnabled()) {
                log.warn(msg, re);
            } else {
                log.warn(msg);
            }
        }
    }
}
Also used : ItemState(org.apache.jackrabbit.core.state.ItemState) RepositoryException(javax.jcr.RepositoryException) SessionItemStateManager(org.apache.jackrabbit.core.state.SessionItemStateManager) ItemId(org.apache.jackrabbit.core.id.ItemId) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Aggregations

SessionItemStateManager (org.apache.jackrabbit.core.state.SessionItemStateManager)7 RepositoryException (javax.jcr.RepositoryException)5 ItemState (org.apache.jackrabbit.core.state.ItemState)5 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)3 ItemId (org.apache.jackrabbit.core.id.ItemId)3 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)3 NodeState (org.apache.jackrabbit.core.state.NodeState)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 NodeDefinition (javax.jcr.nodetype.NodeDefinition)2 NodeId (org.apache.jackrabbit.core.id.NodeId)2 PropertyId (org.apache.jackrabbit.core.id.PropertyId)2 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)2 NodeTypeImpl (org.apache.jackrabbit.core.nodetype.NodeTypeImpl)2 NodeTypeManagerImpl (org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl)2 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)2 PropertyState (org.apache.jackrabbit.core.state.PropertyState)2 Name (org.apache.jackrabbit.spi.Name)2 ArrayList (java.util.ArrayList)1 ConcurrentModificationException (java.util.ConcurrentModificationException)1