chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r920275 - in /incubator/chemistry/trunk/chemistry: chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/ chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/ chemistry-commons/src/main/antlr3/org/apache/chem...
Date Mon, 08 Mar 2010 11:18:22 GMT
Author: fguillaume
Date: Mon Mar  8 11:18:21 2010
New Revision: 920275

URL: http://svn.apache.org/viewvc?rev=920275&view=rev
Log:
CMIS-147: Implement datetime and boolean literals in CMISQL parser

Removed:
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/ContentManagerException.java
Modified:
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObject.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPRepositoryService.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/Connector.java
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlLexer.g
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlParser.g
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/impl/simple/CmisSqlSimpleWalker.g
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/CmisSql.testsuite
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/java/org/apache/chemistry/impl/simple/TestSimpleRepository.java

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObject.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObject.java?rev=920275&r1=920274&r2=920275&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObject.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObject.java
Mon Mar  8 11:18:21 2010
@@ -223,18 +223,14 @@
     }
 
     public void save() {
-        try {
-            if (entry.isCreation()) {
-                create();
-            } else {
-                update();
-            }
-        } catch (ContentManagerException e) { // TODO
-            throw new RuntimeException(e);
+        if (entry.isCreation()) {
+            create();
+        } else {
+            update();
         }
     }
 
-    protected void create() throws ContentManagerException {
+    protected void create() {
         // this link value is local, set by APPConnection#newDocument
         String href = entry.getLink(AtomPub.LINK_UP);
         if (href == null) {
@@ -246,7 +242,7 @@
         entry = entry.connection.connector.postEntry(href, null, entry);
     }
 
-    protected void update() throws ContentManagerException {
+    protected void update() {
         String href = entry.getEditLink();
         if (href == null) {
             throw new CMISRuntimeException("Missing edit link");

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPRepositoryService.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPRepositoryService.java?rev=920275&r1=920274&r2=920275&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPRepositoryService.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPRepositoryService.java
Mon Mar  8 11:18:21 2010
@@ -82,12 +82,12 @@
         repos = connector.getServiceDocument(url);
     }
 
-    public Repository getDefaultRepository() throws ContentManagerException {
+    public Repository getDefaultRepository() {
         loadRepositories();
         return repos.size() == 0 ? null : repos.get(0);
     }
 
-    public Repository getRepository(String id) throws ContentManagerException {
+    public Repository getRepository(String id) {
         loadRepositories();
         for (Repository repository : repos) {
             if (repository.getId().equals(id)) {

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/Connector.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/Connector.java?rev=920275&r1=920274&r2=920275&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/Connector.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/Connector.java
Mon Mar  8 11:18:21 2010
@@ -27,6 +27,7 @@
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 
+import org.apache.chemistry.CMISRuntimeException;
 import org.apache.chemistry.ConstraintViolationException;
 import org.apache.chemistry.ContentStream;
 import org.apache.chemistry.Inclusion;
@@ -77,13 +78,13 @@
             client.executeMethod(method);
             int status = method.getStatusCode();
             if (status >= HttpStatus.SC_BAD_REQUEST) {
-                throw new ContentManagerException(
+                throw new CMISRuntimeException(
                         "Remote server returned error code: " + status);
             }
             return new APPServiceDocumentReader().read(ctx,
                     method.getResponseBodyAsStream());
         } catch (IOException e) {
-            throw new ContentManagerException(e);
+            throw new CMISRuntimeException(e);
         } finally {
             method.releaseConnection();
         }
@@ -109,14 +110,14 @@
             client.executeMethod(method);
             int status = method.getStatusCode();
             if (status >= HttpStatus.SC_BAD_REQUEST) {
-                throw new ContentManagerException(
+                throw new CMISRuntimeException(
                         "Remote server returned error code: " + status);
             }
             return reader.read(ctx, method.getResponseBodyAsStream());
         } catch (IOException e) {
-            throw new ContentManagerException(e);
+            throw new CMISRuntimeException(e);
         } catch (XMLStreamException e) {
-            throw new ContentManagerException(e);
+            throw new CMISRuntimeException(e);
         } finally {
             method.releaseConnection();
         }
@@ -150,14 +151,14 @@
                 throw new ConstraintViolationException(msg);
             }
             if (status >= HttpStatus.SC_BAD_REQUEST) {
-                throw new ContentManagerException(
+                throw new CMISRuntimeException(
                         "Remote server returned error code: " + status);
             }
             return reader.read(ctx, method.getResponseBodyAsStream());
         } catch (IOException e) {
-            throw new ContentManagerException(e);
+            throw new CMISRuntimeException(e);
         } catch (XMLStreamException e) {
-            throw new ContentManagerException(e);
+            throw new CMISRuntimeException(e);
         } finally {
             method.releaseConnection();
         }
@@ -174,7 +175,7 @@
                 throw new ConstraintViolationException("No content stream");
             }
             if (status >= HttpStatus.SC_BAD_REQUEST) {
-                throw new ContentManagerException(
+                throw new CMISRuntimeException(
                         "Remote server returned error code: " + status);
             }
             InputStream is = method.getResponseBodyAsStream();
@@ -191,7 +192,6 @@
         return getObject(href, "", new AllowableActionsReader());
     }
 
-
     public APPObjectEntry putEntry(String href, Header header,
             APPObjectEntry entry) {
         RequestEntity requestEntity = new XmlObjectWriterRequestEntity<ObjectEntry>(
@@ -222,7 +222,7 @@
             client.executeMethod(method);
             int status = method.getStatusCode();
             if (status >= HttpStatus.SC_BAD_REQUEST) {
-                throw new ContentManagerException(
+                throw new CMISRuntimeException(
                         "Remote server returned error code: " + status);
             }
             if (requestEntity instanceof InputStreamRequestEntity) {
@@ -233,9 +233,9 @@
                         method.getResponseBodyAsStream());
             }
         } catch (IOException e) {
-            throw new ContentManagerException(e);
+            throw new CMISRuntimeException(e);
         } catch (XMLStreamException e) {
-            throw new ContentManagerException(e);
+            throw new CMISRuntimeException(e);
         } finally {
             method.releaseConnection();
         }
@@ -256,7 +256,7 @@
             client.executeMethod(method);
             int status = method.getStatusCode();
             if (status != HttpStatus.SC_CREATED) {
-                throw new ContentManagerException(
+                throw new CMISRuntimeException(
                         "Remote server returned error code: " + status);
             }
             APPObjectEntry newEntry = new APPObjectEntryReader().read(ctx,
@@ -265,7 +265,7 @@
             Header loc = method.getResponseHeader("Location");
             Header cloc = method.getResponseHeader("Content-Location");
             if (loc == null) {
-                throw new ContentManagerException(
+                throw new CMISRuntimeException(
                         "Remote server failed to return a Location header");
             }
             if (newEntry == null || !loc.equals(cloc)) {
@@ -275,16 +275,16 @@
                 // ok
                 newEntry = getEntry(loc.getValue(), loc.getValue());
                 if (newEntry == null) {
-                    throw new ContentManagerException(
+                    throw new CMISRuntimeException(
                             "Remote server failed to return an entry for Location: "
                                     + loc);
                 }
             }
             return newEntry;
         } catch (IOException e) {
-            throw new ContentManagerException(e);
+            throw new CMISRuntimeException(e);
         } catch (XMLStreamException e) {
-            throw new ContentManagerException(e);
+            throw new CMISRuntimeException(e);
         } finally {
             method.releaseConnection();
         }
@@ -301,15 +301,15 @@
             client.executeMethod(method);
             int status = method.getStatusCode();
             if (status >= HttpStatus.SC_BAD_REQUEST) {
-                throw new ContentManagerException(
+                throw new CMISRuntimeException(
                         "Remote server returned error code: " + status);
             }
             return new APPObjectFeedReader().read(ctx,
                     method.getResponseBodyAsStream());
         } catch (IOException e) {
-            throw new ContentManagerException(e);
+            throw new CMISRuntimeException(e);
         } catch (XMLStreamException e) {
-            throw new ContentManagerException(e);
+            throw new CMISRuntimeException(e);
         } finally {
             method.releaseConnection();
         }
@@ -331,11 +331,11 @@
                         method.getStatusLine().getReasonPhrase());
             }
             if (status >= HttpStatus.SC_BAD_REQUEST) {
-                throw new ContentManagerException(
+                throw new CMISRuntimeException(
                         "Remote server returned error code: " + status);
             }
         } catch (IOException e) {
-            throw new ContentManagerException(e);
+            throw new CMISRuntimeException(e);
         } finally {
             method.releaseConnection();
         }

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlLexer.g
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlLexer.g?rev=920275&r1=920274&r2=920275&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlLexer.g
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlLexer.g
Mon Mar  8 11:18:21 2010
@@ -90,6 +90,7 @@
 SCORE : ('S'|'s')('C'|'c')('O'|'o')('R'|'r')('E'|'e');
 IN_FOLDER : ('I'|'i')('N'|'n')'_'('F'|'f')('O'|'o')('L'|'l')('D'|'d')('E'|'e')('R'|'r');
 IN_TREE : ('I'|'i')('N'|'n')'_'('T'|'t')('R'|'r')('E'|'e')('E'|'e');
+TIMESTAMP : 'TIMESTAMP'|'timestamp';
 
 STAR : '*';
 LPAR : '(';
@@ -103,13 +104,17 @@
 LTEQ : '<=';
 GTEQ : '>=';
 
-ID :
-    ('a'..'z'|'A'..'Z'|'_')
-    ('a'..'z'|'A'..'Z'|'_'|'0'..'9'|':')*
-    ;
+BOOL_LIT : 'TRUE' | 'true' | 'FALSE' | 'false';
 
 NUM_LIT : '0' | '-'? ('1'..'9')('0'..'9')*;
 
 STRING_LIT : '\'' (~'\''|'\'\'')* '\'';
 
 WS : ( ' ' | '\t' | '\r'? '\n' )+ { $channel=HIDDEN; };
+
+TIME_LIT : TIMESTAMP WS STRING_LIT;
+
+ID :
+    ('a'..'z'|'A'..'Z'|'_')
+    ('a'..'z'|'A'..'Z'|'_'|'0'..'9'|':')*
+    ;

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlParser.g
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlParser.g?rev=920275&r1=920274&r2=920275&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlParser.g
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlParser.g
Mon Mar  8 11:18:21 2010
@@ -179,6 +179,8 @@
 literal:
       NUM_LIT
     | STRING_LIT
+    | TIME_LIT
+    | BOOL_LIT
     ;
 
 in_predicate:

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/impl/simple/CmisSqlSimpleWalker.g
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/impl/simple/CmisSqlSimpleWalker.g?rev=920275&r1=920274&r2=920275&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/impl/simple/CmisSqlSimpleWalker.g
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/impl/simple/CmisSqlSimpleWalker.g
Mon Mar  8 11:18:21 2010
@@ -49,6 +49,7 @@
 package org.apache.chemistry.impl.simple;
 
 import org.apache.chemistry.impl.simple.SimpleData;
+import org.apache.chemistry.util.GregorianCalendar;
 }
 
 @members {
@@ -261,6 +262,20 @@
             String s = $STRING_LIT.text;
             $value = s.substring(1, s.length() - 1);
         }
+    | TIME_LIT
+        {
+            String s = $TIME_LIT.text;
+            s = s.substring(s.indexOf('\'') + 1, s.length() - 1);
+            try {
+                $value = GregorianCalendar.fromAtomPub(s);
+            } catch (IllegalArgumentException e) {
+                throw new UnwantedTokenException(Token.INVALID_TOKEN_TYPE, input);
+            }
+        }
+    | BOOL_LIT
+        {
+            $value = Boolean.valueOf($BOOL_LIT.text);
+        }
     ;
 
 order_by_clause:

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/CmisSql.testsuite
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/CmisSql.testsuite?rev=920275&r1=920274&r2=920275&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/CmisSql.testsuite
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/CmisSql.testsuite
Mon Mar  8 11:18:21 2010
@@ -52,6 +52,17 @@
 "abc'" FAIL
 "'ab'c'" FAIL
 
+BOOL_LIT:
+"TRUE" OK
+"true" OK
+"FALSE" OK
+"false" OK
+
+TIME_LIT:
+"TIMESTAMP '2010-01-01Z01:01:01.000Z'" OK
+"timestamp   '123'" OK
+"TIMESTAMP 123" FAIL
+
 // ----- Parser tests -----
 
 literal:

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/java/org/apache/chemistry/impl/simple/TestSimpleRepository.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/java/org/apache/chemistry/impl/simple/TestSimpleRepository.java?rev=920275&r1=920274&r2=920275&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/java/org/apache/chemistry/impl/simple/TestSimpleRepository.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/java/org/apache/chemistry/impl/simple/TestSimpleRepository.java
Mon Mar  8 11:18:21 2010
@@ -26,6 +26,7 @@
 
 import org.apache.chemistry.BaseType;
 import org.apache.chemistry.CMISObject;
+import org.apache.chemistry.CMISRuntimeException;
 import org.apache.chemistry.CapabilityJoin;
 import org.apache.chemistry.CapabilityQuery;
 import org.apache.chemistry.Connection;
@@ -41,6 +42,7 @@
 import org.apache.chemistry.Type;
 import org.apache.chemistry.Unfiling;
 import org.apache.chemistry.Updatability;
+import org.apache.chemistry.util.GregorianCalendar;
 
 public class TestSimpleRepository extends TestCase {
 
@@ -61,11 +63,15 @@
                 "def:date", null, "date", "Date", "", false,
                 PropertyType.DATETIME, false, null, false, false, null,
                 Updatability.READ_WRITE, true, true, 0, null, null, -1, null);
+        PropertyDefinition d4 = new SimplePropertyDefinition("bool",
+                "def:bool", null, "bool", "Bool", "", false,
+                PropertyType.BOOLEAN, false, null, false, false, null,
+                Updatability.READ_WRITE, true, true, 0, null, null, -1, null);
         SimpleType mt1 = new SimpleType("doc", BaseType.DOCUMENT.getId(),
                 "doc", null, "Doc", "My Doc Type", BaseType.DOCUMENT, "", true,
                 true, true, true, true, true, true, true,
                 ContentStreamPresence.ALLOWED, null, null, Arrays.asList(d1,
-                        d2, d3));
+                        d2, d3, d4));
         SimpleType mt2 = new SimpleType("fold", BaseType.FOLDER.getId(),
                 "fold", null, "Fold", "My Folder Type", BaseType.FOLDER, "",
                 true, true, true, true, true, true, false, false,
@@ -185,7 +191,7 @@
         Connection conn = repo.getConnection(null);
         Folder root = conn.getRootFolder();
         Document d1 = root.newDocument("doc");
-        assertEquals(SimpleType.PROPS_DOCUMENT_BASE.size() + 3,
+        assertEquals(SimpleType.PROPS_DOCUMENT_BASE.size() + 4,
                 d1.getType().getPropertyDefinitions().size());
 
         d1.save();
@@ -265,6 +271,9 @@
         Connection conn = repo.getConnection(null);
         Folder root = conn.getRootFolder();
         Document d1 = root.newDocument("doc");
+        d1.setValue("date",
+                GregorianCalendar.fromAtomPub("2010-01-01T01:01:01.000Z"));
+        d1.setValue("bool", Boolean.TRUE);
         d1.save();
 
         Collection<CMISObject> res = conn.query("SELECT * FROM cmis:folder",
@@ -286,6 +295,23 @@
         res = conn.query("SELECT * FROM doc WHERE cmis:objectId <> '123'",
                 false);
         assertEquals(1, res.size());
+
+        res = conn.query("SELECT * FROM doc WHERE bool = true", false);
+        assertEquals(1, res.size());
+        res = conn.query("SELECT * FROM doc WHERE bool <> FALSE", false);
+        assertEquals(1, res.size());
+
+        res = conn.query(
+                "SELECT * FROM doc WHERE date <> TIMESTAMP '1999-09-09T01:01:01Z'",
+                false);
+        assertEquals(1, res.size());
+        try {
+            res = conn.query(
+                    "SELECT * FROM doc WHERE date <> TIMESTAMP 'foobar'", false);
+            fail();
+        } catch (CMISRuntimeException e) {
+            // ok
+        }
     }
 
 }



Mime
View raw message