jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r983909 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query: QueryImpl.java lucene/NodeIteratorImpl.java lucene/QueryResultImpl.java
Date Tue, 10 Aug 2010 10:05:17 GMT
Author: jukka
Date: Tue Aug 10 10:05:16 2010
New Revision: 983909

URL: http://svn.apache.org/viewvc?rev=983909&view=rev
Log:
JCR-890: concurrent read-only access to a session

Turn Query.execute() and related methods into SessionOperations

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIteratorImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java?rev=983909&r1=983908&r2=983909&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java
Tue Aug 10 10:05:16 2010
@@ -36,11 +36,10 @@ import javax.jcr.query.QueryResult;
 import javax.jcr.version.VersionException;
 
 import org.apache.jackrabbit.core.session.SessionContext;
+import org.apache.jackrabbit.core.session.SessionOperation;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.commons.conversion.NameException;
-import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
-import org.apache.jackrabbit.spi.commons.conversion.NameResolver;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -126,7 +125,13 @@ public class QueryImpl extends AbstractQ
     public QueryResult execute() throws RepositoryException {
         checkInitialized();
         long time = System.currentTimeMillis();
-        QueryResult result = query.execute(offset, limit);
+        QueryResult result = sessionContext.getSessionState().perform(
+                new SessionOperation<QueryResult>() {
+                    public QueryResult perform(SessionContext context)
+                            throws RepositoryException {
+                        return query.execute(offset, limit);
+                    }
+                });
         if (log.isDebugEnabled()) {
             time = System.currentTimeMillis() - time;
             NumberFormat format = NumberFormat.getNumberInstance();

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIteratorImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIteratorImpl.java?rev=983909&r1=983908&r2=983909&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIteratorImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIteratorImpl.java
Tue Aug 10 10:05:16 2010
@@ -18,6 +18,8 @@ package org.apache.jackrabbit.core.query
 
 import org.apache.jackrabbit.core.ItemManager;
 import org.apache.jackrabbit.core.NodeImpl;
+import org.apache.jackrabbit.core.session.SessionContext;
+import org.apache.jackrabbit.core.session.SessionOperation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -36,15 +38,17 @@ class NodeIteratorImpl implements NodeIt
     /** Logger instance for this class */
     private static final Logger log = LoggerFactory.getLogger(NodeIteratorImpl.class);
 
+    /**
+     * Component context of the current session
+     */
+    protected final SessionContext sessionContext;
+
     /** The node ids of the nodes in the result set with their score value */
     protected final ScoreNodeIterator scoreNodes;
 
-    /** The index for the default selector withing {@link #scoreNodes} */
+    /** The index for the default selector within {@link #scoreNodes} */
     private final int selectorIndex;
 
-    /** ItemManager to turn UUIDs into Node instances */
-    protected final ItemManager itemMgr;
-
     /** Number of invalid nodes */
     protected int invalid = 0;
 
@@ -59,16 +63,15 @@ class NodeIteratorImpl implements NodeIt
     /**
      * Creates a new <code>NodeIteratorImpl</code> instance.
      *
-     * @param itemMgr       the <code>ItemManager</code> to turn UUIDs into
-     *                      <code>Node</code> instances.
+     * @param sessionContext component context of the current session
      * @param scoreNodes    iterator over score nodes.
      * @param selectorIndex the index for the default selector within
      *                      <code>scoreNodes</code>.
      */
-    NodeIteratorImpl(ItemManager itemMgr,
-                     ScoreNodeIterator scoreNodes,
-                     int selectorIndex) {
-        this.itemMgr = itemMgr;
+    NodeIteratorImpl(
+            SessionContext sessionContext, ScoreNodeIterator scoreNodes,
+            int selectorIndex) {
+        this.sessionContext = sessionContext;
         this.scoreNodes = scoreNodes;
         this.selectorIndex = selectorIndex;
     }
@@ -175,19 +178,35 @@ class NodeIteratorImpl implements NodeIt
      * method returns, then there are no more valid element in this iterator.
      */
     protected void fetchNext() {
-        // reset
-        next = null;
-        while (next == null && scoreNodes.hasNext()) {
-            ScoreNode[] sn = scoreNodes.nextScoreNodes();
-            try {
-                next = (NodeImpl) itemMgr.getItem(sn[selectorIndex].getNodeId());
-            } catch (RepositoryException e) {
-                log.warn("Exception retrieving Node with UUID: "
-                        + sn[selectorIndex].getNodeId() + ": " + e.toString());
-                // try next
-                invalid++;
+        try {
+            sessionContext.getSessionState().perform(new FetchNext());
+        } catch (RepositoryException e) {
+            log.warn("Failed to fetch next node", e);
+        }
+    }
+
+    private class FetchNext implements SessionOperation<Object> {
+
+        public Object perform(SessionContext context) {
+            next = null; // reset
+
+            ItemManager itemMgr = context.getItemManager();
+            while (next == null && scoreNodes.hasNext()) {
+                ScoreNode[] sn = scoreNodes.nextScoreNodes();
+                try {
+                    next = (NodeImpl) itemMgr.getItem(
+                            sn[selectorIndex].getNodeId());
+                } catch (RepositoryException e) {
+                    log.warn("Failed to retrieve query result node "
+                            + sn[selectorIndex].getNodeId(), e);
+                    // try next
+                    invalid++;
+                }
             }
+
+            return this;
         }
+
     }
 
     protected void initialize() {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java?rev=983909&r1=983908&r2=983909&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
Tue Aug 10 10:05:16 2010
@@ -31,7 +31,6 @@ import javax.jcr.query.RowIterator;
 
 import org.apache.jackrabbit.core.session.SessionContext;
 import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.spi.commons.conversion.NameResolver;
 import org.apache.jackrabbit.spi.commons.query.qom.ColumnImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -182,8 +181,7 @@ public abstract class QueryResultImpl im
      * {@inheritDoc}
      */
     public NodeIterator getNodes() throws RepositoryException {
-        return new NodeIteratorImpl(
-                sessionContext.getItemManager(), getScoreNodes(), 0);
+        return new NodeIteratorImpl(sessionContext, getScoreNodes(), 0);
     }
 
     /**



Mime
View raw message