cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5720, CXF-5721] Dealing with SQL percent and reserved chars, patches from Romain Castan applied
Date Thu, 01 May 2014 14:59:18 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes 81dd727b4 -> c5a89b7c1


[CXF-5720,CXF-5721] Dealing with SQL percent and reserved chars, patches from Romain Castan
applied


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

Branch: refs/heads/2.7.x-fixes
Commit: c5a89b7c137566c045a0d13b62132e987ff81b52
Parents: 81dd727
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Thu May 1 13:40:14 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Thu May 1 15:59:01 2014 +0100

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/ext/search/SearchUtils.java  | 13 ++++++-------
 .../ext/search/jpa/JPATypedQueryVisitorTest.java  | 18 +++++++++++++++++-
 2 files changed, 23 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/c5a89b7c/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
index 472f39b..a91e56e 100644
--- a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
@@ -56,23 +56,22 @@ public final class SearchUtils {
         if (value.contains("\\")) {
             value = value.replaceAll("\\\\", "\\\\\\\\"); 
         }
+        if (value.contains("_")) {
+            value = value.replaceAll("_", "\\\\_");
+        }
         if (value.contains("%")) {
             value = value.replaceAll("%", "\\\\%");
         }
         if (!value.contains("*")) {
             return alwaysWildcard ? "%" + value + "%" : value;
-        }
-        if (value.startsWith("*")) { 
-            value = "%" + value.substring(1);
-        }
-        if (value.endsWith("*")) { 
-            value = value.substring(0, value.length() - 1) + "%";
+        } else {
+            value = value.replaceAll("\\*", "%");
         }
         return value;
     }
     
     public static boolean containsEscapedChar(String value) {
-        return value.contains("\\%") || value.contains("\\\\");
+        return value.contains("\\%") || value.contains("\\\\") || value.contains("\\_");
     }
     
     public static void startSqlQuery(StringBuilder sb, 

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5a89b7c/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
index 3c45f5c..9a4de94 100644
--- a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
+++ b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
@@ -133,7 +133,7 @@ public class JPATypedQueryVisitorTest extends Assert {
             br3.setBook(b3);
             b3.setId(11);
             b3.setBookTitle("num11");
-            b3.setAddress(new OwnerAddress("Street3"));
+            b3.setAddress(new OwnerAddress("Street&'3"));
             b3.getAuthors().add("Barry");
             OwnerInfo info3 = new OwnerInfo();
             info3.setName(new Name("Bill"));
@@ -376,6 +376,22 @@ public class JPATypedQueryVisitorTest extends Assert {
     }
 
     @Test
+    public void testEqualsAddressQuery4() throws Exception {
+        Map<String, String> beanPropertiesMap = new HashMap<String, String>();
+        beanPropertiesMap.put("street", "address.street");
+        List<Book> books = queryBooks("street==Str*t*", null, beanPropertiesMap);
+        assertEquals(3, books.size());
+    }
+    
+    @Test
+    public void testEqualsAddressQuery5() throws Exception {
+        Map<String, String> beanPropertiesMap = new HashMap<String, String>();
+        beanPropertiesMap.put("street", "address.street");
+        List<Book> books = queryBooks("street==Street&'3", null, beanPropertiesMap);
+        assertEquals(1, books.size());
+    }
+
+    @Test
     public void testEqualsOwnerNameQuery() throws Exception {
         List<Book> books = queryBooks("ownerInfo.name.name==Fred");
         assertEquals(1, books.size());


Mime
View raw message