chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r923348 - in /incubator/chemistry/trunk/chemistry/chemistry-commons/src: main/antlr3/org/apache/chemistry/cmissql/ main/antlr3/org/apache/chemistry/impl/simple/ test/gunit/org/apache/chemistry/cmissql/ test/java/org/apache/chemistry/impl/si...
Date Mon, 15 Mar 2010 17:26:21 GMT
Author: fguillaume
Date: Mon Mar 15 17:26:21 2010
New Revision: 923348

URL: http://svn.apache.org/viewvc?rev=923348&view=rev
Log:
CMIS-160: Implement decimal literals in CMISQL parser

Modified:
    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/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-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=923348&r1=923347&r2=923348&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 15 17:26:21 2010
@@ -106,7 +106,11 @@ GTEQ : '>=';
 
 BOOL_LIT : 'TRUE' | 'true' | 'FALSE' | 'false';
 
-NUM_LIT : '0' | '-'? ('1'..'9')('0'..'9')*;
+fragment Sign : ('+'|'-')?;
+fragment Digits : ('0'..'9')+;
+fragment ExactNumLit : Digits DOT Digits | Digits DOT | DOT Digits | Digits;
+fragment ApproxNumLit : ExactNumLit ('e'|'E') Sign Digits;
+NUM_LIT : Sign (ExactNumLit | ApproxNumLit);
 
 STRING_LIT : '\'' (~'\''|'\'\'')* '\'';
 

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=923348&r1=923347&r2=923348&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 15 17:26:21 2010
@@ -48,6 +48,8 @@ options {
  */
 package org.apache.chemistry.impl.simple;
 
+import java.math.BigDecimal;
+
 import org.apache.chemistry.impl.simple.SimpleData;
 import org.apache.chemistry.util.GregorianCalendar;
 }
@@ -255,7 +257,11 @@ arg returns [Object value]
 literal returns [Object value]:
       NUM_LIT
         {
-            $value = Long.valueOf($NUM_LIT.text);
+            try {
+                $value = Long.valueOf($NUM_LIT.text);
+            } catch (NumberFormatException e) {
+                $value = new BigDecimal($NUM_LIT.text);
+            }
         }
     | STRING_LIT
         {

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=923348&r1=923347&r2=923348&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 15 17:26:21 2010
@@ -37,13 +37,27 @@ ID:
 NUM_LIT:
 "123" OK
 "0" OK
-"-0" FAIL
+"-0" OK
 "1" OK
 "-1" OK
 "-123" OK
-"0123" FAIL
-"-0123" FAIL
+"0123" OK
+"-0123" OK
 "123abc" FAIL
+"123E" FAIL
+"123.456" OK
+"+123.456" OK
+"-123.456" OK
+".456" OK
+"+.456" OK
+"-.456" OK
+"123." OK
+"+123." OK
+"-123." OK
+"+123.456E78" OK
+"-123.456E-78" OK
+".456E78" OK
+"+123.E+78" OK
 
 STRING_LIT:
 "'abc'" OK
@@ -69,10 +83,11 @@ literal:
 "123" OK
 "-123" OK
 "0" OK
-"0123" FAIL
+"0123" OK
 "abc123" OK
 "123abc" FAIL
 "'abc'" OK
+"123.345E78" OK
 
 order_by_clause:
 "ORDER BY foo" -> (ORDER_BY (COL foo) ASC)

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=923348&r1=923347&r2=923348&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 15 17:26:21 2010
@@ -18,6 +18,7 @@
 package org.apache.chemistry.impl.simple;
 
 import java.io.InputStream;
+import java.math.BigDecimal;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
@@ -67,11 +68,15 @@ public class TestSimpleRepository extend
                 "def:bool", null, "bool", "Bool", "", false,
                 PropertyType.BOOLEAN, false, null, false, false, null,
                 Updatability.READ_WRITE, true, true, 0, null, null, -1, null);
+        PropertyDefinition d5 = new SimplePropertyDefinition("dec", "def:dec",
+                null, "dec", "Decimal", "", false, PropertyType.DECIMAL, 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, d4));
+                        d2, d3, d4, d5));
         SimpleType mt2 = new SimpleType("fold", BaseType.FOLDER.getId(),
                 "fold", null, "Fold", "My Folder Type", BaseType.FOLDER, "",
                 true, true, true, true, true, true, false, false,
@@ -191,7 +196,7 @@ public class TestSimpleRepository extend
         Connection conn = repo.getConnection(null);
         Folder root = conn.getRootFolder();
         Document d1 = root.newDocument("doc");
-        assertEquals(SimpleType.PROPS_DOCUMENT_BASE.size() + 4,
+        assertEquals(SimpleType.PROPS_DOCUMENT_BASE.size() + 5,
                 d1.getType().getPropertyDefinitions().size());
 
         d1.save();
@@ -274,6 +279,7 @@ public class TestSimpleRepository extend
         d1.setValue("date",
                 GregorianCalendar.fromAtomPub("2010-01-01T01:01:01.000Z"));
         d1.setValue("bool", Boolean.TRUE);
+        d1.setValue("dec", BigDecimal.valueOf(123.456));
         d1.save();
 
         Collection<CMISObject> res = conn.query("SELECT * FROM cmis:folder",
@@ -301,6 +307,11 @@ public class TestSimpleRepository extend
         res = conn.query("SELECT * FROM doc WHERE bool <> FALSE", false);
         assertEquals(1, res.size());
 
+        res = conn.query("SELECT * FROM doc WHERE dec = 123.456", false);
+        assertEquals(1, res.size());
+        res = conn.query("SELECT * FROM doc WHERE dec <> 123", false);
+        assertEquals(1, res.size());
+
         res = conn.query(
                 "SELECT * FROM doc WHERE date <> TIMESTAMP '1999-09-09T01:01:01Z'",
                 false);



Mime
View raw message