use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class VersionManagerImplConfig method createConfiguration.
/**
* Creates a new configuration node.
* <p>
* The nt:confguration is stored within the nt:configurations storage using
* the nodeid of the configuration root (rootId) as path.
*
* @param state the node of the workspace configuration
* @return the node id of the created configuration
* @throws RepositoryException if an error occurs
*/
protected NodeId createConfiguration(NodeStateEx state) throws RepositoryException {
WriteOperation ops = startWriteOperation();
try {
NodeId configId = internalCreateConfiguration(state.getNodeId(), null, null);
// set configuration reference in state
state.setPropertyValue(NameConstants.JCR_CONFIGURATION, InternalValue.create(configId));
state.store();
ops.save();
return configId;
} catch (ItemStateException e) {
throw new RepositoryException(e);
} finally {
ops.close();
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class VersionManagerImplConfig method restore.
/**
* Restores the versions recorded in the given baseline below the specified
* path.
* @param parent the parent state
* @param name the name of the new node (tree)
* @param baseline the baseline that recorded the versions
* @return the node id of the configuration
* @throws RepositoryException if an error occurs
*/
protected NodeId restore(NodeStateEx parent, Name name, InternalBaseline baseline) throws RepositoryException {
// check if nt:configuration exists
NodeId configId = baseline.getConfigurationId();
NodeId rootId = baseline.getConfigurationRootId();
if (stateMgr.hasItemState(rootId)) {
NodeStateEx existing = parent.getNode(rootId);
String msg = "Configuration for the given baseline already exists at: " + safeGetJCRPath(existing);
log.error(msg);
throw new UnsupportedRepositoryOperationException(msg);
}
// find version for configuration root
VersionSet versions = baseline.getBaseVersions();
InternalVersion rootVersion = null;
for (InternalVersion v : versions.versions().values()) {
if (v.getVersionHistory().getVersionableId().equals(rootId)) {
rootVersion = v;
break;
}
}
if (rootVersion == null) {
String msg = "Internal error: supplied baseline has no version for its configuration root.";
log.error(msg);
throw new RepositoryException(msg);
}
// create new node below parent
WriteOperation ops = startWriteOperation();
try {
if (!stateMgr.hasItemState(configId)) {
// create if nt:configuration node is not exists
internalCreateConfiguration(rootId, configId, baseline.getId());
}
NodeStateEx config = parent.getNode(configId);
// create the root node so that the restore works
InternalFrozenNode fn = rootVersion.getFrozenNode();
NodeStateEx state = parent.addNode(name, fn.getFrozenPrimaryType(), fn.getFrozenId());
state.setMixins(fn.getFrozenMixinTypes());
parent.store();
// and finally restore the config and root
internalRestore(config, baseline, null, false);
ops.save();
return configId;
} catch (ItemStateException e) {
throw new RepositoryException(e);
} finally {
ops.close();
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class VersionManagerImplMerge method finishMerge.
/**
* Perform {@link Node#cancelMerge(Version)} or {@link Node#doneMerge(Version)}
* depending on the value of <code>cancel</code>.
* @param state state to finish
* @param version version
* @param cancel flag inidicates if this is a cancel operation
* @throws RepositoryException if an error occurs
*/
protected void finishMerge(NodeStateEx state, Version version, boolean cancel) throws RepositoryException {
// check versionable
if (!checkVersionable(state)) {
throw new UnsupportedRepositoryOperationException("Node not full versionable: " + safeGetJCRPath(state));
}
// check if version is in mergeFailed list
Set<NodeId> failed = getMergeFailed(state);
NodeId versionId = ((VersionImpl) version).getNodeId();
if (!failed.remove(versionId)) {
String msg = "Unable to finish merge. Specified version is not in" + " jcr:mergeFailed property: " + safeGetJCRPath(state);
log.error(msg);
throw new VersionException(msg);
}
WriteOperation ops = startWriteOperation();
try {
// remove version from mergeFailed list
setMergeFailed(state, failed);
if (!cancel) {
// add version to jcr:predecessors list
InternalValue[] vals = state.getPropertyValues(NameConstants.JCR_PREDECESSORS);
InternalValue[] v = new InternalValue[vals.length + 1];
for (int i = 0; i < vals.length; i++) {
v[i] = InternalValue.create(vals[i].getNodeId());
}
v[vals.length] = InternalValue.create(versionId);
state.setPropertyValues(NameConstants.JCR_PREDECESSORS, PropertyType.REFERENCE, v, true);
}
state.store();
ops.save();
} catch (ItemStateException e) {
throw new RepositoryException(e);
} finally {
ops.close();
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class NodeStateEx method removeNode.
/**
* removes the child node with the given child node entry
*
* @param entry entry to remove
* @return <code>true</code> if the child was removed.
* @throws RepositoryException if an error occurs
*/
public boolean removeNode(ChildNodeEntry entry) throws RepositoryException {
try {
if (entry == null) {
return false;
} else {
removeNode(entry.getId());
nodeState.removeChildNodeEntry(entry.getId());
nodeState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
return true;
}
} catch (ItemStateException e) {
throw new RepositoryException(e);
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class NodeStateEx method reload.
/**
* reloads the persistent state recursively
*
* @throws RepositoryException if an error occurs
*/
public void reload() throws RepositoryException {
try {
reload(nodeState);
// refetch node state if discarded
nodeState = (NodeState) stateMgr.getItemState(nodeState.getNodeId());
} catch (ItemStateException e) {
throw new RepositoryException(e);
}
}
Aggregations