use of javax.jcr.InvalidItemStateException in project jackrabbit by apache.
the class HierarchyEntryImpl method transientRemove.
/**
* {@inheritDoc}
* @see HierarchyEntry#transientRemove()
*/
public void transientRemove() throws InvalidItemStateException, RepositoryException {
ItemState state = internalGetItemState();
if (state == null) {
// nothing to do -> correct status must be set upon resolution.
return;
}
// it in order to determine the current status.
if (state.getStatus() == Status.INVALIDATED) {
reload(false);
}
switch(state.getStatus()) {
case Status.NEW:
state.setStatus(Status.REMOVED);
parent.internalRemoveChildEntry(this);
break;
case Status.EXISTING:
case Status.EXISTING_MODIFIED:
state.setStatus(Status.EXISTING_REMOVED);
// if a conflict with a new entry occurs.
break;
case Status.REMOVED:
case Status.STALE_DESTROYED:
throw new InvalidItemStateException("Item has already been removed by someone else. Status = " + Status.getName(state.getStatus()));
default:
throw new RepositoryException("Cannot transiently remove an ItemState with status " + Status.getName(state.getStatus()));
}
}
use of javax.jcr.InvalidItemStateException in project jackrabbit-oak by apache.
the class ConcurrentWriteACLTest method runTest.
@Override
public void runTest() throws Exception {
Session session = null;
try {
session = loginWriter();
for (int i = 0; i < numItems; i++) {
session.refresh(false);
int a = random.nextInt(NODE_COUNT);
int b = random.nextInt(NODE_COUNT);
String path = "/" + ROOT_NODE_NAME + "/node" + a + "/node" + b;
AccessControlManager acMgr = session.getAccessControlManager();
JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(session, path);
if (acl.isEmpty()) {
Privilege[] privileges = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_READ), acMgr.privilegeFromName(Privilege.JCR_READ_ACCESS_CONTROL) };
if (acl.addAccessControlEntry(EveryonePrincipal.getInstance(), privileges)) {
acMgr.setPolicy(path, acl);
}
} else {
for (AccessControlEntry ace : acl.getAccessControlEntries()) {
acl.removeAccessControlEntry(ace);
}
acMgr.setPolicy(path, acl);
}
session.save();
}
} catch (InvalidItemStateException e) {
System.out.printf("error: %s%n", e);
// ignore
} finally {
if (session != null) {
session.logout();
}
}
}
use of javax.jcr.InvalidItemStateException in project jackrabbit-oak by apache.
the class PrivilegeManagerImpl method registerPrivilege.
@Override
public Privilege registerPrivilege(String privilegeName, boolean isAbstract, String[] declaredAggregateNames) throws RepositoryException {
if (root.hasPendingChanges()) {
throw new InvalidItemStateException("Attempt to register a new privilege while there are pending changes.");
}
if (privilegeName == null || privilegeName.isEmpty()) {
throw new RepositoryException("Invalid privilege name " + privilegeName);
}
PrivilegeDefinition definition = new ImmutablePrivilegeDefinition(getOakName(privilegeName), isAbstract, getOakNames(declaredAggregateNames));
PrivilegeDefinitionWriter writer = new PrivilegeDefinitionWriter(getWriteRoot());
writer.writeDefinition(definition);
// refresh the current root to make sure the definition is visible
root.refresh();
return getPrivilege(definition);
}
use of javax.jcr.InvalidItemStateException in project jackrabbit-oak by apache.
the class ConcurrentPropertyUpdateTest method concurrentUpdates.
@Test
public void concurrentUpdates() throws Exception {
final DocumentNodeStore store = mk.getNodeStore();
NodeBuilder builder = store.getRoot().builder();
builder.child("test").setProperty("prop", System.currentTimeMillis());
store.merge(builder, HOOK, CommitInfo.EMPTY);
List<Callable<Object>> tasks = Lists.newArrayList();
for (int i = 0; i < NUM_THREADS; i++) {
tasks.add(new Callable<Object>() {
@Override
public Object call() throws Exception {
for (int i = 0; i < 100; i++) {
try {
NodeBuilder builder = store.getRoot().builder();
builder.getChildNode("test").setProperty("prop", Math.random());
store.merge(builder, HOOK, CommitInfo.EMPTY);
} catch (CommitFailedException e) {
// merge must either succeed or fail
// with an InvalidItemStateException
RepositoryException ex = e.asRepositoryException();
if (!(ex instanceof InvalidItemStateException)) {
throw e;
}
}
}
return null;
}
});
}
List<Future<Object>> results = service.invokeAll(tasks);
for (Future<Object> r : results) {
r.get();
}
}
use of javax.jcr.InvalidItemStateException in project jackrabbit-oak by apache.
the class ReadWriteVersionManager method checkin.
/**
* Performs a checkin on a versionable tree and returns the tree that
* represents the created version.
*
* @param versionable the versionable node to check in.
* @return the created version.
* @throws InvalidItemStateException if the current root has pending
* changes.
* @throws UnsupportedRepositoryOperationException
* if the versionable tree isn't actually
* versionable.
* @throws RepositoryException if an error occurs while checking the
* node type of the tree.
*/
@Nonnull
public Tree checkin(@Nonnull Tree versionable) throws RepositoryException, InvalidItemStateException, UnsupportedRepositoryOperationException {
if (sessionDelegate.hasPendingChanges()) {
throw new InvalidItemStateException("Unable to perform checkin. " + "Session has pending changes.");
}
if (!isVersionable(versionable)) {
throw new UnsupportedRepositoryOperationException(versionable.getPath() + " is not versionable");
}
if (isCheckedOut(versionable)) {
Tree baseVersion = getExistingBaseVersion(versionable);
versionable.setProperty(JCR_ISCHECKEDOUT, Boolean.FALSE, Type.BOOLEAN);
PropertyState created = baseVersion.getProperty(JCR_CREATED);
if (created != null) {
long c = ISO8601.parse(created.getValue(Type.DATE)).getTimeInMillis();
while (System.currentTimeMillis() == c) {
// busy-wait for System.currentTimeMillis to change
// so that the new version has a distinct timestamp
}
}
try {
sessionDelegate.commit();
refresh();
} catch (CommitFailedException e) {
sessionDelegate.refresh(true);
throw e.asRepositoryException();
}
}
return getExistingBaseVersion(getWorkspaceRoot().getTree(versionable.getPath()));
}
Aggregations