use of javax.jcr.version.Version in project jackrabbit by apache.
the class VersionIteratorImpl method nextVersion.
/**
* {@inheritDoc}
*/
public Version nextVersion() {
if (versions.isEmpty()) {
throw new NoSuchElementException();
}
NodeId id = versions.removeFirst();
pos++;
try {
return (Version) session.getNodeById(id);
} catch (RepositoryException e) {
throw new ConcurrentModificationException("Unable to provide element: " + e.toString());
}
}
use of javax.jcr.version.Version in project jackrabbit by apache.
the class VersionEventsTest method testXACheckin.
/**
* Test if checkin of a node in an XA transaction creates two add node
* events: one for the version and one for the frozen node.
*/
public void testXACheckin() throws Exception {
// create versionable node
Node n1 = testRootNode.addNode(nodeName1);
n1.addMixin(mixVersionable);
testRootNode.save();
EventResult listener = new EventResult(log);
addEventListener(listener, Event.NODE_ADDED);
// use a transaction
UserTransaction utx = new UserTransactionImpl(superuser);
// start transaction
utx.begin();
Version v = n1.checkin();
// commit transaction
utx.commit();
removeEventListener(listener);
Event[] events = listener.getEvents(1000);
Set paths = new HashSet();
for (int i = 0; i < events.length; i++) {
paths.add(events[i].getPath());
}
assertTrue("missing 'node added' event: " + v.getPath(), paths.contains(v.getPath()));
String frozenPath = v.getPath() + "/" + jcrFrozenNode;
assertTrue("missing 'node added' event: " + frozenPath, paths.contains(frozenPath));
}
use of javax.jcr.version.Version in project jackrabbit by apache.
the class DerefTest method testDerefToVersionNode.
/**
* Checks if jcr:deref works when dereferencing into the version storage.
*/
public void testDerefToVersionNode() throws RepositoryException {
Node referenced = testRootNode.addNode(nodeName1);
referenced.addMixin(mixVersionable);
testRootNode.save();
Version version = referenced.checkin();
Node referencedVersionNode = version.getNode(jcrFrozenNode);
Node referencer = testRootNode.addNode(nodeName2);
referencer.setProperty(propertyName1, referencedVersionNode);
testRootNode.save();
String query = "/" + testRoot + "/*[@" + propertyName1 + "]/jcr:deref(@" + propertyName1 + ",'*')";
QueryManager qm = superuser.getWorkspace().getQueryManager();
Query q = qm.createQuery(query, Query.XPATH);
QueryResult qr = q.execute();
NodeIterator ni = qr.getNodes();
assertEquals("Must find one result in query", 1, ni.getSize());
while (ni.hasNext()) {
Node node = (Node) ni.next();
assertTrue(node.getProperty("jcr:frozenUuid").getString().equals(referenced.getUUID()));
}
}
use of javax.jcr.version.Version in project jackrabbit by apache.
the class ServerNode method getVersionByUUID.
//---------- Implementation helper -----------------------------------------
/**
* Returns the {@link Version} instance for the given UUID.
*
* @param versionUUID The UUID of the version.
*
* @return The version node.
*
* @throws RepositoryException if an error occurrs accessing the version
* node or if the UUID does not denote a version.
*/
protected Version getVersionByUUID(String versionUUID) throws RepositoryException {
// get the version node by its UUID from the version history's session
Session session = node.getSession();
Node versionNode = session.getNodeByUUID(versionUUID);
// the correct type).
if (versionNode instanceof Version) {
return (Version) versionNode;
}
// otherwise fail
throw new RepositoryException("Cannot find version " + versionUUID);
}
use of javax.jcr.version.Version in project jackrabbit by apache.
the class ServerVersionManager method restore.
@Override
public void restore(String[] versionIdentifiers, boolean removeExisting) throws RepositoryException, RemoteException {
try {
Version[] versions = new Version[versionIdentifiers.length];
for (int i = 0; i < versions.length; i++) {
Version version = (Version) session.getNodeByIdentifier(versionIdentifiers[i]);
versions[i] = version;
}
manager.restore(versions, removeExisting);
} catch (RepositoryException e) {
throw getRepositoryException(e);
}
}
Aggregations