jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1170592 - in /jackrabbit/sandbox/jackrabbit-mk: jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/ jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/
Date Wed, 14 Sep 2011 13:07:01 GMT
Author: mduerig
Date: Wed Sep 14 13:07:01 2011
New Revision: 1170592

URL: http://svn.apache.org/viewvc?rev=1170592&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)  query: cleanup

Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractRepositoryService.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/QueryInfoImpl.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/QueryProcessor.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractRepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractRepositoryService.java?rev=1170592&r1=1170591&r2=1170592&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractRepositoryService.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractRepositoryService.java
Wed Sep 14 13:07:01 2011
@@ -309,8 +309,7 @@ public abstract class AbstractRepository
         if (sessionInfo instanceof SessionInfoImpl) {
             return;
         }
-        throw new RepositoryException("SessionInfo not of type "
-                + SessionInfoImpl.class.getName());
+        throw new RepositoryException("SessionInfo not of type " + SessionInfoImpl.class.getName());
     }
 
     //--------------------------< descriptors >---------------------------------

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/QueryInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/QueryInfoImpl.java?rev=1170592&r1=1170591&r2=1170592&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/QueryInfoImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/QueryInfoImpl.java
Wed Sep 14 13:07:01 2011
@@ -18,8 +18,6 @@
  */
 package org.apache.jackrabbit.spi2microkernel;
 
-import java.util.ArrayList;
-import javax.jcr.RangeIterator;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.QValue;
@@ -28,16 +26,18 @@ import org.apache.jackrabbit.spi.QueryRe
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.jcr.RangeIterator;
+import java.util.ArrayList;
+
 /**
  * A query result.
  */
 public class QueryInfoImpl implements QueryInfo {
-
-    static final Logger log = LoggerFactory.getLogger(QueryInfoImpl.class);
+    private static final Logger log = LoggerFactory.getLogger(QueryInfoImpl.class);
 
     private final String[] columnNames;
     private final Name[] selectorNames;
-    final ArrayList<QueryResultRow> result = new ArrayList<QueryResultRow>();
+    private final ArrayList<QueryResultRow> result = new ArrayList<QueryResultRow>();
 
     QueryInfoImpl(String[] columnNames, Name[] selectorNames) {
         this.columnNames = columnNames;
@@ -62,7 +62,7 @@ public class QueryInfoImpl implements Qu
     public RangeIterator getRows() {
         return new RangeIterator() {
 
-            int pos = 0;
+            int pos;
 
             @Override
             public long getPosition() {
@@ -98,7 +98,6 @@ public class QueryInfoImpl implements Qu
     }
 
     static class QueryResultRowImpl implements QueryResultRow {
-
         private final NodeId node;
         private final QValue[] values;
 

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/QueryProcessor.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/QueryProcessor.java?rev=1170592&r1=1170591&r2=1170592&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/QueryProcessor.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/QueryProcessor.java
Wed Sep 14 13:07:01 2011
@@ -18,19 +18,6 @@
  */
 package org.apache.jackrabbit.spi2microkernel;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.LineNumberReader;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.index.Indexer;
 import org.apache.jackrabbit.mk.index.PrefixIndex;
@@ -49,6 +36,20 @@ import org.apache.jackrabbit.spi.commons
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
 /**
  * A tool to run a list of hardcoded queries.
  */
@@ -62,43 +63,47 @@ public class QueryProcessor {
     final IdFactory idFactory;
     final QValueFactory vf;
 
-    private final String QUERY_PLANS = "queryPlans.txt";
+    private static final String QUERY_PLANS = "queryPlans.txt";
     private long lastModified;
 
-    private ArrayList<QueryPlan> queryPlans = new ArrayList<QueryPlan>();
-    private HashMap<String, Index> indexes = new HashMap<String, Index>();
+    private final ArrayList<QueryPlan> queryPlans = new ArrayList<QueryPlan>();
+    private final HashMap<String, Index> indexes = new HashMap<String, Index>();
 
     public QueryProcessor(MicroKernel microKernel, Indexer indexer, RepositoryServiceImpl
rep) throws RepositoryException {
         this.rep = rep;
         this.microKernel = microKernel;
         this.indexer = indexer;
-        this.idFactory = rep.getIdFactory();
-        this.vf = rep.getQValueFactory();
+        idFactory = rep.getIdFactory();
+        vf = rep.getQValueFactory();
     }
 
-    public String[] checkQueryStatement(String language, String statement, Map<String,
String> namespaces) {
-        log.info("checkQueryStatement " + language + " " + statement);
+    public String[] checkQueryStatement(String language, String statement, Map<String,
String> namespaces)
+            throws RepositoryException {
+        
+        log.info("checkQueryStatement " + language + ' ' + statement);
         loadQueryPlans();
         return new String[0];
     }
 
     public QueryInfo executeQuery(SessionInfo sessionInfo, String statement, String language,
-            Map<String, String> namespaces, long limit, long offset, Map<String,
QValue> values) throws RepositoryException {
+            Map<String, String> namespaces, long limit, long offset, Map<String,
QValue> values)
+            throws RepositoryException {
+        
         loadQueryPlans();
-        log.info("executeQuery " + language + " " + statement);
+        log.info("executeQuery " + language + ' ' + statement);
         for (QueryPlan plan : queryPlans) {
             if (plan.matches(language, statement)) {
                 log.info("using plan " + plan.toString());
                 return plan.execute(sessionInfo);
             }
         }
-        log.warn("unknown query " + language + " " + statement);
+        log.warn("unknown query " + language + ' ' + statement);
         return new QueryInfoImpl(new String[0], new Name[0]);
     }
 
-    private void loadQueryPlans() {
+    private void loadQueryPlans() throws RepositoryException {
         long last = new File(QUERY_PLANS).lastModified();
-        if (queryPlans.size() != 0 && last == lastModified) {
+        if (!queryPlans.isEmpty() && last == lastModified) {
             return;
         }
         queryPlans.clear();
@@ -154,8 +159,8 @@ public class QueryProcessor {
             }
             r.close();
         } catch (IOException e) {
-            e.printStackTrace();
-            log.warn("loadQueryPlans", e);
+            log.warn(e.getMessage(), e);
+            throw new RepositoryException(e.getMessage(), e);
         }
     }
 

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java?rev=1170592&r1=1170591&r2=1170592&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
Wed Sep 14 13:07:01 2011
@@ -112,6 +112,7 @@ import static javax.jcr.Repository.OPTIO
 import static javax.jcr.Repository.OPTION_QUERY_SQL_SUPPORTED;
 import static javax.jcr.Repository.OPTION_UPDATE_MIXIN_NODE_TYPES_SUPPORTED;
 import static javax.jcr.Repository.OPTION_WORKSPACE_MANAGEMENT_SUPPORTED;
+import static javax.jcr.Repository.QUERY_LANGUAGES;
 import static javax.jcr.Repository.QUERY_XPATH_DOC_ORDER;
 import static javax.jcr.Repository.QUERY_XPATH_POS_INDEX;
 import static javax.jcr.Repository.REP_NAME_DESC;
@@ -173,13 +174,22 @@ public class RepositoryServiceImpl exten
             put(QUERY_XPATH_POS_INDEX, FALSE);
             put(LEVEL_1_SUPPORTED, TRUE);
             put(LEVEL_2_SUPPORTED, TRUE);
-            put(OPTION_QUERY_SQL_SUPPORTED, FALSE);
+            put(OPTION_QUERY_SQL_SUPPORTED, TRUE);
+            put(QUERY_LANGUAGES, toQValues(SUPPORTED_LANGUAGES));
         }
         catch (RepositoryException e) {
             throw new IllegalStateException(e); // should not happen
         }
     }};
 
+    private static QValue[] toQValues(String[] strings) throws RepositoryException { // fixme
generalize to array map
+        QValue[] qValues = new QValue[strings.length];
+        for (int k = 0; k < strings.length; k++) {
+            qValues[k] = Values.objectToValue(strings[k]);
+        }
+        return qValues;
+    }
+
     private final MicroKernel microKernel;
     private final Indexer indexer;
     private final PropertyIndex jcrUuidIndex;
@@ -561,6 +571,32 @@ public class RepositoryServiceImpl exten
         subscription(subscription).dispose();
     }
 
+    //------------------------------------------< Query >---
+
+    @Override
+    public String[] getSupportedQueryLanguages(SessionInfo sessionInfo) throws RepositoryException
{
+            checkSessionInfo(sessionInfo);
+
+        return SUPPORTED_LANGUAGES;
+    }
+
+    @Override
+    public String[] checkQueryStatement(SessionInfo sessionInfo, String statement,
+            String language, Map<String, String> namespaces) throws InvalidQueryException,
RepositoryException {
+
+        checkSessionInfo(sessionInfo);
+        return queryProcessor.checkQueryStatement(statement, language, namespaces);
+    }
+
+    @Override
+    public QueryInfo executeQuery(SessionInfo sessionInfo, String statement,
+            String language, Map<String, String> namespaces, long limit, long offset,
Map<String, QValue> values)
+            throws RepositoryException {
+        
+        checkSessionInfo(sessionInfo);
+        return queryProcessor.executeQuery(sessionInfo, statement, language, namespaces,
limit, offset, values);
+    }
+
     //------------------------------------------< private >---
 
     private Path getPath(ItemId itemId, String wspName) throws RepositoryException {
@@ -868,26 +904,4 @@ public class RepositoryServiceImpl exten
         }
     }
 
-
-    public String[] getSupportedQueryLanguages(SessionInfo sessionInfo) throws RepositoryException
{
-        checkSessionInfo(sessionInfo);
-        return SUPPORTED_LANGUAGES;
-        // throw new UnsupportedRepositoryOperationException();
-    }
-
-    public String[] checkQueryStatement(SessionInfo sessionInfo, String statement,
-                                    String language, Map<String, String> namespaces)
throws
-            InvalidQueryException, RepositoryException {
-        checkSessionInfo(sessionInfo);
-        return queryProcessor.checkQueryStatement(statement, language, namespaces);
-    }
-
-    public QueryInfo executeQuery(SessionInfo sessionInfo, String statement,
-                                  String language, Map<String, String> namespaces,
long limit,
-                                  long offset, Map<String, QValue> values) throws RepositoryException
{
-        checkSessionInfo(sessionInfo);
-        return queryProcessor.executeQuery(sessionInfo, statement, language, namespaces,
limit,
-                                  offset, values);
-    }
-
 }



Mime
View raw message