You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by bu...@apache.org on 2003/08/14 01:40:36 UTC

DO NOT REPLY [Bug 22400] New: - SQLTransformer to optionally preserve case of column names

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22400>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22400

SQLTransformer to optionally preserve case of column names

           Summary: SQLTransformer to optionally preserve case of column
                    names
           Product: Cocoon 2
           Version: Current CVS 2.1
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: core
        AssignedTo: dev@cocoon.apache.org
        ReportedBy: saschwarz@hotmail.com


It would be very helpful if there was a parameter to control SQLTransformer's
handling of the case of database column names. Currently it lowercases all
column names. The current behavior could be the default with a configuration
parameter for specifying preserving the case as retrieved from the database.

The attached diff implements this feature as described above.

(a more thorough solution could support multiple options including transforming
column case: preserve, upcase, lowercase, Title Case, camelCase, etc. Seems
overkill :^)

This diff is against 2.1rc2"

--- SQLTransformer.java.old	2003-08-08 10:59:05.000000000 -0500
+++ SQLTransformer.java	2003-08-08 11:35:02.000000000 -0500
@@ -108,6 +108,8 @@
     public static final String MAGIC_VALUE = "value";
     public static final String MAGIC_DOC_ELEMENT = "doc-element";
     public static final String MAGIC_ROW_ELEMENT = "row-element";
+    /** Should ResultSet rows have db column names lowercased (default) */
+    public static final String MAGIC_PRESERVE_COLUMN_CASE = "preserve-column-case";
     public static final String MAGIC_IN_PARAMETER = "in-parameter";
     public static final String MAGIC_IN_PARAMETER_NR_ATTRIBUTE = "nr";
     public static final String MAGIC_IN_PARAMETER_VALUE_ATTRIBUTE = "value";
@@ -281,7 +283,8 @@
             getLogger().debug( "ROW-ELEMENT: " + parameters.getParameter(
SQLTransformer.MAGIC_ROW_ELEMENT, "row" ) );
             getLogger().debug( "NS-URI: " + parameters.getParameter(
SQLTransformer.MAGIC_NS_URI_ELEMENT, NAMESPACE ) );
             getLogger().debug( "NS-PREFIX: " + parameters.getParameter(
SQLTransformer.MAGIC_NS_PREFIX_ELEMENT, "" ) );
-			      getLogger().debug( "CLOB_ENCODING: " + clobEncoding );
+	    getLogger().debug( "CLOB_ENCODING: " + clobEncoding );
+            getLogger().debug( "PRESERVE_COLUMN_CASE: " +
parameters.getParameter( SQLTransformer.MAGIC_PRESERVE_COLUMN_CASE, "" ) );
         }
    }
 
@@ -872,6 +875,9 @@
         /** Mapping out parameters - objectModel **/
         protected HashMap outParametersNames = null;
 
+	/** Check if we should not lowercase column names in results */
+	protected boolean preserveColumnCase = false; 
+
         protected Query( SQLTransformer transformer, int query_index ) {
             this.transformer = transformer;
             this.query_index = query_index;
@@ -1032,6 +1038,7 @@
         protected void execute() throws SQLException {
             this.rowset_name = properties.getParameter(
SQLTransformer.MAGIC_DOC_ELEMENT, "rowset" );
             this.row_name = properties.getParameter(
SQLTransformer.MAGIC_ROW_ELEMENT, "row" );
+	    this.preserveColumnCase = properties.getParameterAsBoolean(
SQLTransformer.MAGIC_PRESERVE_COLUMN_CASE, false );
 
             Enumeration enum = query_parts.elements();
             StringBuffer sb = new StringBuffer();
@@ -1241,9 +1248,12 @@
             AttributesImpl attr = new AttributesImpl();
             if ( !isupdate && !isstoredprocedure ) {
                 for ( int i = 1; i <= md.getColumnCount(); i++ ) {
-                    transformer.start( md.getColumnName( i ).toLowerCase(), attr );
+		    String columnName = md.getColumnName( i );
+		    if (this.preserveColumnCase != true)
+			columnName = columnName.toLowerCase();
+                    transformer.start( columnName, attr );
                     this.serializeData(manager, getColumnValue( i ) );
-                    transformer.end( md.getColumnName( i ).toLowerCase() );
+                    transformer.end( columnName );
                 }
             } else if ( isupdate && !isstoredprocedure ) {
                 transformer.start( "returncode", attr );
@@ -1280,13 +1290,16 @@
                                 while ( rs.next() ) {
                                     transformer.start( this.row_name, attr );
                                     for ( int i = 1; i <= md.getColumnCount();
i++ ) {
-                                        transformer.start( md.getColumnName( i
).toLowerCase(), attr );
+					String columnName = md.getColumnName( i );
+					if (this.preserveColumnCase != true)
+					    columnName = columnName.toLowerCase();
+                                        transformer.start( columnName, attr );
                                         if ( md.getColumnType( i ) == 8 ) { 
//prevent nasty exponent notation
                                             this.serializeData(manager,
SQLTransformer.getStringValue( rs.getBigDecimal( i ) ));
                                         } else {
                                             this.serializeData(manager,
SQLTransformer.getStringValue( rs.getObject( i ) ));
                                         }
-                                        transformer.end( md.getColumnName( i
).toLowerCase() );
+                                        transformer.end(columnName);
                                     }
                                     transformer.end( this.row_name );
                                 }