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 12:40:32 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 55fe54262 -> 0edab8ddf


[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/0edab8dd
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/0edab8dd
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/0edab8dd

Branch: refs/heads/master
Commit: 0edab8ddfc537e3cc3bb36cf206397e9ea132888
Parents: 55fe542
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 13:40:14 2014 +0100

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/ext/search/SearchUtils.java   | 13 ++++++-------
 .../jpa/AbstractJPATypedQueryVisitorTest.java      |  2 +-
 .../search/jpa/JPATypedQueryVisitorFiqlTest.java   | 16 ++++++++++++++++
 .../search/jpa/JPATypedQueryVisitorODataTest.java  | 17 ++++++++++++++++-
 4 files changed, 39 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/0edab8dd/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/0edab8dd/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitorTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitorTest.java
b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitorTest.java
index 379a1bd..35bf72d 100644
--- a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitorTest.java
+++ b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitorTest.java
@@ -133,7 +133,7 @@ public abstract class AbstractJPATypedQueryVisitorTest 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"));

http://git-wip-us.apache.org/repos/asf/cxf/blob/0edab8dd/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorFiqlTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorFiqlTest.java
b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorFiqlTest.java
index f82530f..acfdb5d 100644
--- a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorFiqlTest.java
+++ b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorFiqlTest.java
@@ -236,8 +236,24 @@ public class JPATypedQueryVisitorFiqlTest extends AbstractJPATypedQueryVisitorTe
         assertEquals("Street2", book.getAddress().getStreet());
         
     }
+    
+    @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());

http://git-wip-us.apache.org/repos/asf/cxf/blob/0edab8dd/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorODataTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorODataTest.java
b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorODataTest.java
index bf10043..518ddf7 100644
--- a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorODataTest.java
+++ b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorODataTest.java
@@ -205,10 +205,25 @@ public class JPATypedQueryVisitorODataTest extends AbstractJPATypedQueryVisitorT
         Book book = books.get(0);
         assertTrue(10 == book.getId());
         assertEquals("Street2", book.getAddress().getStreet());
-        
     }
 
     @Test
+    public void testEqualsAddressQuery4() throws Exception {
+        Map<String, String> beanPropertiesMap = new HashMap<String, String>();
+        beanPropertiesMap.put("street", "address.street");
+        List<Book> books = queryBooks("street eq '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 eq 'Street&''3'", null, beanPropertiesMap);
+        assertEquals(1, books.size());
+    }
+    
+    @Test
     public void testEqualsOwnerNameQuery() throws Exception {
         List<Book> books = queryBooks("ownerInfo.name.name eq 'Fred'");
         assertEquals(1, books.size());


Mime
View raw message