haul        2002/08/11 13:08:57

  Modified:    src/java/org/apache/cocoon/components/language/markup/xsp/java
                        Tag: cocoon_2_0_3_branch esql.xsl
  Log:
    <action dev="CH" type="update">
     ESQL: Allow arbitrary types for prepared and callable statements via
     dynamically loading classes like the SQLTransformer does. Is-null now uses
     dynamic colum specification. Fixed skip-row feature, which was off by one.
     Added tag to get connection meta data.
    </action>
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.13.2.8  +33 -26    
xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/esql.xsl
  
  Index: esql.xsl
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/esql.xsl,v
  retrieving revision 1.13.2.7
  retrieving revision 1.13.2.8
  diff -u -r1.13.2.7 -r1.13.2.8
  --- esql.xsl  2 Jul 2002 13:39:22 -0000       1.13.2.7
  +++ esql.xsl  11 Aug 2002 20:08:57 -0000      1.13.2.8
  @@ -1,4 +1,4 @@
  -<?xml version="1.0"?>
  +<?xml version="1.0"?><!-- -*- xsl -*- -->
   
   <!-- $Id$-->
   <!--
  @@ -203,8 +203,7 @@
         <xsl:if test=".//esql:connection/esql:pool">
               private static ComponentSelector _esql_selector = null;
   
  -            public void compose(ComponentManager manager) throws 
org.apache.avalon.framework.component.ComponentException {
  -              super.compose(manager);
  +            protected ComponentSelector _esql_get_selector() throws 
org.apache.avalon.framework.component.ComponentException {
                 if (_esql_selector == null) {
                   try {
                     _esql_selector = (ComponentSelector) 
manager.lookup(DataSourceComponent.ROLE + "Selector");
  @@ -212,6 +211,7 @@
                     getLogger().error("Could not look up the datasource component", 
cme);
                   }
                 }
  +              return _esql_selector;
               }
         </xsl:if>
   
  @@ -286,7 +286,7 @@
         <xsl:choose>
           <xsl:when test="esql:pool">
             try {
  -            _esql_connection.datasource = (DataSourceComponent) 
_esql_selector.select(String.valueOf(<xsl:copy-of select="$pool"/>));
  +            _esql_connection.datasource = (DataSourceComponent) 
_esql_get_selector().select(String.valueOf(<xsl:copy-of select="$pool"/>));
               _esql_connection.connection = 
_esql_connection.datasource.getConnection();
               <xsl:if test="esql:allow-multiple-results">
                _esql_connection.setMultipleResults(String.valueOf(<xsl:copy-of 
select="$allow-multiple-results"/>));
  @@ -362,10 +362,19 @@
   <xsl:template match="esql:connection/esql:username"/>
   <xsl:template match="esql:connection/esql:password"/>
   <xsl:template match="esql:connection/esql:pool"/>
  +<xsl:template match="esql:connection/esql:allow-multiple-results"/>
   <xsl:template match="esql:connection/esql:autocommit"/>
   <xsl:template match="esql:connection/esql:use-limit-clause"/>
   <xsl:template match="esql:connection/esql:property"/>
   
  +<xspdoc:desc>Returns the connection's meta data.</xspdoc:desc>
  +<xsl:template match="esql:get-connection-metadata">
  +  <xsp:expr>_esql_connection.getMetaData()</xsp:expr>
  +</xsl:template>
  +
  +<xsl:template match="esql:connection/esql:get-connection">
  +  <xsp:expr>_esql_connection</xsp:expr>
  +</xsl:template>
   
   <!-- set one parameter of a prepared or callable statement and use correct method 
for type -->
   <xsl:template name="set-query-parameter">
  @@ -386,7 +395,7 @@
   <xsl:template name="set-call-parameter">
     <xsl:if test="@direction='out' or @direction='inout'">
       <xsl:text>_esql_query.getCallableStatement().</xsl:text>
  -    registerOutParameter(<xsl:value-of select="position()"/>, 
Types.<xsl:call-template name="get-Sql-Type"><xsl:with-param name="type"><xsl:value-of 
select="@type"/></xsl:with-param></xsl:call-template><xsl:if test="@typename">, 
<xsl:value-of select="@typename"/> </xsl:if>);
  +    registerOutParameter(<xsl:value-of select="position()"/>, <xsl:call-template 
name="get-Sql-Type"><xsl:with-param name="type"><xsl:value-of 
select="@type"/></xsl:with-param></xsl:call-template><xsl:if test="@typename">, 
<xsl:value-of select="@typename"/> </xsl:if>);
     </xsl:if>
     <xsl:if test="not(@direction) or @direction='inout' or @direction='in'">
       <xsl:text>_esql_query.getCallableStatement().</xsl:text>
  @@ -554,9 +563,6 @@
   </xsl:template>
   
   <xsl:template match="esql:execute-query//esql:call-results">
  -  <xsp:logic>
  -  // call results2
  -  </xsp:logic>
     <xsp:content>
       <xsl:apply-templates/>
     </xsp:content>
  @@ -954,13 +960,13 @@
   </xsl:template>
   
   <xspdoc:desc>returns the type of the given column as int. the column must be 
specified by number, not name.</xspdoc:desc>
  -<xsl:template 
match="esql:row-results//esql:get-column-type|esql:call-results//esql:get-column-type" 
name="get-column-type">
  +<xsl:template match="esql:row-results//esql:get-column-type" name="get-column-type">
     <xsp:expr><xsl:call-template 
name="get-resultset"/>.getMetaData().getColumnType(<xsl:call-template 
name="get-column"/>)</xsp:expr>
   </xsl:template>
   
   <xspdoc:desc>allows null-column testing. Evaluates to a Java expression, which is 
true when the referred column contains a null-value for the current resultset 
row</xspdoc:desc>
  -<xsl:template 
match="esql:row-results//esql:is-null|esql:call-results//esql:is-null">
  -  <xsp:expr>((<xsl:call-template name="get-resultset"/>.getObject("<xsl:value-of 
select="@column"/>") == null) || <xsl:call-template 
name="get-resultset"/>.wasNull())</xsp:expr>
  +<xsl:template match="esql:row-results//esql:is-null">
  +  <xsp:expr>((<xsl:call-template 
name="get-resultset"/>.getObject(<xsl:call-template name="get-column"/>) == null) || 
<xsl:call-template name="get-resultset"/>.wasNull())</xsp:expr>
   </xsl:template>
   
   <xsl:template match="esql:result"/>
  @@ -1080,19 +1086,20 @@
     <xsl:param name="type"/>
     <xsl:choose>
       <!-- just do the 'unusual' mappings -->
  -    <xsl:when test="$type='Byte'">TINYINT</xsl:when>
  -    <xsl:when test="$type='Short'">SMALLINT</xsl:when>
  -    <xsl:when test="$type='Int'">INTEGER</xsl:when>
  -    <xsl:when test="$type='Long'">BIGINT</xsl:when>
  -    <xsl:when test="$type='Float'">REAL</xsl:when>
  -    <xsl:when test="$type='BigDecimal'">DECIMAL</xsl:when>
  -    <xsl:when test="$type='Boolean'">BIT</xsl:when>
  -    <xsl:when test="$type='String'">VARCHAR</xsl:when>
  -    <xsl:when test="$type='Bytes'">BINARY</xsl:when>
  -    <xsl:when test="$type='AsciiStream'">LONGVARCHAR</xsl:when>
  -    <xsl:when test="$type='UnicodeStream'">LONGVARCHAR</xsl:when>
  -    <xsl:when test="$type='BinaryStream'">VARBINARY</xsl:when>
  -    <xsl:otherwise><xsl:value-of 
select="translate(@type,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/></xsl:otherwise>
  +    <xsl:when test="$type='Byte'">Types.TINYINT</xsl:when>
  +    <xsl:when test="$type='Short'">Types.SMALLINT</xsl:when>
  +    <xsl:when test="$type='Int'">Types.INTEGER</xsl:when>
  +    <xsl:when test="$type='Long'">Types.BIGINT</xsl:when>
  +    <xsl:when test="$type='Float'">Types.REAL</xsl:when>
  +    <xsl:when test="$type='BigDecimal'">Types.DECIMAL</xsl:when>
  +    <xsl:when test="$type='Boolean'">Types.BIT</xsl:when>
  +    <xsl:when test="$type='String'">Types.VARCHAR</xsl:when>
  +    <xsl:when test="$type='Bytes'">Types.BINARY</xsl:when>
  +    <xsl:when test="$type='AsciiStream'">Types.LONGVARCHAR</xsl:when>
  +    <xsl:when test="$type='UnicodeStream'">Types.LONGVARCHAR</xsl:when>
  +    <xsl:when test="$type='BinaryStream'">Types.VARBINARY</xsl:when>
  +    <xsl:when test="contains($type,'.')">EsqlQuery.getType("<xsl:value-of 
select="$type"/>")</xsl:when>
  +    <xsl:otherwise>Types.<xsl:value-of 
select="translate(@type,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/></xsl:otherwise>
     </xsl:choose>
   </xsl:template>
   
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to