Package org.apache.jackrabbit.jcr2spi.state

Examples of org.apache.jackrabbit.jcr2spi.state.ItemState


    /**
     * @return the item state or <code>null</code> if the entry isn't resolved.
     */
    ItemState internalGetItemState() {
        ItemState state = null;
        if (target != null) {
            state = (ItemState) target.get();
        }
        return state;
    }
View Full Code Here


    /**
     * @inheritDoc
     * @see HierarchyEntry#getStatus()
     */
    public int getStatus() {
        ItemState state = internalGetItemState();
        if (state == null) {
            return Status._UNDEFINED_;
        } else {
            return state.getStatus();
        }
    }
View Full Code Here

    /**
     * {@inheritDoc}<br>
     * @see HierarchyEntry#getItemState()
     */
    public ItemState getItemState() throws ItemNotFoundException, RepositoryException {
        ItemState state = resolve();
        return state;
    }
View Full Code Here

    /**
     * {@inheritDoc}<br>
     * @see HierarchyEntry#setItemState(ItemState)
     */
    public synchronized void setItemState(ItemState state) {
        ItemState currentState = internalGetItemState();
        if (state == null || state == currentState || denotesNode() != state.isNode()) {
            throw new IllegalArgumentException();
        }
        if (currentState == null) {
            // not connected yet to an item state. either a new entry or
            // an unresolved hierarchy entry.
            target = new SoftReference(state);
        } else {
            // was already resolved before -> merge the existing state
            // with the passed state.
            int currentStatus = currentState.getStatus();
            boolean keepChanges = Status.isTransient(currentStatus) || Status.isStale(currentStatus);
            MergeResult mergeResult = currentState.merge(state, keepChanges);
            if (currentStatus == Status.INVALIDATED) {
                currentState.setStatus(Status.EXISTING);
            } else if (mergeResult.modified()) {
                currentState.setStatus(Status.MODIFIED);
            } // else: not modified. just leave status as it is.
            mergeResult.dispose();
        }
    }
View Full Code Here

    /**
     * {@inheritDoc}<br>
     * @see HierarchyEntry#invalidate(boolean)
     */
    public void invalidate(boolean recursive) {
        ItemState state = internalGetItemState();
        if (state == null) {
            log.debug("Skip invalidation for unresolved HierarchyEntry " + name);
        } else {
            state.invalidate();
        }
    }
View Full Code Here

    /**
     * {@inheritDoc}
     * @see HierarchyEntry#revert()
     */
    public void revert() throws RepositoryException {
        ItemState state = internalGetItemState();
        if (state == null) {
            // nothing to do
            return;
        }

        int oldStatus = state.getStatus();
        switch (oldStatus) {
            case Status.EXISTING_MODIFIED:
            case Status.STALE_MODIFIED:
                // revert state modifications
                state.revert();
                state.setStatus(Status.EXISTING);
                break;
            case Status.EXISTING_REMOVED:
                // revert state modifications
                state.revert();
                state.setStatus(Status.EXISTING);
                break;
            case Status.NEW:
                // reverting a NEW state is equivalent to its removal.
                // however: no need remove the complete hierarchy as revert is
                // always related to Item#refresh(false) which affects the
                // complete tree (and all add-operations within it) anyway.
                state.setStatus(Status.REMOVED);
                parent.internalRemoveChildEntry(this);
                break;
            case Status.STALE_DESTROYED:
                // overlayed does not exist any more -> reverting of pending
                // transient changes (that lead to the stale status) can be
View Full Code Here

    /**
     * {@inheritDoc}
     * @see HierarchyEntry#transientRemove()
     */
    public void transientRemove() throws InvalidItemStateException, RepositoryException {
        ItemState state = internalGetItemState();
        if (state == null) {
            // nothing to do -> correct status must be set upon resolution.
            return;
        }
        // if during recursive removal an invalidated entry is found, reload
        // it in order to determine the current status.
        if (state.getStatus() == Status.INVALIDATED) {
            reload(false);
        }

        switch (state.getStatus()) {
            case Status.NEW:
                state.setStatus(Status.REMOVED);
                parent.internalRemoveChildEntry(this);
                break;
            case Status.EXISTING:
            case Status.EXISTING_MODIFIED:
                state.setStatus(Status.EXISTING_REMOVED);
                // NOTE: parent does not need to be informed. an transiently
                // removed propertyEntry is automatically moved to the 'attic'
                // if a conflict with a new entry occurs.
                break;
            case Status.REMOVED:
            case Status.STALE_DESTROYED:
                throw new InvalidItemStateException("Item has already been removed by someone else. Status = " + Status.getName(state.getStatus()));
            default:
                throw new RepositoryException("Cannot transiently remove an ItemState with status " + Status.getName(state.getStatus()));
        }
    }
View Full Code Here

    //--------------------------------------------------------------------------
    /**
     * @param staleParent
     */
    void internalRemove(boolean staleParent) {
        ItemState state = internalGetItemState();
        int status = getStatus();
        if (state != null) {
            if (status == Status.EXISTING_MODIFIED) {
                state.setStatus(Status.STALE_DESTROYED);
            } else if (status == Status.NEW && staleParent) {
                // keep status NEW
            } else {
                state.setStatus(Status.REMOVED);
                if (!staleParent) {
                    parent.internalRemoveChildEntry(this);
                }
            }
        } else {
View Full Code Here

        Operation an = AddNode.create(getNodeState(), nodeName, nodeTypeName, null);
        session.getSessionItemStateManager().execute(an);

        // finally retrieve the new node
        List<ItemState> addedStates = ((AddNode) an).getAddedStates();
        ItemState nState = addedStates.get(0);
        return (Node) getItemManager().getItem(nState.getHierarchyEntry());
    }
View Full Code Here

        }

        // if this entry has not yet been resolved or if it is 'invalidated'
        // all property entries, that are not contained within the specified
        // collection of property names are removed from this NodeEntry.
        ItemState state = internalGetItemState();
        if (containsExtra && (state == null || state.getStatus() == Status.INVALIDATED)) {
            for (Iterator<Name> it = diff.iterator(); it.hasNext();) {
                Name propName = it.next();
                PropertyEntry pEntry = properties.get(propName);
                if (pEntry != null) {
                    pEntry.remove();
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.jcr2spi.state.ItemState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.