use of org.apache.jackrabbit.core.state.NodeReferences 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.NodeReferences in project jackrabbit by apache.
the class InternalVersionManagerImpl method canCheckout.
/**
* {@inheritDoc}
*
* this method currently does no modifications to the persistence and just
* checks if the checkout is valid in respect to a possible activity set on
* the session
*/
public NodeId canCheckout(NodeStateEx state, NodeId activityId) throws RepositoryException {
NodeId baseId = state.getPropertyValue(NameConstants.JCR_BASEVERSION).getNodeId();
if (activityId != null) {
// exist in 'this' workspace
if (stateMgr.hasNodeReferences(activityId)) {
try {
NodeReferences refs = stateMgr.getNodeReferences(activityId);
for (PropertyId id : refs.getReferences()) {
if (!state.hasNode(id.getParentId())) {
throw new ActivityViolationException("Unable to checkout. " + "Activity is already used for the same node in " + "another workspace.");
}
}
} catch (ItemStateException e) {
throw new RepositoryException("Error during checkout.", e);
}
}
// If there is a version in H that is not an eventual predecessor of N but
// whose jcr:activity references A, then the checkout fails with an
// ActivityViolationException
InternalActivityImpl a = (InternalActivityImpl) getItem(activityId);
NodeId historyId = state.getPropertyValue(NameConstants.JCR_VERSIONHISTORY).getNodeId();
InternalVersionHistory history = (InternalVersionHistory) getItem(historyId);
InternalVersion version = a.getLatestVersion(history);
if (version != null) {
InternalVersion baseVersion = (InternalVersion) getItem(baseId);
while (baseVersion != null && !baseVersion.getId().equals(version.getId())) {
baseVersion = baseVersion.getLinearPredecessor();
}
if (baseVersion == null) {
throw new ActivityViolationException("Unable to checkout. " + "Activity is used by another version on a different branch: " + version.getName());
}
}
}
return baseId;
}
use of org.apache.jackrabbit.core.state.NodeReferences in project jackrabbit by apache.
the class VersionItemStateManager method setNodeReferences.
/**
* Sets the
* @param references
* @return
*/
public boolean setNodeReferences(ChangeLog references) {
try {
ChangeLog log = new ChangeLog();
for (NodeReferences source : references.modifiedRefs()) {
// filter out version storage intern ones
NodeReferences target = new NodeReferences(source.getTargetId());
for (PropertyId id : source.getReferences()) {
if (!hasNonVirtualItemState(id.getParentId())) {
target.addReference(id);
}
}
log.modified(target);
}
if (log.hasUpdates()) {
pMgr.store(log);
}
return true;
} catch (ItemStateException e) {
log.error("Error while setting references: " + e.toString());
return false;
}
}
use of org.apache.jackrabbit.core.state.NodeReferences in project jackrabbit by apache.
the class NodeImpl method getReferences.
/**
* {@inheritDoc}
*/
public PropertyIterator getReferences(String name) throws RepositoryException {
// check state of this instance
sanityCheck();
try {
if (stateMgr.hasNodeReferences(getNodeId())) {
NodeReferences refs = stateMgr.getNodeReferences(getNodeId());
// refs.getReferences() returns a list of PropertyId's
List<PropertyId> idList = refs.getReferences();
if (name != null) {
Name qName;
try {
qName = sessionContext.getQName(name);
} catch (NameException e) {
throw new RepositoryException("invalid property name: " + name, e);
}
ArrayList<PropertyId> filteredList = new ArrayList<PropertyId>(idList.size());
for (PropertyId propId : idList) {
if (propId.getName().equals(qName)) {
filteredList.add(propId);
}
}
idList = filteredList;
}
return new LazyItemIterator(sessionContext, idList);
} else {
// there are no references, return empty iterator
return PropertyIteratorAdapter.EMPTY;
}
} catch (ItemStateException e) {
String msg = "Unable to retrieve REFERENCE properties that refer to " + id;
log.debug(msg);
throw new RepositoryException(msg, e);
}
}
use of org.apache.jackrabbit.core.state.NodeReferences in project jackrabbit by apache.
the class InternalVersionManagerBase method internalRemoveActivity.
/**
* Removes the specified activity
*
* @param activity the activity to remove
* @throws javax.jcr.RepositoryException if any other error occurs.
*/
protected void internalRemoveActivity(InternalActivityImpl activity) throws RepositoryException {
WriteOperation operation = startWriteOperation();
try {
// check if the activity has any references in the workspaces
NodeId nodeId = activity.getId();
if (stateMgr.hasNodeReferences(nodeId)) {
NodeReferences refs = stateMgr.getNodeReferences(nodeId);
if (refs.hasReferences()) {
throw new ReferentialIntegrityException("Unable to delete activity. still referenced.");
}
}
// TODO:
// check if the activity is used in anywhere in the version storage
// and reject removal
// remove activity and possible empty parent directories
NodeStateEx act = getNodeStateEx(nodeId);
NodeId parentId = act.getParentId();
Name name = act.getName();
while (parentId != null) {
NodeStateEx parent = getNodeStateEx(parentId);
parent.removeNode(name);
parent.store();
if (parent.getChildNodes().length == 0 && !parentId.equals(activitiesId)) {
name = parent.getName();
parentId = parent.getParentId();
} else {
parentId = null;
}
}
operation.save();
} catch (ItemStateException e) {
log.error("Error while storing: " + e.toString());
} finally {
operation.close();
}
}
Aggregations