Package org.apache.jackrabbit.jcr2spi.state

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


    /**
     * @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<ItemState>(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}
     * @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:
                // state 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

         * @throws javax.jcr.version.VersionException
         */
        private void execute(ChangeLog changeLog) throws RepositoryException, ConstraintViolationException, AccessDeniedException, ItemExistsException, NoSuchNodeTypeException, UnsupportedRepositoryOperationException, VersionException {
            RepositoryException ex = null;
            try {
                ItemState target = changeLog.getTarget();
                batch = service.createBatch(sessionInfo, target.getId());
                for (Operation op : changeLog.getOperations()) {
                    log.debug("executing " + op.getName());
                    op.accept(this);
                }
            } catch (RepositoryException e) {
View Full Code Here

        }
        if (log.isDebugEnabled()) {
            log.debug("update item " + item);
        }

        ItemState state = ((ItemImpl) item).getItemState();
        // touch the corresponding cache entry
        Item cacheEntry = getItem(state);
        if (cacheEntry == null) {
            // .. or add the item to the cache, if not present yet.
            cacheItem(state, item);
View Full Code Here

     * Returns the the state of this instance in a human readable format.
     */
    public String toString() {
        StringBuilder builder = new StringBuilder();
        for (Map.Entry<ItemState, Item> entry : cache.entrySet()) {
            ItemState state = entry.getKey();
            Item item = entry.getValue();
            if (item.isNode()) {
                builder.append("Node: ");
            } else {
                builder.append("Property: ");
View Full Code Here

     * @see ItemManager#itemExists(HierarchyEntry)
     */
    public boolean itemExists(HierarchyEntry hierarchyEntry) throws RepositoryException {
        try {
            // session-sanity & permissions are checked upon itemExists(ItemState)
            ItemState state = hierarchyEntry.getItemState();
            return itemExists(state);
        } catch (ItemNotFoundException e) {
            return false;
        }
    }
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.