Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>MacRoman =================================================================== --- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java (revision Local version) +++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java (revision Shelved version) @@ -29,6 +29,7 @@ import org.apache.jackrabbit.oak.api.ChangeExtractor; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.jcr.SessionDelegate; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry; import org.apache.jackrabbit.oak.spi.state.NodeState; @@ -40,6 +41,7 @@ import static org.apache.jackrabbit.oak.util.Iterators.singleton; class ChangeProcessor extends TimerTask { + private final SessionDelegate sessionDelegate; private final NamePathMapper namePathMapper; private final ChangeExtractor changeExtractor; private final EventListener listener; @@ -47,10 +49,10 @@ private volatile boolean stopped; - public ChangeProcessor(NamePathMapper namePathMapper, ChangeExtractor changeExtractor, EventListener listener, - ChangeFilter filter) { - this.namePathMapper = namePathMapper; - this.changeExtractor = changeExtractor; + public ChangeProcessor(SessionDelegate sessionDelegate, EventListener listener, ChangeFilter filter) { + this.sessionDelegate = sessionDelegate; + this.namePathMapper = sessionDelegate.getNamePathMapper(); + this.changeExtractor = sessionDelegate.getChangeExtractor(); this.listener = listener; filterRef = new AtomicReference(filter); } @@ -68,6 +70,7 @@ public void run() { EventGeneratingNodeStateDiff diff = new EventGeneratingNodeStateDiff(); changeExtractor.getChanges(diff); + sessionDelegate.setRefresh(); diff.sendEvents(); } Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>MacRoman =================================================================== --- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java (revision Local version) +++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java (revision Shelved version) @@ -54,10 +54,15 @@ @Override @Nonnull public String getName() throws RepositoryException { + return sessionDelegate.perform(new SessionOperation() { + @Override + public String perform(Context context) throws RepositoryException { - String oakName = dlg.getName(); - // special case name of root node - return oakName.isEmpty() ? "" : toJcrPath(dlg.getName()); - } + String oakName = dlg.getName(); + // special case name of root node + return oakName.isEmpty() ? "" : toJcrPath(dlg.getName()); + } + }); + } /** * @see javax.jcr.Property#getPath() @@ -65,7 +70,12 @@ @Override @Nonnull public String getPath() throws RepositoryException { + return sessionDelegate.perform(new SessionOperation() { + @Override + public String perform(Context context) throws RepositoryException { - return toJcrPath(dlg.getPath()); + return toJcrPath(dlg.getPath()); + } + }); } @Override Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>MacRoman =================================================================== --- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java (revision Local version) +++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java (revision Shelved version) @@ -110,12 +110,18 @@ @Nonnull public Node getParent() throws RepositoryException { checkStatus(); + + return sessionDelegate.perform(new SessionOperation() { + @Override + public NodeImpl perform(Context context) throws RepositoryException { - NodeDelegate parent = dlg.getParent(); - if (parent == null) { - throw new ItemNotFoundException("Root has no parent"); - } - return new NodeImpl(parent); - } + NodeDelegate parent = dlg.getParent(); + if (parent == null) { + throw new ItemNotFoundException("Root has no parent"); + } + return new NodeImpl(parent); + } + }); + } /** * @see javax.jcr.Item#isNew() @@ -123,8 +129,14 @@ @Override public boolean isNew() { try { + return sessionDelegate.perform(new SessionOperation() { + @Override + public Boolean perform(Context context) throws InvalidItemStateException { - return !dlg.isStale() && dlg.getStatus() == Status.NEW; + return !dlg.isStale() && dlg.getStatus() == Status.NEW; - } catch (InvalidItemStateException e) { + } + }); + } + catch (RepositoryException e) { return false; } } @@ -135,8 +147,14 @@ @Override public boolean isModified() { try { + return sessionDelegate.perform(new SessionOperation() { + @Override + public Boolean perform(Context context) throws InvalidItemStateException { - return !dlg.isStale() && dlg.getStatus() == Status.MODIFIED; + return !dlg.isStale() && dlg.getStatus() == Status.MODIFIED; - } catch (InvalidItemStateException e) { + } + }); + } + catch (RepositoryException e) { return false; } } @@ -147,12 +165,19 @@ @Override public void remove() throws RepositoryException { checkStatus(); + + sessionDelegate.perform(new SessionOperation() { + @Override + public Void perform(Context context) throws RepositoryException { - if (dlg.isRoot()) { - throw new RepositoryException("Cannot remove the root node"); - } + if (dlg.isRoot()) { + throw new RepositoryException("Cannot remove the root node"); + } - dlg.remove(); + dlg.remove(); + return null; - } + } + }); + } /** * @see Item#accept(javax.jcr.ItemVisitor) @@ -176,72 +201,82 @@ @Override @Nonnull - public Node addNode(String relPath, String primaryNodeTypeName) throws RepositoryException { + public Node addNode(final String relPath, final String primaryNodeTypeName) throws RepositoryException { checkStatus(); + return sessionDelegate.perform(new SessionOperation() { + @Override + public Node perform(Context context) throws RepositoryException { - String oakPath = sessionDelegate.getOakPathKeepIndexOrThrowNotFound(relPath); - String oakName = PathUtils.getName(oakPath); - String parentPath = sessionDelegate.getOakPathOrThrow(PathUtils.getParentPath(oakPath)); + String oakPath = sessionDelegate.getOakPathKeepIndexOrThrowNotFound(relPath); + String oakName = PathUtils.getName(oakPath); + String parentPath = sessionDelegate.getOakPathOrThrow(PathUtils.getParentPath(oakPath)); - // handle index - if (oakName.contains("[")) { - throw new RepositoryException("Cannot create a new node using a name including an index"); - } + // handle index + if (oakName.contains("[")) { + throw new RepositoryException("Cannot create a new node using a name including an index"); + } - NodeDelegate parent = dlg.getChild(parentPath); - if (parent == null) { - // is it a property? - String grandParentPath = PathUtils.getParentPath(parentPath); - NodeDelegate grandParent = dlg.getChild(grandParentPath); - if (grandParent != null) { - String propname = PathUtils.getName(parentPath); - if (grandParent.getProperty(propname) != null) { - throw new ConstraintViolationException("Can't add new node to property."); - } - } + NodeDelegate parent = dlg.getChild(parentPath); + if (parent == null) { + // is it a property? + String grandParentPath = PathUtils.getParentPath(parentPath); + NodeDelegate grandParent = dlg.getChild(grandParentPath); + if (grandParent != null) { + String propname = PathUtils.getName(parentPath); + if (grandParent.getProperty(propname) != null) { + throw new ConstraintViolationException("Can't add new node to property."); + } + } - throw new PathNotFoundException(relPath); - } + throw new PathNotFoundException(relPath); + } - if (parent.getChild(oakName) != null) { - throw new ItemExistsException(relPath); - } + if (parent.getChild(oakName) != null) { + throw new ItemExistsException(relPath); + } - if (primaryNodeTypeName == null) { - // TODO retrieve matching nt from effective definition based on name-matching. + // TODO retrieve matching nt from effective definition based on name-matching. - primaryNodeTypeName = NodeType.NT_UNSTRUCTURED; - } + String ntName = primaryNodeTypeName == null ? NodeType.NT_UNSTRUCTURED : primaryNodeTypeName; - // TODO: figure out the right place for this check - NodeTypeManager ntm = sessionDelegate.getNodeTypeManager(); + // TODO: figure out the right place for this check + NodeTypeManager ntm = sessionDelegate.getNodeTypeManager(); - NodeType nt = ntm.getNodeType(primaryNodeTypeName); // throws on not found + NodeType nt = ntm.getNodeType(ntName); // throws on not found - if (nt.isAbstract() || nt.isMixin()) { - throw new ConstraintViolationException(); - } - // TODO: END + if (nt.isAbstract() || nt.isMixin()) { + throw new ConstraintViolationException(); + } + // TODO: END - NodeDelegate added = parent.addChild(oakName); - if (added == null) { - throw new ItemExistsException(); - } + NodeDelegate added = parent.addChild(oakName); + if (added == null) { + throw new ItemExistsException(); + } - Node childNode = new NodeImpl(added); + Node childNode = new NodeImpl(added); - childNode.setPrimaryType(primaryNodeTypeName); + childNode.setPrimaryType(ntName); - return childNode; - } + return childNode; + } + }); + } @Override - public void orderBefore(String srcChildRelPath, String destChildRelPath) throws RepositoryException { + public void orderBefore(final String srcChildRelPath, final String destChildRelPath) throws RepositoryException { checkStatus(); + + sessionDelegate.perform(new SessionOperation() { + @Override + public Void perform(Context context) throws RepositoryException { - String oakSrcChildRelPath = - sessionDelegate.getOakPathOrThrowNotFound(srcChildRelPath); - String oakDestChildRelPath = null; - if (destChildRelPath != null) { - oakDestChildRelPath = - sessionDelegate.getOakPathOrThrowNotFound(destChildRelPath); - } - dlg.orderBefore(oakSrcChildRelPath, oakDestChildRelPath); + String oakSrcChildRelPath = + sessionDelegate.getOakPathOrThrowNotFound(srcChildRelPath); + String oakDestChildRelPath = null; + if (destChildRelPath != null) { + oakDestChildRelPath = + sessionDelegate.getOakPathOrThrowNotFound(destChildRelPath); + } + dlg.orderBefore(oakSrcChildRelPath, oakDestChildRelPath); + return null; - } + } + }); + } /** * @see Node#setProperty(String, javax.jcr.Value) @@ -261,23 +296,28 @@ */ @Override @CheckForNull - public Property setProperty(String jcrName, Value value, int type) + public Property setProperty(final String jcrName, final Value value, final int type) throws RepositoryException { checkStatus(); + return sessionDelegate.perform(new SessionOperation() { + @Override + public PropertyImpl perform(Context context) throws RepositoryException { - String oakName = sessionDelegate.getOakPathOrThrow(jcrName); - if (value == null) { - dlg.removeProperty(oakName); - return null; - } else { - int targetType = getTargetType(value, type); - Value targetValue = - ValueHelper.convert(value, targetType, getValueFactory()); - CoreValue oakValue = - ValueConverter.toCoreValue(targetValue, sessionDelegate); - return new PropertyImpl(dlg.setProperty(oakName, oakValue)); - } - } + String oakName = sessionDelegate.getOakPathOrThrow(jcrName); + if (value == null) { + dlg.removeProperty(oakName); + return null; + } else { + int targetType = getTargetType(value, type); + Value targetValue = + ValueHelper.convert(value, targetType, getValueFactory()); + CoreValue oakValue = + ValueConverter.toCoreValue(targetValue, sessionDelegate); + return new PropertyImpl(dlg.setProperty(oakName, oakValue)); + } + } + }); + } /** * @see Node#setProperty(String, javax.jcr.Value[]) @@ -296,21 +336,26 @@ @Override @Nonnull - public Property setProperty(String jcrName, Value[] values, int type) throws RepositoryException { + public Property setProperty(final String jcrName, final Value[] values, final int type) throws RepositoryException { checkStatus(); + return sessionDelegate.perform(new SessionOperation() { + @Override + public Property perform(Context context) throws RepositoryException { - int targetType = getTargetType(values, type); - Value[] targetValues = ValueHelper.convert(values, targetType, getValueFactory()); - if (targetValues == null) { - Property p = getProperty(jcrName); - p.remove(); - return p; - } else { - String oakName = sessionDelegate.getOakPathOrThrow(jcrName); - List oakValue = ValueConverter.toCoreValues(targetValues, sessionDelegate); - return new PropertyImpl(dlg.setProperty(oakName, oakValue)); - } - } + int targetType = getTargetType(values, type); + Value[] targetValues = ValueHelper.convert(values, targetType, getValueFactory()); + if (targetValues == null) { + Property p = getProperty(jcrName); + p.remove(); + return p; + } else { + String oakName = sessionDelegate.getOakPathOrThrow(jcrName); + List oakValue = ValueConverter.toCoreValues(targetValues, sessionDelegate); + return new PropertyImpl(dlg.setProperty(oakName, oakValue)); + } + } + }); + } /** * @see Node#setProperty(String, String[]) @@ -436,28 +481,38 @@ @Override @Nonnull - public Node getNode(String relPath) throws RepositoryException { + public Node getNode(final String relPath) throws RepositoryException { checkStatus(); + return sessionDelegate.perform(new SessionOperation() { + @Override + public NodeImpl perform(Context context) throws RepositoryException { - String oakPath = sessionDelegate.getOakPathOrThrowNotFound(relPath); + String oakPath = sessionDelegate.getOakPathOrThrowNotFound(relPath); - NodeDelegate nd = dlg.getChild(oakPath); - if (nd == null) { - throw new PathNotFoundException(relPath); - } else { - return new NodeImpl(nd); - } - } + NodeDelegate nd = dlg.getChild(oakPath); + if (nd == null) { + throw new PathNotFoundException(relPath); + } else { + return new NodeImpl(nd); + } + } + }); + } @Override @Nonnull public NodeIterator getNodes() throws RepositoryException { checkStatus(); + return sessionDelegate.perform(new SessionOperation() { + @Override + public NodeIterator perform(Context context) throws RepositoryException { - Iterator children = dlg.getChildren(); - long size = dlg.getChildCount(); - return new NodeIteratorAdapter(nodeIterator(children), size); - } + Iterator children = dlg.getChildren(); + long size = dlg.getChildCount(); + return new NodeIteratorAdapter(nodeIterator(children), size); + } + }); + } @Override @Nonnull @@ -465,104 +520,134 @@ throws RepositoryException { checkStatus(); + return sessionDelegate.perform(new SessionOperation() { + @Override + public NodeIterator perform(Context context) throws RepositoryException { - Iterator children = filter(dlg.getChildren(), - new Predicate() { - @Override - public boolean evaluate(NodeDelegate state) { - try { - return ItemNameMatcher.matches(toJcrPath(state.getName()), namePattern); - } catch (InvalidItemStateException e) { - return false; - } - } - }); + Iterator children = filter(dlg.getChildren(), + new Predicate() { + @Override + public boolean evaluate(NodeDelegate state) { + try { + return ItemNameMatcher.matches(toJcrPath(state.getName()), namePattern); + } catch (InvalidItemStateException e) { + return false; + } + } + }); - return new NodeIteratorAdapter(nodeIterator(children)); - } + return new NodeIteratorAdapter(nodeIterator(children)); + } + }); + } @Override @Nonnull public NodeIterator getNodes(final String[] nameGlobs) throws RepositoryException { checkStatus(); + return sessionDelegate.perform(new SessionOperation() { + @Override + public NodeIterator perform(Context context) throws RepositoryException { - Iterator children = filter(dlg.getChildren(), - new Predicate() { - @Override - public boolean evaluate(NodeDelegate state) { - try { - return ItemNameMatcher.matches(toJcrPath(state.getName()), nameGlobs); - } catch (InvalidItemStateException e) { - return false; - } - } - }); + Iterator children = filter(dlg.getChildren(), + new Predicate() { + @Override + public boolean evaluate(NodeDelegate state) { + try { + return ItemNameMatcher.matches(toJcrPath(state.getName()), nameGlobs); + } catch (InvalidItemStateException e) { + return false; + } + } + }); - return new NodeIteratorAdapter(nodeIterator(children)); - } + return new NodeIteratorAdapter(nodeIterator(children)); + } + }); + } @Override @Nonnull - public Property getProperty(String relPath) throws RepositoryException { + public Property getProperty(final String relPath) throws RepositoryException { checkStatus(); + return sessionDelegate.perform(new SessionOperation() { + @Override + public PropertyImpl perform(Context context) throws RepositoryException { - String oakPath = sessionDelegate.getOakPathOrThrowNotFound(relPath); - PropertyDelegate pd = dlg.getProperty(oakPath); - if (pd == null) { - throw new PathNotFoundException(relPath + " not found on " + getPath()); - } else { - return new PropertyImpl(pd); - } - } + String oakPath = sessionDelegate.getOakPathOrThrowNotFound(relPath); + PropertyDelegate pd = dlg.getProperty(oakPath); + if (pd == null) { + throw new PathNotFoundException(relPath + " not found on " + getPath()); + } else { + return new PropertyImpl(pd); + } + } + }); + } @Override @Nonnull public PropertyIterator getProperties() throws RepositoryException { checkStatus(); + return sessionDelegate.perform(new SessionOperation() { + @Override + public PropertyIterator perform(Context context) throws RepositoryException { - Iterator properties = dlg.getProperties(); - long size = dlg.getPropertyCount(); - return new PropertyIteratorAdapter(propertyIterator(properties), size); - } + Iterator properties = dlg.getProperties(); + long size = dlg.getPropertyCount(); + return new PropertyIteratorAdapter(propertyIterator(properties), size); + } + }); + } @Override @Nonnull public PropertyIterator getProperties(final String namePattern) throws RepositoryException { checkStatus(); + return sessionDelegate.perform(new SessionOperation() { + @Override + public PropertyIterator perform(Context context) throws RepositoryException { - Iterator properties = filter(dlg.getProperties(), - new Predicate() { - @Override - public boolean evaluate(PropertyDelegate entry) { - try { - return ItemNameMatcher.matches(toJcrPath(entry.getName()), namePattern); - } catch (InvalidItemStateException e) { - return false; - } - } - }); + Iterator properties = filter(dlg.getProperties(), + new Predicate() { + @Override + public boolean evaluate(PropertyDelegate entry) { + try { + return ItemNameMatcher.matches(toJcrPath(entry.getName()), namePattern); + } catch (InvalidItemStateException e) { + return false; + } + } + }); - return new PropertyIteratorAdapter(propertyIterator(properties)); - } + return new PropertyIteratorAdapter(propertyIterator(properties)); + } + }); + } @Override @Nonnull public PropertyIterator getProperties(final String[] nameGlobs) throws RepositoryException { checkStatus(); + return sessionDelegate.perform(new SessionOperation() { + @Override + public PropertyIterator perform(Context context) throws RepositoryException { - Iterator propertyNames = filter(dlg.getProperties(), - new Predicate() { - @Override - public boolean evaluate(PropertyDelegate entry) { - try { - return ItemNameMatcher.matches(toJcrPath(entry.getName()), nameGlobs); - } catch (InvalidItemStateException e) { - return false; - } - } - }); + Iterator propertyNames = filter(dlg.getProperties(), + new Predicate() { + @Override + public boolean evaluate(PropertyDelegate entry) { + try { + return ItemNameMatcher.matches(toJcrPath(entry.getName()), nameGlobs); + } catch (InvalidItemStateException e) { + return false; + } + } + }); - return new PropertyIteratorAdapter(propertyIterator(propertyNames)); - } + return new PropertyIteratorAdapter(propertyIterator(propertyNames)); + } + }); + } /** * @see javax.jcr.Node#getPrimaryItem() @@ -571,18 +656,24 @@ @Nonnull public Item getPrimaryItem() throws RepositoryException { checkStatus(); + + return sessionDelegate.perform(new SessionOperation() { + @Override + public Item perform(Context context) throws RepositoryException { - String name = getPrimaryNodeType().getPrimaryItemName(); - if (name == null) { - throw new ItemNotFoundException("No primary item present on node " + this); - } - if (hasProperty(name)) { - return getProperty(name); - } else if (hasNode(name)) { - return getNode(name); - } else { - throw new ItemNotFoundException("Primary item " + name + " does not exist on node " + this); - } - } + String name = getPrimaryNodeType().getPrimaryItemName(); + if (name == null) { + throw new ItemNotFoundException("No primary item present on node " + this); + } + if (hasProperty(name)) { + return getProperty(name); + } else if (hasNode(name)) { + return getNode(name); + } else { + throw new ItemNotFoundException("Primary item " + name + " does not exist on node " + this); + } + } + }); + } /** * @see javax.jcr.Node#getUUID() @@ -592,19 +683,30 @@ public String getUUID() throws RepositoryException { checkStatus(); + return sessionDelegate.perform(new SessionOperation() { + @Override + public String perform(Context context) throws RepositoryException { - if (isNodeType(NodeType.MIX_REFERENCEABLE)) { - return getIdentifier(); - } + if (isNodeType(NodeType.MIX_REFERENCEABLE)) { + return getIdentifier(); + } - throw new UnsupportedRepositoryOperationException("Node is not referenceable."); - } + throw new UnsupportedRepositoryOperationException("Node is not referenceable."); + } + }); + } @Override @Nonnull public String getIdentifier() throws RepositoryException { checkStatus(); + + return sessionDelegate.perform(new SessionOperation() { + @Override + public String perform(Context context) throws RepositoryException { - return dlg.getIdentifier(); - } + return dlg.getIdentifier(); + } + }); + } @Override public int getIndex() throws RepositoryException { @@ -626,12 +728,17 @@ public PropertyIterator getReferences(String name) throws RepositoryException { checkStatus(); + return sessionDelegate.perform(new SessionOperation() { + @Override + public PropertyIterator perform(Context context) throws RepositoryException { - if (!isNodeType(JcrConstants.MIX_REFERENCEABLE)) { - return PropertyIteratorAdapter.EMPTY; - } else { - throw new UnsupportedRepositoryOperationException("TODO: Node.getReferences"); - } - } + if (!isNodeType(JcrConstants.MIX_REFERENCEABLE)) { + return PropertyIteratorAdapter.EMPTY; + } else { + throw new UnsupportedRepositoryOperationException("TODO: Node.getReferences"); + } + } + }); + } /** * @see javax.jcr.Node#getWeakReferences() @@ -647,42 +754,67 @@ public PropertyIterator getWeakReferences(String name) throws RepositoryException { checkStatus(); + return sessionDelegate.perform(new SessionOperation() { + @Override + public PropertyIterator perform(Context context) throws RepositoryException { - if (!isNodeType(JcrConstants.MIX_REFERENCEABLE)) { - return PropertyIteratorAdapter.EMPTY; - } else { - throw new UnsupportedRepositoryOperationException("TODO: Node.getWeakReferences"); - } - } + if (!isNodeType(JcrConstants.MIX_REFERENCEABLE)) { + return PropertyIteratorAdapter.EMPTY; + } else { + throw new UnsupportedRepositoryOperationException("TODO: Node.getWeakReferences"); + } + } + }); + } @Override - public boolean hasNode(String relPath) throws RepositoryException { + public boolean hasNode(final String relPath) throws RepositoryException { checkStatus(); + return sessionDelegate.perform(new SessionOperation() { + @Override + public Boolean perform(Context context) throws RepositoryException { - String oakPath = sessionDelegate.getOakPathOrThrow(relPath); - return dlg.getChild(oakPath) != null; - } + String oakPath = sessionDelegate.getOakPathOrThrow(relPath); + return dlg.getChild(oakPath) != null; + } + }); + } @Override - public boolean hasProperty(String relPath) throws RepositoryException { + public boolean hasProperty(final String relPath) throws RepositoryException { checkStatus(); + return sessionDelegate.perform(new SessionOperation() { + @Override + public Boolean perform(Context context) throws RepositoryException { - String oakPath = sessionDelegate.getOakPathOrThrow(relPath); - return dlg.getProperty(oakPath) != null; - } + String oakPath = sessionDelegate.getOakPathOrThrow(relPath); + return dlg.getProperty(oakPath) != null; + } + }); + } @Override public boolean hasNodes() throws RepositoryException { checkStatus(); + return sessionDelegate.perform(new SessionOperation() { + @Override + public Boolean perform(Context context) throws RepositoryException { - return dlg.getChildCount() != 0; - } + return dlg.getChildCount() != 0; + } + }); + } @Override public boolean hasProperties() throws RepositoryException { checkStatus(); + return sessionDelegate.perform(new SessionOperation() { + @Override + public Boolean perform(Context context) throws RepositoryException { - return dlg.getPropertyCount() != 0; - } + return dlg.getPropertyCount() != 0; + } + }); + } /** * @see javax.jcr.Node#getPrimaryNodeType() @@ -692,15 +824,20 @@ public NodeType getPrimaryNodeType() throws RepositoryException { checkStatus(); + return sessionDelegate.perform(new SessionOperation() { + @Override + public NodeType perform(Context context) throws RepositoryException { - // TODO: check if transient changes to mixin-types are reflected here - NodeTypeManager ntMgr = sessionDelegate.getNodeTypeManager(); - String primaryNtName; - primaryNtName = hasProperty(Property.JCR_PRIMARY_TYPE) - ? getProperty(Property.JCR_PRIMARY_TYPE).getString() - : NodeType.NT_UNSTRUCTURED; + // TODO: check if transient changes to mixin-types are reflected here + NodeTypeManager ntMgr = sessionDelegate.getNodeTypeManager(); + String primaryNtName; + primaryNtName = hasProperty(Property.JCR_PRIMARY_TYPE) + ? getProperty(Property.JCR_PRIMARY_TYPE).getString() + : NodeType.NT_UNSTRUCTURED; - return ntMgr.getNodeType(primaryNtName); - } + return ntMgr.getNodeType(primaryNtName); + } + }); + } /** * @see javax.jcr.Node#getMixinNodeTypes() @@ -710,129 +847,162 @@ public NodeType[] getMixinNodeTypes() throws RepositoryException { checkStatus(); + return sessionDelegate.perform(new SessionOperation() { + @Override + public NodeType[] perform(Context context) throws RepositoryException { - // TODO: check if transient changes to mixin-types are reflected here - if (hasProperty(Property.JCR_MIXIN_TYPES)) { - NodeTypeManager ntMgr = sessionDelegate.getNodeTypeManager(); - Value[] mixinNames = getProperty(Property.JCR_MIXIN_TYPES).getValues(); - NodeType[] mixinTypes = new NodeType[mixinNames.length]; - for (int i = 0; i < mixinNames.length; i++) { - mixinTypes[i] = ntMgr.getNodeType(mixinNames[i].getString()); - } - return mixinTypes; - } else { - return new NodeType[0]; - } - } + // TODO: check if transient changes to mixin-types are reflected here + if (hasProperty(Property.JCR_MIXIN_TYPES)) { + NodeTypeManager ntMgr = sessionDelegate.getNodeTypeManager(); + Value[] mixinNames = getProperty(Property.JCR_MIXIN_TYPES).getValues(); + NodeType[] mixinTypes = new NodeType[mixinNames.length]; + for (int i = 0; i < mixinNames.length; i++) { + mixinTypes[i] = ntMgr.getNodeType(mixinNames[i].getString()); + } + return mixinTypes; + } else { + return new NodeType[0]; + } + } + }); + } @Override - public boolean isNodeType(String nodeTypeName) throws RepositoryException { + public boolean isNodeType(final String nodeTypeName) throws RepositoryException { checkStatus(); + return sessionDelegate.perform(new SessionOperation() { + @Override + public Boolean perform(Context context) throws RepositoryException { - // TODO: might be expanded, need a better way for this - NameMapper mapper = sessionDelegate.getNamePathMapper(); - String oakName = mapper.getOakName(nodeTypeName); - if (oakName == null) { - return false; // An unknown name can't belong to a valid type - } - String jcrName = mapper.getJcrName(oakName); + // TODO: might be expanded, need a better way for this + NameMapper mapper = sessionDelegate.getNamePathMapper(); + String oakName = mapper.getOakName(nodeTypeName); + if (oakName == null) { + return false; // An unknown name can't belong to a valid type + } + String jcrName = mapper.getJcrName(oakName); - // TODO: figure out the right place for this check - NodeTypeManager ntm = sessionDelegate.getNodeTypeManager(); - NodeType ntToCheck = ntm.getNodeType(jcrName); // throws on not found - String nameToCheck = ntToCheck.getName(); + // TODO: figure out the right place for this check + NodeTypeManager ntm = sessionDelegate.getNodeTypeManager(); + NodeType ntToCheck = ntm.getNodeType(jcrName); // throws on not found + String nameToCheck = ntToCheck.getName(); - NodeType currentPrimaryType = getPrimaryNodeType(); - if (currentPrimaryType.isNodeType(nameToCheck)) { - return true; - } + NodeType currentPrimaryType = getPrimaryNodeType(); + if (currentPrimaryType.isNodeType(nameToCheck)) { + return true; + } - for (NodeType mixin : getMixinNodeTypes()) { - if (mixin.isNodeType(nameToCheck)) { - return true; - } - } - // TODO: END + for (NodeType mixin : getMixinNodeTypes()) { + if (mixin.isNodeType(nameToCheck)) { + return true; + } + } + // TODO: END - return false; - } + return false; + } + }); + } @Override - public void setPrimaryType(String nodeTypeName) throws RepositoryException { + public void setPrimaryType(final String nodeTypeName) throws RepositoryException { checkStatus(); + sessionDelegate.perform(new SessionOperation() { + @Override + public Void perform(Context context) throws RepositoryException { - // TODO: figure out the right place for this check - NodeTypeManager ntm = sessionDelegate.getNodeTypeManager(); - NodeType nt = ntm.getNodeType(nodeTypeName); // throws on not found - if (nt.isAbstract() || nt.isMixin()) { - throw new ConstraintViolationException(); - } - // TODO: END + // TODO: figure out the right place for this check + NodeTypeManager ntm = sessionDelegate.getNodeTypeManager(); + NodeType nt = ntm.getNodeType(nodeTypeName); // throws on not found + if (nt.isAbstract() || nt.isMixin()) { + throw new ConstraintViolationException(); + } + // TODO: END - String jcrPrimaryType = sessionDelegate.getOakPathOrThrow(Property.JCR_PRIMARY_TYPE); - CoreValue cv = ValueConverter.toCoreValue(nodeTypeName, PropertyType.NAME, sessionDelegate); - dlg.setProperty(jcrPrimaryType, cv); + String jcrPrimaryType = sessionDelegate.getOakPathOrThrow(Property.JCR_PRIMARY_TYPE); + CoreValue cv = ValueConverter.toCoreValue(nodeTypeName, PropertyType.NAME, sessionDelegate); + dlg.setProperty(jcrPrimaryType, cv); + return null; - } + } + }); + } @Override - public void addMixin(String mixinName) throws RepositoryException { + public void addMixin(final String mixinName) throws RepositoryException { checkStatus(); + + sessionDelegate.perform(new SessionOperation() { + @Override + public Void perform(Context context) throws RepositoryException { - // TODO: figure out the right place for this check - NodeTypeManager ntm = sessionDelegate.getNodeTypeManager(); - NodeType nt = ntm.getNodeType(mixinName); // throws on not found - // TODO: END + // TODO: figure out the right place for this check + NodeTypeManager ntm = sessionDelegate.getNodeTypeManager(); + NodeType nt = ntm.getNodeType(mixinName); // throws on not found + // TODO: END - String jcrMixinTypes = sessionDelegate.getOakPathOrThrow(Property.JCR_MIXIN_TYPES); - PropertyDelegate mixins = dlg.getProperty(jcrMixinTypes); + String jcrMixinTypes = sessionDelegate.getOakPathOrThrow(Property.JCR_MIXIN_TYPES); + PropertyDelegate mixins = dlg.getProperty(jcrMixinTypes); - CoreValue cv = ValueConverter.toCoreValue(mixinName, PropertyType.NAME, sessionDelegate); + CoreValue cv = ValueConverter.toCoreValue(mixinName, PropertyType.NAME, sessionDelegate); - boolean nodeModified = false; + boolean nodeModified = false; - if (mixins == null) { - nodeModified = true; - dlg.setProperty(jcrMixinTypes, Collections.singletonList(cv)); - } else { - List values = new ArrayList(); - for (CoreValue existingValue : mixins.getValues()) { - if (!values.contains(existingValue)) { - values.add(existingValue); - } - } - if (!values.contains(cv)) { - values.add(cv); - nodeModified = true; - dlg.setProperty(jcrMixinTypes, values); - } - } + if (mixins == null) { + nodeModified = true; + dlg.setProperty(jcrMixinTypes, Collections.singletonList(cv)); + } else { + List values = new ArrayList(); + for (CoreValue existingValue : mixins.getValues()) { + if (!values.contains(existingValue)) { + values.add(existingValue); + } + } + if (!values.contains(cv)) { + values.add(cv); + nodeModified = true; + dlg.setProperty(jcrMixinTypes, values); + } + } - // TODO: hack -- make sure we assign a UUID - if (nodeModified && nt.isNodeType(NodeType.MIX_REFERENCEABLE)) { - String jcrUuid = sessionDelegate.getOakPathOrThrow(Property.JCR_UUID); - dlg.setProperty(jcrUuid, ValueConverter.toCoreValue(UUID.randomUUID().toString(), PropertyType.STRING, sessionDelegate)); - } + // TODO: hack -- make sure we assign a UUID + if (nodeModified && nt.isNodeType(NodeType.MIX_REFERENCEABLE)) { + String jcrUuid = sessionDelegate.getOakPathOrThrow(Property.JCR_UUID); + dlg.setProperty(jcrUuid, ValueConverter.toCoreValue(UUID.randomUUID().toString(), PropertyType.STRING, sessionDelegate)); + } + return null; - } + } + }); + } @Override - public void removeMixin(String mixinName) throws RepositoryException { + public void removeMixin(final String mixinName) throws RepositoryException { checkStatus(); + sessionDelegate.perform(new SessionOperation() { + @Override + public Void perform(Context context) throws RepositoryException { - if (!isNodeType(mixinName)) { - throw new NoSuchNodeTypeException(); - } + if (!isNodeType(mixinName)) { + throw new NoSuchNodeTypeException(); + } - throw new ConstraintViolationException(); - } + throw new ConstraintViolationException(); + } + }); + } @Override - public boolean canAddMixin(String mixinName) throws RepositoryException { + public boolean canAddMixin(final String mixinName) throws RepositoryException { checkStatus(); + return sessionDelegate.perform(new SessionOperation() { + @Override + public Boolean perform(Context context) throws RepositoryException { - // TODO: figure out the right place for this check - NodeTypeManager ntm = sessionDelegate.getNodeTypeManager(); - ntm.getNodeType(mixinName); // throws on not found - // TODO: END + // TODO: figure out the right place for this check + NodeTypeManager ntm = sessionDelegate.getNodeTypeManager(); + ntm.getNodeType(mixinName); // throws on not found + // TODO: END - return isSupportedMixinName(mixinName); + return isSupportedMixinName(mixinName); + } + }); } @Override Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>MacRoman =================================================================== --- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java (revision Local version) +++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java (revision Shelved version) @@ -28,7 +28,6 @@ import javax.jcr.observation.ObservationManager; import org.apache.jackrabbit.commons.iterator.EventListenerIteratorAdapter; -import org.apache.jackrabbit.oak.api.ChangeExtractor; import org.apache.jackrabbit.oak.jcr.SessionDelegate; import org.apache.jackrabbit.oak.jcr.util.LazyValue; @@ -57,10 +56,8 @@ ChangeProcessor processor = processors.get(listener); if (processor == null) { - ChangeExtractor extractor = sessionDelegate.getChangeExtractor(); ChangeFilter filter = new ChangeFilter(eventTypes, absPath, isDeep, uuid, nodeTypeName, noLocal); - ChangeProcessor changeProcessor = new ChangeProcessor(sessionDelegate.getNamePathMapper(), extractor, - listener, filter); + ChangeProcessor changeProcessor = new ChangeProcessor(sessionDelegate, listener, filter); processors.put(listener, changeProcessor); timer.get().schedule(changeProcessor, 100, 1000); } Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>MacRoman =================================================================== --- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java (revision Local version) +++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java (revision Shelved version) @@ -24,7 +24,6 @@ import javax.annotation.Nonnull; import javax.jcr.Binary; -import javax.jcr.InvalidItemStateException; import javax.jcr.ItemNotFoundException; import javax.jcr.ItemVisitor; import javax.jcr.Node; @@ -71,8 +70,13 @@ @Override @Nonnull public Node getParent() throws RepositoryException { + return sessionDelegate.perform(new SessionOperation() { + @Override + public NodeImpl perform(Context context) throws RepositoryException { - return new NodeImpl(dlg.getParent()); - } + return new NodeImpl(dlg.getParent()); + } + }); + } /** * @see javax.jcr.Item#isNew() @@ -80,9 +84,14 @@ @Override public boolean isNew() { try { + return sessionDelegate.perform(new SessionOperation() { + @Override + public Boolean perform(Context context) throws RepositoryException { - return dlg.getStatus() == Status.NEW; - } + return dlg.getStatus() == Status.NEW; + } - catch (InvalidItemStateException e) { + }); + } + catch (RepositoryException e) { return false; } } @@ -93,9 +102,14 @@ @Override public boolean isModified() { try { + return sessionDelegate.perform(new SessionOperation() { + @Override + public Boolean perform(Context context) throws RepositoryException { - return dlg.getStatus() == Status.MODIFIED; - } + return dlg.getStatus() == Status.MODIFIED; + } - catch (InvalidItemStateException e) { + }); + } + catch (RepositoryException e) { return false; } } @@ -106,8 +120,15 @@ @Override public void remove() throws RepositoryException { checkStatus(); + + sessionDelegate.perform(new SessionOperation() { + @Override + public Void perform(Context context) throws RepositoryException { - dlg.remove(); + dlg.remove(); + return null; - } + } + }); + } /** * @see javax.jcr.Item#accept(javax.jcr.ItemVisitor) @@ -135,31 +156,37 @@ * @see Property#setValue(Value[]) */ @Override - public void setValue(Value[] values) throws RepositoryException { + public void setValue(final Value[] values) throws RepositoryException { checkStatus(); + sessionDelegate.perform(new SessionOperation() { + @Override + public Void perform(Context context) throws RepositoryException { - // assert equal types for all values entries - int valueType = PropertyType.UNDEFINED; - if (values != null) { - for (Value value : values) { - if (value == null) { - // skip null values as those will be purged later - continue; - } - if (valueType == PropertyType.UNDEFINED) { - valueType = value.getType(); - } - else if (valueType != value.getType()) { - String msg = "Inhomogeneous type of values (" + this + ')'; - log.debug(msg); - throw new ValueFormatException(msg); - } - } - } + // assert equal types for all values entries + int valueType = PropertyType.UNDEFINED; + if (values != null) { + for (Value value : values) { + if (value == null) { + // skip null values as those will be purged later + continue; + } + if (valueType == PropertyType.UNDEFINED) { + valueType = value.getType(); + } + else if (valueType != value.getType()) { + String msg = "Inhomogeneous type of values (" + this + ')'; + log.debug(msg); + throw new ValueFormatException(msg); + } + } + } - int reqType = getRequiredType(valueType); - setValues(values, reqType); + int reqType = getRequiredType(valueType); + setValues(values, reqType); + return null; - } + } + }); + } /** * @see Property#setValue(String) @@ -310,23 +337,35 @@ @Nonnull public Value getValue() throws RepositoryException { checkStatus(); + + return sessionDelegate.perform(new SessionOperation() { + @Override + public Value perform(Context context) throws RepositoryException { - if (isMultiple()) { - throw new ValueFormatException(this + " is multi-valued."); - } + if (isMultiple()) { + throw new ValueFormatException(this + " is multi-valued."); + } - return ValueConverter.toValue(dlg.getValue(), sessionDelegate); - } + return ValueConverter.toValue(dlg.getValue(), sessionDelegate); + } + }); + } @Override @Nonnull public Value[] getValues() throws RepositoryException { checkStatus(); + + return sessionDelegate.perform(new SessionOperation() { + @Override + public Value[] perform(Context context) throws RepositoryException { - if (!isMultiple()) { - throw new ValueFormatException(this + " is not multi-valued."); - } + if (!isMultiple()) { + throw new ValueFormatException(this + " is not multi-valued."); + } - return ValueConverter.toValues(dlg.getValues(), sessionDelegate); - } + return ValueConverter.toValues(dlg.getValues(), sessionDelegate); + } + }); + } /** * @see Property#getString() @@ -404,49 +443,54 @@ @Override @Nonnull public Node getNode() throws RepositoryException { + return sessionDelegate.perform(new SessionOperation() { + @Override + public Node perform(Context context) throws RepositoryException { - Value value = getValue(); - switch (value.getType()) { - case PropertyType.REFERENCE: - case PropertyType.WEAKREFERENCE: - return getSession().getNodeByIdentifier(value.getString()); + Value value = getValue(); + switch (value.getType()) { + case PropertyType.REFERENCE: + case PropertyType.WEAKREFERENCE: + return getSession().getNodeByIdentifier(value.getString()); - case PropertyType.PATH: - case PropertyType.NAME: - String path = value.getString(); - if (path.startsWith("[") && path.endsWith("]")) { - // TODO OAK-23 - // TODO correct for NAME? - return getSession().getNodeByIdentifier(path.substring(1, path.length() - 1)); - } - else { - try { - return (path.charAt(0) == '/') ? getSession().getNode(path) : getParent().getNode(path); - } catch (PathNotFoundException e) { - throw new ItemNotFoundException(path); - } - } + case PropertyType.PATH: + case PropertyType.NAME: + String path = value.getString(); + if (path.startsWith("[") && path.endsWith("]")) { + // TODO OAK-23 + // TODO correct for NAME? + return getSession().getNodeByIdentifier(path.substring(1, path.length() - 1)); + } + else { + try { + return (path.charAt(0) == '/') ? getSession().getNode(path) : getParent().getNode(path); + } catch (PathNotFoundException e) { + throw new ItemNotFoundException(path); + } + } - case PropertyType.STRING: - try { - Value refValue = ValueHelper.convert(value, PropertyType.REFERENCE, getValueFactory()); - return getSession().getNodeByIdentifier(refValue.getString()); - } catch (ItemNotFoundException e) { - throw e; - } catch (RepositoryException e) { - // try if STRING value can be interpreted as PATH value - Value pathValue = ValueHelper.convert(value, PropertyType.PATH, getValueFactory()); - path = pathValue.getString(); - try { - return (path.charAt(0) == '/') ? getSession().getNode(path) : getParent().getNode(path); - } catch (PathNotFoundException e1) { - throw new ItemNotFoundException(pathValue.getString()); - } - } + case PropertyType.STRING: + try { + Value refValue = ValueHelper.convert(value, PropertyType.REFERENCE, getValueFactory()); + return getSession().getNodeByIdentifier(refValue.getString()); + } catch (ItemNotFoundException e) { + throw e; + } catch (RepositoryException e) { + // try if STRING value can be interpreted as PATH value + Value pathValue = ValueHelper.convert(value, PropertyType.PATH, getValueFactory()); + path = pathValue.getString(); + try { + return (path.charAt(0) == '/') ? getSession().getNode(path) : getParent().getNode(path); + } catch (PathNotFoundException e1) { + throw new ItemNotFoundException(pathValue.getString()); + } + } - default: - throw new ValueFormatException("Property value cannot be converted to a PATH, REFERENCE or WEAKREFERENCE"); - } - } + default: + throw new ValueFormatException("Property value cannot be converted to a PATH, REFERENCE or WEAKREFERENCE"); + } + } + }); + } /** * @see javax.jcr.Property#getProperty() @@ -454,15 +498,20 @@ @Override @Nonnull public Property getProperty() throws RepositoryException { + return sessionDelegate.perform(new SessionOperation() { + @Override + public Property perform(Context context) throws RepositoryException { - Value value = getValue(); - Value pathValue = ValueHelper.convert(value, PropertyType.PATH, getValueFactory()); - String path = pathValue.getString(); - try { - return (path.charAt(0) == '/') ? getSession().getProperty(path) : getParent().getProperty(path); - } catch (PathNotFoundException e) { - throw new ItemNotFoundException(path); - } - } + Value value = getValue(); + Value pathValue = ValueHelper.convert(value, PropertyType.PATH, getValueFactory()); + String path = pathValue.getString(); + try { + return (path.charAt(0) == '/') ? getSession().getProperty(path) : getParent().getProperty(path); + } catch (PathNotFoundException e) { + throw new ItemNotFoundException(path); + } + } + }); + } /** * @see javax.jcr.Property#getLength() @@ -490,31 +539,47 @@ @Override @Nonnull public PropertyDefinition getDefinition() throws RepositoryException { + return sessionDelegate.perform(new SessionOperation() { + @Override + public PropertyDefinition perform(Context context) { - return dlg.getDefinition(); - } + return dlg.getDefinition(); + } + }); + } /** * @see javax.jcr.Property#getType() */ @Override public int getType() throws RepositoryException { + return sessionDelegate.perform(new SessionOperation() { + @Override + public Integer perform(Context context) throws RepositoryException { - if (isMultiple()) { - Value[] values = getValues(); - if (values.length == 0) { - // retrieve the type from the property definition - return getRequiredType(PropertyType.UNDEFINED); - } else { - return values[0].getType(); - } - } else { - return getValue().getType(); - } - } + if (isMultiple()) { + Value[] values = getValues(); + if (values.length == 0) { + // retrieve the type from the property definition + return getRequiredType(PropertyType.UNDEFINED); + } else { + return values[0].getType(); + } + } else { + return getValue().getType(); + } + } + }); + } @Override public boolean isMultiple() throws RepositoryException { checkStatus(); + + return sessionDelegate.perform(new SessionOperation() { + @Override + public Boolean perform(Context context) throws RepositoryException { - return dlg.isMultivalue(); + return dlg.isMultivalue(); + } + }); } //------------------------------------------------------------< private >--- \ No newline at end of file Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>MacRoman =================================================================== --- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java (revision Local version) +++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java (revision Shelved version) @@ -51,6 +51,7 @@ import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.commons.PathUtils; import org.apache.jackrabbit.oak.core.DefaultConflictHandler; +import org.apache.jackrabbit.oak.jcr.SessionOperation.Context; import org.apache.jackrabbit.oak.jcr.nodetype.NodeTypeManagerDelegate; import org.apache.jackrabbit.oak.jcr.observation.ObservationManagerImpl; import org.apache.jackrabbit.oak.jcr.util.LazyValue; @@ -78,6 +79,8 @@ private ObservationManagerImpl observationManager; private boolean isAlive = true; + private volatile boolean refreshNeeded; + private int reentranceCounter; SessionDelegate(Repository repository, NodeTypeManagerDelegate nodeTypeManagerDelegate, LazyValue observationTimer, ContentSession contentSession) throws RepositoryException { @@ -93,6 +96,26 @@ this.session = new SessionImpl(this); this.root = contentSession.getCurrentRoot(); this.conflictHandler = new AnnotatingConflictHandler(contentSession.getCoreValueFactory()); + } + + public void setRefresh() { + refreshNeeded = true; + } + + public T perform(SessionOperation sessionOperation) throws RepositoryException { + Context context = new Context() { }; + + try { + reentranceCounter++; + if (reentranceCounter <= 1 && refreshNeeded) { + refreshNeeded = false; + refresh(true); + } + return sessionOperation.perform(context); + } + finally { + reentranceCounter--; + } } public boolean isAlive() { Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>MacRoman =================================================================== --- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java (revision Local version) +++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java (revision Shelved version) @@ -107,8 +107,14 @@ @Nonnull public Node getRootNode() throws RepositoryException { ensureIsAlive(); + + return dlg.perform(new SessionOperation() { + @Override + public NodeImpl perform(Context context) { - return new NodeImpl(dlg.getRoot()); - } + return new NodeImpl(dlg.getRoot()); + } + }); + } @Override @Nonnull @@ -118,30 +124,43 @@ @Override @Nonnull - public Node getNodeByIdentifier(String id) throws RepositoryException { + public Node getNodeByIdentifier(final String id) throws RepositoryException { ensureIsAlive(); + + return dlg.perform(new SessionOperation() { + @Override + public NodeImpl perform(Context context) throws RepositoryException { - NodeDelegate d = dlg.getNodeByIdentifier(id); - if (d == null) { - throw new ItemNotFoundException("Node with id " + id + " does not exist."); - } - return new NodeImpl(d); - } + NodeDelegate d = dlg.getNodeByIdentifier(id); + if (d == null) { + throw new ItemNotFoundException("Node with id " + id + " does not exist."); + } + return new NodeImpl(d); + } + }); + } @Override - public void move(String srcAbsPath, String destAbsPath) throws RepositoryException { + public void move(final String srcAbsPath, final String destAbsPath) throws RepositoryException { ensureIsAlive(); + dlg.perform(new SessionOperation() { + @Override + public Void perform(Context context) throws RepositoryException { - String oakPath = dlg.getOakPathKeepIndexOrThrowNotFound(destAbsPath); - String oakName = PathUtils.getName(oakPath); - // handle index - if (oakName.contains("[")) { - throw new RepositoryException("Cannot create a new node using a name including an index"); - } + String oakPath = dlg.getOakPathKeepIndexOrThrowNotFound(destAbsPath); + String oakName = PathUtils.getName(oakPath); + // handle index + if (oakName.contains("[")) { + throw new RepositoryException("Cannot create a new node using a name including an index"); + } - dlg.move( - dlg.getOakPathOrThrowNotFound(srcAbsPath), - dlg.getOakPathOrThrowNotFound(oakPath), - true); + dlg.move( + dlg.getOakPathOrThrowNotFound(srcAbsPath), + dlg.getOakPathOrThrowNotFound(oakPath), + true); + + return null; + } + }); } @Override \ No newline at end of file Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionOperation.java =================================================================== --- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionOperation.java (revision Shelved version) +++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionOperation.java (revision Shelved version) @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.jackrabbit.oak.jcr; + +import javax.jcr.RepositoryException; + +/** + * + */ +public interface SessionOperation { + interface Context { + } + + T perform(Context context) throws RepositoryException; +}