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