cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steve Schwarz" <saschw...@hotmail.com>
Subject SQLTransformer mod to optionally preserve case of column names
Date Fri, 08 Aug 2003 16:31:18 GMT
Hi
I'm new to Cocoon and found a need to preserve the case of database column 
names when using the SQLTransformer. I found some older mail archive 
discussions about this enhancement but no code changes were posted. I just 
merged my change into the latest 2.1 source (I have changes in 2.04 in case 
anyone is interested).

With this modification the current behavior (lowercasing column names) is 
preserved by default.

Here are the diffs for your consideration. Any comments/criticism are 
greatly appreciated.
Best Regards,
Steve

diff -u SQLTransformer.java.old SQLTransformer.java
--- SQLTransformer.java.old     2003-08-08 10:59:05.000000000 -0500
+++ SQLTransformer.java 2003-08-08 11:17:33.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,7 +1290,10 @@
                                 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 {

_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE*  
http://join.msn.com/?page=features/virus


Mime
View raw message