cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject cayenne git commit: CAY-1978 ESCAPE clause should be included in LIKE parenthesis
Date Tue, 09 Dec 2014 08:08:34 GMT
Repository: cayenne
Updated Branches:
  refs/heads/4.0.M2_prerelease 1ab1caa9f -> 525f320a0


CAY-1978 ESCAPE clause should be included in LIKE parenthesis


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

Branch: refs/heads/4.0.M2_prerelease
Commit: 525f320a00137b16be0f58fca79b46852effff75
Parents: 1ab1caa
Author: aadamchik <aadamchik@apache.org>
Authored: Tue Dec 9 10:42:31 2014 +0300
Committer: aadamchik <aadamchik@apache.org>
Committed: Tue Dec 9 11:08:26 2014 +0300

----------------------------------------------------------------------
 .../translator/select/QualifierTranslator.java  | 52 ++++++++++----------
 .../org/apache/cayenne/query/SelectQueryIT.java | 29 +++++++++++
 docs/doc/src/main/resources/RELEASE-NOTES.txt   |  1 +
 3 files changed, 56 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/525f320a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QualifierTranslator.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QualifierTranslator.java
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QualifierTranslator.java
index 35d09d6..4fa0fcc 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QualifierTranslator.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QualifierTranslator.java
@@ -419,32 +419,32 @@ public class QualifierTranslator extends QueryAssemblerHelper implements
Travers
      */
     public void endNode(Expression node, Expression parentNode) {
 
-        try {
-            // check if we need to use objectMatchTranslator to finish building the
-            // expression
-            if (node.getOperandCount() == 2 && matchingObject) {
-                appendObjectMatch();
-            }
-
-            boolean parenthesisNeeded = parenthesisNeeded(node, parentNode);
-            boolean likeIgnoreCase = (node.getType() == Expression.LIKE_IGNORE_CASE || node
-                    .getType() == Expression.NOT_LIKE_IGNORE_CASE);
-            boolean isPatternMatchNode = PatternMatchNode.class.isAssignableFrom(node
-                    .getClass());
-
-            if (parenthesisNeeded)
-                out.append(')');
-
-            if (isPatternMatchNode && !likeIgnoreCase)
-                appendLikeEscapeCharacter((PatternMatchNode) node);
-
-            if (likeIgnoreCase && !caseInsensitive)
-                out.append(')');
-
-            if (isPatternMatchNode && likeIgnoreCase)
-                appendLikeEscapeCharacter((PatternMatchNode) node);
-
-        }
+		try {
+			// check if we need to use objectMatchTranslator to finish building
+			// the
+			// expression
+			if (node.getOperandCount() == 2 && matchingObject) {
+				appendObjectMatch();
+			}
+
+			boolean parenthesisNeeded = parenthesisNeeded(node, parentNode);
+			boolean likeIgnoreCase = (node.getType() == Expression.LIKE_IGNORE_CASE || node.getType()
== Expression.NOT_LIKE_IGNORE_CASE);
+			boolean isPatternMatchNode = PatternMatchNode.class.isAssignableFrom(node.getClass());
+
+			// closing UPPER parenthesis
+			if (likeIgnoreCase && !caseInsensitive) {
+				out.append(')');
+			}
+
+			if (isPatternMatchNode) {
+				appendLikeEscapeCharacter((PatternMatchNode) node);
+			}
+
+			// closing LIKE parenthesis
+			if (parenthesisNeeded) {
+				out.append(')');
+			}
+		}
         catch (IOException ioex) {
             throw new CayenneRuntimeException("Error appending content", ioex);
         }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/525f320a/cayenne-server/src/test/java/org/apache/cayenne/query/SelectQueryIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/SelectQueryIT.java b/cayenne-server/src/test/java/org/apache/cayenne/query/SelectQueryIT.java
index f8c9a1e..8421310 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/query/SelectQueryIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/query/SelectQueryIT.java
@@ -295,6 +295,35 @@ public class SelectQueryIT extends ServerCase {
         List<?> objects = context.performQuery(query);
         assertEquals(1, objects.size());
     }
+    
+	@Test
+	public void testSelectLikeSingleWildcardMatchAndEscape_AndOtherCriteria() throws Exception
{
+
+		createArtistsWildcardDataSet();
+
+		// CAY-1978 - combining LIKE..ESCAPE with another clause generated bad
+		// syntax
+		SelectQuery<Artist> query = new SelectQuery<Artist>(Artist.class);
+		query.andQualifier(ExpressionFactory.likeExp("artistName", "=_%", '='));
+		query.andQualifier(Artist.ARTIST_NAME.eq("_X"));
+
+		List<?> objects = context.performQuery(query);
+		assertEquals(1, objects.size());
+	}
+	
+	@Test
+	public void testSelectLikeSingleWildcardMatchIgnoreCaseAndEscape_AndOtherCriteria() throws
Exception {
+
+		createArtistsWildcardDataSet();
+
+		// CAY-1978 - combining LIKE..ESCAPE with another clause generated bad SQL
+		SelectQuery<Artist> query = new SelectQuery<Artist>(Artist.class);
+		query.andQualifier(ExpressionFactory.likeIgnoreCaseExp("artistName", "=_%", '='));
+		query.andQualifier(Artist.ARTIST_NAME.eq("_X"));
+
+		List<?> objects = context.performQuery(query);
+		assertEquals(1, objects.size());
+	}
 
     @Test
     public void testSelectLikeMultipleWildcardMatch() throws Exception {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/525f320a/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 1c3e454..b294588 100644
--- a/docs/doc/src/main/resources/RELEASE-NOTES.txt
+++ b/docs/doc/src/main/resources/RELEASE-NOTES.txt
@@ -105,6 +105,7 @@ CAY-1943 XML file not deleted when a DataMap is deleted from the project
 CAY-1961 Fix RemoveAction for DataMaps in ProjectTree
 CAY-1964 Fix convertAdditionalDataMaps() in CayenneGeneratorMojo.java
 CAY-1973 error while generating classes
+CAY-1978 ESCAPE clause should be included in LIKE parenthesis
 
 ----------------------------------
 Release: 3.2M1


Mime
View raw message