Search in sources :

Example 6 with UserTransactionImpl

use of org.apache.jackrabbit.core.UserTransactionImpl 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 7 with UserTransactionImpl

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

the class XATransaction method execute.

public NodeIterator execute() throws Exception {
    UserTransactionImpl tx = new UserTransactionImpl(getSession());
    log.info("begin transaction");
    tx.begin();
    NodeIterator it = op.execute();
    log.info("commit transaction");
    tx.commit();
    return it;
}
Also used : NodeIterator(javax.jcr.NodeIterator) UserTransactionImpl(org.apache.jackrabbit.core.UserTransactionImpl)

Example 8 with UserTransactionImpl

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

the class ConcurrentLockingWithTransactionsTest method testConcurrentCreateAndLockUnLockInTransaction.

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

        public void execute(Session session, Node test) throws RepositoryException {
            // add versionable nodes
            for (int i = 0; i < NUM_OPERATIONS / CONCURRENCY; i++) {
                try {
                    final UserTransaction utx = new UserTransactionImpl(test.getSession());
                    utx.begin();
                    Node n = test.addNode("test" + i);
                    n.addMixin(mixLockable);
                    session.save();
                    Lock l = n.lock(false, true);
                    n.unlock();
                    utx.commit();
                } 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)

Example 9 with UserTransactionImpl

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

the class LockTimeoutTest method testExpired.

private void testExpired(boolean xa) throws Exception {
    Session s = testRootNode.getSession();
    Node n = testRootNode.addNode(nodeName1);
    n.addMixin(mixLockable);
    s.save();
    UserTransaction utx = null;
    if (xa) {
        utx = new UserTransactionImpl(s);
        utx.begin();
    }
    javax.jcr.lock.LockManager lm = s.getWorkspace().getLockManager();
    boolean isDeep;
    boolean isSessionScoped;
    long timeoutHint;
    String ownerInfo;
    isDeep = false;
    isSessionScoped = false;
    timeoutHint = 1;
    ownerInfo = "";
    Session s2 = getHelper().getSuperuserSession();
    Lock l = lm.lock(n.getPath(), isDeep, isSessionScoped, timeoutHint, ownerInfo);
    // this works only for timeout = 1,
    // as getSecondsRemaining always returns a positive value
    assertEquals(timeoutHint, l.getSecondsRemaining());
    assertTrue(l.isLive());
    if (xa) {
        utx.commit();
    }
    long start = System.currentTimeMillis();
    while (true) {
        Thread.sleep(100);
        long now = System.currentTimeMillis();
        boolean success;
        try {
            s2.getNode(n.getPath()).setProperty("x", 1);
            s2.save();
            success = true;
        } catch (Exception e) {
            success = false;
        }
        long t = now - start;
        if (t > timeoutHint + 3000) {
            assertTrue(success);
            break;
        } else if (t < timeoutHint) {
            assertFalse(success);
        }
    }
    n.remove();
    s.save();
}
Also used : UserTransaction(javax.transaction.UserTransaction) Node(javax.jcr.Node) UserTransactionImpl(org.apache.jackrabbit.core.UserTransactionImpl) Session(javax.jcr.Session) Lock(javax.jcr.lock.Lock)

Example 10 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)

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