cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1520301 - in /cxf/branches/2.7.x-fixes: ./ rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/ rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/ rt/rs/extensions/search/src/main/java/org/apache/c...
Date Thu, 05 Sep 2013 13:31:57 GMT
Author: sergeyb
Date: Thu Sep  5 13:31:56 2013
New Revision: 1520301

URL: http://svn.apache.org/r1520301
Log:
Merged revisions 1520298 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1520298 | sergeyb | 2013-09-05 14:23:31 +0100 (Thu, 05 Sep 2013) | 1 line
  
  [CXF-5253] Updating JPA visitor to support exact match for non wildcard strings by default
........

Added:
    cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchUtilsTest.java
      - copied unchanged from r1520298, cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchUtilsTest.java
Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
    cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
    cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
    cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitor.java
    cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1520298

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java?rev=1520301&r1=1520300&r2=1520301&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
Thu Sep  5 13:31:56 2013
@@ -52,6 +52,20 @@ public final class SearchUtils {
         return visitor.getQuery();
     }
     
+    public static String toSqlWildcardString(String value, boolean alwaysWildcard) {
+        if (!value.contains("*")) {
+            return alwaysWildcard ? "%" + value + "%" : value;
+        }
+        
+        if (value.startsWith("*")) { 
+            value = "%" + value.substring(1);
+        }
+        if (value.endsWith("*")) { 
+            value = value.substring(0, value.length() - 1) + "%";
+        }
+        return value;
+    }
+    
     public static void startSqlQuery(StringBuilder sb, 
                                      String table,
                                      String tableAlias,

Modified: cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java?rev=1520301&r1=1520300&r2=1520301&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
Thu Sep  5 13:31:56 2013
@@ -40,6 +40,7 @@ import org.apache.cxf.jaxrs.ext.search.C
 import org.apache.cxf.jaxrs.ext.search.OrSearchCondition;
 import org.apache.cxf.jaxrs.ext.search.PrimitiveStatement;
 import org.apache.cxf.jaxrs.ext.search.SearchCondition;
+import org.apache.cxf.jaxrs.ext.search.SearchUtils;
 import org.apache.cxf.jaxrs.ext.search.collections.CollectionCheckInfo;
 import org.apache.cxf.jaxrs.ext.search.visitor.AbstractSearchConditionVisitor;
 
@@ -196,11 +197,12 @@ public abstract class AbstractJPATypedQu
             break;
         case EQUALS:
             if (clazz.equals(String.class)) {
-                String theValue = value.toString();
-                if (theValue.contains("*")) {
-                    theValue = ((String)value).replaceAll("\\*", "");
+                String theValue = SearchUtils.toSqlWildcardString(value.toString(), isWildcardStringMatch());
+                if (theValue.contains("%")) {
+                    pred = builder.like((Expression<String>)exp, theValue);
+                } else {
+                    pred = builder.equal(exp, clazz.cast(value));
                 }
-                pred = builder.like((Expression<String>)exp, "%" + theValue + "%");
             } else {
                 pred = builder.equal(exp, clazz.cast(value));
             }

Modified: cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java?rev=1520301&r1=1520300&r2=1520301&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
Thu Sep  5 13:31:56 2013
@@ -140,18 +140,18 @@ public class LuceneQueryVisitor<T> exten
         Query query = null;
         if (cls == String.class) {
             String strValue = value.toString();
-            int wildCardIndex = strValue.indexOf('*'); 
+            boolean isWildCard = strValue.contains("*") || super.isWildcardStringMatch();

             
             String theContentsFieldName = getContentsFieldName(name);
             if (theContentsFieldName == null) {
                 Term term = new Term(name, strValue);
                 
-                if (wildCardIndex == -1) {
+                if (!isWildCard) {
                     query = new TermQuery(term);
                 } else {
                     query = new WildcardQuery(term);
                 } 
-            } else if (wildCardIndex == -1) {
+            } else if (!isWildCard) {
                 PhraseQuery pquery = new PhraseQuery();
                 pquery.add(new Term(theContentsFieldName, name));
                 pquery.add(new Term(theContentsFieldName, strValue));

Modified: cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitor.java?rev=1520301&r1=1520300&r2=1520301&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitor.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitor.java
Thu Sep  5 13:31:56 2013
@@ -70,16 +70,16 @@ public class SQLPrinterVisitor<T> extend
                 String name = getRealPropertyName(statement.getProperty());
                 String value = getPropertyValue(name, statement.getValue());
                 validatePropertyValue(name, value);
-                String rvalStr = value.replaceAll("\\*", "%");
                 
+                value = SearchUtils.toSqlWildcardString(value, isWildcardStringMatch());
                                 
                 if (tableAlias != null) {
                     name = tableAlias + "." + name;
                 }
                 
                 sb.append(name).append(" ").append(
-                            SearchUtils.conditionTypeToSqlOperator(sc.getConditionType(),
rvalStr))
-                            .append(" ").append("'").append(rvalStr).append("'");
+                            SearchUtils.conditionTypeToSqlOperator(sc.getConditionType(),
value))
+                            .append(" ").append("'").append(value).append("'");
             }
         } else {
             boolean first = true;

Modified: cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java?rev=1520301&r1=1520300&r2=1520301&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java
Thu Sep  5 13:31:56 2013
@@ -37,6 +37,7 @@ public abstract class AbstractSearchCond
     private Map<String, String> fieldMap;
     private Map<String, Class<?>> primitiveFieldTypeMap;
     private PropertyValidator<Object> validator;
+    private boolean wildcardStringMatch;
     
     protected AbstractSearchConditionVisitor(Map<String, String> fieldMap) {
         this.fieldMap = fieldMap;
@@ -169,4 +170,12 @@ public abstract class AbstractSearchCond
     public void setValidator(PropertyValidator<Object> validator) {
         this.validator = validator;
     }
+
+    public boolean isWildcardStringMatch() {
+        return wildcardStringMatch;
+    }
+
+    public void setWildcardStringMatch(boolean wildcardStringMatch) {
+        this.wildcardStringMatch = wildcardStringMatch;
+    }
 }



Mime
View raw message