use of org.apache.jackrabbit.core.state.SessionItemStateManager in project jackrabbit by apache.
the class ItemManager method stateDiscarded.
/**
* {@inheritDoc}
*/
public void stateDiscarded(ItemState discarded) {
ItemData data = retrieveItem(discarded.getId());
if (data != null && data.getState() == discarded) {
if (discarded.isTransient()) {
switch(discarded.getStatus()) {
/**
* persistent item that has been transiently removed
*/
case ItemState.STATUS_EXISTING_REMOVED:
case ItemState.STATUS_EXISTING_MODIFIED:
ItemState persistentState = discarded.getOverlayedState();
// the state is a transient wrapper for the underlying
// persistent state, therefore restore the persistent state
// and resurrect this item instance if necessary
SessionItemStateManager stateMgr = sessionContext.getItemStateManager();
stateMgr.disconnectTransientItemState(discarded);
data.setState(persistentState);
return;
/**
* persistent item that has been transiently modified or
* removed and the underlying persistent state has been
* externally destroyed since the transient
* modification/removal.
*/
case ItemState.STATUS_STALE_DESTROYED:
/**
* first notify the listeners that this instance has been
* permanently invalidated
*/
itemDestroyed(discarded.getId(), data);
// now set state of this instance to 'destroyed'
data.setStatus(ItemImpl.STATUS_DESTROYED);
data.setState(null);
return;
/**
* new item that has been transiently added
*/
case ItemState.STATUS_NEW:
/**
* first notify the listeners that this instance has been
* permanently invalidated
*/
itemDestroyed(discarded.getId(), data);
// now set state of this instance to 'destroyed'
// finally dispose state
data.setStatus(ItemImpl.STATUS_DESTROYED);
data.setState(null);
return;
}
}
/**
* first notify the listeners that this instance has been
* invalidated
*/
itemInvalidated(discarded.getId(), data);
// now render this instance 'invalid'
data.setStatus(ItemImpl.STATUS_INVALIDATED);
}
}
use of org.apache.jackrabbit.core.state.SessionItemStateManager in project jackrabbit by apache.
the class ItemSaveOperation method restoreTransientItems.
/**
* walk through list of transient states and re-apply transient changes
*/
private void restoreTransientItems(SessionContext context, Iterable<ItemState> items) {
ItemManager itemMgr = context.getItemManager();
SessionItemStateManager stateMgr = context.getItemStateManager();
for (ItemState itemState : items) {
ItemId id = itemState.getId();
ItemImpl item;
try {
if (stateMgr.isItemStateInAttic(id)) {
// If an item has been removed and then again created, the
// item is lost after persistTransientItems() and the
// TransientItemStateManager will bark because of a deleted
// state in its attic. We therefore have to forge a new item
// instance ourself.
item = itemMgr.createItemInstance(itemState);
itemState.setStatus(ItemState.STATUS_NEW);
} else {
try {
item = itemMgr.getItem(id, false);
} catch (ItemNotFoundException infe) {
// itemState probably represents a 'new' item and the
// ItemImpl instance wrapping it has already been gc'ed;
// we have to re-create the ItemImpl instance
item = itemMgr.createItemInstance(itemState);
itemState.setStatus(ItemState.STATUS_NEW);
}
}
// for persistent nodes undo effect of item.makePersistent()
if (item.isNode()) {
NodeImpl node = (NodeImpl) item;
node.restoreTransient((NodeState) itemState);
} else {
PropertyImpl prop = (PropertyImpl) item;
prop.restoreTransient((PropertyState) itemState);
}
} catch (RepositoryException re) {
// something went wrong, log exception and carry on
String msg = itemMgr.safeGetJCRPath(id) + ": failed to restore transient state";
if (log.isDebugEnabled()) {
log.warn(msg, re);
} else {
log.warn(msg);
}
}
}
}
Aggregations