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);
}
}
}
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;
}
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());
}
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);
}
}
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();
}
Aggregations