cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steve Schwarz" <saschw...@hotmail.com>
Subject Re: SQLTransformer mod to optionally preserve case of column names
Date Fri, 08 Aug 2003 16:46:07 GMT
Hi again,
Sorry for the thrash, I had a paste error in the diff I posted - here is the 
correct one
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: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 );
                                 }

_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*  
http://join.msn.com/?page=features/junkmail


Mime
View raw message