Search in sources :

Example 11 with UserTransactionImpl

use of org.apache.jackrabbit.core.UserTransactionImpl in project jackrabbit by apache.

the class RemoveVersionTest method testRemoveVersionAndCheckinXA_JCR2.

/**
     * Removes a version in 1 transaction and tries to commit afterwards the
     * versionable node using a 2nd transaction. Uses the JCR2.0 API.
     *
     * Tests error reported in JCR-2613
     * 
     * @throws Exception if an error occurs
     */
public void testRemoveVersionAndCheckinXA_JCR2() throws Exception {
    UserTransaction tx = new UserTransactionImpl(superuser);
    tx.begin();
    Node n = testRootNode.addNode(nodeName1);
    n.addMixin(mixVersionable);
    superuser.save();
    // create two versions
    String path = n.getPath();
    String v1 = superuser.getWorkspace().getVersionManager().checkpoint(path).getName();
    String v2 = superuser.getWorkspace().getVersionManager().checkpoint(path).getName();
    tx.commit();
    tx = new UserTransactionImpl(superuser);
    tx.begin();
    // remove one version
    superuser.getWorkspace().getVersionManager().getVersionHistory(path).removeVersion(v1);
    tx.commit();
    // new session
    Session session = getHelper().getSuperuserSession();
    tx = new UserTransactionImpl(session);
    tx.begin();
    session.getWorkspace().getVersionManager().checkin(path);
    tx.commit();
}
Also used : UserTransaction(javax.transaction.UserTransaction) Node(javax.jcr.Node) UserTransactionImpl(org.apache.jackrabbit.core.UserTransactionImpl) Session(javax.jcr.Session)

Example 12 with UserTransactionImpl

use of org.apache.jackrabbit.core.UserTransactionImpl in project jackrabbit by apache.

the class ConcurrentLockingWithTransactionsTest method testConcurrentRefreshInTransaction.

public void testConcurrentRefreshInTransaction() 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(mixLockable);
                session.save();
                for (i = 0; i < NUM_OPERATIONS / CONCURRENCY; i++) {
                    Lock lock = n.lock(false, true);
                    final UserTransaction utx = new UserTransactionImpl(test.getSession());
                    utx.begin();
                    lock.refresh();
                    utx.commit();
                    n.unlock();
                }
            } 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 : UserTransaction(javax.transaction.UserTransaction) StaleItemStateException(org.apache.jackrabbit.core.state.StaleItemStateException) Node(javax.jcr.Node) UserTransactionImpl(org.apache.jackrabbit.core.UserTransactionImpl) RepositoryException(javax.jcr.RepositoryException) RepositoryException(javax.jcr.RepositoryException) StaleItemStateException(org.apache.jackrabbit.core.state.StaleItemStateException) Session(javax.jcr.Session) Lock(javax.jcr.lock.Lock)

Aggregations

UserTransactionImpl (org.apache.jackrabbit.core.UserTransactionImpl)12 Node (javax.jcr.Node)11 UserTransaction (javax.transaction.UserTransaction)9 Session (javax.jcr.Session)6 Version (javax.jcr.version.Version)4 Lock (javax.jcr.lock.Lock)3 HashSet (java.util.HashSet)2 Set (java.util.Set)2 RepositoryException (javax.jcr.RepositoryException)2 Event (javax.jcr.observation.Event)2 StaleItemStateException (org.apache.jackrabbit.core.state.StaleItemStateException)2 EventResult (org.apache.jackrabbit.test.api.observation.EventResult)2 NodeIterator (javax.jcr.NodeIterator)1 ReferentialIntegrityException (javax.jcr.ReferentialIntegrityException)1 Privilege (javax.jcr.security.Privilege)1 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)1