cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1399195 - in /cxf/trunk/rt/rs/extensions/search/src: main/java/org/apache/cxf/jaxrs/ext/search/ main/java/org/apache/cxf/jaxrs/ext/search/jpa/ main/java/org/apache/cxf/jaxrs/ext/search/lucene/ main/java/org/apache/cxf/jaxrs/ext/search/sql/...
Date Wed, 17 Oct 2012 12:24:46 GMT
Author: sergeyb
Date: Wed Oct 17 12:24:46 2012
New Revision: 1399195

URL: http://svn.apache.org/viewvc?rev=1399195&view=rev
Log:
[CXF-4578] Adding a query type parameter to SearchConditionVisitor

Added:
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
  (with props)
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPACriteriaQueryVisitor.java
  (with props)
Modified:
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractComplexCondition.java
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractSearchConditionVisitor.java
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/PrimitiveSearchCondition.java
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchCondition.java
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchConditionVisitor.java
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitor.java
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitor.java
    cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
    cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitorTest.java
    cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitorTest.java

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractComplexCondition.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractComplexCondition.java?rev=1399195&r1=1399194&r2=1399195&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractComplexCondition.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractComplexCondition.java
Wed Oct 17 12:24:46 2012
@@ -71,7 +71,7 @@ public abstract class AbstractComplexCon
         return SearchUtils.toSQL(this, table, columns);
     }
 
-    public void accept(SearchConditionVisitor<T> visitor) {
+    public void accept(SearchConditionVisitor<T, ?> visitor) {
         visitor.visit(this);    
     }
     

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractSearchConditionVisitor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractSearchConditionVisitor.java?rev=1399195&r1=1399194&r2=1399195&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractSearchConditionVisitor.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractSearchConditionVisitor.java
Wed Oct 17 12:24:46 2012
@@ -24,7 +24,7 @@ import java.util.logging.Logger;
 import org.apache.cxf.common.logging.LogUtils;
 
 
-public abstract class AbstractSearchConditionVisitor <T> implements SearchConditionVisitor<T>
{
+public abstract class AbstractSearchConditionVisitor <T, E> implements SearchConditionVisitor<T,
E> {
 
     private static final Logger LOG = LogUtils.getL7dLogger(AbstractSearchConditionVisitor.class);
     
@@ -60,4 +60,8 @@ public abstract class AbstractSearchCond
     public void setPrimitiveFieldTypeMap(Map<String, Class<?>> primitiveFieldTypeMap)
{
         this.primitiveFieldTypeMap = primitiveFieldTypeMap;
     }
+    
+    public SearchConditionVisitor<T, E> visitor() {
+        return this;
+    }
 }

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/PrimitiveSearchCondition.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/PrimitiveSearchCondition.java?rev=1399195&r1=1399194&r2=1399195&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/PrimitiveSearchCondition.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/PrimitiveSearchCondition.java
Wed Oct 17 12:24:46 2012
@@ -95,7 +95,7 @@ public class PrimitiveSearchCondition<T>
         return SearchUtils.toSQL(this, table, columns);
     }
 
-    public void accept(SearchConditionVisitor<T> visitor) {
+    public void accept(SearchConditionVisitor<T, ?> visitor) {
         visitor.visit(this);    
     }
    

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchCondition.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchCondition.java?rev=1399195&r1=1399194&r2=1399195&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchCondition.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchCondition.java
Wed Oct 17 12:24:46 2012
@@ -90,6 +90,6 @@ public interface SearchCondition<T> {
      * a custom expression, for example, into the SQL statement, etc 
      * @param visitor
      */
-    void accept(SearchConditionVisitor<T> visitor);
+    void accept(SearchConditionVisitor<T, ?> visitor);
     
 }

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchConditionVisitor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchConditionVisitor.java?rev=1399195&r1=1399194&r2=1399195&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchConditionVisitor.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchConditionVisitor.java
Wed Oct 17 12:24:46 2012
@@ -24,9 +24,15 @@ package org.apache.cxf.jaxrs.ext.search;
  * specific query language such as SQL, etc
  */
 
-public interface SearchConditionVisitor<T> {
+public interface SearchConditionVisitor<T, E> {
     /*
-     * Callback providing a current SearchCondition object 
+     * Accept a current SearchCondition object 
      */
     void visit(SearchCondition<T> sc);
+    
+    /**
+     * Return a built query object 
+     * @return the query
+     */
+    E getQuery();
 }

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java?rev=1399195&r1=1399194&r2=1399195&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
Wed Oct 17 12:24:46 2012
@@ -290,7 +290,7 @@ public class SimpleSearchCondition<T> im
         }
     }
 
-    public void accept(SearchConditionVisitor<T> visitor) {
+    public void accept(SearchConditionVisitor<T, ?> visitor) {
         visitor.visit(this);
     }
     

Added: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java?rev=1399195&view=auto
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
(added)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
Wed Oct 17 12:24:46 2012
@@ -0,0 +1,165 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.ext.search.jpa;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Stack;
+
+import javax.persistence.EntityManager;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+
+import org.apache.cxf.jaxrs.ext.search.AbstractSearchConditionVisitor;
+import org.apache.cxf.jaxrs.ext.search.ConditionType;
+import org.apache.cxf.jaxrs.ext.search.OrSearchCondition;
+import org.apache.cxf.jaxrs.ext.search.PrimitiveStatement;
+import org.apache.cxf.jaxrs.ext.search.SearchCondition;
+
+public abstract class AbstractJPATypedQueryVisitor<T, E> 
+    extends AbstractSearchConditionVisitor<T, E> {
+
+    private EntityManager em;
+    private Class<T> tClass;
+    private Root<T> root;
+    private CriteriaBuilder builder;
+    private CriteriaQuery<T> cq;
+    private Stack<List<Predicate>> predStack = new Stack<List<Predicate>>();
+    private boolean criteriaFinalized;
+    
+    public AbstractJPATypedQueryVisitor(EntityManager em, Class<T> tClass) {
+        this(em, tClass, null);
+    }
+    
+    public AbstractJPATypedQueryVisitor(EntityManager em, Class<T> tClass, Map<String,
String> fieldMap) {
+        super(fieldMap);
+        this.em = em;
+        this.tClass = tClass;
+    }
+    
+    protected EntityManager getEntityManager() {
+        return em;
+    }
+    
+    public void visit(SearchCondition<T> sc) {
+        if (builder == null) {
+            builder = em.getCriteriaBuilder();
+            cq = builder.createQuery(tClass);
+            root = cq.from(tClass);
+            predStack.push(new ArrayList<Predicate>());
+        }
+        PrimitiveStatement statement = sc.getStatement();
+        if (statement != null) {
+            if (statement.getProperty() != null) {
+                predStack.peek().add(buildPredicate(sc.getConditionType(), 
+                                                    statement.getProperty(), 
+                                                    statement.getValue()));
+            }
+        } else {
+            predStack.push(new ArrayList<Predicate>());
+            for (SearchCondition<T> condition : sc.getSearchConditions()) {
+                condition.accept(this);
+            }
+            List<Predicate> predsList = predStack.pop();
+            Predicate[] preds = predsList.toArray(new Predicate[predsList.size()]);
+            Predicate newPred;
+            if (sc instanceof OrSearchCondition) {
+                newPred = builder.or(preds);
+            } else {
+                newPred = builder.and(preds);
+            }
+            predStack.peek().add(newPred);
+        }
+    }
+
+    public CriteriaQuery<T> getCriteriaQuery() {
+        if (!criteriaFinalized) {
+            List<Predicate> predsList = predStack.pop();
+            cq.where(predsList.toArray(new Predicate[predsList.size()]));
+            criteriaFinalized = true;
+        }
+        return cq;
+    }
+    
+    
+    @SuppressWarnings({ "unchecked", "rawtypes" })
+    private Predicate buildPredicate(ConditionType ct, String name, Object value) {
+
+        name = super.getRealPropertyName(name);
+        Class<? extends Comparable> clazz = (Class<? extends Comparable>)
+            getPrimitiveFieldClass(name, value.getClass());
+        
+        
+        Path<?> path = getPath(root, name);
+        
+        Predicate pred = null;
+        switch (ct) {
+        case GREATER_THAN:
+            pred = builder.greaterThan(path.as(clazz), clazz.cast(value));
+            break;
+        case EQUALS:
+            if (clazz.equals(String.class)) {
+                String theValue = (String)value;
+                if (theValue.contains("*")) {
+                    theValue = ((String)value).replaceAll("\\*", "");
+                }
+                pred = builder.like(path.as(String.class), "%" + theValue + "%");
+            } else {
+                pred = builder.equal(path.as(clazz), clazz.cast(value));
+            }
+            break;
+        case NOT_EQUALS:
+            pred = builder.notEqual(path.as(clazz), 
+                                    clazz.cast(value));
+            break;
+        case LESS_THAN:
+            pred = builder.lessThan(path.as(clazz), 
+                                    clazz.cast(value));
+            break;
+        case LESS_OR_EQUALS:
+            pred = builder.lessThanOrEqualTo(path.as(clazz), 
+                                             clazz.cast(value));
+            break;
+        case GREATER_OR_EQUALS:
+            pred = builder.greaterThanOrEqualTo(path.as(clazz), 
+                                                clazz.cast(value));
+            break;
+        default: 
+            break;
+        }
+        return pred;
+    }
+
+    private Path<?> getPath(Path<?> element, String name) {
+        if (name.contains(".")) {
+            String pre = name.substring(0, name.indexOf('.'));
+            String post = name.substring(name.indexOf('.') + 1);
+            Path<?> newPath = element.get(pre);
+            return getPath(newPath, post);
+        } else {
+            return element.get(name);
+        }
+    }
+    
+    
+}

Propchange: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPACriteriaQueryVisitor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPACriteriaQueryVisitor.java?rev=1399195&view=auto
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPACriteriaQueryVisitor.java
(added)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPACriteriaQueryVisitor.java
Wed Oct 17 12:24:46 2012
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.ext.search.jpa;
+
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+import javax.persistence.criteria.CriteriaQuery;
+
+public class JPACriteriaQueryVisitor<T> extends AbstractJPATypedQueryVisitor<T,
CriteriaQuery<T>> {
+
+    public JPACriteriaQueryVisitor(EntityManager em, Class<T> tClass) {
+        this(em, tClass, null);
+    }
+    
+    public JPACriteriaQueryVisitor(EntityManager em, Class<T> tClass, Map<String,
String> fieldMap) {
+        super(em, tClass, fieldMap);
+    }
+    
+    public CriteriaQuery<T> getQuery() {
+        return getCriteriaQuery();
+    }
+        
+}

Propchange: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPACriteriaQueryVisitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPACriteriaQueryVisitor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitor.java?rev=1399195&r1=1399194&r2=1399195&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitor.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitor.java
Wed Oct 17 12:24:46 2012
@@ -18,148 +18,23 @@
  */
 package org.apache.cxf.jaxrs.ext.search.jpa;
 
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Map;
-import java.util.Stack;
 
 import javax.persistence.EntityManager;
 import javax.persistence.TypedQuery;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Path;
-import javax.persistence.criteria.Predicate;
-import javax.persistence.criteria.Root;
 
-import org.apache.cxf.jaxrs.ext.search.AbstractSearchConditionVisitor;
-import org.apache.cxf.jaxrs.ext.search.ConditionType;
-import org.apache.cxf.jaxrs.ext.search.OrSearchCondition;
-import org.apache.cxf.jaxrs.ext.search.PrimitiveStatement;
-import org.apache.cxf.jaxrs.ext.search.SearchCondition;
+public class JPATypedQueryVisitor<T> extends AbstractJPATypedQueryVisitor<T, TypedQuery<T>>
{
 
-public class JPATypedQueryVisitor<T> extends AbstractSearchConditionVisitor<T>
{
-
-    private EntityManager em;
-    private Class<T> tClass;
-    private Root<T> root;
-    private CriteriaBuilder builder;
-    private CriteriaQuery<T> cq;
-    private Stack<List<Predicate>> predStack = new Stack<List<Predicate>>();
-    private boolean criteriaFinalized;
-    
     public JPATypedQueryVisitor(EntityManager em, Class<T> tClass) {
         this(em, tClass, null);
     }
     
     public JPATypedQueryVisitor(EntityManager em, Class<T> tClass, Map<String, String>
fieldMap) {
-        super(fieldMap);
-        this.em = em;
-        this.tClass = tClass;
+        super(em, tClass, fieldMap);
     }
     
-    public void visit(SearchCondition<T> sc) {
-        if (builder == null) {
-            builder = em.getCriteriaBuilder();
-            cq = builder.createQuery(tClass);
-            root = cq.from(tClass);
-            predStack.push(new ArrayList<Predicate>());
-        }
-        PrimitiveStatement statement = sc.getStatement();
-        if (statement != null) {
-            if (statement.getProperty() != null) {
-                predStack.peek().add(buildPredicate(sc.getConditionType(), 
-                                                    statement.getProperty(), 
-                                                    statement.getValue()));
-            }
-        } else {
-            predStack.push(new ArrayList<Predicate>());
-            for (SearchCondition<T> condition : sc.getSearchConditions()) {
-                condition.accept(this);
-            }
-            List<Predicate> predsList = predStack.pop();
-            Predicate[] preds = predsList.toArray(new Predicate[predsList.size()]);
-            Predicate newPred;
-            if (sc instanceof OrSearchCondition) {
-                newPred = builder.or(preds);
-            } else {
-                newPred = builder.and(preds);
-            }
-            predStack.peek().add(newPred);
-        }
-    }
-
     public TypedQuery<T> getQuery() {
-        return em.createQuery(getCriteriaQuery());
+        return getEntityManager().createQuery(getCriteriaQuery());
     }
-    
-    public CriteriaQuery<T> getCriteriaQuery() {
-        if (!criteriaFinalized) {
-            List<Predicate> predsList = predStack.pop();
-            cq.where(predsList.toArray(new Predicate[predsList.size()]));
-            criteriaFinalized = true;
-        }
-        return cq;
-    }
-    
-    
-    @SuppressWarnings({ "unchecked", "rawtypes" })
-    private Predicate buildPredicate(ConditionType ct, String name, Object value) {
-
-        name = super.getRealPropertyName(name);
-        Class<? extends Comparable> clazz = (Class<? extends Comparable>)
-            getPrimitiveFieldClass(name, value.getClass());
-        
         
-        Path<?> path = getPath(root, name);
-        
-        Predicate pred = null;
-        switch (ct) {
-        case GREATER_THAN:
-            pred = builder.greaterThan(path.as(clazz), clazz.cast(value));
-            break;
-        case EQUALS:
-            if (clazz.equals(String.class)) {
-                String theValue = (String)value;
-                if (theValue.contains("*")) {
-                    theValue = ((String)value).replaceAll("\\*", "");
-                }
-                pred = builder.like(path.as(String.class), "%" + theValue + "%");
-            } else {
-                pred = builder.equal(path.as(clazz), clazz.cast(value));
-            }
-            break;
-        case NOT_EQUALS:
-            pred = builder.notEqual(path.as(clazz), 
-                                    clazz.cast(value));
-            break;
-        case LESS_THAN:
-            pred = builder.lessThan(path.as(clazz), 
-                                    clazz.cast(value));
-            break;
-        case LESS_OR_EQUALS:
-            pred = builder.lessThanOrEqualTo(path.as(clazz), 
-                                             clazz.cast(value));
-            break;
-        case GREATER_OR_EQUALS:
-            pred = builder.greaterThanOrEqualTo(path.as(clazz), 
-                                                clazz.cast(value));
-            break;
-        default: 
-            break;
-        }
-        return pred;
-    }
-
-    private Path<?> getPath(Path<?> element, String name) {
-        if (name.contains(".")) {
-            String pre = name.substring(0, name.indexOf('.'));
-            String post = name.substring(name.indexOf('.') + 1);
-            Path<?> newPath = element.get(pre);
-            return getPath(newPath, post);
-        } else {
-            return element.get(name);
-        }
-    }
-    
-    
 }

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java?rev=1399195&r1=1399194&r2=1399195&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
Wed Oct 17 12:24:46 2012
@@ -40,7 +40,7 @@ import org.apache.lucene.search.Query;
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.WildcardQuery;
 
-public class LuceneQueryVisitor<T> extends AbstractSearchConditionVisitor<T>
{
+public class LuceneQueryVisitor<T> extends AbstractSearchConditionVisitor<T, Query>
{
 
     //private Analyzer analyzer;
     private String contentsFieldName;

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitor.java?rev=1399195&r1=1399194&r2=1399195&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitor.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitor.java
Wed Oct 17 12:24:46 2012
@@ -28,7 +28,7 @@ import org.apache.cxf.jaxrs.ext.search.S
 import org.apache.cxf.jaxrs.ext.search.SearchUtils;
 
 
-public class SQLPrinterVisitor<T> extends AbstractSearchConditionVisitor<T> {
+public class SQLPrinterVisitor<T> extends AbstractSearchConditionVisitor<T, String>
{
 
     private StringBuilder sb;
     private String table;

Modified: cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java?rev=1399195&r1=1399194&r2=1399195&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
Wed Oct 17 12:24:46 2012
@@ -28,6 +28,7 @@ import javax.persistence.Persistence;
 import javax.persistence.TypedQuery;
 
 import org.apache.cxf.jaxrs.ext.search.SearchCondition;
+import org.apache.cxf.jaxrs.ext.search.SearchConditionVisitor;
 import org.apache.cxf.jaxrs.ext.search.fiql.FiqlParser;
 
 import org.junit.After;
@@ -174,7 +175,7 @@ public class JPATypedQueryVisitorTest ex
     
     private List<Book> queryBooks(String expression) throws Exception {
         SearchCondition<Book> filter = new FiqlParser<Book>(Book.class).parse(expression);
-        JPATypedQueryVisitor<Book> jpa = new JPATypedQueryVisitor<Book>(em, Book.class);
+        SearchConditionVisitor<Book, TypedQuery<Book>> jpa = new JPATypedQueryVisitor<Book>(em,
Book.class);
         filter.accept(jpa);
         TypedQuery<Book> query = jpa.getQuery();
         return query.getResultList();

Modified: cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitorTest.java?rev=1399195&r1=1399194&r2=1399195&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitorTest.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitorTest.java
Wed Oct 17 12:24:46 2012
@@ -22,6 +22,7 @@ import java.util.Collections;
 
 import org.apache.cxf.jaxrs.ext.search.SearchBean;
 import org.apache.cxf.jaxrs.ext.search.SearchCondition;
+import org.apache.cxf.jaxrs.ext.search.SearchConditionVisitor;
 import org.apache.cxf.jaxrs.ext.search.fiql.FiqlParser;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
@@ -92,6 +93,14 @@ public class LuceneQueryVisitorTest exte
     }
     
     @Test
+    public void testTextContentMatchNotEqualPositive() throws Exception {
+        
+        Query query = createTermQuery("contents", "ct!=bar");
+        doTestNoMatch(query);
+            
+    }
+    
+    @Test
     public void testTextContentMatchWildcardEnd() throws Exception {
         doTestTextContentMatch("ct==tex*");
     }
@@ -279,7 +288,7 @@ public class LuceneQueryVisitorTest exte
     private Query createTermQuery(String expression) throws Exception {
         SearchCondition<SearchBean> filter = 
             new FiqlParser<SearchBean>(SearchBean.class).parse(expression);
-        LuceneQueryVisitor<SearchBean> lucene = new LuceneQueryVisitor<SearchBean>();
+        SearchConditionVisitor<SearchBean, Query> lucene = new LuceneQueryVisitor<SearchBean>();
         lucene.visit(filter);
         return lucene.getQuery();
     }

Modified: cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitorTest.java?rev=1399195&r1=1399194&r2=1399195&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitorTest.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitorTest.java
Wed Oct 17 12:24:46 2012
@@ -38,7 +38,7 @@ public class SQLPrinterVisitorTest exten
     public void testSQL1() throws SearchParseException {
         SearchCondition<Condition> filter = parser.parse("name==ami*;level=gt=10");
         SQLPrinterVisitor<Condition> visitor = new SQLPrinterVisitor<Condition>("table");
-        filter.accept(visitor);
+        filter.accept(visitor.visitor());
         String sql = visitor.getQuery();
         
         assertTrue("SELECT * FROM table WHERE (name LIKE 'ami%') AND (level > '10')".equals(sql)



Mime
View raw message