Search in sources :

Example 1 with Version

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());
    }
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) Version(javax.jcr.version.Version) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) NoSuchElementException(java.util.NoSuchElementException)

Example 2 with Version

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));
}
Also used : UserTransaction(javax.transaction.UserTransaction) EventResult(org.apache.jackrabbit.test.api.observation.EventResult) HashSet(java.util.HashSet) Set(java.util.Set) Version(javax.jcr.version.Version) Node(javax.jcr.Node) UserTransactionImpl(org.apache.jackrabbit.core.UserTransactionImpl) Event(javax.jcr.observation.Event) HashSet(java.util.HashSet)

Example 3 with Version

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()));
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Version(javax.jcr.version.Version) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager)

Example 4 with Version

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);
}
Also used : Version(javax.jcr.version.Version) RemoteVersion(org.apache.jackrabbit.rmi.remote.RemoteVersion) RemoteNode(org.apache.jackrabbit.rmi.remote.RemoteNode) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

Example 5 with Version

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);
    }
}
Also used : Version(javax.jcr.version.Version) RemoteVersion(org.apache.jackrabbit.rmi.remote.RemoteVersion) RepositoryException(javax.jcr.RepositoryException)

Aggregations

Version (javax.jcr.version.Version)265 Node (javax.jcr.Node)155 VersionManager (javax.jcr.version.VersionManager)65 RepositoryException (javax.jcr.RepositoryException)45 VersionHistory (javax.jcr.version.VersionHistory)29 VersionException (javax.jcr.version.VersionException)25 NodeIterator (javax.jcr.NodeIterator)23 Session (javax.jcr.Session)19 Test (org.junit.Test)19 Property (javax.jcr.Property)16 VersionIterator (javax.jcr.version.VersionIterator)16 Value (javax.jcr.Value)14 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)14 ItemExistsException (javax.jcr.ItemExistsException)13 HashSet (java.util.HashSet)12 NodeDefinition (javax.jcr.nodetype.NodeDefinition)12 ArrayList (java.util.ArrayList)11 Set (java.util.Set)7 DavException (org.apache.jackrabbit.webdav.DavException)7 UserTransaction (javax.transaction.UserTransaction)6