cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5731] Optimizing joins in JPA queries, patch from Romain Castan applied
Date Tue, 06 May 2014 20:15:16 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes c23e47661 -> b819dbbb2


[CXF-5731] Optimizing joins in JPA queries, patch 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/b819dbbb
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/b819dbbb
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/b819dbbb

Branch: refs/heads/2.7.x-fixes
Commit: b819dbbb2e1923881523cf89f4faa8489d725a61
Parents: c23e476
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Tue May 6 21:12:12 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Tue May 6 21:14:48 2014 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/ext/search/SearchUtils.java       | 10 ++++++---
 .../jpa/AbstractJPATypedQueryVisitor.java       | 23 +++++++++++++++++---
 2 files changed, 27 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/b819dbbb/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 db9a81e..c6bc2ca 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
@@ -78,7 +78,11 @@ public final class SearchUtils {
     }
     
     public static boolean containsEscapedChar(String value) {
-        return value.contains("\\%") || value.contains("\\\\") || value.contains("\\_");
+        return containsEscapedPercent(value) || value.contains("\\\\") || value.contains("\\_");
+    }
+    
+    public static boolean containsEscapedPercent(String value) {
+        return value.contains("\\%");
     }
     
     public static void startSqlQuery(StringBuilder sb, 
@@ -109,10 +113,10 @@ public final class SearchUtils {
         String op;
         switch (ct) {
         case EQUALS:
-            op = containsEscapedChar(value) || value.contains("%") ? "LIKE" : "=";
+            op = containsEscapedPercent(value) || value.contains("%") ? "LIKE" : "=";
             break;
         case NOT_EQUALS:
-            op = containsEscapedChar(value) || value.contains("%") ? "NOT LIKE" : "<>";
+            op = containsEscapedPercent(value) || value.contains("%") ? "NOT LIKE" : "<>";
             break;
         case GREATER_THAN:
             op = ">";

http://git-wip-us.apache.org/repos/asf/cxf/blob/b819dbbb/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
index 474f97c..d084cf3 100644
--- a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
@@ -31,6 +31,7 @@ import javax.persistence.TypedQuery;
 import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Expression;
+import javax.persistence.criteria.From;
 import javax.persistence.criteria.Join;
 import javax.persistence.criteria.Path;
 import javax.persistence.criteria.Predicate;
@@ -198,7 +199,7 @@ public abstract class AbstractJPATypedQueryVisitor<T, T1, E>
         case EQUALS:
             if (clazz.equals(String.class)) {
                 String theValue = SearchUtils.toSqlWildcardString(value.toString(), isWildcardStringMatch());
-                if (SearchUtils.containsEscapedChar(theValue)) {
+                if (SearchUtils.containsEscapedPercent(theValue)) {
                     pred = builder.like((Expression<String>)exp, theValue, '\\');
                 } else if (theValue.contains("%")) {
                     pred = builder.like((Expression<String>)exp, theValue);
@@ -212,7 +213,7 @@ public abstract class AbstractJPATypedQueryVisitor<T, T1, E>
         case NOT_EQUALS:
             if (clazz.equals(String.class)) {
                 String theValue = SearchUtils.toSqlWildcardString(value.toString(), isWildcardStringMatch());
-                if (SearchUtils.containsEscapedChar(theValue)) {
+                if (SearchUtils.containsEscapedPercent(theValue)) {
                     pred = builder.notLike((Expression<String>)exp, theValue, '\\');
                 } else if (theValue.contains("%")) {
                     pred = builder.notLike((Expression<String>)exp, theValue);
@@ -286,7 +287,13 @@ public abstract class AbstractJPATypedQueryVisitor<T, T1, E>
     private Path<?> getNextPath(Path<?> element, String name, ClassValue cv,
CollectionCheckInfo collSize) {
         if (collSize == null
             && (cv.isCollection(name) || isJoinProperty(name)) && (element
== root || element instanceof Join)) {
-            return element == root ? root.join(name) : ((Join<?, ?>)element).join(name);
+            
+            final Path<?> path = getExistingJoinProperty((From<?, ?>)element,
name);
+            if (path != null) {
+                return path;
+            } else {
+                return element == root ? root.join(name) : ((Join<?, ?>)element).join(name);
+            }
         } else {
             return element.get(name);
         }
@@ -296,4 +303,14 @@ public abstract class AbstractJPATypedQueryVisitor<T, T1, E>
         return joinProperties == null ? false : joinProperties.contains(prop);
     }
     
+    private Path<?> getExistingJoinProperty(From<?, ?> element, String prop)
{
+        final Set<?> joins = element.getJoins();
+        for (Object object : joins) {
+            Join<?, ?> join = (Join<?, ?>) object;
+            if (join.getAttribute().getName().equals(prop)) {
+                return join;
+            }
+        }
+        return null;
+    }
 }


Mime
View raw message