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 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));
}
use of org.apache.jackrabbit.core.UserTransactionImpl in project jackrabbit by apache.
the class RemoveVersionTest method testRemoveVersionAndCheckinXA.
/**
* Removes a version in 1 transaction and tries to commit afterwards the
* versionable node using a 2nd transaction.
*
* Tests error reported in JCR-2613
*
* @throws Exception if an error occurs
*/
public void testRemoveVersionAndCheckinXA() throws Exception {
UserTransaction tx = new UserTransactionImpl(superuser);
tx.begin();
Node n = testRootNode.addNode(nodeName1);
n.addMixin(mixVersionable);
n.addMixin(mixReferenceable);
testRootNode.save();
String uuid = n.getUUID();
// create two versions
String v1 = n.checkin().getName();
n.checkout();
n.checkin();
n.checkout();
tx.commit();
tx = new UserTransactionImpl(superuser);
tx.begin();
// remove one version
n = superuser.getNodeByUUID(uuid);
n.getVersionHistory().removeVersion(v1);
n.save();
tx.commit();
// new session
Session session = getHelper().getSuperuserSession();
tx = new UserTransactionImpl(session);
tx.begin();
n = session.getNodeByUUID(uuid);
n.checkin();
tx.commit();
}
Aggregations