use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class EventState method nodeMovedWithInfo.
/**
* Creates a new {@link javax.jcr.observation.Event} of type
* <code>NODE_MOVED</code>. The parent node associated with this event type
* is the parent node of the destination of the move!
*
* @param parentId the id of the parent node associated with this
* <code>EventState</code>.
* @param destPath the path of the destination of the move.
* @param childId the id of the child node associated with this event.
* @param srcPath the path of the source of the move.
* @param nodeType the node type of the parent node.
* @param mixins mixins assigned to the parent node.
* @param session the session that removed the node.
* @param external flag indicating whether this is an external event
* @return an <code>EventState</code> instance.
* @throws ItemStateException if <code>destPath</code> does not have a
* parent.
*/
public static EventState nodeMovedWithInfo(NodeId parentId, Path destPath, NodeId childId, Path srcPath, Name nodeType, Set<Name> mixins, Session session, boolean external) throws ItemStateException {
try {
EventState es = nodeMoved(parentId, destPath.getAncestor(1), childId, destPath, nodeType, mixins, session, external);
Map<String, InternalValue> info = new HashMap<String, InternalValue>();
info.put(SRC_ABS_PATH, InternalValue.create(srcPath));
info.put(DEST_ABS_PATH, InternalValue.create(destPath));
es.setInfo(info);
return es;
} catch (RepositoryException e) {
// should never happen actually
String msg = "Unable to resolve parent for path: " + destPath;
log.error(msg);
throw new ItemStateException(msg, e);
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class PersistenceCopier method copy.
/**
* Recursively copies the identified node and all its descendants.
* Explicitly excluded nodes and nodes that have already been copied
* are automatically skipped.
*
* @param id identifier of the node to be copied
* @throws RepositoryException if the copy operation fails
*/
public void copy(NodeId id) throws RepositoryException {
if (!exclude.contains(id)) {
try {
NodeState node = source.load(id);
for (ChildNodeEntry entry : node.getChildNodeEntries()) {
copy(entry.getId());
}
copy(node);
exclude.add(id);
} catch (ItemStateException e) {
throw new RepositoryException("Unable to copy " + id, e);
}
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class ConsistencyCheckerImpl method repair.
/**
* Repair any errors found during a {@link #check}. Should be run after a {#check} and
* (if needed) {@link #doubleCheckErrors}.
*
* @throws RepositoryException
*/
public void repair() throws RepositoryException {
checkLostNFound();
bundles = new HashMap<NodeId, NodePropBundle>();
if (hasRepairableErrors()) {
boolean successful = false;
final CheckerUpdate update = new CheckerUpdate();
try {
eventChannel.updateCreated(update);
for (ConsistencyCheckerError error : errors) {
if (error.isRepairable()) {
try {
error.repair(update.getChanges());
info(null, "Repairing " + error);
} catch (ItemStateException e) {
error(null, "Failed to repair error: " + error, e);
}
}
}
final ChangeLog changes = update.getChanges();
if (changes.hasUpdates()) {
eventChannel.updatePrepared(update);
for (NodePropBundle bundle : bundles.values()) {
storeBundle(bundle);
}
update.setAttribute(ATTRIBUTE_UPDATE_SIZE, changes.getUpdateSize());
successful = true;
}
} catch (ClusterException e) {
throw new RepositoryException("Cannot create update", e);
} finally {
if (successful) {
eventChannel.updateCommitted(update, "checker@");
} else {
eventChannel.updateCancelled(update);
}
}
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class BundleFsPersistenceManager method storeBundle.
/**
* {@inheritDoc}
*/
protected synchronized void storeBundle(NodePropBundle bundle) throws ItemStateException {
try {
StringBuffer buf = buildNodeFolderPath(null, bundle.getId());
buf.append('.');
buf.append(NODEFILENAME);
String fileName = buf.toString();
String dir = fileName.substring(0, fileName.lastIndexOf(FileSystem.SEPARATOR_CHAR));
if (!itemFs.exists(dir)) {
itemFs.createFolder(dir);
}
OutputStream out = itemFs.getOutputStream(fileName);
try {
binding.writeBundle(out, bundle);
} finally {
out.close();
}
} catch (Exception e) {
String msg = "failed to write bundle: " + bundle.getId();
BundleFsPersistenceManager.log.error(msg, e);
throw new ItemStateException(msg, e);
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class BundleFsPersistenceManager method destroyBundle.
/**
* {@inheritDoc}
*/
protected synchronized void destroyBundle(NodePropBundle bundle) throws ItemStateException {
try {
StringBuffer buf = buildNodeFilePath(null, bundle.getId());
itemFs.deleteFile(buf.toString());
} catch (Exception e) {
if (e instanceof NoSuchItemStateException) {
throw (NoSuchItemStateException) e;
}
String msg = "failed to delete bundle: " + bundle.getId();
BundleFsPersistenceManager.log.error(msg, e);
throw new ItemStateException(msg, e);
}
}
Aggregations