chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1384637 - in /chemistry/opencmis/trunk/chemistry-opencmis-client: chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/ chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runti...
Date Fri, 14 Sep 2012 04:26:38 GMT
Author: jens
Date: Fri Sep 14 04:26:37 2012
New Revision: 1384637

URL: http://svn.apache.org/viewvc?rev=1384637&view=rev
Log:
add escaping support for CONTAINS in query

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/QueryStatement.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/QueryStatementImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/QueryStatementTest.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/QueryStatement.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/QueryStatement.java?rev=1384637&r1=1384636&r2=1384637&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/QueryStatement.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/QueryStatement.java
Fri Sep 14 04:26:37 2012
@@ -89,11 +89,17 @@ public interface QueryStatement extends 
 
     /**
      * Sets the designated parameter to the given string. It does not escape
-     * backslashes ('\') in front of "%' and '_'.
+     * backslashes ('\') in front of '%' and '_'.
      */
     void setStringLike(int parameterIndex, String str);
 
     /**
+     * Sets the designated parameter to the given string. It does not escape
+     * backslashes ('\') in front of '*',  '?' and '-'.
+     */
+    void setStringContains(int parameterIndex, String str);
+    
+    /**
      * Sets the designated parameter to the given object id.
      */
     void setId(int parameterIndex, ObjectId... id);

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/QueryStatementImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/QueryStatementImpl.java?rev=1384637&r1=1384636&r2=1384637&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/QueryStatementImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/QueryStatementImpl.java
Fri Sep 14 04:26:37 2012
@@ -142,6 +142,15 @@ public class QueryStatementImpl implemen
         parametersMap.put(parameterIndex, sb.toString());
     }
 
+
+    public void setStringContains(int parameterIndex, String str) {
+        if (str == null) {
+            throw new IllegalArgumentException("String must be set!");
+        }
+
+        parametersMap.put(parameterIndex, escapeContains(str));
+    }
+
     public void setStringLike(int parameterIndex, String str) {
         if (str == null) {
             throw new IllegalArgumentException("String must be set!");
@@ -419,6 +428,29 @@ public class QueryStatementImpl implemen
         return sb.toString();
     }
 
+    private static String escapeContains(String str) {
+        StringBuilder sb = new StringBuilder("'");
+        for (int i = 0; i < str.length(); i++) {
+            char c = str.charAt(i);
+
+            if (c == '\'') {
+                sb.append("\\\\");
+            } else if (c == '\\') {
+                if (i + 1 < str.length() && (str.charAt(i + 1) == '*' || str.charAt(i
+ 1) == '?' || str.charAt(i + 1) == '-')) {
+                    // no additional back slash
+                } else {
+                    sb.append("\\\\");
+                }
+            }
+
+            sb.append(c);
+        }
+
+        sb.append("'");
+
+        return sb.toString();
+    }
+
     private static String convert(Date date) {
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
         sdf.setTimeZone(TimeZone.getTimeZone("GMT"));

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/QueryStatementTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/QueryStatementTest.java?rev=1384637&r1=1384636&r2=1384637&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/QueryStatementTest.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/QueryStatementTest.java
Fri Sep 14 04:26:37 2012
@@ -79,6 +79,13 @@ public class QueryStatementTest {
         assertEquals("SELECT * FROM cmis:document WHERE abc:string LIKE '\\_test\\%blah\\\\\\\\blah'",
                 st.toQueryString());
 
+        // contains
+        query = "SELECT * FROM cmis:document WHERE CONTAINS(?)";
+        st = new QueryStatementImpl(session, query);
+        st.setStringContains(1, "John'sPresentation\\-Version2");
+        assertEquals("SELECT * FROM cmis:document WHERE CONTAINS('John\\\\'sPresentation\\-Version2')",
+                st.toQueryString());
+
         // ids
         query = "SELECT * FROM cmis:document WHERE abc:id = ?";
         st = new QueryStatementImpl(session, query);



Mime
View raw message