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();
}
}
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;
}
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);
}
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();
}
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();
}
Aggregations