Search in sources :

Example 6 with ItemState

use of org.apache.jackrabbit.jcr2spi.state.ItemState in project jackrabbit by apache.

the class HierarchyEntryImpl method setItemState.

/**
     * {@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();
    }
}
Also used : ItemState(org.apache.jackrabbit.jcr2spi.state.ItemState) MergeResult(org.apache.jackrabbit.jcr2spi.state.ItemState.MergeResult)

Example 7 with ItemState

use of org.apache.jackrabbit.jcr2spi.state.ItemState in project jackrabbit by apache.

the class NodeImpl method createNode.

//---------------------------------------------< private implementation >---
/**
     * Create a new <code>NodeState</code> and subsequently retrieves the
     * corresponding <code>Node</code> object.
     *
     * @param nodeName     name of the new node
     * @param nodeTypeName name of the new node's node type or <code>null</code>
     *                     if it should be determined automatically
     * @return the newly added node
     * @throws ItemExistsException
     * @throws NoSuchNodeTypeException
     * @throws VersionException
     * @throws ConstraintViolationException
     * @throws LockException
     * @throws RepositoryException
     */
private synchronized Node createNode(Name nodeName, Name nodeTypeName) throws ItemExistsException, NoSuchNodeTypeException, VersionException, ConstraintViolationException, LockException, RepositoryException {
    QNodeDefinition definition = session.getItemDefinitionProvider().getQNodeDefinition(getNodeState().getAllNodeTypeNames(), nodeName, nodeTypeName);
    if (nodeTypeName == null) {
        // use default node type
        nodeTypeName = definition.getDefaultPrimaryType();
    }
    // validation check are performed by item state manager
    // NOTE: uuid is generated while creating new state.
    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());
}
Also used : ItemState(org.apache.jackrabbit.jcr2spi.state.ItemState) AddNode(org.apache.jackrabbit.jcr2spi.operation.AddNode) Node(javax.jcr.Node) Operation(org.apache.jackrabbit.jcr2spi.operation.Operation) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) AddNode(org.apache.jackrabbit.jcr2spi.operation.AddNode)

Example 8 with ItemState

use of org.apache.jackrabbit.jcr2spi.state.ItemState in project jackrabbit by apache.

the class ItemCacheImpl method toString.

//--------------------------------------------------------==---< Object >---
/**
     * 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: ");
        }
        if (item.isNew()) {
            builder.append("new ");
        } else if (item.isModified()) {
            builder.append("modified ");
        } else {
            builder.append("- ");
        }
        String path;
        try {
            path = item.getPath();
        } catch (RepositoryException e) {
            path = "-";
        }
        builder.append(state + "\t" + path + " (" + item + ")\n");
    }
    return builder.toString();
}
Also used : Item(javax.jcr.Item) ItemState(org.apache.jackrabbit.jcr2spi.state.ItemState) RepositoryException(javax.jcr.RepositoryException) Map(java.util.Map) LRUMap(org.apache.commons.collections.map.LRUMap)

Example 9 with ItemState

use of org.apache.jackrabbit.jcr2spi.state.ItemState in project jackrabbit by apache.

the class ItemCacheImpl method itemUpdated.

public void itemUpdated(Item item, boolean modified) {
    if (!(item instanceof ItemImpl)) {
        String msg = "Incompatible Item object: " + ItemImpl.class.getName() + " expected.";
        throw new IllegalArgumentException(msg);
    }
    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);
    }
}
Also used : Item(javax.jcr.Item) ItemState(org.apache.jackrabbit.jcr2spi.state.ItemState)

Aggregations

ItemState (org.apache.jackrabbit.jcr2spi.state.ItemState)9 Item (javax.jcr.Item)3 RepositoryException (javax.jcr.RepositoryException)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 InvalidItemStateException (javax.jcr.InvalidItemStateException)1 ItemNotFoundException (javax.jcr.ItemNotFoundException)1 Node (javax.jcr.Node)1 LRUMap (org.apache.commons.collections.map.LRUMap)1 AddNode (org.apache.jackrabbit.jcr2spi.operation.AddNode)1 Operation (org.apache.jackrabbit.jcr2spi.operation.Operation)1 MergeResult (org.apache.jackrabbit.jcr2spi.state.ItemState.MergeResult)1 NodeState (org.apache.jackrabbit.jcr2spi.state.NodeState)1 PropertyState (org.apache.jackrabbit.jcr2spi.state.PropertyState)1 Name (org.apache.jackrabbit.spi.Name)1 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)1