use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class XMLPersistenceManager method exists.
/**
* {@inheritDoc}
*/
public synchronized boolean exists(PropertyId id) throws ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
try {
String propFilePath = buildPropFilePath(id);
FileSystemResource propFile = new FileSystemResource(itemStateFS, propFilePath);
return propFile.exists();
} catch (FileSystemException fse) {
String msg = "failed to check existence of item state: " + id;
log.error(msg, fse);
throw new ItemStateException(msg, fse);
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class XMLPersistenceManager method loadReferencesTo.
/**
* {@inheritDoc}
*/
public synchronized NodeReferences loadReferencesTo(NodeId id) throws NoSuchItemStateException, ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
Exception e = null;
String refsFilePath = buildNodeReferencesFilePath(id);
try {
if (!itemStateFS.isFile(refsFilePath)) {
throw new NoSuchItemStateException(id.toString());
}
InputStream in = itemStateFS.getInputStream(refsFilePath);
try {
DOMWalker walker = new DOMWalker(in);
NodeReferences refs = new NodeReferences(id);
readState(walker, refs);
return refs;
} finally {
in.close();
}
} catch (IOException ioe) {
e = ioe;
// fall through
} catch (FileSystemException fse) {
e = fse;
// fall through
}
String msg = "failed to load references: " + id;
log.debug(msg);
throw new ItemStateException(msg, e);
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class VersionManagerImplRestore method restoreByLabel.
/**
* @param state the state to restore
* @param versionLabel the name of the version to restore
* @param removeExisting remove existing flag
* @throws RepositoryException if an error occurs
*
* @see VersionManager#restoreByLabel(String, String, boolean)
*/
protected void restoreByLabel(NodeStateEx state, Name versionLabel, boolean removeExisting) throws RepositoryException {
checkVersionable(state);
InternalVersion v = getVersionHistory(state).getVersionByLabel(versionLabel);
if (v == null) {
String msg = "No version for label " + versionLabel + " found.";
log.error(msg);
throw new VersionException(msg);
}
WriteOperation ops = startWriteOperation();
try {
internalRestore(state, v, new LabelVersionSelector(versionLabel), removeExisting);
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 VersionManagerImplRestore method restore.
/**
* Restores the <code>version</code> below the <code>parent</code> node
* using the indicated <code>name</code>
*
* @param parent parent node
* @param name desired name
* @param v version to restore
* @param removeExisting remove exiting flag
* @throws RepositoryException if an error occurs
*/
protected void restore(NodeStateEx parent, Name name, InternalVersion v, boolean removeExisting) throws RepositoryException {
// check if versionable node exists
InternalFrozenNode fn = v.getFrozenNode();
if (stateMgr.hasItemState(fn.getFrozenId())) {
if (removeExisting) {
NodeStateEx existing = parent.getNode(fn.getFrozenId());
checkVersionable(existing);
// move versionable node below this one using the given "name"
WriteOperation ops = startWriteOperation();
try {
NodeStateEx exParent = existing.getParent();
NodeStateEx state = parent.moveFrom(existing, name, false);
exParent.store();
parent.store();
// and restore it
internalRestore(state, v, new DateVersionSelector(v.getCreated()), removeExisting);
ops.save();
} catch (ItemStateException e) {
throw new RepositoryException(e);
} finally {
ops.close();
}
} else {
String msg = "Unable to restore version. Versionable node already exists.";
log.error(msg);
throw new ItemExistsException(msg);
}
} else {
WriteOperation ops = startWriteOperation();
try {
// create new node below parent
NodeStateEx state = parent.addNode(name, fn.getFrozenPrimaryType(), fn.getFrozenId());
state.setMixins(fn.getFrozenMixinTypes());
internalRestore(state, v, new DateVersionSelector(v.getCreated()), removeExisting);
parent.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 VersionManagerImplRestore method restore.
/**
* @param state the state to restore
* @param v the version to restore
* @param removeExisting remove existing flag
* @throws RepositoryException if an error occurs
*
* @see javax.jcr.version.VersionManager#restore(String, Version, boolean)
*/
protected void restore(NodeStateEx state, InternalVersion v, boolean removeExisting) throws RepositoryException {
checkVersionable(state);
// check if 'own' version
if (!v.getVersionHistory().equals(getVersionHistory(state))) {
String msg = "Unable to restore version. Not same version history.";
log.error(msg);
throw new VersionException(msg);
}
WriteOperation ops = startWriteOperation();
try {
internalRestore(state, v, new DateVersionSelector(v.getCreated()), removeExisting);
ops.save();
} catch (ItemStateException e) {
throw new RepositoryException(e);
} finally {
ops.close();
}
}
Aggregations