chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r955301 - in /incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src: main/java/org/apache/chemistry/opencmis/inmemory/query/ test/java/org/apache/chemistry/opencmis/inmemory/query/
Date Wed, 16 Jun 2010 17:04:25 GMT
Author: jens
Date: Wed Jun 16 17:04:25 2010
New Revision: 955301

URL: http://svn.apache.org/viewvc?rev=955301&view=rev
Log:
CMIS-216
implement in_folder and in_tree for in-memory query

Modified:
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryTestDataCreator.java

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.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/query/InMemoryQueryProcessor.java?rev=955301&r1=955300&r2=955301&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java
Wed Jun 16 17:04:25 2010
@@ -40,6 +40,8 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectListImpl;
 import org.apache.chemistry.opencmis.inmemory.TypeManager;
 import org.apache.chemistry.opencmis.inmemory.query.QueryObject.SortSpec;
+import org.apache.chemistry.opencmis.inmemory.storedobj.api.Filing;
+import org.apache.chemistry.opencmis.inmemory.storedobj.api.Folder;
 import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoredObject;
 import org.apache.chemistry.opencmis.inmemory.types.PropertyCreationHelper;
 import org.apache.chemistry.opencmis.server.support.query.CalendarHelper;
@@ -522,11 +524,58 @@ public class InMemoryQueryProcessor impl
     }
 
     private boolean evalWhereInFolder(StoredObject so, Tree node, Tree colNode, Tree paramNode)
{
-        throw new RuntimeException("Operator IN_FOLDER not supported in InMemory server.");
+        if (null != colNode) {
+            getTableReference(colNode); 
+            // just for error checking we do not evaluate this, there is only one from without
join support
+        }
+        Object lit = onLiteral(paramNode);
+        if (!(lit instanceof String))
+            throw new RuntimeException("Folder id in IN_FOLDER must be of type String");
+        String folderId = (String) lit;
+        
+        // check if object is in folder
+        if (so instanceof Filing)
+            return hasParent((Filing)so, folderId);
+        else
+            return false;
     }
 
     private boolean evalWhereInTree(StoredObject so, Tree node, Tree colNode, Tree paramNode)
{
-        throw new RuntimeException("Operator IN_TREE not supported in InMemory server.");
+        if (null != colNode) {
+            getTableReference(colNode); 
+            // just for error checking we do not evaluate this, there is only one from without
join support
+        }
+        Object lit = onLiteral(paramNode);
+        if (!(lit instanceof String))
+            throw new RuntimeException("Folder id in IN_FOLDER must be of type String");
+        String folderId = (String) lit;
+        
+        // check if object is in folder
+        if (so instanceof Filing)
+            return hasAncestor((Filing) so, folderId);
+        else
+            return false;
+    }
+    
+    private boolean hasParent(Filing objInFolder, String folderId) {
+        List<Folder> parents = objInFolder.getParents();
+        
+        for (Folder folder : parents)
+            if (folderId.equals(folder.getId()))
+                return true;
+        return false;
+    }
+
+    private boolean hasAncestor(Filing objInFolder, String folderId) {
+        List<Folder> parents = objInFolder.getParents();
+        
+        for (Folder folder : parents)
+            if (folderId.equals(folder.getId()))
+                return true;
+        for (Folder folder : parents)
+            if (hasAncestor(folder, folderId))
+                return true;
+        return false;
     }
 
     private Object onLiteral(Tree node) {
@@ -627,6 +676,13 @@ public class InMemoryQueryProcessor impl
             throw new RuntimeException("Unexpected numerical value function in where clause");
     }
     
+    private String getTableReference(Tree tableNode) {
+        String typeQueryName = queryObj.getTypeQueryName(tableNode.getText());
+        if (null == typeQueryName)
+            throw new RuntimeException("Inavlid type in IN_FOLDER() or IN_TREE(), must be
in FROM list: " + tableNode.getText());
+        return typeQueryName;
+    }
+
     private Object getPropertyValue(Tree columnNode, StoredObject so) {
         ColumnReference colRef = getColumnReference(columnNode);
         TypeDefinition td = colRef.getTypeDefinition();

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.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/query/EvalQueryTest.java?rev=955301&r1=955300&r2=955301&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java
Wed Jun 16 17:04:25 2010
@@ -528,7 +528,7 @@ public class EvalQueryTest extends Abstr
     
     @Test
     public void testLike() {
-        dataCreator.createLikeTestDocuments();
+        dataCreator.createLikeTestDocuments(fRootFolderId);
         String statement = "SELECT * FROM " + COMPLEX_TYPE + " WHERE " + UnitTestTypeSystemCreator.PROP_ID_STRING
+ " LIKE 'ABC%'";
         ObjectList res = doQuery(statement);
         assertEquals(2, res.getObjects().size());
@@ -555,7 +555,7 @@ public class EvalQueryTest extends Abstr
 
     @Test
     public void testNotLike() {
-        dataCreator.createLikeTestDocuments();
+        dataCreator.createLikeTestDocuments(fRootFolderId);
         String statement = "SELECT * FROM " + COMPLEX_TYPE + " WHERE " + UnitTestTypeSystemCreator.PROP_ID_STRING
+ " NOT LIKE 'ABC%'";
         ObjectList res = doQuery(statement);
         assertEquals(6, res.getObjects().size());
@@ -570,6 +570,51 @@ public class EvalQueryTest extends Abstr
         assertTrue(resultContains("epsilon", res));    
     }
     
+    @Test
+    public void testInFolder() {
+        String statement = "SELECT * FROM " + COMPLEX_TYPE + " WHERE IN_FOLDER('" + fRootFolderId
+ "')";
+        ObjectList res = doQuery(statement);
+        assertEquals(5, res.getObjects().size());
+        assertTrue(resultContains("alpha", res));    
+        assertTrue(resultContains("beta", res));    
+        assertTrue(resultContains("gamma", res));    
+        assertTrue(resultContains("delta", res));    
+        assertTrue(resultContains("epsilon", res));    
+
+        statement = "SELECT * FROM " + COMPLEX_TYPE + " WHERE IN_FOLDER('" + dataCreator.getFolder1()
+ "')";
+        res = doQuery(statement);
+        assertEquals(0, res.getObjects().size());
+
+        statement = "SELECT * FROM " + COMPLEX_TYPE + " WHERE IN_FOLDER(" + COMPLEX_TYPE
+ ", '" + fRootFolderId + "')";
+        res = doQuery(statement);
+        assertEquals(5, res.getObjects().size());
+        assertTrue(resultContains("alpha", res));    
+        assertTrue(resultContains("beta", res));    
+        assertTrue(resultContains("gamma", res));    
+        assertTrue(resultContains("delta", res));    
+        assertTrue(resultContains("epsilon", res));    
+    }
+
+    @Test
+    public void testInTree() {
+        dataCreator.createLikeTestDocuments(dataCreator.getFolder11());
+
+        String statement = "SELECT * FROM " + COMPLEX_TYPE + " WHERE IN_TREE('" + dataCreator.getFolder1()
+ "')";
+        ObjectList res = doQuery(statement);
+        assertEquals(3, res.getObjects().size());
+        assertTrue(resultContains("likedoc1", res));    
+        assertTrue(resultContains("likedoc2", res));    
+        assertTrue(resultContains("likedoc3", res));
+        
+        statement = "SELECT * FROM " + COMPLEX_TYPE + " WHERE IN_FOLDER(" + COMPLEX_TYPE
+ ", '" + dataCreator.getFolder1() + "')";
+        res = doQuery(statement);
+        assertEquals(0, res.getObjects().size());
+
+        statement = "SELECT * FROM " + COMPLEX_TYPE + " WHERE IN_TREE('" + dataCreator.getFolder2()
+ "')";
+        res = doQuery(statement);
+        assertEquals(0, res.getObjects().size());
+    }
+
     private ObjectList doQuery(String queryString) {
         log.debug("\nExecuting query: " + queryString);
         ObjectList res = fDiscSvc.query(fRepositoryId, queryString, false, false,

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryTestDataCreator.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/query/QueryTestDataCreator.java?rev=955301&r1=955300&r2=955301&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryTestDataCreator.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryTestDataCreator.java
Wed Jun 16 17:04:25 2010
@@ -80,6 +80,16 @@ public class QueryTestDataCreator {
         fObjSvc = objSvc;
     }
     
+    public String getFolder1() {
+        return folder1;
+    }
+    public String getFolder2() {
+        return folder2;
+    }
+    public String getFolder11() {
+        return folder11;
+    }
+    
     public void createBasicTestData() {
         createTestFolders();
         createBasicTestDocuments();
@@ -200,28 +210,28 @@ public class QueryTestDataCreator {
     }
     
     @SuppressWarnings("serial")
-    public void createLikeTestDocuments() {
+    public void createLikeTestDocuments(String folderId) {
 
         final Map<String, Object> propertyMap1 = 
             new HashMap<String, Object>() {
             { 
                 put(PROP_ID_STRING, "ABCDEF");
             }};           
-        createDocument("likedoc1", rootFolderId, COMPLEX_TYPE, propertyMap1);
+        createDocument("likedoc1", folderId, COMPLEX_TYPE, propertyMap1);
 
         final Map<String, Object> propertyMap2 = 
             new HashMap<String, Object>() {
             { 
                 put(PROP_ID_STRING, "ABC123");
             }};           
-        createDocument("likedoc2", rootFolderId, COMPLEX_TYPE, propertyMap2);
+        createDocument("likedoc2", folderId, COMPLEX_TYPE, propertyMap2);
         
         final Map<String, Object> propertyMap3 = 
             new HashMap<String, Object>() {
             { 
                 put(PROP_ID_STRING, "123ABC");
             }};           
-        createDocument("likedoc3", rootFolderId, COMPLEX_TYPE, propertyMap3);
+        createDocument("likedoc3", folderId, COMPLEX_TYPE, propertyMap3);
     }
     
     private String createFolder(String folderName, String parentFolderId, String typeId,
Map<String, Object> properties) {



Mime
View raw message