You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by md...@apache.org on 2011/08/25 18:57:31 UTC
svn commit: r1161637 - in /jackrabbit/sandbox/jackrabbit-mk: ./
jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/
jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/
jackrabbit-jcr-commons/src/main/java/org/apache...
Author: mduerig
Date: Thu Aug 25 16:57:31 2011
New Revision: 1161637
URL: http://svn.apache.org/viewvc?rev=1161637&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)
merge changes from trunk
Added:
jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/FilterIterator.java
- copied unchanged from r1161636, jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/FilterIterator.java
jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/SizedIterator.java
- copied unchanged from r1161636, jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/SizedIterator.java
Modified:
jackrabbit/sandbox/jackrabbit-mk/ (props changed)
jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/BTreeManager.java
jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/FilterIterator.java
jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/SizedIterator.java
jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/TreeTraverser.java
jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
Propchange: jackrabbit/sandbox/jackrabbit-mk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Aug 25 16:57:31 2011
@@ -1,2 +1,2 @@
/jackrabbit/sandbox/JCR-2415-lucene-3.0:1060860-1064038
-/jackrabbit/trunk:1158344-1161059
+/jackrabbit/trunk:1158344-1161636
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java?rev=1161637&r1=1161636&r2=1161637&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java Thu Aug 25 16:57:31 2011
@@ -29,6 +29,7 @@ import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.util.StringTokenizer;
import javax.imageio.spi.ServiceRegistry;
import javax.jcr.Binary;
@@ -41,6 +42,7 @@ import javax.jcr.PropertyType;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.RepositoryFactory;
+import javax.jcr.Session;
import javax.jcr.Value;
import javax.jcr.nodetype.NodeType;
import javax.jcr.query.QueryResult;
@@ -864,4 +866,275 @@ public class JcrUtils {
}
}
+ /**
+ * Creates or gets the {@link javax.jcr.Node Node} at the given Path.
+ * In case it has to create the Node all non-existent intermediate path-elements
+ * will be created with the given NodeType.
+ *
+ * <p>
+ * Changes made are not saved by this method, so <code>session.save()</code>
+ * has to be called to persist them.
+ *
+ * @param absolutePath absolute path to create
+ * @param nodeType to use for creation of nodes If <code>null</code> the node type
+ * is determined by the child node definitions of the parent node.
+ * @param session to use
+ * @return the Node at path
+ * @throws RepositoryException in case of exception accessing the Repository
+ */
+ public static Node getOrCreateByPath(String absolutePath, String nodeType, Session session)
+ throws RepositoryException {
+ return getOrCreateByPath(absolutePath, false, nodeType, nodeType, session, false);
+ }
+
+ /**
+ * Creates or gets the {@link javax.jcr.Node Node} at the given Path.
+ * In case it has to create the Node all non-existent intermediate path-elements
+ * will be created with the given intermediate node type and the returned node
+ * will be created with the given nodeType.
+ *
+ * @param absolutePath absolute path to create
+ * @param intermediateNodeType to use for creation of intermediate nodes. If <code>null</code> the node type
+ * is determined by the child node definitions of the parent node.
+ * @param nodeType to use for creation of the final node. If <code>null</code> the node type
+ * is determined by the child node definitions of the parent node.
+ * @param session to use
+ * @param autoSave Should save be called when a new node is created?
+ * @return the Node at absolutePath
+ * @throws RepositoryException in case of exception accessing the Repository
+ */
+ public static Node getOrCreateByPath(String absolutePath,
+ String intermediateNodeType,
+ String nodeType,
+ Session session,
+ boolean autoSave)
+ throws RepositoryException {
+ return getOrCreateByPath(absolutePath, false, intermediateNodeType, nodeType, session, autoSave);
+ }
+
+ /**
+ * Creates a {@link javax.jcr.Node Node} at the given Path. In case it has
+ * to create the Node all non-existent intermediate path-elements will be
+ * created with the given intermediate node type and the returned node will
+ * be created with the given nodeType.
+ *
+ * <p>
+ * If the path points to an existing node, the leaf node name will be
+ * regarded as a name hint and a unique node name will be created by
+ * appending a number to the given name (eg. <code>/some/path/foobar2</code>).
+ * Please note that <b>the uniqueness check is not an atomic JCR operation</b>,
+ * so it is possible that you get a {@link RepositoryException} (path
+ * already exists) if another concurrent session created the same node in
+ * the meantime.
+ *
+ * <p>
+ * Changes made are not saved by this method, so <code>session.save()</code>
+ * has to be called to persist them.
+ *
+ * @param pathHint
+ * path to create
+ * @param nodeType
+ * to use for creation of nodes. . If <code>null</code> the node type
+ * is determined by the child node definitions of the parent node.
+ * @param session
+ * to use
+ * @return the newly created Node
+ * @throws RepositoryException
+ * in case of exception accessing the Repository
+ */
+ public static Node getOrCreateUniqueByPath(String pathHint, String nodeType, Session session)
+ throws RepositoryException {
+ return getOrCreateByPath(pathHint, true, nodeType, nodeType, session, false);
+ }
+
+ /**
+ * Creates or gets the {@link javax.jcr.Node Node} at the given Path. In
+ * case it has to create the Node all non-existent intermediate
+ * path-elements will be created with the given intermediate node type and
+ * the returned node will be created with the given nodeType.
+ *
+ * <p>
+ * If the parameter <code>createUniqueLeaf</code> is set, it will not get
+ * an existing node but rather try to create a unique node by appending a
+ * number to the last path element (leaf node). Please note that <b>the
+ * uniqueness check is not an atomic JCR operation</b>, so it is possible
+ * that you get a {@link RepositoryException} (path already exists) if
+ * another concurrent session created the same node in the meantime.
+ *
+ * @param absolutePath
+ * absolute path to create
+ * @param createUniqueLeaf
+ * whether the leaf of the path should be regarded as a name hint
+ * and a unique node name should be created by appending a number
+ * to the given name (eg. <code>/some/path/foobar2</code>)
+ * @param intermediateNodeType
+ * to use for creation of intermediate nodes. If <code>null</code> the node type
+ * is determined by the child node definitions of the parent node.
+ * @param nodeType
+ * to use for creation of the final node. If <code>null</code> the node type
+ * is determined by the child node definitions of the parent node.
+ * @param session
+ * to use
+ * @param autoSave
+ * Should save be called when a new node is created?
+ * @return the Node at absolutePath
+ * @throws RepositoryException
+ * in case of exception accessing the Repository
+ */
+ public static Node getOrCreateByPath(String absolutePath,
+ boolean createUniqueLeaf,
+ String intermediateNodeType,
+ String nodeType,
+ Session session,
+ boolean autoSave)
+ throws RepositoryException {
+ if (absolutePath == null || absolutePath.length() == 0 || "/".equals(absolutePath)) {
+ // path denotes root node
+ return session.getRootNode();
+ }
+ // create path relative to the root node
+ return getOrCreateByPath(session.getRootNode(), absolutePath.substring(1),
+ createUniqueLeaf, intermediateNodeType, nodeType, autoSave);
+ }
+
+ /**
+ * Creates or gets the {@link javax.jcr.Node Node} at the given Path. In
+ * case it has to create the Node all non-existent intermediate
+ * path-elements will be created with the given intermediate node type and
+ * the returned node will be created with the given nodeType.
+ *
+ * <p>
+ * If the node name points to an existing node, the node name will be
+ * regarded as a name hint and a unique node name will be created by
+ * appending a number to the given name (eg. <code>/some/path/foobar2</code>).
+ * Please note that <b>the uniqueness check is not an atomic JCR operation</b>,
+ * so it is possible that you get a {@link RepositoryException} (path
+ * already exists) if another concurrent session created the same node in
+ * the meantime.
+ *
+ * <p>
+ * Changes made are not saved by this method, so <code>session.save()</code>
+ * has to be called to persist them.
+ *
+ * @param parent
+ * existing parent node for the new node
+ * @param nodeNameHint
+ * name hint for the new node
+ * @param nodeType
+ * to use for creation of the node. If <code>null</code> the node type
+ * is determined by the child node definitions of the parent node.
+ * @return the newly created Node
+ * @throws RepositoryException
+ * in case of exception accessing the Repository
+ */
+ public static Node getOrCreateUniqueByPath(Node parent,
+ String nodeNameHint,
+ String nodeType)
+ throws RepositoryException {
+ return getOrCreateByPath(parent, nodeNameHint, true, nodeType, nodeType, false);
+ }
+
+ /**
+ * Creates or gets the {@link javax.jcr.Node Node} at the given path
+ * relative to the baseNode. In case it has to create the Node all
+ * non-existent intermediate path-elements will be created with the given
+ * intermediate node type and the returned node will be created with the
+ * given nodeType.
+ *
+ * <p>
+ * If the parameter <code>createUniqueLeaf</code> is set, it will not get
+ * an existing node but rather try to create a unique node by appending a
+ * number to the last path element (leaf node). Please note that <b>the
+ * uniqueness check is not an atomic JCR operation</b>, so it is possible
+ * that you get a {@link RepositoryException} (path already exists) if
+ * another concurrent session created the same node in the meantime.
+ *
+ * @param baseNode
+ * existing node that should be the base for the relative path
+ * @param path
+ * relative path to create
+ * @param createUniqueLeaf
+ * whether the leaf of the path should be regarded as a name hint
+ * and a unique node name should be created by appending a number
+ * to the given name (eg. <code>/some/path/foobar2</code>)
+ * @param intermediateNodeType
+ * to use for creation of intermediate nodes. If <code>null</code> the node type
+ * is determined by the child node definitions of the parent node.
+ * @param nodeType
+ * to use for creation of the final node. If <code>null</code> the node type
+ * is determined by the child node definitions of the parent node.
+ * @param autoSave
+ * Should save be called when a new node is created?
+ * @return the Node at path
+ * @throws RepositoryException
+ * in case of exception accessing the Repository
+ */
+ public static Node getOrCreateByPath(Node baseNode,
+ String path,
+ boolean createUniqueLeaf,
+ String intermediateNodeType,
+ String nodeType,
+ boolean autoSave)
+ throws RepositoryException {
+
+ if (!createUniqueLeaf && baseNode.hasNode(path)) {
+ // node at path already exists, quicker way
+ return baseNode.getNode(path);
+ }
+
+ Node node = baseNode;
+ int pos = path.lastIndexOf('/');
+
+ // intermediate path elements
+ if (pos != -1) {
+ final StringTokenizer st = new StringTokenizer(path.substring(0, pos), "/");
+ while (st.hasMoreTokens()) {
+ final String token = st.nextToken();
+ if (!node.hasNode(token)) {
+ try {
+ if ( intermediateNodeType != null ) {
+ node.addNode(token, intermediateNodeType);
+ } else {
+ node.addNode(token);
+ }
+ if (autoSave) node.getSession().save();
+ } catch (RepositoryException e) {
+ // we ignore this as this folder might be created from a different task
+ node.refresh(false);
+ }
+ }
+ node = node.getNode(token);
+ }
+ path = path.substring(pos + 1);
+ }
+
+ // last path element (path = leaf node name)
+ if (!node.hasNode(path)) {
+ if ( nodeType != null ) {
+ node.addNode(path, nodeType);
+ } else {
+ node.addNode(path);
+ }
+ if (autoSave) node.getSession().save();
+ } else if (createUniqueLeaf) {
+ // leaf node already exists, create new unique name
+ String leafNodeName;
+ int i = 0;
+ do {
+ leafNodeName = path + String.valueOf(i);
+ i++;
+ } while (node.hasNode(leafNodeName));
+
+ Node leaf;
+ if ( nodeType != null ) {
+ leaf = node.addNode(leafNodeName, nodeType);
+ } else {
+ leaf = node.addNode(leafNodeName);
+ }
+ if (autoSave) node.getSession().save();
+ return leaf;
+ }
+
+ return node.getNode(path);
+ }
}
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/BTreeManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/BTreeManager.java?rev=1161637&r1=1161636&r2=1161637&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/BTreeManager.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/BTreeManager.java Thu Aug 25 16:57:31 2011
@@ -17,6 +17,8 @@
package org.apache.jackrabbit.commons.flat;
import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.commons.iterator.FilterIterator;
+import org.apache.jackrabbit.commons.iterator.SizedIterator;
import org.apache.jackrabbit.commons.predicate.Predicate;
import javax.jcr.Item;
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/FilterIterator.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/FilterIterator.java?rev=1161637&r1=1161636&r2=1161637&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/FilterIterator.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/FilterIterator.java Thu Aug 25 16:57:31 2011
@@ -24,53 +24,18 @@ import java.util.NoSuchElementException;
/**
* Iterator filtering out items which do not match a given predicate.
* @param <T>
+ * @deprecated use {@link org.apache.jackrabbit.commons.iterator.FilterIterator}
*/
-public class FilterIterator<T> implements Iterator<T> {
- private final Iterator<T> iterator;
- private final Predicate predicate;
-
- private T next = null;
+public class FilterIterator<T> extends org.apache.jackrabbit.commons.iterator.FilterIterator<T> {
/**
* Create a new filtered iterator based on the given <code>iterator</code>.
*
* @param iterator iterator to filter
- * @param predicate only item matching this predicate are included
- */
- public FilterIterator(Iterator<T> iterator, Predicate predicate) {
- super();
- this.iterator = iterator;
- this.predicate = predicate;
- }
-
- public boolean hasNext() {
- while (next == null && iterator.hasNext()) {
- T e = iterator.next();
- if (predicate.evaluate(e)) {
- next = e;
- }
- }
-
- return next != null;
- }
-
- public T next() {
- if (hasNext()) {
- T e = next;
- next = null;
- return e;
- }
- else {
- throw new NoSuchElementException();
- }
- }
-
- /**
- * @throws UnsupportedOperationException always
- * @see java.util.Iterator#remove()
+ * @param predicate only item matching this predicate are included
*/
- public void remove() {
- throw new UnsupportedOperationException();
+ public FilterIterator(Iterator<T> tIterator, Predicate predicate) {
+ super(tIterator, predicate);
}
}
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/SizedIterator.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/SizedIterator.java?rev=1161637&r1=1161636&r2=1161637&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/SizedIterator.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/SizedIterator.java Thu Aug 25 16:57:31 2011
@@ -19,17 +19,11 @@ package org.apache.jackrabbit.commons.fl
import java.util.Iterator;
/**
- * <code>SizedIterator</code> extends {@link Iterator} with a
+ * <code>SizedIterator</code> extends {@link java.util.Iterator} with a
* <code>getSize</code> method.
*
* @param <T> the type of elements of this iterator
+ * @deprecated use {@link org.apache.jackrabbit.commons.iterator.SizedIterator}
*/
-public interface SizedIterator<T> extends Iterator<T> {
-
- /**
- * The number of elements of this iterator or -1 if not known.
- *
- * @return number of elements.
- */
- long getSize();
+public interface SizedIterator<T> extends org.apache.jackrabbit.commons.iterator.SizedIterator<T> {
}
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/TreeTraverser.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/TreeTraverser.java?rev=1161637&r1=1161636&r2=1161637&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/TreeTraverser.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/flat/TreeTraverser.java Thu Aug 25 16:57:31 2011
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.commons.fl
import static org.apache.jackrabbit.commons.iterator.LazyIteratorChain.chain;
+import org.apache.jackrabbit.commons.iterator.FilterIterator;
import org.apache.jackrabbit.commons.predicate.Predicate;
import javax.jcr.Item;
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java?rev=1161637&r1=1161636&r2=1161637&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java Thu Aug 25 16:57:31 2011
@@ -89,7 +89,7 @@ public class WorkspaceItemStateFactory e
if (isUpToDate(cached, entry)) {
info = cached.info;
} else {
- // otherwise retreive item info from service and cache the whole batch
+ // otherwise retrieve item info from service and cache the whole batch
Iterator<? extends ItemInfo> infos = service.getItemInfos(sessionInfo, nodeId);
info = first(infos, cache, entry.getGeneration());
if (info == null || !info.denotesNode()) {
@@ -168,7 +168,7 @@ public class WorkspaceItemStateFactory e
if (isUpToDate(cached, entry)) {
info = cached.info;
} else {
- // otherwise retreive item info from service and cache the whole batch
+ // otherwise retrieve item info from service and cache the whole batch
Iterator<? extends ItemInfo> infos = service.getItemInfos(sessionInfo, propertyId);
info = first(infos, cache, entry.getGeneration());
if (info == null || info.denotesNode()) {
@@ -215,7 +215,7 @@ public class WorkspaceItemStateFactory e
} else {
long generation = entry.getGeneration();
if (isOutdated(cached, entry)) {
- // if not, retreive the item info from the service and put the whole batch into the cache
+ // if not, retrieve the item info from the service and put the whole batch into the cache
infos = service.getItemInfos(sessionInfo, propertyId);
info = first(infos, cache, generation);
} else if (infos != null) {