jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r783005 - in /jackrabbit/trunk: jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/ jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/quer...
Date Tue, 09 Jun 2009 13:58:49 GMT
Author: angela
Date: Tue Jun  9 13:58:49 2009
New Revision: 783005

URL: http://svn.apache.org/viewvc?rev=783005&view=rev
Log:
JCR-2107: JSR 283 Query (work in progress)

Modified:
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResourceImpl.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryManagerImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractReadableRepositoryService.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java
    jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
    jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
    jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
    jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/search/SearchInfo.java

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResourceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResourceImpl.java?rev=783005&r1=783004&r2=783005&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResourceImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResourceImpl.java
Tue Jun  9 13:58:49 2009
@@ -146,6 +146,13 @@
                     session.setNamespacePrefix(prefix, uri);
                 }
                 q = qMgr.createQuery(sInfo.getQuery(), sInfo.getLanguageName());
+
+                if (SearchInfo.NRESULTS_UNDEFINED != sInfo.getNumberResults()) {
+                    q.setLimit(sInfo.getNumberResults());
+                }
+                if (SearchInfo.OFFSET_UNDEFINED != sInfo.getOffset()) {
+                    q.setOffset(sInfo.getOffset());
+                }
             } finally {
                 // reset namespace mappings
                 for (Iterator it = namespaces.values().iterator(); it.hasNext(); ) {

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java?rev=783005&r1=783004&r2=783005&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
Tue Jun  9 13:58:49 2009
@@ -310,12 +310,14 @@
      * @param language   the query language.
      * @param namespaces the locally remapped namespaces which might be used in
      *                   the query statement.
+     * @param limit
+     * @param offset
      * @return
      * @throws RepositoryException
      */
-    public QueryInfo executeQuery(String statement, String language, Map namespaces)
-            throws RepositoryException {
-        return service.executeQuery(sessionInfo, statement, language, namespaces);
+    public QueryInfo executeQuery(String statement, String language, Map namespaces,
+                                  long limit, long offset) throws RepositoryException {
+        return service.executeQuery(sessionInfo, statement, language, namespaces, limit,
offset);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java?rev=783005&r1=783004&r2=783005&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java
Tue Jun  9 13:58:49 2009
@@ -85,6 +85,18 @@
     private WorkspaceManager wspManager;
 
     /**
+     * The maximum result size
+     * TODO: review default value
+     */
+    private long limit = Long.MAX_VALUE;
+
+    /**
+     * The offset in the total result set
+     * TODO: review default value
+     */
+    private long offset = 0;
+
+    /**
      * Creates a new query.
      *
      * @param session          the session that created this query.
@@ -151,7 +163,7 @@
      */
     public QueryResult execute() throws RepositoryException {
         QueryInfo qI = wspManager.executeQuery(
-                statement, language, getNamespaceMappings());
+                statement, language, getNamespaceMappings(), limit, offset);
         return new QueryResultImpl(itemManager, mgrProvider, qI);
     }
 
@@ -229,7 +241,7 @@
      * @see Query#bindValue(String, Value)
      */
     public void bindValue(String varName, Value value) throws RepositoryException {
-        //TODO
+        //TODO implementation missing
         throw new UnsupportedOperationException("JCR-2107: Implementation missing");
     }
 
@@ -237,15 +249,13 @@
      * @see Query#setLimit(long)
      */
     public void setLimit(long limit) {
-        // TODO
-        throw new UnsupportedOperationException("JCR-2107: Implementation missing");
+        this.limit = limit;
     }
 
     /**
      * @see Query#setOffset(long)
      */
     public void setOffset(long offset) {
-        // TODO
-        throw new UnsupportedOperationException("JCR-2107: Implementation missing");
+        this.offset = offset;
     }
 }

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryManagerImpl.java?rev=783005&r1=783004&r2=783005&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryManagerImpl.java
Tue Jun  9 13:58:49 2009
@@ -19,6 +19,8 @@
 import org.apache.jackrabbit.jcr2spi.ItemManager;
 import org.apache.jackrabbit.jcr2spi.WorkspaceManager;
 import org.apache.jackrabbit.jcr2spi.ManagerProvider;
+import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelFactoryImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
@@ -27,6 +29,7 @@
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 import javax.jcr.query.qom.QueryObjectModelFactory;
+import javax.jcr.query.qom.QueryObjectModel;
 
 /**
  * This class implements the {@link QueryManager} interface.
@@ -54,6 +57,11 @@
     private final WorkspaceManager wspManager;
 
     /**
+     * The query object model factory.
+     */
+    private final QueryObjectModelFactory qomFactory;
+
+    /**
      * Creates a new <code>QueryManagerImpl</code> for the passed
      * <code>Session</code>.
      *
@@ -65,11 +73,20 @@
     public QueryManagerImpl(Session session,
                             ManagerProvider mgrProvider,
                             ItemManager itemMgr,
-                            WorkspaceManager wspManager) {
+                            WorkspaceManager wspManager) throws RepositoryException {
         this.session = session;
         this.mgrProvider = mgrProvider;
         this.itemMgr = itemMgr;
         this.wspManager = wspManager;
+        this.qomFactory = new QueryObjectModelFactoryImpl(
+                mgrProvider.getNamePathResolver(), mgrProvider.getJcrValueFactory()) {
+            
+            protected QueryObjectModel createQuery(QueryObjectModelTree qomTree)
+                    throws InvalidQueryException, RepositoryException {
+                // TODO implementation missing
+                throw new UnsupportedOperationException("Implementation missing: JCR-2107");
+            }
+        };
     }
 
     /**
@@ -101,8 +118,7 @@
      * @see QueryManager#getQOMFactory()
      */
     public QueryObjectModelFactory getQOMFactory() {
-        // TODO
-        throw new UnsupportedOperationException("JCR-2107: Implementation missing");    
   
+        return qomFactory;        
     }
 
     //------------------------------------------------------------< private >---

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractReadableRepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractReadableRepositoryService.java?rev=783005&r1=783004&r2=783005&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractReadableRepositoryService.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractReadableRepositoryService.java
Tue Jun  9 13:58:49 2009
@@ -783,4 +783,10 @@
             RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
+
+    public QueryInfo executeQuery(SessionInfo sessionInfo, String statement,
+                                  String language, Map namespaces, long limit,
+                                  long offset) throws RepositoryException {
+        throw new UnsupportedRepositoryOperationException();
+    }
 }

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java?rev=783005&r1=783004&r2=783005&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java
Tue Jun  9 13:58:49 2009
@@ -564,6 +564,17 @@
                 new Object[]{unwrap(sessionInfo), statement, language, namespaces});
     }
 
+    public QueryInfo executeQuery(final SessionInfo sessionInfo, final String statement,
+            final String language, final Map namespaces, final long limit, final long offset)
throws RepositoryException {
+
+        return (QueryInfo) execute(new Callable() {
+            public Object call() throws RepositoryException {
+                return service.executeQuery(unwrap(sessionInfo), statement, language, namespaces,
limit, offset);
+            }
+        }, "executeQuery(SessionInfo, String, String, Map, long, long)",
+                new Object[]{unwrap(sessionInfo), statement, language, namespaces, limit,
offset});
+    }
+
     public EventFilter createEventFilter(final SessionInfo sessionInfo, final int eventTypes,
             final Path absPath, final boolean isDeep, final String[] uuid, final Name[] qnodeTypeName,
             final boolean noLocal) throws RepositoryException {

Modified: jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java?rev=783005&r1=783004&r2=783005&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
Tue Jun  9 13:58:49 2009
@@ -825,7 +825,7 @@
      * @param activityId
      * @throws javax.jcr.UnsupportedRepositoryOperationException
      * @throws javax.jcr.RepositoryException
-     * @see javax.jcr.version.VersionManager#removeActivity(String)
+     * @see javax.jcr.version.VersionManager#removeActivity(Node)
      * @since JCR 2.0
      */
     public void removeActivity(SessionInfo sessionInfo, NodeId activityId) throws UnsupportedRepositoryOperationException,
RepositoryException;
@@ -900,6 +900,25 @@
      */
     public QueryInfo executeQuery(SessionInfo sessionInfo, String statement, String language,
Map namespaces) throws RepositoryException;
 
+    /**
+     * Execute the given query statement with the specified query language. The
+     * additional <code>namespaces</code> parameter provides a mapping of prefix
+     * to namespace uri in order to be able to properly resolve prefix:localname
+     * patterns present within the query statement.
+     *
+     * @param sessionInfo
+     * @param statement the query statement to be execute.
+     * @param language the query language used to parse the query <code>statement</code>.
+     * @param namespaces the locally re-mapped namespace which may be used in
+     * the query <code>statement</code>.
+     * @param limit The maximum result size.
+     * @param offset The offset in the total result set.
+     * @return The query info.
+     * @throws javax.jcr.RepositoryException
+     * @see javax.jcr.query.Query#execute()
+     */
+    public QueryInfo executeQuery(SessionInfo sessionInfo, String statement, String language,
Map namespaces, long limit, long offset) throws RepositoryException;
+
     //--------------------------------------------------------< Observation >---
     /**
      * Creates an event filter. If the repository supports observation, the

Modified: jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java?rev=783005&r1=783004&r2=783005&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
Tue Jun  9 13:58:49 2009
@@ -1703,6 +1703,37 @@
     }
 
     /**
+     * @see RepositoryService#executeQuery(SessionInfo, String, String, Map, long, long)
+     */
+    public QueryInfo executeQuery(SessionInfo sessionInfo, String statement, String language,
Map namespaces, long limit, long offset) throws RepositoryException {
+        SearchMethod method = null;
+        try {
+            String uri = uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName());
+            SearchInfo sInfo = new SearchInfo(language,
+                    Namespace.EMPTY_NAMESPACE, statement, namespaces);
+            
+            sInfo.setNumberResults(limit);
+            sInfo.setOffset(offset);
+
+            method = new SearchMethod(uri, sInfo);
+            getClient(sessionInfo).executeMethod(method);
+            method.checkSuccess();
+
+            MultiStatus ms = method.getResponseBodyAsMultiStatus();
+            NamePathResolver resolver = getNamePathResolver(sessionInfo);
+            return new QueryInfoImpl(ms, sessionInfo, uriResolver, resolver, valueFactory,
getQValueFactory());
+        } catch (IOException e) {
+            throw new RepositoryException(e);
+        } catch (DavException e) {
+            throw ExceptionConverter.generate(e);
+        }  finally {
+            if (method != null) {
+                method.releaseConnection();
+            }
+        }
+    }
+
+    /**
      * @see RepositoryService#createEventFilter(SessionInfo, int, Path, boolean, String[],
Name[], boolean)
      */
     public EventFilter createEventFilter(SessionInfo sessionInfo,

Modified: jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java?rev=783005&r1=783004&r2=783005&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
Tue Jun  9 13:58:49 2009
@@ -1040,6 +1040,16 @@
                 sInfo.getNamePathResolver(), getQValueFactory());
     }
 
+    public QueryInfo executeQuery(SessionInfo sessionInfo, String statement, String language,
Map namespaces, long limit, long offset) throws RepositoryException {
+        SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
+        Query query = createQuery(sInfo.getSession(), statement,
+                language, namespaces);
+        query.setLimit(limit);
+        query.setOffset(offset);
+        return new QueryInfoImpl(query.execute(), idFactory,
+                sInfo.getNamePathResolver(), getQValueFactory());
+    }
+
     /**
      * {@inheritDoc}
      */

Modified: jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/search/SearchInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/search/SearchInfo.java?rev=783005&r1=783004&r2=783005&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/search/SearchInfo.java
(original)
+++ jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/search/SearchInfo.java
Tue Jun  9 13:58:49 2009
@@ -62,6 +62,13 @@
 
     private static Logger log = LoggerFactory.getLogger(SearchInfo.class);
 
+    public static final long NRESULTS_UNDEFINED = -1;
+    public static final long OFFSET_UNDEFINED = -1;
+
+    private static final String LIMIT = "limit";
+    private static final String NRESULTS = "nresults";
+    private static final String OFFSET = "offset";
+
     /**
      * Set of namespace uri String which are ignored in the search request.
      */
@@ -80,6 +87,9 @@
     private final String query;
     private final Map namespaces;
 
+    private long nresults = NRESULTS_UNDEFINED;
+    private long offset = OFFSET_UNDEFINED;
+
     /**
      * Create a new <code>SearchInfo</code> instance.
      *
@@ -143,6 +153,42 @@
     }
 
     /**
+     * Returns the maximal number of search results that should be returned.
+     *
+     * @return the maximal number of search results that should be returned.
+     */
+    public long getNumberResults() {
+        return nresults;
+    }
+
+    /**
+     * Sets the maximal number of search results that should be returned.
+     *
+     * @param nresults The maximal number of search results
+     */
+    public void setNumberResults(long nresults) {
+        this.nresults = nresults;
+    }
+
+    /**
+     * Returns the desired offset in the total result set.
+     *
+     * @return the desired offset in the total result set.
+     */
+    public long getOffset() {
+        return offset;
+    }
+
+    /**
+     * Sets the desired offset in the total result set.
+     *
+     * @param offset The desired offset in the total result set.
+     */
+    public void setOffset(long offset) {
+        this.offset = offset;
+    }
+
+    /**
      * Return the xml representation of this <code>SearchInfo</code> instance.
      *
      * @return xml representation
@@ -156,6 +202,16 @@
             DomUtil.setNamespaceAttribute(sRequestElem, prefix, uri);
         }
         DomUtil.addChildElement(sRequestElem, language, languageNamespace, query);
+        if (nresults != NRESULTS_UNDEFINED|| offset != OFFSET_UNDEFINED) {
+            Element limitE = DomUtil.addChildElement(sRequestElem, LIMIT, NAMESPACE);
+            if (nresults != NRESULTS_UNDEFINED) {
+                DomUtil.addChildElement(limitE, NRESULTS, NAMESPACE, nresults + "");
+            }
+            if (offset != OFFSET_UNDEFINED) {
+                // TODO define reasonable namespace...
+                DomUtil.addChildElement(limitE, OFFSET, Namespace.EMPTY_NAMESPACE, offset
+ "");
+            }
+        }
         return sRequestElem;
     }
 
@@ -182,11 +238,35 @@
                 namespaces.put(nsAttributes[i].getLocalName(), nsAttributes[i].getValue());
             }
         }
+        SearchInfo sInfo;
         if (first != null) {
-            return new SearchInfo(first.getLocalName(), DomUtil.getNamespace(first), DomUtil.getText(first),
namespaces);
+            sInfo = new SearchInfo(first.getLocalName(), DomUtil.getNamespace(first), DomUtil.getText(first),
namespaces);
         } else {
             log.warn("A single child element is expected with the 'DAV:searchrequest'.");
             throw new DavException(DavServletResponse.SC_BAD_REQUEST);
         }
+
+        Element limit = DomUtil.getChildElement(searchRequest, LIMIT, NAMESPACE);
+        if (limit != null) {
+            // try to get the value DAV:nresults element
+            String nresults = DomUtil.getChildTextTrim(limit, NRESULTS, NAMESPACE);
+            if (nresults != null) {
+                try {
+                    sInfo.setNumberResults(Long.valueOf(nresults));
+                } catch (NumberFormatException e) {
+                    log.error("DAV:nresults cannot be parsed into a long -> ignore.");
+                }
+            }
+            // try of an offset is defined within the DAV:limit element.
+            String offset = DomUtil.getChildTextTrim(limit, OFFSET, Namespace.EMPTY_NAMESPACE);
+            if (offset != null) {
+                try {
+                    sInfo.setOffset(Long.valueOf(offset));
+                } catch (NumberFormatException e) {
+                    log.error("'offset' cannot be parsed into a long -> ignore.");
+                }
+            }
+        }
+        return sInfo;
     }
 }
\ No newline at end of file



Mime
View raw message