Search in sources :

Example 1 with ItemState

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

the class HierarchyEntryImpl method internalRemove.

// --------------------------------------------------------------------------
/**
 * @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 {
        // unresolved
        if (!staleParent && parent != null) {
            parent.internalRemoveChildEntry(this);
        }
    }
}
Also used : ItemState(org.apache.jackrabbit.jcr2spi.state.ItemState)

Example 2 with ItemState

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

the class ItemManagerImpl method getItem.

/**
 * @see ItemManager#getItem(HierarchyEntry)
 */
public Item getItem(HierarchyEntry hierarchyEntry) throws ItemNotFoundException, RepositoryException {
    session.checkIsAlive();
    ItemState state = hierarchyEntry.getItemState();
    if (!state.isValid()) {
        throw new ItemNotFoundException(LogUtil.safeGetJCRPath(state, session.getPathResolver()));
    }
    // first try to access item from cache
    Item item = itemCache.getItem(state);
    // not yet in cache, need to create instance
    if (item == null) {
        // create instance of item
        if (hierarchyEntry.denotesNode()) {
            item = createNodeInstance((NodeState) state);
        } else {
            item = createPropertyInstance((PropertyState) state);
        }
    }
    return item;
}
Also used : Item(javax.jcr.Item) NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) ItemState(org.apache.jackrabbit.jcr2spi.state.ItemState) ItemNotFoundException(javax.jcr.ItemNotFoundException) PropertyState(org.apache.jackrabbit.jcr2spi.state.PropertyState)

Example 3 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 4 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)

Example 5 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)

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