Author: ekoneil
Date: Tue Apr 12 08:09:04 2005
New Revision: 161062

URL: http://svn.apache.org/viewcvs?view=rev&rev=161062
Log:
Add a SQLSupportConfig object.  This allows the SQL generated for ORDER BY and 
WHERE clauses to be configured externally or with DatabaseMetaData.  Supported 
config options:

  - quoteChar
  - supportsLikeEscapeClause

DRT: NetUI pass
BVT: NetUI pass (2 known failures)


Added:
    
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/DatabaseMetaDataSQLSupportConfig.java
   (with props)
    
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/DefaultSQLSupportConfig.java
   (with props)
    
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/SQLSupportConfig.java
   (with props)
    
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/SQLSupportConfigFactory.java
   (with props)
Modified:
    
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/filter/FilterOperationHint.java
    
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/SQLSupport.java
    
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/util/data-grid-default.properties
    
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/netui.properties
    
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/datagrid/SQLSupportTest.java

Modified: 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/filter/FilterOperationHint.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/filter/FilterOperationHint.java?view=diff&r1=161061&r2=161062
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/filter/FilterOperationHint.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/filter/FilterOperationHint.java
 Tue Apr 12 08:09:04 2005
@@ -17,8 +17,11 @@
  */
 package org.apache.beehive.netui.databinding.datagrid.api.filter;
 
-public class FilterOperationHint
-{
+/**
+ *
+ */
+public class FilterOperationHint {
+
     public static final int INT_NONE = 0;
     public static final int INT_EQUAL = 1;
     public static final int INT_NOT_EQUAL = 2;
@@ -46,49 +49,58 @@
     public static final FilterOperationHint IS_NOT_EMPTY = new 
FilterOperationHint(INT_IS_NOT_EMPTY);
 
     private int _val;
-    
-    private FilterOperationHint( int val )
-    {
+
+    private FilterOperationHint(int val) {
         _val = val;
     }
-    
-    public String toString()
-    {
-        switch ( _val )
-        {
-            case INT_NONE: return "NONE";
-            case INT_EQUAL: return "EQUAL";
-            case INT_NOT_EQUAL: return "NOT_EQUAL";
-            case INT_GREATER_THAN: return "GREATER_THAN";
-            case INT_LESS_THAN: return "LESS_THAN";
-            case INT_GREATER_THAN_OR_EQUAL: return "GREATER_THAN_OR_EQUAL";
-            case INT_LESS_THAN_OR_EQUAL: return "LESS_THAN_OR_EQUAL";
-            case INT_IS_ONE_OF: return "IS_ONE_OF";
-            case INT_STARTS_WITH: return "STARTS_WITH";
-            case INT_CONTAINS: return "CONTAINS";
-            case INT_IS_EMPTY: return "IS_EMPTY";
-            case INT_IS_NOT_EMPTY: return "IS_NOT_EMPTY";
+
+    public final String toString() {
+        switch (_val) {
+            case INT_NONE:
+                return "NONE";
+            case INT_EQUAL:
+                return "EQUAL";
+            case INT_NOT_EQUAL:
+                return "NOT_EQUAL";
+            case INT_GREATER_THAN:
+                return "GREATER_THAN";
+            case INT_LESS_THAN:
+                return "LESS_THAN";
+            case INT_GREATER_THAN_OR_EQUAL:
+                return "GREATER_THAN_OR_EQUAL";
+            case INT_LESS_THAN_OR_EQUAL:
+                return "LESS_THAN_OR_EQUAL";
+            case INT_IS_ONE_OF:
+                return "IS_ONE_OF";
+            case INT_STARTS_WITH:
+                return "STARTS_WITH";
+            case INT_CONTAINS:
+                return "CONTAINS";
+            case INT_IS_EMPTY:
+                return "IS_EMPTY";
+            case INT_IS_NOT_EMPTY:
+                return "IS_NOT_EMPTY";
         }
-        
+
         assert false : _val;
         return "<unknown FilterOperationHint>";
     }
-    
-    public boolean equals( Object o )
-    {
-        if ( o == null ) return false;
-        if ( o == this ) return true;
-        if ( ! ( o instanceof FilterOperationHint ) ) return false;
-        return ( ( FilterOperationHint ) o )._val == _val;
+
+    public boolean equals(Object o) {
+        if(o == this)
+            return true;
+
+        if(o == null || !(o instanceof FilterOperationHint))
+            return false;
+
+        return ((FilterOperationHint)o)._val == _val;
     }
-    
-    public int hashCode()
-    {
+
+    public int hashCode() {
         return _val;
     }
 
-    public int getValue()
-    {
+    public int getValue() {
         return _val;
     }
 }

Added: 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/DatabaseMetaDataSQLSupportConfig.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/DatabaseMetaDataSQLSupportConfig.java?view=auto&rev=161062
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/DatabaseMetaDataSQLSupportConfig.java
 (added)
+++ 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/DatabaseMetaDataSQLSupportConfig.java
 Tue Apr 12 08:09:04 2005
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.databinding.datagrid.runtime.sql;
+
+import java.sql.SQLException;
+import java.sql.DatabaseMetaData;
+
+/**
+ *
+ */
+class DatabaseMetaDataSQLSupportConfig
+    extends DefaultSQLSupportConfig {
+
+    DatabaseMetaDataSQLSupportConfig(DatabaseMetaData databaseMetaData)
+        throws SQLException {
+        setQuoteChar(databaseMetaData.getIdentifierQuoteString());
+        
setSupportsLikeEscapeClause(databaseMetaData.supportsLikeEscapeClause());
+    }
+}

Propchange: 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/DatabaseMetaDataSQLSupportConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/DefaultSQLSupportConfig.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/DefaultSQLSupportConfig.java?view=auto&rev=161062
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/DefaultSQLSupportConfig.java
 (added)
+++ 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/DefaultSQLSupportConfig.java
 Tue Apr 12 08:09:04 2005
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.databinding.datagrid.runtime.sql;
+
+/**
+ *
+ */
+class DefaultSQLSupportConfig
+    extends SQLSupportConfig {
+
+    private static final String DEFAULT_QUOTE_CHAR = "'";
+    private static final boolean DEFAULT_SUPPORTS_LIKE_ESCAPE_CLAUSE = true;
+
+    private String _quoteChar = DEFAULT_QUOTE_CHAR;
+    private Boolean _supportsLikeEscapeClause = null;
+
+    DefaultSQLSupportConfig() {
+    }
+
+    /**
+     * Setter to provide the character used to quote strings built when 
constructing
+     * SQL statements.  The default quote value is a single quote.
+     *
+     * @param quoteChar the quote character to use; usually a single or double 
quote
+     */
+    public void setQuoteChar(String quoteChar) {
+        _quoteChar = quoteChar;
+    }
+
+    public String getQuoteChar() {
+        return _quoteChar;
+    }
+
+    public void setSupportsLikeEscapeClause(boolean supportsLikeEscapeClause) {
+        _supportsLikeEscapeClause = new Boolean(supportsLikeEscapeClause);
+    }
+
+    public boolean getSupportsLikeEscapeClause() {
+        return (_supportsLikeEscapeClause != null ? 
_supportsLikeEscapeClause.booleanValue() : DEFAULT_SUPPORTS_LIKE_ESCAPE_CLAUSE);
+    }
+}

Propchange: 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/DefaultSQLSupportConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/SQLSupport.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/SQLSupport.java?view=diff&r1=161061&r2=161062
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/SQLSupport.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/SQLSupport.java
 Tue Apr 12 08:09:04 2005
@@ -20,6 +20,8 @@
 import java.util.Map;
 import java.util.LinkedHashMap;
 import java.util.List;
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
 
 import 
org.apache.beehive.netui.databinding.datagrid.api.filter.FilterOperation;
 import 
org.apache.beehive.netui.databinding.datagrid.api.filter.FilterOperationHint;
@@ -28,21 +30,22 @@
 import org.apache.beehive.netui.databinding.datagrid.api.sort.SortDirection;
 import org.apache.beehive.netui.databinding.datagrid.api.sort.Sort;
 import 
org.apache.beehive.netui.databinding.datagrid.api.exceptions.IllegalFilterException;
+import org.apache.beehive.netui.util.Bundle;
+import org.apache.beehive.netui.util.logging.Logger;
 
 /**
  * @netui:jspfunctions
  */
 public final class SQLSupport {
 
-    private static final String EMPTY_STRING = "";
+    private static final Logger LOGGER = Logger.getInstance(SQLSupport.class);
+    private static final String EMPTY = "";
     private static final FilterOperation[] FILTER_OPERATIONS;
-
-    /* todo: the QUOTE_CHAR needs to be settable manually or from 
aDatabaseMetaData */
-    private static final String QUOTE_CHAR = "'";
+    private static final SQLSupportConfig DEFAULT_SQL_SUPPORT_CONFIG = 
SQLSupportConfigFactory.getInstance();
 
     static {
         FILTER_OPERATIONS = new FilterOperation[]{
-            new FilterOperation(0, "*", "filter.sql.none.", 
FilterOperationHint.NONE),
+            new FilterOperation(0, "*", "filter.sql.none", 
FilterOperationHint.NONE),
             new FilterOperation(1, "eq", "filter.sql.equal", 
FilterOperationHint.EQUAL),
             new FilterOperation(2, "ne", "filter.sql.notequal", 
FilterOperationHint.NOT_EQUAL),
             new FilterOperation(3, "gt", "filter.sql.greaterthan", 
FilterOperationHint.GREATER_THAN),
@@ -57,11 +60,23 @@
         };
     }
 
-    private static final FilterOperation STRING_FILTER_OPERATION = 
FILTER_OPERATIONS[9];
-    private static final FilterOperation OTHER_FILTER_OPERATION = 
FILTER_OPERATIONS[1];
+    private static final FilterOperation DEFAULT_STRING_FILTER_OPERATION = 
FILTER_OPERATIONS[9];
+    private static final FilterOperation DEFAULT_NONSTRING_FILTER_OPERATION = 
FILTER_OPERATIONS[1];
 
     public static SQLSupport getInstance() {
-        return new SQLSupport();
+        return getInstance(DEFAULT_SQL_SUPPORT_CONFIG);
+    }
+
+    public static SQLSupport getInstance(DatabaseMetaData databaseMetaData)
+        throws SQLException {
+        SQLSupportConfig config = 
SQLSupportConfigFactory.getInstance(databaseMetaData);
+        return getInstance(config);
+    }
+
+    public static SQLSupport getInstance(SQLSupportConfig config) {
+        SQLSupport sqlSupport = new SQLSupport();
+        sqlSupport.configure(config);
+        return sqlSupport;
     }
 
     /**
@@ -74,6 +89,7 @@
         LinkedHashMap ops = new LinkedHashMap/*<String, String>*/();
 
         /* todo: i18n */
+        /* todo: caching of the filterOps for a given type hint */
         ops.put(FILTER_OPERATIONS[0].getAbbreviation(), "No Filter");
         ops.put(FILTER_OPERATIONS[1].getAbbreviation(), "Equals");
         ops.put(FILTER_OPERATIONS[2].getAbbreviation(), "Not Equal");
@@ -103,9 +119,9 @@
      * signature="java.lang.String 
lookupDefaultFilterOperations(java.lang.String)"
      */
     public static String lookoupDefaultFilterOperationAbbreviation(String 
typeHint) {
-        FilterOperation fOp = OTHER_FILTER_OPERATION;
+        FilterOperation fOp = DEFAULT_NONSTRING_FILTER_OPERATION;
         if(typeHint == null || 
FilterTypeHint.STRING.equals(FilterTypeHint.getTypeHint(typeHint)))
-            fOp = STRING_FILTER_OPERATION;
+            fOp = DEFAULT_STRING_FILTER_OPERATION;
 
         return fOp.getAbbreviation();
     }
@@ -128,13 +144,18 @@
         return null;
     }
 
+    private SQLSupportConfig _config = null;
+
     /* non-public constructor */
-    private SQLSupport() {
+    private SQLSupport() {}
+
+    public void configure(SQLSupportConfig config) {
+        _config = config;
     }
 
     public final String createOrderByFragment(List/*<Sort>*/ sorts) {
         if(sorts == null || sorts.size() == 0)
-            return EMPTY_STRING;
+            return EMPTY;
 
         StringBuffer sql = new StringBuffer();
         internalCreateOrderByFragment(sql, sorts);
@@ -143,7 +164,7 @@
 
     public final String createOrderByClause(List/*<Sort>*/ sorts) {
         if(sorts == null || sorts.size() == 0)
-            return EMPTY_STRING;
+            return EMPTY;
 
         StringBuffer sql = new StringBuffer(64);
         sql.append("ORDER BY ");
@@ -153,7 +174,7 @@
 
     public String createWhereFragment(List/*<Filter>*/ filters) {
         if(filters == null || filters.size() == 0)
-            return EMPTY_STRING;
+            return EMPTY;
 
         StringBuffer sql = new StringBuffer(64);
         internalCreateWhereFragment(sql, filters);
@@ -162,7 +183,7 @@
 
     public String createWhereClause(List/*<Filter>*/ filters) {
         if(filters == null || filters.size() == 0)
-            return EMPTY_STRING;
+            return EMPTY;
 
         StringBuffer sql = new StringBuffer();
         sql.append("WHERE ");
@@ -186,39 +207,52 @@
         for(int i = 0; i < filters.size(); i++) {
             Filter filter = (Filter) filters.get(i);
 
+            if(filter == null)
+                continue;
+
+            FilterOperation fOp = filter.getOperation();
+            FilterOperationHint fOpHint = null;
+            String fExpr = filter.getFilterExpression();
+            if(fOp == null && filter.getOperationHint() != null) {
+                fOpHint = filter.getOperationHint();
+                fOp = mapFilterHintToOperation(fOpHint);
+            }
+            else {
+                fOpHint = filter.getOperation().getOperationHint();
+            }
+
+            if(fOp == null) {
+                String message = 
Bundle.getErrorString("DataGridFilter_NoFilterOperation", new Object[] 
{filter.getFilterExpression()});
+                LOGGER.error(message);
+                throw new IllegalFilterException(message);
+            }
+
             /* todo: feature. pluggable conjunctions AND and OR here */
             if(i > 0)
                 sql.append(" AND ");
 
             if (filter.getValue() == null) {
-                if (filter.getOperation().getOperationHint() == 
FilterOperationHint.EQUAL) {
+                if (fOpHint == FilterOperationHint.EQUAL) {
                     sql.append("(");
-                    sql.append(filter.getFilterExpression());
+                    sql.append(fExpr);
                     sql.append(" IS NULL)");
                 }
-                else if (filter.getOperation().getOperationHint() == 
FilterOperationHint.NOT_EQUAL) {
+                else if (fOpHint == FilterOperationHint.NOT_EQUAL) {
                     sql.append("(");
-                    sql.append(filter.getFilterExpression());
+                    sql.append(fExpr);
                     sql.append(" IS NOT NULL)");
                 }
             }
 
-            switch(filter.getOperation().getOperationHint().getValue()) {
+            switch(fOpHint.getValue()) {
                 case FilterOperationHint.INT_STARTS_WITH:
                 case FilterOperationHint.INT_CONTAINS:
                     {
-                        boolean bEscape = true;
-/* todo: there is architectural work needed here to return a SQLSupport 
instance that exposes getter / setter methods for the things DatabaseMetaData 
is used for */
-/*
-                        try {
-                            bEscape = null == _mdDatabase || 
_mdDatabase.supportsLikeEscapeClause();
-                        } catch(SQLException x) {
-                        }
-*/
+                        boolean bEscape = 
_config.getSupportsLikeEscapeClause();
                         String strValue = bEscape ? 
convertSQLPattern(filter.getValue()) : filter.getValue().toString();
                         strValue = convertSQLString(strValue);
-                        
sql.append("(").append(filter.getFilterExpression()).append(" LIKE '");
-                        if(filter.getOperation().getOperationHint() == 
FilterOperationHint.CONTAINS)
+                        sql.append("(").append(fExpr).append(" LIKE '");
+                        if(fOpHint == FilterOperationHint.CONTAINS)
                             sql.append("%");
                         sql.append(strValue).append("%'");
                         if(bEscape)
@@ -228,12 +262,12 @@
                     }
                 case FilterOperationHint.INT_IS_NOT_EMPTY:
                     {
-                        
sql.append("(").append(filter.getFilterExpression()).append(" IS NOT NULL)");
+                        sql.append("(").append(fExpr).append(" IS NOT NULL)");
                         break;
                     }
                 case FilterOperationHint.INT_IS_EMPTY:
                     {
-                        
sql.append("(").append(filter.getFilterExpression()).append(" IS NULL)");
+                        sql.append("(").append(fExpr).append(" IS NULL)");
                         break;
                     }
                 case FilterOperationHint.INT_EQUAL:
@@ -245,12 +279,12 @@
                     {
                         /* todo: conider using SQLFragment from the 
DatabaseControl here. */
                         sql.append("(");
-                        sql.append(filter.getFilterExpression());
-                        
sql.append(lookupOperator(filter.getOperation().getOperationHint()));
+                        sql.append(fExpr);
+                        sql.append(lookupOperator(fOpHint));
                         addParameter(sql, filter.getValue(), 
filter.getTypeHint());
-                        if(filter.getOperation().getOperationHint() == 
FilterOperationHint.NOT_EQUAL) {
+                        if(fOpHint == FilterOperationHint.NOT_EQUAL) {
                             sql.append(" OR ");
-                            sql.append(filter.getFilterExpression());
+                            sql.append(fExpr);
                             sql.append(" IS NULL");
                         }
                         sql.append(")");
@@ -267,7 +301,7 @@
                             break;
 
                         sql.append("(");
-                        sql.append(filter.getFilterExpression());
+                        sql.append(fExpr);
                         sql.append(" IN (");
                         String comma = "";
                         for(int j = 0; j < arr.length; j++) {
@@ -277,36 +311,36 @@
                             comma = ",";
                         }
                         sql.append("))");
+                        break;
                     }
                 default:
-                    throw new IllegalFilterException("Found an unknown filter 
operation");
+                    throw new 
IllegalFilterException(Bundle.getErrorString("DataGridFilter_UnknownFilterOperation",
 new Object[] {fOp}));
             }
         }
     }
 
     private String convertSQLPattern(Object o) {
-        String s = o.toString();
-        s = s.replaceAll("\\\\", "\\\\\\\\");
-        s = s.replaceAll("%", "\\\\%");
-        s = s.replaceAll("_", "\\\\_");
-        return s;
+        if(o == null)
+            return EMPTY;
+        else {
+            String s = o.toString();
+            s = s.replaceAll("\\\\", "\\\\\\\\");
+            s = s.replaceAll("%", "\\\\%");
+            s = s.replaceAll("_", "\\\\_");
+            return s;
+        }
     }
 
-
     private String convertSQLString(Object o) {
-        String s = o.toString();
-        s = s.replaceAll("'", "''");
-        return s;
+        if(o == null)
+            return EMPTY;
+        else return (o.toString()).replaceAll("'", "''");
     }
 
     private void addParameter(StringBuffer sql, Object value, FilterTypeHint 
typeHint) {
-        if(typeHint.equals(FilterTypeHint.STRING)) {
-            sql.append(QUOTE_CHAR);
-            sql.append(value);
-            sql.append(QUOTE_CHAR);
-        } else {
-            sql.append(value);
-        }
+        if(typeHint == FilterTypeHint.STRING)
+            
sql.append(_config.getQuoteChar()).append(value).append(_config.getQuoteChar());
+        else sql.append(value);
     }
 
     private String lookupOperator(FilterOperationHint op) {

Added: 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/SQLSupportConfig.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/SQLSupportConfig.java?view=auto&rev=161062
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/SQLSupportConfig.java
 (added)
+++ 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/SQLSupportConfig.java
 Tue Apr 12 08:09:04 2005
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.databinding.datagrid.runtime.sql;
+
+/**
+ *
+ */
+public abstract class SQLSupportConfig {
+
+    public abstract void setQuoteChar(String quoteChar);
+
+    public abstract String getQuoteChar();
+
+    public abstract void setSupportsLikeEscapeClause(boolean 
supportsLikeEscapeClause);
+
+    public abstract boolean getSupportsLikeEscapeClause();
+}

Propchange: 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/SQLSupportConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/SQLSupportConfigFactory.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/SQLSupportConfigFactory.java?view=auto&rev=161062
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/SQLSupportConfigFactory.java
 (added)
+++ 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/SQLSupportConfigFactory.java
 Tue Apr 12 08:09:04 2005
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.databinding.datagrid.runtime.sql;
+
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
+
+/**
+ *
+ */
+public final class SQLSupportConfigFactory {
+
+    public static final SQLSupportConfig getInstance() {
+        return new DefaultSQLSupportConfig();
+    }
+
+    public static final SQLSupportConfig getInstance(DatabaseMetaData 
databaseMetaData)
+        throws SQLException {
+        SQLSupportConfig config = new 
DatabaseMetaDataSQLSupportConfig(databaseMetaData);
+        return config;
+    }
+}

Propchange: 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/SQLSupportConfigFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/util/data-grid-default.properties
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/util/data-grid-default.properties?view=diff&r1=161061&r2=161062
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/util/data-grid-default.properties
 (original)
+++ 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/util/data-grid-default.properties
 Tue Apr 12 08:09:04 2005
@@ -14,4 +14,17 @@
 pager.msg.previous=Previous
 pager.msg.next=Next
 pager.msg.last=Last
-pager.fmt.banner=Page {0} of {1}
\ No newline at end of file
+pager.fmt.banner=Page {0} of {1}
+
+filter.sql.none=No Filter
+filter.sql.equal=Equals
+filter.sql.notequal=Not Equal
+filter.sql.greaterthan=Greater Than
+filter.sql.lessthan=Less Than
+filter.sql.greaterthanorequal=Is Greater Than or Equal To
+filter.sql.lessthanorequal=Is Less Than or Equal To
+filter.sql.isoneof=Is One Of (eg: 1;2;3)
+filter.sql.startswith=Starts With
+filter.sql.contains=Contains
+filter.sql.isempty=Is Empty
+filter.sql.isnotempty=Is Not Empty
\ No newline at end of file

Modified: 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/netui.properties
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/netui.properties?view=diff&r1=161061&r2=161062
==============================================================================
--- 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/netui.properties
 (original)
+++ 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/netui.properties
 Tue Apr 12 08:09:04 2005
@@ -669,6 +669,8 @@
 HeaderCell_CantSetSortHrefAndAction=Can not set both the sort action and href 
attributes
 HeaderCell_CantEnableSorting=Can not enable sorting on a column with a null 
sort expression
 HeaderCell_CantEnableFiltering=Can not enable filtering on a column with a 
null filter expression
+DataGridFilter_NoFilterOperation=Can not determine the operation for a filter 
with filter expression \"{0}\"
+DataGridFilter_UnknownFilterOperation=Can not include the filter with 
operation \"{0}\" in a SQL statement; the operation is unknown
 
 #
 # Utility Strings

Modified: 
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/datagrid/SQLSupportTest.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/datagrid/SQLSupportTest.java?view=diff&r1=161061&r2=161062
==============================================================================
--- 
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/datagrid/SQLSupportTest.java
 (original)
+++ 
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/datagrid/SQLSupportTest.java
 Tue Apr 12 08:09:04 2005
@@ -33,6 +33,8 @@
 import org.apache.beehive.netui.databinding.datagrid.api.sort.Sort;
 import org.apache.beehive.netui.databinding.datagrid.api.sort.SortDirection;
 import org.apache.beehive.netui.databinding.datagrid.runtime.sql.SQLSupport;
+import 
org.apache.beehive.netui.databinding.datagrid.runtime.sql.SQLSupportConfigFactory;
+import 
org.apache.beehive.netui.databinding.datagrid.runtime.sql.SQLSupportConfig;
 
 /**
  *
@@ -42,7 +44,7 @@
 
     public void testSortEncoding() {
         DataGridConfig config = DataGridTestUtil.getDataGridConfig();
-        Sort sort = config.createSort();
+        Sort sort = config.createSort();                            
         sort.setDirection(SortDirection.DESCENDING);
         sort.setSortExpression("CUSTOMERS");
         List list = new ArrayList();
@@ -60,30 +62,82 @@
         filter.setValue("1234");
         List filters = Collections.singletonList(filter);
 
+        SQLSupport sqlSupport = SQLSupport.getInstance();
         /* isnotempty testing */
         fOp = SQLSupport.mapFilterAbbreviationToOperation("isnotempty");
         filter.setOperation(fOp);
-        assertEquals("WHERE (CUSTOMERID IS NOT NULL)", 
SQLSupport.getInstance().createWhereClause(filters));
+        assertEquals("WHERE (CUSTOMERID IS NOT NULL)", 
sqlSupport.createWhereClause(filters));
         fOp = 
SQLSupport.mapFilterHintToOperation(FilterOperationHint.IS_NOT_EMPTY);
         filter.setOperation(fOp);
-        assertEquals("WHERE (CUSTOMERID IS NOT NULL)", 
SQLSupport.getInstance().createWhereClause(filters));
+        assertEquals("WHERE (CUSTOMERID IS NOT NULL)", 
sqlSupport.createWhereClause(filters));
         fOp = 
SQLSupport.mapFilterHintToOperation(FilterOperationHint.IS_NOT_EMPTY);
         filter.setOperation(fOp);
         filter.setTypeHint(FilterTypeHint.DATE);
-        assertEquals("WHERE (CUSTOMERID IS NOT NULL)", 
SQLSupport.getInstance().createWhereClause(filters));
+        assertEquals("WHERE (CUSTOMERID IS NOT NULL)", 
sqlSupport.createWhereClause(filters));
 
         /* equals testing */
         fOp = SQLSupport.mapFilterAbbreviationToOperation("eq");
         filter.setOperation(fOp);
         filter.setTypeHint(FilterTypeHint.STRING);
-        assertEquals("WHERE (CUSTOMERID='1234')", 
SQLSupport.getInstance().createWhereClause(filters));
+        assertEquals("WHERE (CUSTOMERID='1234')", 
sqlSupport.createWhereClause(filters));
         fOp = SQLSupport.mapFilterHintToOperation(FilterOperationHint.EQUAL);
         filter.setOperation(fOp);
-        assertEquals("WHERE (CUSTOMERID='1234')", 
SQLSupport.getInstance().createWhereClause(filters));
+        assertEquals("WHERE (CUSTOMERID='1234')", 
sqlSupport.createWhereClause(filters));
         fOp = SQLSupport.mapFilterHintToOperation(FilterOperationHint.EQUAL);
         filter.setTypeHint(FilterTypeHint.NUMERIC);
         filter.setOperation(fOp);
-        assertEquals("WHERE (CUSTOMERID=1234)", 
SQLSupport.getInstance().createWhereClause(filters));
+        assertEquals("WHERE (CUSTOMERID=1234)", 
sqlSupport.createWhereClause(filters));
+    }
+
+    public void testFitlerEncodingDoubleQuote() {
+        DataGridConfig config = DataGridTestUtil.getDataGridConfig();
+        FilterOperation fOp = null;
+        Filter filter = config.createFilter();
+        filter.setFilterExpression("CUSTOMERID");
+        filter.setValue("1234");
+        List filters = Collections.singletonList(filter);
+
+        SQLSupportConfig sqlSupportConfig = 
SQLSupportConfigFactory.getInstance();
+        sqlSupportConfig.setQuoteChar("\"");
+
+        SQLSupport sqlSupport = SQLSupport.getInstance(sqlSupportConfig);
+
+        /* isnotempty testing */
+        fOp = SQLSupport.mapFilterAbbreviationToOperation("isnotempty");
+        filter.setOperation(fOp);
+        assertEquals("WHERE (CUSTOMERID IS NOT NULL)", 
sqlSupport.createWhereClause(filters));
+        fOp = 
SQLSupport.mapFilterHintToOperation(FilterOperationHint.IS_NOT_EMPTY);
+        filter.setOperation(fOp);
+        assertEquals("WHERE (CUSTOMERID IS NOT NULL)", 
sqlSupport.createWhereClause(filters));
+        fOp = 
SQLSupport.mapFilterHintToOperation(FilterOperationHint.IS_NOT_EMPTY);
+        filter.setOperation(fOp);
+        filter.setTypeHint(FilterTypeHint.DATE);
+        assertEquals("WHERE (CUSTOMERID IS NOT NULL)", 
sqlSupport.createWhereClause(filters));
+
+        /* equals testing */
+        fOp = SQLSupport.mapFilterAbbreviationToOperation("eq");
+        filter.setOperation(fOp);
+        filter.setTypeHint(FilterTypeHint.STRING);
+        assertEquals("WHERE (CUSTOMERID=\"1234\")", 
sqlSupport.createWhereClause(filters));
+        fOp = SQLSupport.mapFilterHintToOperation(FilterOperationHint.EQUAL);
+        filter.setOperation(fOp);
+        assertEquals("WHERE (CUSTOMERID=\"1234\")", 
sqlSupport.createWhereClause(filters));
+        fOp = SQLSupport.mapFilterHintToOperation(FilterOperationHint.EQUAL);
+        filter.setTypeHint(FilterTypeHint.NUMERIC);
+        filter.setOperation(fOp);
+        assertEquals("WHERE (CUSTOMERID=1234)", 
sqlSupport.createWhereClause(filters));
+    }
+
+    public void testFilterOperationInference() {
+        DataGridConfig config = DataGridTestUtil.getDataGridConfig();
+        Filter filter = config.createFilter();
+        filter.setOperationHint(FilterOperationHint.GREATER_THAN);
+        filter.setFilterExpression("CUSTOMERID");
+        filter.setTypeHint(FilterTypeHint.NUMERIC);
+        filter.setValue("1234");
+        List filters = Collections.singletonList(filter);
+        SQLSupport sqlSupport = SQLSupport.getInstance();
+        assertEquals("WHERE (CUSTOMERID>1234)", 
sqlSupport.createWhereClause(filters));
     }
 
     protected void setUp() {


Reply via email to