Search in sources :

Example 46 with Version

use of javax.jcr.version.Version in project jackrabbit by apache.

the class RestoreTest method testRestoreWithXA.

public void testRestoreWithXA() throws Exception {
    Node n = testRootNode.addNode(nodeName1);
    n.addMixin(mixVersionable);
    testRootNode.save();
    UserTransactionImpl tx = new UserTransactionImpl(superuser);
    tx.begin();
    Version v10 = n.checkin();
    String versionName = v10.getName();
    n.restore(v10, true);
    assertEquals("Wrong version restored", versionName, n.getBaseVersion().getName());
    tx.commit();
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) UserTransactionImpl(org.apache.jackrabbit.core.UserTransactionImpl)

Example 47 with Version

use of javax.jcr.version.Version in project jackrabbit by apache.

the class CheckinRemoveVersionTest method testCheckinRemoveVersionWithXA.

public void testCheckinRemoveVersionWithXA() throws Exception {
    Node n = testRootNode.addNode(nodeName1);
    n.addMixin(mixVersionable);
    testRootNode.save();
    UserTransactionImpl tx = new UserTransactionImpl(superuser);
    tx.begin();
    try {
        Version v10 = n.checkin();
        assertTrue("Version.getReferences() must return base version", v10.getReferences().hasNext());
        try {
            n.getVersionHistory().removeVersion(v10.getName());
            fail("VersionHistory.removeVersion() must throw ReferentialIntegrityException when" + " version is still referenced.");
        } catch (ReferentialIntegrityException e) {
        // expected
        }
    } finally {
        tx.rollback();
    }
}
Also used : Version(javax.jcr.version.Version) ReferentialIntegrityException(javax.jcr.ReferentialIntegrityException) Node(javax.jcr.Node) UserTransactionImpl(org.apache.jackrabbit.core.UserTransactionImpl)

Example 48 with Version

use of javax.jcr.version.Version in project jackrabbit by apache.

the class NodeImpl method restoreByLabel.

/**
     * @see Node#restoreByLabel(String, boolean)
     */
public void restoreByLabel(String versionLabel, boolean removeExisting) throws VersionException, ItemExistsException, UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException {
    checkSessionHasPendingChanges();
    // check for version-enabled and lock are performed with subsequent calls.
    Version v = getVersionHistory().getVersionByLabel(versionLabel);
    if (v == null) {
        throw new VersionException("No version for label " + versionLabel + " found.");
    }
    restore(this, null, v, removeExisting);
}
Also used : Version(javax.jcr.version.Version) VersionException(javax.jcr.version.VersionException)

Example 49 with Version

use of javax.jcr.version.Version in project jackrabbit by apache.

the class NodeImpl method checkpoint.

Version checkpoint() throws RepositoryException {
    checkIsVersionable();
    checkHasPendingChanges();
    checkIsLocked();
    if (!isCheckedOut()) {
        checkout();
        return getBaseVersion();
    } else {
        NodeEntry newVersion;
        if (session.isSupportedOption(Repository.OPTION_ACTIVITIES_SUPPORTED)) {
            NodeImpl activity = (NodeImpl) session.getWorkspace().getVersionManager().getActivity();
            NodeId activityId = (activity == null) ? null : activity.getNodeState().getNodeId();
            newVersion = session.getVersionStateManager().checkpoint(getNodeState(), activityId);
        } else {
            newVersion = session.getVersionStateManager().checkpoint(getNodeState());
        }
        return (Version) getItemManager().getItem(newVersion);
    }
}
Also used : NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) Version(javax.jcr.version.Version) NodeId(org.apache.jackrabbit.spi.NodeId)

Example 50 with Version

use of javax.jcr.version.Version in project jackrabbit by apache.

the class ConcurrentVersioningWithTransactionsTest method testConcurrentRestoreInTransaction.

public void testConcurrentRestoreInTransaction() throws RepositoryException {
    runTask(new Task() {

        public void execute(Session session, Node test) throws RepositoryException {
            int i = 0;
            try {
                Node n = test.addNode("test");
                n.addMixin(mixVersionable);
                session.save();
                // create 3 version
                List versions = new ArrayList();
                for (i = 0; i < 3; i++) {
                    n.checkout();
                    versions.add(n.checkin());
                }
                // do random restores
                Random rand = new Random();
                for (i = 0; i < NUM_OPERATIONS / CONCURRENCY; i++) {
                    Version v = (Version) versions.get(rand.nextInt(versions.size()));
                    n.restore(v, true);
                }
                n.checkout();
            } catch (Exception e) {
                final String threadName = Thread.currentThread().getName();
                final Throwable deepCause = getLevel2Cause(e);
                if (deepCause != null && deepCause instanceof StaleItemStateException) {
                // ignore
                } else {
                    throw new RepositoryException(threadName + ", i=" + i + ":" + e.getClass().getName(), e);
                }
            }
        }
    }, CONCURRENCY);
}
Also used : Random(java.util.Random) Version(javax.jcr.version.Version) StaleItemStateException(org.apache.jackrabbit.core.state.StaleItemStateException) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) List(java.util.List) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) StaleItemStateException(org.apache.jackrabbit.core.state.StaleItemStateException) InvalidItemStateException(javax.jcr.InvalidItemStateException) Session(javax.jcr.Session)

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