cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1059923 - in /cxf/trunk/rt: frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/ frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/ management-web/src/main/java/org/apache/cxf/management/web/logging/atom/
Date Mon, 17 Jan 2011 13:42:02 GMT
Author: sergeyb
Date: Mon Jan 17 13:42:01 2011
New Revision: 1059923

URL: http://svn.apache.org/viewvc?rev=1059923&view=rev
Log:
[CXF-3145] Applying a slightly modified patch on behalf of Brian Topping - thanks

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SQLPrinterConditionVisitor.java
  (with props)
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchConditionVisitor.java
  (with props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractComplexCondition.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/PrimitiveSearchCondition.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/PrimitiveStatement.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchCondition.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/FiqlParserTest.java
    cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractComplexCondition.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractComplexCondition.java?rev=1059923&r1=1059922&r2=1059923&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractComplexCondition.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractComplexCondition.java
Mon Jan 17 13:42:01 2011
@@ -68,23 +68,11 @@ public abstract class AbstractComplexCon
     }
 
     public String toSQL(String table, String... columns) {
-        StringBuilder sb = new StringBuilder();
-        
-        if (table != null) {
-            SearchUtils.startSqlQuery(sb, table, columns);
-        }
-        
-        boolean first = true;
-        for (SearchCondition<T> sc : conditions) {
-            if (!first) {
-                sb.append(" " + cType.toString() + " ");
-            } else {
-                first = false;
-            }
-            
-            sb.append("(").append(sc.toSQL(null)).append(")");
-        }
-        return sb.toString();
+        return SearchUtils.toSQL(this, table, columns);
     }
 
+    public void accept(SearchConditionVisitor<T> visitor) {
+        visitor.visit(this);    
+    }
+    
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/PrimitiveSearchCondition.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/PrimitiveSearchCondition.java?rev=1059923&r1=1059922&r2=1059923&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/PrimitiveSearchCondition.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/PrimitiveSearchCondition.java
Mon Jan 17 13:42:01 2011
@@ -87,21 +87,13 @@ public class PrimitiveSearchCondition<T>
     }
     
     public String toSQL(String table, String... columns) {
-        StringBuilder sb = new StringBuilder();
-        
-        if (table != null) {
-            SearchUtils.startSqlQuery(sb, table, columns);
-        }
-        
-        String rvalStr = propertyValue.toString();
-        rvalStr = rvalStr.replaceAll("\\*", "%");
-        
-        
-        sb.append(propertyName).append(" ").append(
-            SearchUtils.conditionTypeToSqlOperator(cType, rvalStr)).append(" ")
-            .append("'").append(rvalStr).append("'");
-        return sb.toString();
+        return SearchUtils.toSQL(this, table, columns);
+    }
+
+    public void accept(SearchConditionVisitor<T> visitor) {
+        visitor.visit(this);    
     }
+   
 
     private boolean isPrimitive(T pojo) {
         return pojo.getClass().getName().startsWith("java.lang");

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/PrimitiveStatement.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/PrimitiveStatement.java?rev=1059923&r1=1059922&r2=1059923&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/PrimitiveStatement.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/PrimitiveStatement.java
Mon Jan 17 13:42:01 2011
@@ -24,18 +24,18 @@ package org.apache.cxf.jaxrs.ext.search;
 
 public class PrimitiveStatement {
 
-    private String propery;
+    private String property;
     private Object value;
     private ConditionType condition;
     
     public PrimitiveStatement(String property, Object value, ConditionType condition) {
-        this.propery = property;
+        this.property = property;
         this.value = value;
         this.condition = condition;
     }
     
-    public String getPropery() {
-        return propery;
+    public String getProperty() {
+        return property;
     }
     
     public Object getValue() {

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SQLPrinterConditionVisitor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SQLPrinterConditionVisitor.java?rev=1059923&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SQLPrinterConditionVisitor.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SQLPrinterConditionVisitor.java
Mon Jan 17 13:42:01 2011
@@ -0,0 +1,72 @@
+/**
+ * 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;
+
+
+public class SQLPrinterConditionVisitor<T> implements SearchConditionVisitor<T>
{
+
+    private StringBuilder sb;
+    private String table;
+    private String[] columns;
+
+    
+    public SQLPrinterConditionVisitor(String table, String... columns) {
+        this.columns = columns;
+        this.table = table;
+    }
+    
+    
+    @Override
+    public void visit(SearchCondition<T> sc) {
+        
+        if (sb == null) {
+            sb = new StringBuilder();
+            if (table != null) {
+                SearchUtils.startSqlQuery(sb, table, columns);
+            }
+        }
+        
+        PrimitiveStatement statement = sc.getStatement();
+        if (statement != null) {
+            if (statement.getProperty() != null) {
+                String rvalStr = statement.getValue().toString().replaceAll("\\*", "%");
+                sb.append(statement.getProperty()).append(" ").append(
+                            SearchUtils.conditionTypeToSqlOperator(sc.getConditionType(),
rvalStr))
+                            .append(" ").append("'").append(rvalStr).append("'");
+            }
+        } else {
+            boolean first = true;
+            for (SearchCondition<T> condition : sc.getSearchConditions()) {
+                if (!first) {
+                    sb.append(" ").append(sc.getConditionType().toString()).append(" ");
+                } else {
+                    first = false;
+                }
+                sb.append("(");
+                condition.accept(this);
+                sb.append(")");
+            }
+        }
+    }
+    
+
+    public String getResult() {
+        return sb == null ? null : sb.toString();
+    }
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SQLPrinterConditionVisitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SQLPrinterConditionVisitor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchCondition.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchCondition.java?rev=1059923&r1=1059922&r2=1059923&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchCondition.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchCondition.java
Mon Jan 17 13:42:01 2011
@@ -65,30 +65,45 @@ public interface SearchCondition<T> {
     
     /**
      * Primitive statement such a > b, i < 5, etc
-     * this condition may represent  
+     * this condition may represent. Complex conditions will return null.  
      *  
      * @return primitive search statement, can be null 
      */
     PrimitiveStatement getStatement();
     
     /**
-     * List of conditions this SearchCondition may represent  
+     * List of conditions this SearchCondition may represent.
+     * Composite SearchConditions will return a list of conditions they are
+     * composed from, primitive ones will return null  
      * @return list of conditions, can be null
      */
     List<SearchCondition<T>> getSearchConditions();
     
     /**
-     * Type of condition this SearchCondition represents
+     * Returns the type of the condition this SearchCondition represents
      * @return condition type
      */
     ConditionType getConditionType();
+
+    /**
+     * Provides a visitor which will convert this SearchCondition into
+     * a custom expression, for example, into the SQL statement, etc 
+     * @param visitor
+     */
+    void accept(SearchConditionVisitor<T> visitor);
     
     /**
+     * 
+     * This method is now deprecated and will be removed soon.
+     * 
      * Utility method for converting this condition into an SQL expression
      * @param table table name
      * @param columns column names, a wildcard as in 'SELECT * from table' will be used
      *                if names are not provided 
      * @return SQL expression
      */    
+    @Deprecated
     String toSQL(String table, String... columns);
+    
+    
 }

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchConditionVisitor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchConditionVisitor.java?rev=1059923&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchConditionVisitor.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchConditionVisitor.java
Mon Jan 17 13:42:01 2011
@@ -0,0 +1,39 @@
+/**
+ * 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;
+
+/**
+ * Interface for visitors to SearchCondition objects.
+ * Custom implementations can use it to convert SearchCondition into
+ * specific query language such as SQL, etc
+ */
+
+public interface SearchConditionVisitor<T> {
+    /*
+     * Callback providing a current SearchCondition object 
+     */
+    void visit(SearchCondition<T> sc);
+    
+    /**
+     * Recover the accumulated query
+     * @return query string
+     */
+    String getResult();
+
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchConditionVisitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchConditionVisitor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java?rev=1059923&r1=1059922&r2=1059923&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
Mon Jan 17 13:42:01 2011
@@ -24,6 +24,12 @@ public final class SearchUtils {
         
     }
     
+    public static <T> String toSQL(SearchCondition<T> sc, String table, String...
columns) {
+        SearchConditionVisitor<T> visitor = new SQLPrinterConditionVisitor<T>(table,
columns);
+        sc.accept(visitor);
+        return visitor.getResult();
+    }
+    
     public static void startSqlQuery(StringBuilder sb, String table, String... columns) {
         sb.append("SELECT ");
         if (columns.length > 0) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java?rev=1059923&r1=1059922&r2=1059923&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
Mon Jan 17 13:42:01 2011
@@ -270,30 +270,7 @@ public class SimpleSearchCondition<T> im
     }
 
     public String toSQL(String table, String... columns) {
-        if (isPrimitive(condition)) {
-            return null;
-        }
-        StringBuilder sb = new StringBuilder();
-        
-        if (table != null) {
-            SearchUtils.startSqlQuery(sb, table, columns);
-        }
-        
-        boolean first = true;
-        for (SearchCondition<T> sc : scts) {
-            PrimitiveStatement ps = sc.getStatement();
-            if (ps.getPropery() == null) {
-                continue;
-            }
-            if (!first) {
-                sb.append(" " + joiningType.toString() + " ");
-            } else {
-                first = false;
-            }
-            
-            sb.append(sc.toSQL(null));
-        }
-        return sb.toString();
+        return SearchUtils.toSQL(this, table, columns);
     }
     
     public PrimitiveStatement getStatement() {
@@ -303,6 +280,11 @@ public class SimpleSearchCondition<T> im
             return null;
         }
     }
+
+    @Override
+    public void accept(SearchConditionVisitor<T> visitor) {
+        visitor.visit(this);
+    }
     
     
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/FiqlParserTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/FiqlParserTest.java?rev=1059923&r1=1059922&r2=1059923&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/FiqlParserTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/FiqlParserTest.java
Mon Jan 17 13:42:01 2011
@@ -170,12 +170,13 @@ public class FiqlParserTest extends Asse
         assertFalse(filter.isMet(new Condition("am", 20, null)));
     }
     
+    @SuppressWarnings("deprecation")
     @Test
     public void testSQL1() throws FiqlParseException {
         SearchCondition<Condition> filter = parser.parse("name==ami*;level=gt=10");
         String sql = filter.toSQL("table");
-        assertTrue("SELECT * FROM table WHERE name LIKE 'ami%' AND level > '10'".equals(sql)
-                   || "SELECT * FROM table WHERE level > '10' AND name LIKE 'ami%'".equals(sql));
+        assertTrue("SELECT * FROM table WHERE (name LIKE 'ami%') AND (level > '10')".equals(sql)
+                   || "SELECT * FROM table WHERE (level > '10') AND (name LIKE 'ami%')".equals(sql));
     }
 
     @Test
@@ -186,6 +187,7 @@ public class FiqlParserTest extends Asse
         assertFalse(filter.isMet(new Condition("foo", 0, null)));
     }
 
+    @SuppressWarnings("deprecation")
     @Test
     public void testSQL2() throws FiqlParseException {
         SearchCondition<Condition> filter = parser.parse("name==ami*,level=gt=10");
@@ -203,6 +205,7 @@ public class FiqlParserTest extends Asse
         assertFalse(filter.isMet(new Condition("bar", 20, null)));
     }
 
+    @SuppressWarnings("deprecation")
     @Test
     public void testSQL3() throws FiqlParseException {
         SearchCondition<Condition> filter = parser.parse("name==foo*;(name!=*bar,level=gt=10)");
@@ -213,6 +216,7 @@ public class FiqlParserTest extends Asse
                    + "((level > '10') OR (name NOT LIKE '%bar'))").equals(sql));
     }
     
+    @SuppressWarnings("deprecation")
     @Test
     public void testSQL4() throws FiqlParseException {
         SearchCondition<Condition> filter = parser.parse("(name==test,level==18);(name==test1,level!=19)");
@@ -223,6 +227,14 @@ public class FiqlParserTest extends Asse
                    + " AND ((name = 'test') OR (level = '18'))").equals(sql));
     }
     
+    @SuppressWarnings("deprecation")
+    @Test
+    public void testSQL5() throws FiqlParseException {
+        SearchCondition<Condition> filter = parser.parse("name==test");
+        String sql = filter.toSQL("table");
+        assertTrue("SELECT * FROM table WHERE name = 'test'".equals(sql));
+    }
+    
     @Test
     public void testParseComplex4() throws FiqlParseException {
         SearchCondition<Condition> filter = parser.parse("name==foo*;name!=*bar,level=gt=10");

Modified: cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java?rev=1059923&r1=1059922&r2=1059923&view=diff
==============================================================================
--- cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java
(original)
+++ cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java
Mon Jan 17 13:42:01 2011
@@ -46,6 +46,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.SearchConditionVisitor;
 import org.apache.cxf.management.web.logging.LogLevel;
 import org.apache.cxf.management.web.logging.LogRecord;
 import org.apache.cxf.management.web.logging.ReadWriteLogStorage;
@@ -467,8 +468,10 @@ public class AtomPullServer extends Abst
         public String toSQL(String table, String... columns) {
             return null;
         }
-        
-        
+
+        @Override
+        public void accept(SearchConditionVisitor<LogRecord> visitor) {
+        }
     }
     
     private static class LogRecordComparator implements Comparator<LogRecord> {



Mime
View raw message