chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r946049 - in /incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src: main/java/org/apache/chemistry/opencmis/inmemory/server/ test/java/org/apache/chemistry/opencmis/inmemory/
Date Wed, 19 May 2010 06:45:08 GMT
Author: jens
Date: Wed May 19 06:45:08 2010
New Revision: 946049

URL: http://svn.apache.org/viewvc?rev=946049&view=rev
Log:
InMemoryServer: avoid parsing query string for each object in the repository

Modified:
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryDiscoveryServiceImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/DiscoveryServiceTest.java

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryDiscoveryServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryDiscoveryServiceImpl.java?rev=946049&r1=946048&r2=946049&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryDiscoveryServiceImpl.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryDiscoveryServiceImpl.java
Wed May 19 06:45:08 2010
@@ -118,7 +118,7 @@ public class InMemoryDiscoveryServiceImp
         }
     }
 
-    public ObjectList query(CallContext context, String repositoryId, String statement, Boolean
searchAllVersions,
+     public ObjectList query(CallContext context, String repositoryId, String statement,
Boolean searchAllVersions,
             Boolean includeAllowableActions, IncludeRelationships includeRelationships, String
renditionFilter,
             BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
 
@@ -127,33 +127,52 @@ public class InMemoryDiscoveryServiceImp
         ObjectStore objectStore = fStoreManager.getObjectStore(repositoryId);
 
         String user = context.getUsername();
-        String tableName = null;
         List<ObjectData> lod = new ArrayList<ObjectData>();
-        // iterate over all the objects and check for each if the query matches
-        for (String objectId : ((ObjectStoreImpl) objectStore).getIds()) {
-            StoredObject so = objectStore.getObjectById(objectId);
-            if (tableName != null) {
-                // type already available: check early
-                if (!typeMatches(context, repositoryId, tableName, so.getTypeId())) {
-                    continue;
-                }
+
+        try {
+            CMISQLParser parser = getParser(statement);
+
+            CMISQLParser.query_return parsedStatement = parser.query();
+            if (parser.errorMessage != null) {
+                throw new CmisRuntimeException("Cannot parse query: " + statement + " ("
+ parser.errorMessage + ")");
             }
-            InMemoryQueryWalker.query_return ret = queryStoredObject(statement, so);
-            if (tableName == null) {
-                // first time: check late
-                tableName = ret.tableName.toLowerCase();
-                if (!typeMatches(context, repositoryId, tableName, so.getTypeId())) {
-                    continue;
+            CommonTree tree = (CommonTree) parsedStatement.getTree();            
+            TokenStream tokens = parser.getTokenStream();
+
+            String tableName = null;
+            // iterate over all the objects and check for each if the query matches
+            for (String objectId : ((ObjectStoreImpl) objectStore).getIds()) {
+                StoredObject so = objectStore.getObjectById(objectId);
+                if (tableName != null) {
+                    // type already available: check early
+                    if (!typeMatches(context, repositoryId, tableName, so.getTypeId())) {
+                        continue;
+                    }
+                }
+                CommonTreeNodeStream nodes = new CommonTreeNodeStream(tree);
+                nodes.setTokenStream(tokens);
+                InMemoryQueryWalker walker = new InMemoryQueryWalker(nodes);
+                InMemoryQueryWalker.query_return ret = matchStoredObject(walker, so);
+                if (tableName == null) {
+                    // first time: check late
+                    tableName = ret.tableName.toLowerCase();
+                    if (!typeMatches(context, repositoryId, tableName, so.getTypeId())) {
+                        continue;
+                    }
+                }
+                if (ret.matches) {
+                    String filter = "*"; // TODO select_list
+                    ObjectData od = PropertyCreationHelper.getObjectData(fStoreManager, so,
filter, user,
+                            includeAllowableActions, includeRelationships, renditionFilter,
false, false, null);
+                    lod.add(od);
                 }
             }
-            if (ret.matches) {
-                String filter = "*"; // TODO select_list
-                ObjectData od = PropertyCreationHelper.getObjectData(fStoreManager, so, filter,
user,
-                        includeAllowableActions, includeRelationships, renditionFilter, false,
false, null);
-                lod.add(od);
-            }
-        }
 
+        } catch (IOException e) {
+            throw new CmisRuntimeException(e.getMessage(), e);
+        } catch (RecognitionException e) {
+            throw new CmisRuntimeException("Cannot parse query: " + statement, e);
+        }
         // TODO order_by_clause
 
         ObjectListImpl objList = new ObjectListImpl();
@@ -176,6 +195,20 @@ public class InMemoryDiscoveryServiceImp
         return false;
     }
 
+
+    private CMISQLParser getParser(String statement) throws RecognitionException, IOException
{
+        CharStream input = new ANTLRInputStream(new ByteArrayInputStream(statement.getBytes("UTF-8")));
+        TokenSource lexer = new CMISQLLexer(input);
+        TokenStream tokens = new CommonTokenStream(lexer);
+        CMISQLParser parser = new CMISQLParser(tokens);
+        return parser;
+    }
+        
+    private InMemoryQueryWalker.query_return matchStoredObject(InMemoryQueryWalker walker,
StoredObject so) throws RecognitionException {
+        InMemoryQueryWalker.query_return res = walker.query(so);
+        return res;
+    }
+    
     protected InMemoryQueryWalker.query_return queryStoredObject(String statement, StoredObject
so) {
         try {
             CharStream input = new ANTLRInputStream(new ByteArrayInputStream(statement.getBytes("UTF-8")));

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/DiscoveryServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/DiscoveryServiceTest.java?rev=946049&r1=946048&r2=946049&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/DiscoveryServiceTest.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/DiscoveryServiceTest.java
Wed May 19 06:45:08 2010
@@ -92,6 +92,11 @@ public class DiscoveryServiceTest extend
         // root + 2 at level 1 + 2*2 at level 2 = 7
         assertEquals(BigInteger.valueOf(7), res.getNumItems());
 
+        statement = "SELECT * FROM cmis:folder WHERE name='Jens'";
+        res = fDiscSvc.query(fRepositoryId, statement, searchAllVersions, includeAllowableActions,
+                includeRelationships, renditionFilter, maxItems, skipCount, null);
+        assertEquals(BigInteger.valueOf(0), res.getNumItems());
+
         log.info("... testQuery() finished.");
     }
 



Mime
View raw message