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