cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject cvs commit: xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java esql.xsl
Date Thu, 16 May 2002 16:01:54 GMT
haul        02/05/16 09:01:54

  Modified:    src/java/org/apache/cocoon/components/language/markup/xsp/java
                        esql.xsl
  Log:
  Fixes bugs / patches
  7507 [PATCH] esql - support CLOB in get-xml
  9004 [PATCH] add failure-ok to eql:query and documentation
  7181 esql:group behaves erratically
  8737 esql.xsl: getUrl() for datatypes OTHER
  with modifications:
  
  failure-ok is _not_ added. Instead error-results are evaulated when an exception is caught.
  If error-results is absent, an exception is raised. If it is present but empty, the error
  is swallowed.
  
  grouping code is completely redone. that should fix most problems previously encountered
  but one: footers are still not supported as that would require to have scrollable cursors
  or cache one row. Will add scrollable cursors as option in another patch.
  
  PS: will commit to cocoon_2_0_3_branch with time lag since I would like to see if there
  are complaints first...
  
  Revision  Changes    Path
  1.21      +118 -120  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.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- esql.xsl	14 May 2002 12:16:08 -0000	1.20
  +++ esql.xsl	16 May 2002 16:01:54 -0000	1.21
  @@ -1,6 +1,6 @@
   <?xml version="1.0"?>
   
  -<!-- $Id: esql.xsl,v 1.20 2002/05/14 12:16:08 tcurdt Exp $-->
  +<!-- $Id: esql.xsl,v 1.21 2002/05/16 16:01:54 haul Exp $-->
   <!--
   
    ============================================================================
  @@ -56,7 +56,7 @@
    * ESQL Logicsheet
    *
    * @author ?
  - * @version CVS $Revision: 1.20 $ $Date: 2002/05/14 12:16:08 $
  + * @version CVS $Revision: 1.21 $ $Date: 2002/05/16 16:01:54 $
   -->
   
   <xsl:stylesheet version="1.0"
  @@ -358,6 +358,51 @@
   <xsl:template match="esql:connection/esql:use-limit-clause"/>
   <xsl:template match="esql:connection/esql:property"/>
   
  +
  +<!-- set one parameter of a prepared or callable statement and use correct method for
type -->
  +<xsl:template name="set-query-parameter">
  +  <xsl:choose>
  +    <xsl:when test="@type">
  +      <xsl:variable name="type"><xsl:value-of select="concat(translate(substring(@type,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'),substring(@type,2))"/></xsl:variable>
  +      <xsl:text>set</xsl:text><xsl:value-of select="$type"/>(<xsl:value-of
select="position()"/>,<xsl:call-template name="get-nested-content"><xsl:with-param
name="content" select="."/></xsl:call-template>);<xsl:text>
  +      </xsl:text>
  +    </xsl:when>
  +    <xsl:otherwise>
  +      <xsl:text>setString(</xsl:text><xsl:value-of select="position()"/>,String.valueOf(<xsl:call-template
name="get-nested-string"><xsl:with-param name="content" select="."/></xsl:call-template>));<xsl:text>
  +      </xsl:text>
  +    </xsl:otherwise>
  +  </xsl:choose>
  +</xsl:template>
  +
  +<xspdoc:desc> internal. set one parameter of a callable statement </xspdoc:desc>
  +<xsl:template name="set-call-parameter">
  +  //try {
  +  <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>);
  +  </xsl:if>
  +  <xsl:if test="not(@direction) or @direction='inout' or @direction='in'">
  +    <xsl:text>_esql_query.getCallableStatement().</xsl:text>
  +    <xsl:call-template name="set-query-parameter"/>
  +  </xsl:if>
  +  //} catch (SQLException _esql_exception_<xsl:value-of select="generate-id(.)"/>)
{
  +  //  throw new RuntimeException("Error setting parameter on statement: " + _esql_query.getQueryString()
+ ": "+_esql_exception_<xsl:value-of select="generate-id(.)"/>);
  +  //}
  +</xsl:template>
  +
  +
  +
  +<xspdoc:desc> internal. set one parameter of a prepared statement </xspdoc:desc>
  +<xsl:template name="set-parameter">
  +  //try {
  +  <xsl:text>_esql_query.getPreparedStatement().</xsl:text>
  +  <xsl:call-template name="set-query-parameter"/>
  +  //} catch (SQLException _esql_exception_<xsl:value-of select="generate-id(.)"/>)
{
  +  //   throw new RuntimeException("Error setting parameter on statement: " + _esql_query.getQueryString()
+ ": "+_esql_exception_<xsl:value-of select="generate-id(.)"/>);
  +  //}
  +</xsl:template>
  +
  +
   <xsl:template match="esql:connection//esql:execute-query">
   
     <xsl:variable name="query"><xsl:choose><xsl:when test="esql:query"><xsl:call-template
name="get-nested-string"><xsl:with-param name="content" select="esql:query"/></xsl:call-template></xsl:when><xsl:when
test="esql:call"><xsl:call-template name="get-nested-string"><xsl:with-param name="content"
select="esql:call"/></xsl:call-template></xsl:when></xsl:choose></xsl:variable>
  @@ -385,82 +430,46 @@
       try {
         <xsl:choose>
           <xsl:when test="esql:call">
  -          try {
  +          //try {
               _esql_query.prepareCall();
  -          } catch (SQLException _esql_exception_<xsl:value-of select="generate-id(.)"/>)
{
  -            throw new RuntimeException("Error preparing statement: " + _esql_query.getQueryString()
+ ": "+_esql_exception_<xsl:value-of select="generate-id(.)"/>.getMessage());
  -          }
  +          //} catch (SQLException _esql_exception_<xsl:value-of select="generate-id(.)"/>)
{
  +          //  throw new RuntimeException("Error preparing statement: " + _esql_query.getQueryString()
+ ": "+_esql_exception_<xsl:value-of select="generate-id(.)"/>.getMessage());
  +          //}
             <xsl:for-each select="esql:call//esql:parameter">
  -            try {
  -            <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>);
  -            </xsl:if>
  -            <xsl:if test="not(@direction) or @direction='inout' or @direction='in'">
  -              <xsl:text>_esql_query.getCallableStatement().</xsl:text>
  -              <xsl:choose>
  -                <xsl:when test="@type">
  -                  <xsl:variable name="type"><xsl:value-of select="concat(translate(substring(@type,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'),substring(@type,2))"/></xsl:variable>
  -                  <xsl:text>set</xsl:text><xsl:value-of select="$type"/>(<xsl:value-of
select="position()"/>,<xsl:call-template name="get-nested-content"><xsl:with-param
name="content" select="."/></xsl:call-template>);<xsl:text>
  -</xsl:text>
  -              </xsl:when>
  -              <xsl:otherwise>
  -                <xsl:text>setString(</xsl:text><xsl:value-of select="position()"/>,String.valueOf(<xsl:call-template
name="get-nested-string"><xsl:with-param name="content" select="."/></xsl:call-template>));<xsl:text>
  -</xsl:text>
  -              </xsl:otherwise>
  -            </xsl:choose>
  -          </xsl:if>
  -            } catch (SQLException _esql_exception_<xsl:value-of select="generate-id(.)"/>)
{
  -              throw new RuntimeException("Error setting parameter on statement: " + _esql_query.getQueryString()
+ ": "+_esql_exception_<xsl:value-of select="generate-id(.)"/>);
  -            }
  +            <xsl:call-template name="set-call-parameter"/>
             </xsl:for-each>
  -          try {
  +          //try {
             <xsl:choose>
               <xsl:when test="esql:call[@needs-query='true' or @needs-query='yes']">_esql_query.execute(true);</xsl:when>
               <xsl:when test="esql:call[@resultset-from-object]">_esql_query.execute(<xsl:copy-of
select="esql:call[@resultset-from-object]"/>);</xsl:when>
               <xsl:otherwise>_esql_query.execute();</xsl:otherwise>
             </xsl:choose>
  -          } catch (SQLException _esql_exception_<xsl:value-of select="generate-id(.)"/>)
{
  -            throw new RuntimeException("Error executing prepared statement: " + _esql_query.getQueryString()
+ ": "+_esql_exception_<xsl:value-of select="generate-id(.)"/>);
  -          }
  +          //} catch (SQLException _esql_exception_<xsl:value-of select="generate-id(.)"/>)
{
  +          //  throw new RuntimeException("Error executing prepared statement: " + _esql_query.getQueryString()
+ ": "+_esql_exception_<xsl:value-of select="generate-id(.)"/>);
  +          //}
           </xsl:when>
           <xsl:when test="esql:query//esql:parameter">
  -          try {
  +          //try {
               _esql_query.prepareStatement();
  -          } catch (SQLException _esql_exception_<xsl:value-of select="generate-id(.)"/>)
{
  -            throw new RuntimeException("Error preparing statement: " + _esql_query.getQueryString()
+ ": "+_esql_exception_<xsl:value-of select="generate-id(.)"/>.getMessage());
  -          }
  +          //} catch (SQLException _esql_exception_<xsl:value-of select="generate-id(.)"/>)
{
  +          //  throw new RuntimeException("Error preparing statement: " + _esql_query.getQueryString()
+ ": "+_esql_exception_<xsl:value-of select="generate-id(.)"/>.getMessage());
  +          //}
             <xsl:for-each select="esql:query//esql:parameter">
  -            try {
  -              <xsl:text>_esql_query.getPreparedStatement().</xsl:text>
  -              <xsl:choose>
  -                <xsl:when test="@type">
  -                  <xsl:variable name="type"><xsl:value-of select="concat(translate(substring(@type,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'),substring(@type,2))"/></xsl:variable>
  -                  <xsl:text>set</xsl:text><xsl:value-of select="$type"/>(<xsl:value-of
select="position()"/>,<xsl:call-template name="get-nested-content"><xsl:with-param
name="content" select="."/></xsl:call-template>);<xsl:text>
  -</xsl:text>
  -                </xsl:when>
  -                <xsl:otherwise>
  -                  <xsl:text>setString(</xsl:text><xsl:value-of select="position()"/>,String.valueOf(<xsl:call-template
name="get-nested-string"><xsl:with-param name="content" select="."/></xsl:call-template>));<xsl:text>
  -</xsl:text>
  -                </xsl:otherwise>
  -              </xsl:choose>
  -            } catch (SQLException _esql_exception_<xsl:value-of select="generate-id(.)"/>)
{
  -              throw new RuntimeException("Error setting parameter on statement: " + _esql_query.getQueryString()
+ ": "+_esql_exception_<xsl:value-of select="generate-id(.)"/>);
  -            }
  +            <xsl:call-template name="set-parameter"/>
             </xsl:for-each>
  -          try {
  +          //try {
               _esql_query.execute();
  -          } catch (SQLException _esql_exception_<xsl:value-of select="generate-id(.)"/>)
{
  -            throw new RuntimeException("Error executing prepared statement: " + _esql_query.getQueryString()
+ ": "+_esql_exception_<xsl:value-of select="generate-id(.)"/>);
  -          }
  +          //} catch (SQLException _esql_exception_<xsl:value-of select="generate-id(.)"/>)
{
  +          //  throw new RuntimeException("Error executing prepared statement: " + _esql_query.getQueryString()
+ ": "+_esql_exception_<xsl:value-of select="generate-id(.)"/>);
  +          //}
           </xsl:when>
           <xsl:otherwise>
             _esql_query.createStatement();
  -          try {
  +          //try {
               _esql_query.execute();
  -          } catch (SQLException _esql_exception_<xsl:value-of select="generate-id(.)"/>)
{
  -            throw new RuntimeException("Error executing statement: " + _esql_query.getQueryString()
+ ": "+_esql_exception_<xsl:value-of select="generate-id(.)"/>);
  -          }
  +          //} catch (SQLException _esql_exception_<xsl:value-of select="generate-id(.)"/>)
{
  +          //  throw new RuntimeException("Error executing statement: " + _esql_query.getQueryString()
+ ": "+_esql_exception_<xsl:value-of select="generate-id(.)"/>);
  +          //}
           </xsl:otherwise>
         </xsl:choose>
         getLogger().debug("esql query: " + _esql_query.getQueryString());
  @@ -493,9 +502,9 @@
         }
         _esql_query.getStatement().close();
       } catch (SQLException _esql_exception_<xsl:value-of select="generate-id(.)"/>)
{
  -      try {
           <xsl:choose>
             <xsl:when test="esql:error-results">
  +          try {
               _esql_exception = _esql_exception_<xsl:value-of select="generate-id(.)"/>;
               _esql_exception_writer = new StringWriter();
               _esql_exception.printStackTrace(new PrintWriter(_esql_exception_writer));
  @@ -503,14 +512,17 @@
               if (!_esql_connection.getAutoCommit()) {
                 _esql_connection.rollback();
               }
  +          } catch (Exception _esql_exception_<xsl:value-of select="generate-id(.)"/>_2)
{}
             </xsl:when>
             <xsl:otherwise>
  +          try {
               if (!_esql_connection.getAutoCommit()) {
                 _esql_connection.rollback();
               }
  +          } catch (Exception _esql_exception_<xsl:value-of select="generate-id(.)"/>_2)
{}
  +          throw new RuntimeException("Error executing statement: " + _esql_query.getQueryString()
+ ": "+_esql_exception_<xsl:value-of select="generate-id(.)"/>);
             </xsl:otherwise>
           </xsl:choose>
  -      } catch (Exception _esql_exception_<xsl:value-of select="generate-id(.)"/>_2)
{}
       }
       if (_esql_queries.empty()) {
         _esql_query = null;
  @@ -562,17 +574,11 @@
   <xsl:template match="esql:results//esql:row-results">
     <xsl:variable name="group" select=".//esql:group"/>
     <xsp:logic>
  -
  -    //create booleans for group change watches and strings for old values.
  -    <xsl:apply-templates select=".//esql:group" mode="vars"/>
  -
       do {
         <xsp:content>
           <xsl:apply-templates/>
         </xsp:content>
  -      <xsl:if test="count($group) &lt; 1">	
  -        <xsl:call-template name="nextRow"/>
  -      </xsl:if>
  +      <xsl:call-template name="nextRow"/>
       } while ( _esql_query.keepGoing() );
   
       if (_esql_query.getSkipRows() > 0 ) {
  @@ -587,17 +593,23 @@
   
   
   
  +<xspdoc:desc>Only advance one row if no nested groups exist in this query. Ignore
nested queries.</xspdoc:desc>
   <xsl:template name="nextRow">
  +  <xsl:if test="not(.//esql:group) or generate-id(.//esql:group)=generate-id(.//esql:execute-query//esql:group)">
  +    <xsp:logic>
     //checking out early?
       if (_esql_query.getMaxRows() != -1 &amp;&amp; _esql_query.getCurrentRow() -
_esql_query.getSkipRows() == _esql_query.getMaxRows()) {
         _esql_query.setKeepGoing( false );
       } else {	//if not, advance normally
         _esql_query.setKeepGoing( _esql_query.nextRow() );
       }
  +    </xsp:logic>
  +  </xsl:if>
   </xsl:template>
   
   
   
  +
   <xsl:template match="esql:results//esql:previous-results"/>
   
   
  @@ -609,67 +621,41 @@
   
   
   
  -<xsl:template match="esql:group" mode="vars">
  -  _esql_query.setGroupingVar("<xsl:value-of select="@group-on"/>Changed", new Boolean(true));
  -</xsl:template>
  -
  -
   
   <xspdoc:desc>Allows header and footer elements around groups of consecutive records
with identical values in column named by @group-on.  Facilitates a single query with joins
to be used in lieu of some nested queries.</xspdoc:desc>
  -<xsl:template match="esql:group|esql:group//esql:group[.//esql:member]" priority="3">
  -<xsp:logic>
  -  if (((Boolean)_esql_query.getGroupingVar("<xsl:value-of select="@group-on"/>Changed")).booleanValue()){

  -    //header contents
  -    <xsp:content>
  -      <xsl:apply-templates>
  -        <xsl:with-param name="group-on" select="@group-on"/>
  -      </xsl:apply-templates>
  -    </xsp:content>
  -  }
  -</xsp:logic>
  -</xsl:template>
  -
  -
  -
  -<xsl:template match="esql:group//node()[.//esql:member]">
  -  <xsl:param name="group-on"/>
  -  <xsl:copy>
  -    <xsl:apply-templates select="@*|*|text()">
  -      <xsl:with-param name="group-on" select="$group-on"/>
  -    </xsl:apply-templates>
  -  </xsl:copy>
  +<xsl:template match="esql:group//esql:member">
  +  <xsp:logic>
  +    do {
  +       <xsp:content>
  +         <xsl:apply-templates/>
  +       </xsp:content>
  +       <xsl:call-template name="nextRow"/>
  +    } while (_esql_query.keepGoing() &amp;&amp; !_esql_query.hasGroupingVarChanged());
  +     </xsp:logic>
   </xsl:template>
   
   
  -
   <xspdoc:desc>Used in conjunction with and nested inside esql:group.  Formatting for
individual records goes within esql:member. Header and footer stuff goes in between group
and member.</xspdoc:desc>
  -<xsl:template match="esql:member|esql:group//esql:member[.//esql:member]">
  -  <xsl:param name="group-on"/>
  -  <xsl:variable name="group" select=".//esql:group"/>
  +<xsl:template match="esql:group">
  +  <xsl:variable name="group">
  +    <xsl:call-template name="get-column">
  +      <xsl:with-param name="name">group-on</xsl:with-param>
  +    </xsl:call-template>
  +  </xsl:variable>
  +
     <xsp:logic>
  -  }
  -    _esql_query.setGroupingVar("<xsl:value-of select="$group-on"/>Old", _esql_query.getResultSet().getString("<xsl:value-of
select="$group-on"/>"));	
  +    _esql_query.groupLevelPlusPlus();
  +    if (!_esql_query.groupLevelExists()) {
  +       _esql_query.setGroupingVar(<xsl:copy-of select="$group"/>);
  +    }
       <xsp:content>
  -      <xsl:apply-templates>
  -        <xsl:with-param name="group-on" select="$group-on"/>
  -      </xsl:apply-templates>
  +      <xsl:apply-templates/>
       </xsp:content>
  -
  -    <xsl:if test="count($group) &lt; 1">	
  -      <xsl:call-template name="nextRow"/>
  -    </xsl:if>
  -  if ( _esql_query.keepGoing() ) {
  -    _esql_query.setGroupingVar("<xsl:value-of select="$group-on"/>Changed", new Boolean(!((String)_esql_query.getGroupingVar("<xsl:value-of
select="$group-on"/>Old")).equals(_esql_query.getResultSet().getString("<xsl:value-of
select="$group-on"/>"))));
  -  } else {
  -    _esql_query.setGroupingVar("<xsl:value-of select="$group-on"/>Changed", new Boolean(true));
  -  }
  -  if (((Boolean)_esql_query.getGroupingVar("<xsl:value-of select="$group-on"/>Changed")).booleanValue())
{	
  -    //footer contents
  +    _esql_query.groupLevelMinusMinus();
     </xsp:logic>
   </xsl:template>
   
   
  -
   <xsl:template match="esql:results//esql:more-results"/>
   
   <xsl:template match="esql:results//esql:more-results" mode="more">
  @@ -863,7 +849,12 @@
     <xsp:expr><xsl:call-template name="get-resultset"/>.getShort(<xsl:call-template
name="get-column"/>)</xsp:expr>
   </xsl:template>
   
  -<xspdoc:desc>returns the value of the given column as a clob</xspdoc:desc>
  +<xspdoc:desc>returns the value of the given column as unicode string (column can
be string or clob</xspdoc:desc>
  +<xsl:template match="esql:row-results//esql:get-clob" name="get-clob">
  +	<xsp:expr>EsqlHelper.getStringOrClob(<xsl:call-template name="get-resultset"/>,<xsl:call-template
name="get-column"/>)</xsp:expr>
  +</xsl:template>
  +
  +<xspdoc:desc>returns the value of the given column as a clob as ascii string with
optinal encoding</xspdoc:desc>
   <xsl:template match="esql:row-results//esql:get-ascii|esql:call-results//esql:get-ascii">
     <xsp:expr>EsqlHelper.getAscii(<xsl:call-template name="get-resultset"/>,
<xsl:call-template name="get-column"/>)</xsp:expr>
   </xsl:template>
  @@ -1022,9 +1013,10 @@
   
   <xspdoc:desc>used internally to determine which column is the given column. if a
column attribute exists and its value is a number, it is taken to be the column's position.
if the value is not a number, it is taken to be the column's name. if a column attribute does
not exist, an esql:column element is assumed to exist and to render as a string (after all
of the xsp instructions have been evaluated), which is taken to be the column's name.</xspdoc:desc>
   <xsl:template name="get-column">
  +  <xsl:param name="name">column</xsl:param>
     <xsl:variable name="column">
        <xsl:call-template name="get-parameter">
  -       <xsl:with-param name="name">column</xsl:with-param>
  +       <xsl:with-param name="name"><xsl:value-of select="$name"/></xsl:with-param>
          <xsl:with-param name="required">true</xsl:with-param>
        </xsl:call-template>
     </xsl:variable>
  @@ -1065,7 +1057,7 @@
     </xsl:variable>
     <xsl:choose>
       <xsl:when test="$encoding = 'default'">
  -      <xsl:value-of select="$resultset"/>.getString(<xsl:value-of select="$column-spec"/>)
  +      EsqlHelper.getAscii(<xsl:value-of select="$resultset"/>,<xsl:value-of select="$column-spec"/>)
       </xsl:when>
       <xsl:otherwise>
         EsqlHelper.getStringFromByteArray(<xsl:value-of select="$resultset"/>.getBytes
  @@ -1102,6 +1094,12 @@
     <xsl:param name="message"/>
     <xsl:message terminate="yes"><xsl:value-of select="$message"/></xsl:message>
   </xsl:template>
  +
  +<!--
  +     swallow esql:param tags
  +-->
  +<xsl:template match="esql:param"/>
  +
   
   <xsl:template match="@*|node()" priority="-1">
     <xsl:copy>
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message