cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gian...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/databases/java/org/apache/cocoon/transformation SQLTransformer.java
Date Fri, 18 Jul 2003 14:46:30 GMT
gianugo     2003/07/18 07:46:30

  Modified:    .        status.xml
               src/documentation/xdocs/userdocs/transformers
                        sql-transformer.xml
               src/blocks/databases/java/org/apache/cocoon/transformation
                        SQLTransformer.java
  Log:
  Added CLOB support.
  
  Revision  Changes    Path
  1.94      +4 -1      cocoon-2.1/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/status.xml,v
  retrieving revision 1.93
  retrieving revision 1.94
  diff -u -r1.93 -r1.94
  --- status.xml	18 Jul 2003 11:24:29 -0000	1.93
  +++ status.xml	18 Jul 2003 14:46:30 -0000	1.94
  @@ -185,6 +185,9 @@
   
    <release version="@version@" date="@date@">
     <action dev="GR" type="add">
  +    Added CLOB support in SQLTransformer.
  +  </action>
  +  <action dev="GR" type="add">
       Added an (unstable) HTMLTransformer to the html block, to parse and
       tidy an XML containing escaped (and possibly incorrect) HTML
     </action>
  
  
  
  1.2       +5 -0      cocoon-2.1/src/documentation/xdocs/userdocs/transformers/sql-transformer.xml
  
  Index: sql-transformer.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/documentation/xdocs/userdocs/transformers/sql-transformer.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- sql-transformer.xml	9 Mar 2003 00:08:27 -0000	1.1
  +++ sql-transformer.xml	18 Jul 2003 14:46:30 -0000	1.2
  @@ -107,6 +107,7 @@
         <map:transform type="sql">
           <map:parameter name="use-connection" value="personnel"/>
           <map:parameter name="show-nr-of-rows" value="true"/> 
  +        <map:parameter name="clob-encoding" value="UTF-8"/> 
         </map:transform>
        ]]>
       </source>
  @@ -124,6 +125,10 @@
   want to know how many rows it contains, you have to count the  number of rows in 
   another transformer or your stored procedure has to return it also (last 
   solution is the best one)
  +</p>
  +<p>
  +The "clob-encoding" parameter defines what encoding should be used in 
  +getting content from CLOB columns.
   </p>
   <p>
   The output XML will look as follows:
  
  
  
  1.7       +27 -2     cocoon-2.1/src/blocks/databases/java/org/apache/cocoon/transformation/SQLTransformer.java
  
  Index: SQLTransformer.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/databases/java/org/apache/cocoon/transformation/SQLTransformer.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SQLTransformer.java	11 Jun 2003 00:28:31 -0000	1.6
  +++ SQLTransformer.java	18 Jul 2003 14:46:30 -0000	1.7
  @@ -72,6 +72,7 @@
   import org.xml.sax.SAXException;
   import org.xml.sax.helpers.AttributesImpl;
   
  +import java.io.InputStream;
   import java.io.IOException;
   import java.io.StringReader;
   import java.lang.reflect.Field;
  @@ -86,6 +87,7 @@
    * @author <a href="mailto:giacomo.pati@pwr.ch">Giacomo Pati</a>
    *         (PWR Organisation & Entwicklung)
    * @author <a href="mailto:sven.beauprez@the-ecorp.com">Sven Beauprez</a>
  + * @author <a href="mailto:a.saglimbeni@pro-netics.com">Alfio Saglimbeni</a>
    * @version CVS $Id$
    */
   public class SQLTransformer
  @@ -127,6 +129,7 @@
       public static final String MAGIC_NAME_ATTRIBUTE = "name";
       public static final String MAGIC_STORED_PROCEDURE_ATTRIBUTE = "isstoredprocedure";
       public static final String MAGIC_UPDATE_ATTRIBUTE = "isupdate";
  +	  public static final String CLOB_ENCODING = "clob-encoding";
   
       /** The states we are allowed to be in **/
       protected static final int STATE_OUTSIDE = 0;
  @@ -184,6 +187,9 @@
       protected XMLDeserializer interpreter;
       protected SAXParser parser;
   
  +    /** Encoding we use for CLOB field */
  +	protected String clobEncoding;
  +	
       /**
        * Constructor
        */
  @@ -263,6 +269,7 @@
           this.current_state = SQLTransformer.STATE_OUTSIDE;
   
           this.showNrOfRows = parameters.getParameterAsBoolean( SQLTransformer.MAGIC_NR_OF_ROWS,
false );
  +		    this.clobEncoding = parameters.getParameter(SQLTransformer.CLOB_ENCODING, "");
           if ( getLogger().isDebugEnabled() ) {
               if ( this.parameters.getParameter( SQLTransformer.MAGIC_CONNECTION , null )
!= null ) {
                   getLogger().debug( "CONNECTION: " + this.parameters.getParameter( SQLTransformer.MAGIC_CONNECTION
, null ) );
  @@ -274,6 +281,7 @@
               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 );
           }
      }
   
  @@ -1114,9 +1122,26 @@
           }
   
           protected String getColumnValue( int i ) throws SQLException {
  +			int numberOfChar = 1024;
               String retval =  SQLTransformer.getStringValue( rs.getObject( i ) );
  -            if (rs.getMetaData().getColumnType(i) == 8)
  +			
  +			if (rs.getMetaData().getColumnType(i) == 8) {
               retval = SQLTransformer.getStringValue( rs.getBigDecimal( i ) );
  +			} else if (rs.getMetaData().getColumnType(i) == java.sql.Types.CLOB) {
  +				Clob clob = rs.getClob(i);
  +				InputStream inputStream = clob.getAsciiStream();
  +				byte[] readByte = new byte[numberOfChar];
  +				StringBuffer buffer = new StringBuffer();
  +				try {
  +					while(inputStream.read(readByte) > -1) {
  +						String string = new String(readByte, clobEncoding);
  +						buffer.append(string);
  +					}
  +				} catch(java.io.IOException ioException) {
  +					throw new SQLException("Error reading stream from CLOB");
  +				}
  +				retval = buffer.toString();
  +			}
               return retval;
           }
   
  
  
  

Mime
View raw message