use of org.apache.jackrabbit.core.state.ItemState in project jackrabbit by apache.
the class ItemSaveOperation method removeTransientItems.
/**
* walk through list of transient items marked 'removed' and
* definitively remove each one
*/
private void removeTransientItems(SessionItemStateManager sism, Iterable<ItemState> states) throws StaleItemStateException {
for (ItemState transientState : states) {
ItemState persistentState = transientState.getOverlayedState();
// permanently invalidate all Item instances wrapping it
assert persistentState != null;
if (transientState.getModCount() != persistentState.getModCount()) {
throw new StaleItemStateException(transientState.getId() + " has been modified externally");
}
sism.destroy(persistentState);
}
}
use of org.apache.jackrabbit.core.state.ItemState 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);
}
}
}
}
use of org.apache.jackrabbit.core.state.ItemState in project jackrabbit by apache.
the class ItemSaveOperation method initVersionHistories.
/**
* Initialises the version history of all new nodes of node type
* <code>mix:versionable</code>.
*
* @param states
* @return true if this call generated new transient state; otherwise false
* @throws RepositoryException
*/
private boolean initVersionHistories(SessionContext context, Iterable<ItemState> states) throws RepositoryException {
SessionImpl session = context.getSessionImpl();
ItemManager itemMgr = context.getItemManager();
// walk through list of transient items and search for new versionable nodes
boolean createdTransientState = false;
for (ItemState itemState : states) {
if (itemState.isNode()) {
NodeState nodeState = (NodeState) itemState;
EffectiveNodeType nt = getEffectiveNodeType(context.getRepositoryContext().getNodeTypeRegistry(), nodeState);
if (nt.includesNodeType(NameConstants.MIX_VERSIONABLE)) {
if (!nodeState.hasPropertyName(NameConstants.JCR_VERSIONHISTORY)) {
NodeImpl node = (NodeImpl) itemMgr.getItem(itemState.getId(), false);
InternalVersionManager vMgr = session.getInternalVersionManager();
/**
* check if there's already a version history for that
* node; this would e.g. be the case if a versionable
* node had been exported, removed and re-imported with
* either IMPORT_UUID_COLLISION_REMOVE_EXISTING or
* IMPORT_UUID_COLLISION_REPLACE_EXISTING;
* otherwise create a new version history
*/
VersionHistoryInfo history = vMgr.getVersionHistory(session, nodeState, null);
InternalValue historyId = InternalValue.create(history.getVersionHistoryId());
InternalValue versionId = InternalValue.create(history.getRootVersionId());
node.internalSetProperty(NameConstants.JCR_VERSIONHISTORY, historyId);
node.internalSetProperty(NameConstants.JCR_BASEVERSION, versionId);
node.internalSetProperty(NameConstants.JCR_ISCHECKEDOUT, InternalValue.create(true));
node.internalSetProperty(NameConstants.JCR_PREDECESSORS, new InternalValue[] { versionId });
createdTransientState = true;
}
} else if (nt.includesNodeType(NameConstants.MIX_SIMPLE_VERSIONABLE)) {
// we need to check the version manager for an existing
// version history, since simple versioning does not
// expose it's reference in a property
InternalVersionManager vMgr = session.getInternalVersionManager();
vMgr.getVersionHistory(session, nodeState, null);
// create isCheckedOutProperty if not already exists
NodeImpl node = (NodeImpl) itemMgr.getItem(itemState.getId(), false);
if (!nodeState.hasPropertyName(NameConstants.JCR_ISCHECKEDOUT)) {
node.internalSetProperty(NameConstants.JCR_ISCHECKEDOUT, InternalValue.create(true));
createdTransientState = true;
}
}
}
}
return createdTransientState;
}
use of org.apache.jackrabbit.core.state.ItemState in project jackrabbit by apache.
the class ItemSaveOperation method processShareableNodes.
/**
* Process all items given in iterator and check whether <code>mix:shareable</code>
* or (some derived node type) has been added or removed:
* <ul>
* <li>If the mixin <code>mix:shareable</code> (or some derived node type),
* then initialize the shared set inside the state.</li>
* <li>If the mixin <code>mix:shareable</code> (or some derived node type)
* has been removed, throw.</li>
* </ul>
*/
private void processShareableNodes(NodeTypeRegistry registry, Iterable<ItemState> states) throws RepositoryException {
for (ItemState is : states) {
if (is.isNode()) {
NodeState ns = (NodeState) is;
boolean wasShareable = false;
if (ns.hasOverlayedState()) {
NodeState old = (NodeState) ns.getOverlayedState();
EffectiveNodeType ntOld = getEffectiveNodeType(registry, old);
wasShareable = ntOld.includesNodeType(NameConstants.MIX_SHAREABLE);
}
EffectiveNodeType ntNew = getEffectiveNodeType(registry, ns);
boolean isShareable = ntNew.includesNodeType(NameConstants.MIX_SHAREABLE);
if (!wasShareable && isShareable) {
// mix:shareable has been added
ns.addShare(ns.getParentId());
} else if (wasShareable && !isShareable) {
// mix:shareable has been removed: not supported
String msg = "Removing mix:shareable is not supported.";
log.debug(msg);
throw new UnsupportedRepositoryOperationException(msg);
}
}
}
}
use of org.apache.jackrabbit.core.state.ItemState in project jackrabbit by apache.
the class PropertyImpl method getPropertyState.
/**
* Checks that this property is valid (session not closed, property not
* removed, etc.) and returns the underlying property state if all is OK.
*
* @return property state
* @throws RepositoryException if the property is not valid
*/
private PropertyState getPropertyState() throws RepositoryException {
// JCR-1272: Need to get the state reference now so it
// doesn't get invalidated after the sanity check
ItemState state = getItemState();
sanityCheck();
return (PropertyState) state;
}
Aggregations