cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject cayenne git commit: CAY-2232 Proper conversion to String for new functional expressions
Date Thu, 16 Feb 2017 11:42:50 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 51a3399d4 -> 5c805019a


CAY-2232 Proper conversion to String for new functional expressions


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/5c805019
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/5c805019
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/5c805019

Branch: refs/heads/master
Commit: 5c805019a21c10f182e86ca98bc5063246e36851
Parents: 51a3399
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Thu Feb 16 14:42:40 2017 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Thu Feb 16 14:42:40 2017 +0300

----------------------------------------------------------------------
 .../cayenne/exp/parser/ASTFunctionCall.java     | 29 ++++++++++++++++---
 .../apache/cayenne/exp/parser/ASTAbsTest.java   | 11 +++++++
 .../cayenne/exp/parser/ASTAggregateTest.java    | 30 ++++++++++++++++----
 .../cayenne/exp/parser/ASTConcatTest.java       | 10 +++++++
 .../cayenne/exp/parser/ASTLocateTest.java       | 12 ++++++++
 .../apache/cayenne/exp/parser/ASTLowerTest.java | 11 +++++++
 .../apache/cayenne/exp/parser/ASTModTest.java   | 12 ++++++++
 .../apache/cayenne/exp/parser/ASTSqrtTest.java  | 11 +++++++
 .../cayenne/exp/parser/ASTSubstringTest.java    | 11 +++++++
 .../apache/cayenne/exp/parser/ASTTrimTest.java  | 12 ++++++++
 .../apache/cayenne/exp/parser/ASTUpperTest.java | 12 ++++++++
 docs/doc/src/main/resources/RELEASE-NOTES.txt   |  1 +
 12 files changed, 152 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/5c805019/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ASTFunctionCall.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ASTFunctionCall.java
b/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ASTFunctionCall.java
index 004a306..c8d7f06 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ASTFunctionCall.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ASTFunctionCall.java
@@ -19,6 +19,9 @@
 
 package org.apache.cayenne.exp.parser;
 
+import java.io.IOException;
+import java.util.List;
+
 import org.apache.cayenne.exp.Expression;
 
 /**
@@ -57,12 +60,9 @@ public abstract class ASTFunctionCall extends SimpleNode {
         return functionName;
     }
 
-    /**
-     * TODO what should this method return?
-     */
     @Override
     protected String getExpressionOperator(int index) {
-        return functionName;
+        return ",";
     }
 
     @Override
@@ -78,4 +78,25 @@ public abstract class ASTFunctionCall extends SimpleNode {
     public int hashCode() {
         return 31 * super.hashCode() + functionName.hashCode();
     }
+
+    @Override
+    public void appendAsString(Appendable out) throws IOException {
+        out.append(getFunctionName());
+        if(parent == null) {
+            // else call to super method will append parenthesis
+            out.append("(");
+        }
+        super.appendAsString(out);
+        if(parent == null) {
+            out.append(")");
+        }
+    }
+
+    @Override
+    public void appendAsEJBQL(List<Object> parameterAccumulator, Appendable out, String
rootId) throws IOException {
+        out.append(getFunctionName());
+        out.append("(");
+        super.appendChildrenAsEJBQL(parameterAccumulator, out, rootId);
+        out.append(")");
+    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/5c805019/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTAbsTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTAbsTest.java b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTAbsTest.java
index a8ec060..c5c88d1 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTAbsTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTAbsTest.java
@@ -19,6 +19,8 @@
 
 package org.apache.cayenne.exp.parser;
 
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.testdo.table_primitives.TablePrimitives;
 import org.junit.Test;
 
@@ -42,4 +44,13 @@ public class ASTAbsTest {
         assertEquals(10.0, res);
     }
 
+    @Test
+    public void parseTest() throws Exception {
+        String expString = "ABS(xyz)";
+        Expression exp = ExpressionFactory.exp(expString);
+
+        assertTrue(exp instanceof ASTAbs);
+        String toString = exp.toString();
+        assertEquals(expString, toString);
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/5c805019/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTAggregateTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTAggregateTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTAggregateTest.java
index 496e449..67ce3d0 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTAggregateTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTAggregateTest.java
@@ -46,10 +46,13 @@ public class ASTAggregateTest {
 
     @Test
     public void testAvgParse() throws Exception {
-        Expression exp = ExpressionFactory.exp("AVG(artistName)");
+        String expressionString = "AVG(artistName)";
+        Expression exp = ExpressionFactory.exp(expressionString);
         assertTrue(exp instanceof ASTAvg);
         assertEquals(1, exp.getOperandCount());
         assertTrue(exp.getOperand(0) instanceof ASTObjPath);
+
+        assertEquals(expressionString, exp.toString());
     }
 
     @Test
@@ -60,18 +63,24 @@ public class ASTAggregateTest {
 
     @Test
     public void testCountExpParse() throws Exception {
-        Expression exp = ExpressionFactory.exp("COUNT(artistName)");
+        String expressionString = "COUNT(artistName)";
+        Expression exp = ExpressionFactory.exp(expressionString);
         assertTrue(exp instanceof ASTCount);
         assertEquals(1, exp.getOperandCount());
         assertTrue(exp.getOperand(0) instanceof ASTObjPath);
+
+        assertEquals(expressionString, exp.toString());
     }
 
     @Test
     public void testCountAsteriskParse() throws Exception {
-        Expression exp = ExpressionFactory.exp("COUNT(*)");
+        String expressionString = "COUNT(*)";
+        Expression exp = ExpressionFactory.exp(expressionString);
         assertTrue(exp instanceof ASTCount);
         assertEquals(1, exp.getOperandCount());
         assertTrue(exp.getOperand(0) instanceof ASTAsterisk);
+
+        assertEquals(expressionString, exp.toString());
     }
 
     @Test
@@ -82,10 +91,13 @@ public class ASTAggregateTest {
 
     @Test
     public void testMinParse() throws Exception {
-        Expression exp = ExpressionFactory.exp("MIN(artistName)");
+        String expressionString = "MIN(artistName)";
+        Expression exp = ExpressionFactory.exp(expressionString);
         assertTrue(exp instanceof ASTMin);
         assertEquals(1, exp.getOperandCount());
         assertTrue(exp.getOperand(0) instanceof ASTObjPath);
+
+        assertEquals(expressionString, exp.toString());
     }
 
     @Test
@@ -96,10 +108,13 @@ public class ASTAggregateTest {
 
     @Test
     public void testMaxParse() throws Exception {
-        Expression exp = ExpressionFactory.exp("MAX(artistName)");
+        String expressionString = "MAX(artistName)";
+        Expression exp = ExpressionFactory.exp(expressionString);
         assertTrue(exp instanceof ASTMax);
         assertEquals(1, exp.getOperandCount());
         assertTrue(exp.getOperand(0) instanceof ASTObjPath);
+
+        assertEquals(expressionString, exp.toString());
     }
 
     @Test
@@ -110,10 +125,13 @@ public class ASTAggregateTest {
 
     @Test
     public void testSumParse() throws Exception {
-        Expression exp = ExpressionFactory.exp("SUM(artistName)");
+        String expressionString = "SUM(artistName)";
+        Expression exp = ExpressionFactory.exp(expressionString);
         assertTrue(exp instanceof ASTSum);
         assertEquals(1, exp.getOperandCount());
         assertTrue(exp.getOperand(0) instanceof ASTObjPath);
+
+        assertEquals(expressionString, exp.toString());
     }
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/5c805019/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTConcatTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTConcatTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTConcatTest.java
index b468efe..d951327 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTConcatTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTConcatTest.java
@@ -63,4 +63,14 @@ public class ASTConcatTest {
         assertEquals("name test", res);
     }
 
+    @Test
+    public void parseTest() throws Exception {
+        String expString = "CONCAT(xyz , \" \" , abc)";
+        Expression exp = ExpressionFactory.exp(expString);
+
+        assertTrue(exp instanceof ASTConcat);
+        String toString = exp.toString();
+        assertEquals(expString, toString);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/5c805019/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLocateTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLocateTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLocateTest.java
index 9c4090c..9e1a0e8 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLocateTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLocateTest.java
@@ -19,6 +19,8 @@
 
 package org.apache.cayenne.exp.parser;
 
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.junit.Test;
 
@@ -50,4 +52,14 @@ public class ASTLocateTest {
         assertEquals(0, res);
     }
 
+    @Test
+    public void parseTest() throws Exception {
+        String expString = "LOCATE(\"xyz\" , abc , 4)";
+        Expression exp = ExpressionFactory.exp(expString);
+
+        assertTrue(exp instanceof ASTLocate);
+        String toString = exp.toString();
+        assertEquals(expString, toString);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/5c805019/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLowerTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLowerTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLowerTest.java
index 887e5b5..96a6671 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLowerTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLowerTest.java
@@ -19,6 +19,8 @@
 
 package org.apache.cayenne.exp.parser;
 
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.junit.Test;
 
@@ -43,4 +45,13 @@ public class ASTLowerTest {
         assertEquals("abcdefg02x", res);
     }
 
+    @Test
+    public void parseTest() throws Exception {
+        String expString = "LOWER(xyz)";
+        Expression exp = ExpressionFactory.exp(expString);
+
+        assertTrue(exp instanceof ASTLower);
+        String toString = exp.toString();
+        assertEquals(expString, toString);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/5c805019/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTModTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTModTest.java b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTModTest.java
index fb014f6..0f9febd 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTModTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTModTest.java
@@ -19,6 +19,8 @@
 
 package org.apache.cayenne.exp.parser;
 
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.testdo.table_primitives.TablePrimitives;
 import org.junit.Test;
 
@@ -42,4 +44,14 @@ public class ASTModTest {
         assertEquals(1.0, res);
     }
 
+    @Test
+    public void parseTest() throws Exception {
+        String expString = "MOD(xyz , 3)";
+        Expression exp = ExpressionFactory.exp(expString);
+
+        assertTrue(exp instanceof ASTMod);
+        String toString = exp.toString();
+        assertEquals(expString, toString);
+    }
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/5c805019/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTSqrtTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTSqrtTest.java b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTSqrtTest.java
index 50dbf2f..13c015b 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTSqrtTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTSqrtTest.java
@@ -19,6 +19,8 @@
 
 package org.apache.cayenne.exp.parser;
 
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.testdo.table_primitives.TablePrimitives;
 import org.junit.Test;
 
@@ -41,4 +43,13 @@ public class ASTSqrtTest {
         assertEquals(3.0, res);
     }
 
+    @Test
+    public void parseTest() throws Exception {
+        String expString = "SQRT(xyz)";
+        Expression exp = ExpressionFactory.exp(expString);
+
+        assertTrue(exp instanceof ASTSqrt);
+        String toString = exp.toString();
+        assertEquals(expString, toString);
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/5c805019/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTSubstringTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTSubstringTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTSubstringTest.java
index ac51846..ee6a74a 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTSubstringTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTSubstringTest.java
@@ -19,6 +19,8 @@
 
 package org.apache.cayenne.exp.parser;
 
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.junit.Test;
 
@@ -45,4 +47,13 @@ public class ASTSubstringTest {
         assertEquals("34567890", res);
     }
 
+    @Test
+    public void parseTest() throws Exception {
+        String expString = "SUBSTRING(xyz , 2 , 3)";
+        Expression exp = ExpressionFactory.exp(expString);
+
+        assertTrue(exp instanceof ASTSubstring);
+        String toString = exp.toString();
+        assertEquals(expString, toString);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/5c805019/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTTrimTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTTrimTest.java b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTTrimTest.java
index 6a45370..65b94ea 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTTrimTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTTrimTest.java
@@ -19,6 +19,8 @@
 
 package org.apache.cayenne.exp.parser;
 
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.junit.Test;
 
@@ -42,4 +44,14 @@ public class ASTTrimTest {
         assertEquals("testArtist", res);
     }
 
+    @Test
+    public void parseTest() throws Exception {
+        String expString = "TRIM(xyz)";
+        Expression exp = ExpressionFactory.exp(expString);
+
+        assertTrue(exp instanceof ASTTrim);
+        String toString = exp.toString();
+        assertEquals(expString, toString);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/5c805019/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTUpperTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTUpperTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTUpperTest.java
index 6918041..375fe8d 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTUpperTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTUpperTest.java
@@ -19,6 +19,8 @@
 
 package org.apache.cayenne.exp.parser;
 
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.junit.Test;
 
@@ -43,4 +45,14 @@ public class ASTUpperTest {
         assertEquals("ABCDEFX981", res);
     }
 
+    @Test
+    public void parseTest() throws Exception {
+        String expString = "UPPER(xyz)";
+        Expression exp = ExpressionFactory.exp(expString);
+
+        assertTrue(exp instanceof ASTUpper);
+        String toString = exp.toString();
+        assertEquals(expString, toString);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/5c805019/docs/doc/src/main/resources/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/docs/doc/src/main/resources/RELEASE-NOTES.txt b/docs/doc/src/main/resources/RELEASE-NOTES.txt
index 56984e8..94d9729 100644
--- a/docs/doc/src/main/resources/RELEASE-NOTES.txt
+++ b/docs/doc/src/main/resources/RELEASE-NOTES.txt
@@ -31,6 +31,7 @@ CAY-2212 cdbimport cleanup and configuration schema refactoring
 CAY-2223 JCacheQueryCache - a query cache provider to plug in JCache implementers
 CAY-2225 Extensible CacheInvalidationFilter logic
 CAY-2228 Deprecate multiple cache groups in caching and query API
+CAY-2232 Proper conversion to String for new functional expressions
 CAY-2235 Deprecate Query.getDataMap() method
 
 Bug Fixes:


Mime
View raw message