balld 01/01/10 20:57:13
Modified: src/org/apache/cocoon/components/language/markup/xsp/java
Tag: xml-cocoon2 esql.xsl
Log:
unified the c1 and c2 esql logicsheets
Revision Changes Path
No revision
No revision
1.1.2.21 +620 -678
xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/java/Attic/esql.xsl
Index: esql.xsl
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/java/Attic/esql.xsl,v
retrieving revision 1.1.2.20
retrieving revision 1.1.2.21
diff -u -r1.1.2.20 -r1.1.2.21
--- esql.xsl 2001/01/09 14:15:28 1.1.2.20
+++ esql.xsl 2001/01/11 04:57:13 1.1.2.21
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
-<!-- $Id: esql.xsl,v 1.1.2.20 2001/01/09 14:15:28 bloritsch Exp $-->
+<!-- $Id: esql.xsl,v 1.1.2.21 2001/01/11 04:57:13 balld Exp $-->
<!--
============================================================================
@@ -52,713 +52,655 @@
-->
<xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:xsp="http://apache.org/xsp"
- xmlns:esql="http://apache.org/cocoon/SQL/v2"
- xmlns:xspdoc="http://apache.org/cocoon/XSPDoc/v1"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xsp="http://apache.org/xsp"
+ xmlns:esql="http://apache.org/cocoon/SQL/v2"
+ xmlns:xspdoc="http://apache.org/cocoon/XSPDoc/v1"
>
-<xspdoc:title>the esql logicsheet</xspdoc:title>
-
- <xsl:template name="get-nested-content">
- <xsl:param name="content"/>
- <xsl:choose>
- <xsl:when test="$content/*">
- <xsl:apply-templates select="$content/*"/>
- </xsl:when>
- <xsl:otherwise>"<xsl:value-of select="$content"/>"</xsl:otherwise>
- </xsl:choose>
- </xsl:template>
-
- <xsl:template name="get-nested-string">
- <xsl:param name="content"/>
- <xsl:choose>
- <xsl:when test="$content/*">
- ""
- <xsl:for-each select="$content/node()">
- <xsl:choose>
- <xsl:when test="name(.)">
- <xsl:choose>
- <xsl:when test="namespace-uri(.)='http://apache.org/xsp' and
local-name(.)='text'">
- + "<xsl:value-of select="."/>"
- </xsl:when>
- <xsl:otherwise>
- + <xsl:apply-templates select="."/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:otherwise>
- + "<xsl:value-of select="translate(.,'	 ','
')"/>"
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
- </xsl:when>
- <xsl:otherwise>"<xsl:value-of
select="normalize-space($content)"/>"</xsl:otherwise>
- </xsl:choose>
- </xsl:template>
-
- <xsl:template match="xsp:page">
- <xsp:page>
- <xsl:apply-templates select="@*"/>
- <xsp:structure>
- <xsp:include>java.sql.DriverManager</xsp:include>
- <xsp:include>java.sql.Connection</xsp:include>
- <xsp:include>java.sql.Statement</xsp:include>
- <xsp:include>java.sql.PreparedStatement</xsp:include>
- <xsp:include>java.sql.ResultSet</xsp:include>
- <xsp:include>java.sql.ResultSetMetaData</xsp:include>
- <xsp:include>java.sql.SQLException</xsp:include>
- <xsp:include>java.text.SimpleDateFormat</xsp:include>
- <xsp:include>java.text.DecimalFormat</xsp:include>
-
<xsp:include>org.apache.cocoon.components.datasource.DataSourceComponent</xsp:include>
- </xsp:structure>
- <xsp:logic>
-
- class EsqlSession {
- Connection connection=null;
- String query;
- Statement statement;
- PreparedStatement preparedStatement;
- ResultSet resultset;
- ResultSetMetaData resultsetMetadata;
- int count;
- int maxRows;
- int skipRows;
- boolean hasResultset;
- int updateCount;
- }
-
- </xsp:logic>
- <xsl:for-each select=".//esql:execute-query[not(@inner-method='no')]">
- <xsl:call-template name="generate-code">
- <xsl:with-param name="inner-method">yes</xsl:with-param>
- </xsl:call-template>
- </xsl:for-each>
- <xsl:apply-templates/>
- </xsp:page>
- </xsl:template>
-
- <xsl:template
match="xsp:page/*[not(namespace-uri(.)='http://www.apache.org/1999/XSP/Core')]">
- <xsl:copy>
- <xsl:apply-templates select="@*"/>
- <xsp:logic>
-
- Stack esqlSessions = new Stack();
- EsqlSession esqlSession = null;
-
- </xsp:logic>
- <xsl:apply-templates/>
- </xsl:copy>
- </xsl:template>
-
- <!-- =========================================================== -->
-
- <xspdoc:desc>
- Indicates that a sql connection is going to be defined and one or
- more queries may be executed
- </xspdoc:desc>
-
- <xsl:template match="esql:execute-query">
- <xsl:choose>
- <xsl:when test="@inner-method='no'">
- <xsl:call-template name="generate-code">
- <xsl:with-param name="inner-method">no</xsl:with-param>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsp:logic>esqlExecuteQuery_<xsl:value-of
select="generate-id(.)"/>(esqlSessions,esqlSession);</xsp:logic>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
-
- <xsl:template name="generate-code">
- <xsl:param name="inner-method"/>
-
- <xsl:variable name="use-connection">
- <xsl:call-template name="get-nested-string">
- <xsl:with-param name="content" select="esql:use-connection"/>
- </xsl:call-template>
- </xsl:variable>
-
- <xsl:variable name="driver">
- <xsl:call-template name="get-nested-string">
- <xsl:with-param name="content" select="esql:driver"/>
- </xsl:call-template>
- </xsl:variable>
-
- <xsl:variable name="dburl">
- <xsl:call-template name="get-nested-string">
- <xsl:with-param name="content" select="esql:dburl"/>
- </xsl:call-template>
- </xsl:variable>
-
- <xsl:variable name="username">
- <xsl:call-template name="get-nested-string">
- <xsl:with-param name="content" select="esql:username"/>
- </xsl:call-template>
- </xsl:variable>
-
- <xsl:variable name="password">
- <xsl:call-template name="get-nested-string">
- <xsl:with-param name="content" select="esql:password"/>
- </xsl:call-template>
- </xsl:variable>
-
- <xsl:variable name="max-rows">
- <xsl:call-template name="get-nested-string">
- <xsl:with-param name="content" select="esql:max-rows"/>
- </xsl:call-template>
- </xsl:variable>
-
- <xsl:variable name="skip-rows">
- <xsl:call-template name="get-nested-string">
- <xsl:with-param name="content" select="esql:skip-rows"/>
- </xsl:call-template>
- </xsl:variable>
-
- <xsl:variable name="query">
- <xsl:call-template name="get-nested-string">
- <xsl:with-param name="content" select="esql:query"/>
- </xsl:call-template>
- </xsl:variable>
-
- <xsl:variable name="statement">
- <xsl:call-template name="get-nested-string">
- <xsl:with-param name="content" select="esql:statement"/>
- </xsl:call-template>
- </xsl:variable>
+<!--
+-->
- <xsp:logic>
+<xsl:param name="XSP-ENVIRONMENT"/>
+<xsl:param name="XSP-VERSION"/>
+<xsl:param name="filename"/>
+<xsl:param name="language"/>
+
+<xsl:variable name="cocoon1-environment">Cocoon 1</xsl:variable>
+<xsl:variable name="cocoon2-environment">something else</xsl:variable>
+
+<xsl:variable
name="cocoon1-xsp-namespace-uri">http://www.apache.org/1999/XSP/Core</xsl:variable>
+<xsl:variable
name="cocoon2-xsp-namespace-uri">http://apache.org/xsp</xsl:variable>
+
+<xsl:variable name="environment">
+ <xsl:choose>
+ <xsl:when test="starts-with($XSP-ENVIRONMENT,$cocoon1-environment)">
+ <xsl:text>cocoon1</xsl:text>
+ </xsl:when>
+ <xsl:when test="starts-with($XSP-ENVIRONMENT,$cocoon2-environment)">
+ <xsl:text>cocoon2</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>cocoon2</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:variable>
+
+<xsl:variable name="xsp-namespace-uri">
+ <xsl:choose>
+ <xsl:when test="$environment = 'cocoon1'">
+ <xsl:value-of select="$cocoon1-xsp-namespace-uri"/>
+ </xsl:when>
+ <xsl:when test="$environment = 'cocoon2'">
+ <xsl:value-of select="$cocoon2-xsp-namespace-uri"/>
+ </xsl:when>
+ </xsl:choose>
+</xsl:variable>
+
+<xsl:template name="get-nested-content">
+ <xsl:param name="content"/>
+ <xsl:choose>
+ <xsl:when test="$content/*">
+ <xsl:apply-templates select="$content/*"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$content"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="get-nested-string">
+ <xsl:param name="content"/>
+ <xsl:choose>
+ <xsl:when test="$environment = 'cocoon1'">
<xsl:choose>
- <xsl:when test="$inner-method='yes'">
- void esqlExecuteQuery_<xsl:value-of select="generate-id(.)"/>(
- Stack esqlSessions,
- EsqlSession esqlSession)
- throws Exception {
+ <xsl:when test="$content/*">
+ ""
+ <xsl:for-each select="$content/node()">
+ <xsl:choose>
+ <xsl:when test="name(.)">
+ + <xsl:apply-templates select="."/>
+ </xsl:when>
+ <xsl:otherwise>
+ + "<xsl:value-of select="translate(.,'	 ','
')"/>"
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
</xsl:when>
- <xsl:when test="$inner-method='no'">
- {
+ <xsl:otherwise>
+ "<xsl:value-of select="normalize-space($content)"/>"
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:when>
+ <xsl:when test="$environment = 'cocoon2'">
+ <xsl:choose>
+ <xsl:when test="$content/*">
+ ""
+ <xsl:for-each select="$content/node()">
+ <xsl:choose>
+ <xsl:when test="name(.)">
+ <xsl:choose>
+ <xsl:when test="namespace-uri(.)='http://apache.org/xsp'
and local-name(.)='text'">
+ + "<xsl:value-of select="."/>"
+ </xsl:when>
+ <xsl:otherwise>
+ + <xsl:apply-templates select="."/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:when>
+ <xsl:otherwise>
+ + "<xsl:value-of select="translate(.,'	 ','
')"/>"
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
</xsl:when>
+ <xsl:otherwise>"<xsl:value-of
select="normalize-space($content)"/>"</xsl:otherwise>
</xsl:choose>
-
- if (esqlSession != null) {
- esqlSessions.push(esqlSession);
+ </xsl:when>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template match="xsp:page">
+ <xsp:page>
+ <xsl:apply-templates select="@*"/>
+ <xsp:structure>
+ <xsp:include>java.sql.DriverManager</xsp:include>
+ <xsp:include>java.sql.Connection</xsp:include>
+ <xsp:include>java.sql.Statement</xsp:include>
+ <xsp:include>java.sql.PreparedStatement</xsp:include>
+ <xsp:include>java.sql.ResultSet</xsp:include>
+ <xsp:include>java.sql.ResultSetMetaData</xsp:include>
+ <xsp:include>java.sql.SQLException</xsp:include>
+ <xsp:include>java.text.SimpleDateFormat</xsp:include>
+ <xsp:include>java.text.DecimalFormat</xsp:include>
+ <xsp:include>java.io.StringWriter</xsp:include>
+ <xsp:include>java.io.PrintWriter</xsp:include>
+
<xsp:include>org.apache.turbine.services.db.PoolBrokerService</xsp:include>
+ <xsp:include>org.apache.turbine.util.db.pool.DBConnection</xsp:include>
+ </xsp:structure>
+ <xsp:logic>
+ /** environment - <xsl:value-of select="$environment"/> **/
+ /** xsp namespace uri - <xsl:value-of select="$xsp-namespace-uri"/> **/
+ static PoolBrokerService _esql_pool = PoolBrokerService.getInstance();
+ class EsqlConnection {
+ DBConnection db_connection = null;
+ Connection connection = null;
+ String dburl = null;
+ String username = null;
+ String password = null;
}
-
- esqlSession = new EsqlSession();
-
- try {
- esqlSession.maxRows = Integer.parseInt(String.valueOf(<xsl:copy-of
select="$max-rows"/>).trim());
- } catch (Exception esqlE) {
- cocoonLogger.debug("Row retrieval is not limited");
- esqlSession.maxRows = -1;
+ class EsqlQuery {
+ String query;
+ Statement statement;
+ PreparedStatement prepared_statement;
+ ResultSet resultset;
+ ResultSetMetaData resultset_metadata;
+ /** the position of the current row in the resultset **/
+ int position = -1;
+ int max_rows = -1;
+ int skip_rows = 0;
+ boolean results;
}
+ </xsp:logic>
+ <xsl:apply-templates/>
+ </xsp:page>
+</xsl:template>
+<xsl:template match="xsp:page/*[not(namespace-uri(.)=$xsp-namespace-uri)]">
+ <xsl:copy>
+ <xsl:apply-templates select="@*"/>
+ <xsp:logic>
+ Stack _esql_connections = new Stack();
+ EsqlConnection _esql_connection = null;
+ Stack _esql_queries = new Stack();
+ EsqlQuery _esql_query = null;
+ SQLException _esql_exception = null;
+ StringWriter _esql_exception_writer = null;
+ </xsp:logic>
+ <xsl:apply-templates/>
+ </xsl:copy>
+</xsl:template>
+
+<xsl:template match="esql:connection">
+ <xsl:variable name="driver"><xsl:call-template
name="get-nested-string"><xsl:with-param name="content"
select="esql:driver"/></xsl:call-template></xsl:variable>
+ <xsl:variable name="dburl"><xsl:call-template
name="get-nested-string"><xsl:with-param name="content"
select="esql:dburl"/></xsl:call-template></xsl:variable>
+ <xsl:variable name="username"><xsl:call-template
name="get-nested-string"><xsl:with-param name="content"
select="esql:username"/></xsl:call-template></xsl:variable>
+ <xsl:variable name="password"><xsl:call-template
name="get-nested-string"><xsl:with-param name="content"
select="esql:password"/></xsl:call-template></xsl:variable>
+ <xsl:variable name="pool"><xsl:call-template
name="get-nested-string"><xsl:with-param name="content"
select="esql:pool"/></xsl:call-template></xsl:variable>
+ <xsl:variable name="autocommit"><xsl:call-template
name="get-nested-string"><xsl:with-param name="content"
select="esql:autocommit"/></xsl:call-template></xsl:variable>
+ <xsp:logic>
+ if (_esql_connection != null) {
+ _esql_connections.push(_esql_connection);
+ }
+ _esql_connection = new EsqlConnection();
+ try {
+ <xsl:choose>
+ <xsl:when test="esql:pool">
+ _esql_connection.db_connection =
_esql_pool.getConnection(String.valueOf(<xsl:copy-of select="$pool"/>));
+ _esql_connection.connection =
_esql_connection.db_connection.getConnection();
+ </xsl:when>
+ <xsl:otherwise>
+ try {
+ Class.forName(String.valueOf(<xsl:copy-of
select="$driver"/>)).newInstance();
+ } catch (Exception _esql_exception_<xsl:value-of
select="generate-id(.)"/>) {
+ throw new RuntimeException("Error loading driver:
"+String.valueOf(<xsl:copy-of select="$driver"/>));
+ }
+ try {
+ <xsl:choose>
+ <xsl:when test="esql:username">
+ _esql_connection.connection = DriverManager.getConnection(
+ String.valueOf(<xsl:copy-of select="$dburl"/>),
+ String.valueOf(<xsl:copy-of select="$username"/>),
+ String.valueOf(<xsl:copy-of select="$password"/>)
+ );
+ </xsl:when>
+ <xsl:otherwise>
+ _esql_connection.connection = DriverManager.getConnection(
+ String.valueOf(<xsl:copy-of select="$dburl"/>)
+ );
+ </xsl:otherwise>
+ </xsl:choose>
+ } catch (Exception _esql_exception_<xsl:value-of
select="generate-id(.)"/>) {
+ throw new RuntimeException("Error opening connection to dburl:
"+String.valueOf(<xsl:copy-of select="$dburl"/>));
+ }
+ </xsl:otherwise>
+ </xsl:choose>
try {
- esqlSession.skipRows =
Integer.parseInt(String.valueOf(<xsl:copy-of select="$skip-rows"/>).trim());
- } catch (Exception esqlE) {
- cocoonLogger.debug("We are not skipping any rows");
- esqlSession.skipRows = 0;
+ if ("false".equals(String.valueOf(<xsl:copy-of
select="$autocommit"/>))) {
+ _esql_connection.connection.setAutoCommit(false);
+ } else {
+ _esql_connection.connection.setAutoCommit(true);
+ }
+ } catch (Exception _esql_exception_<xsl:value-of
select="generate-id(.)"/>) {
+ throw new RuntimeException("Error setting connection autocommit");
}
-
+ <xsl:apply-templates/>
+ } finally {
try {
- <xsl:choose>
- <xsl:when test="not(esql:use-connection or esql:dburl)">
- esqlSession.connection =
((EsqlSession)esqlSessions.peek()).connection;
- </xsl:when>
- <xsl:when test="esql:use-connection">
- ComponentSelector esqlDSSelector = (ComponentSelector)
this.manager.lookup(Roles.DB_CONNECTION);
- DataSourceComponent esqlDS = (DataSourceComponent)
esqlDSSelector.select(String.valueOf(<xsl:copy-of select="$use-connection"/>));
- esqlSession.connection = esqlDS.getConnection();
- </xsl:when>
- <xsl:otherwise>
- ClassUtils.newInstance(String.valueOf(<xsl:copy-of
select="$driver"/>).trim());
-
+ if(!_esql_connection.connection.getAutoCommit()) {
+ _esql_connection.connection.commit();
+ }
+ <xsl:choose>
+ <xsl:when test="esql:pool">
+ _esql_pool.releaseConnection(_esql_connection.db_connection);
+ </xsl:when>
+ <xsl:otherwise>
+ _esql_connection.connection.close();
+ </xsl:otherwise>
+ </xsl:choose>
+ if (_esql_connections.empty()) {
+ _esql_connection = null;
+ } else {
+ _esql_connection = (EsqlConnection)_esql_connections.pop();
+ }
+ } catch (Exception _esql_exception_<xsl:value-of
select="generate-id(.)"/>) {}
+ }
+ </xsp:logic>
+</xsl:template>
+
+<xsl:template match="esql:connection/esql:driver"/>
+<xsl:template match="esql:connection/esql:dburl"/>
+<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:autocommit"/>
+
+<xsl:template match="esql:connection//esql:execute-query">
+ <xsl:variable name="query"><xsl:call-template
name="get-nested-string"><xsl:with-param name="content"
select="esql:query"/></xsl:call-template></xsl:variable>
+ <xsl:variable name="maxrows"><xsl:call-template
name="get-nested-string"><xsl:with-param name="content"
select="esql:max-rows"/></xsl:call-template></xsl:variable>
+ <xsl:variable name="skiprows"><xsl:call-template
name="get-nested-string"><xsl:with-param name="content"
select="esql:skip-rows"/></xsl:call-template></xsl:variable>
+ <xsp:logic>
+ if (_esql_query != null) {
+ _esql_queries.push(_esql_query);
+ }
+ _esql_query = new EsqlQuery();
+ _esql_query.query = String.valueOf(<xsl:copy-of select="$query"/>);
+ try {
+ _esql_query.max_rows = Integer.parseInt(String.valueOf(<xsl:copy-of
select="$maxrows"/>));
+ } catch (NumberFormatException e) {}
+ try {
+ _esql_query.skip_rows = Integer.parseInt(String.valueOf(<xsl:copy-of
select="$skiprows"/>));
+ } catch (NumberFormatException e) {}
+ try {
+ <xsl:choose>
+ <!-- this is a prepared statement -->
+ <xsl:when test="esql:query//esql:parameter">
+ try {
+ _esql_query.prepared_statement =
_esql_connection.connection.prepareStatement(_esql_query.query);
+ } catch (SQLException _esql_exception_<xsl:value-of
select="generate-id(.)"/>) {
+ throw new RuntimeException("Error preparing statement:
"+_esql_query.query);
+ }
+ _esql_query.statement = _esql_query.prepared_statement;
+ <xsl:for-each select="esql:query//esql:parameter">
+ try {
+ <xsl:text>_esql_query.prepared_statement.</xsl:text>
<xsl:choose>
- <xsl:when test="esql:username">
- esqlSession.connection = DriverManager.getConnection(
- String.valueOf(<xsl:copy-of
select="$dburl"/>).trim(),
- String.valueOf(<xsl:copy-of
select="$username"/>).trim(),
- String.valueOf(<xsl:copy-of
select="$password"/>).trim()
- );
+ <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>
- esqlSession.connection = DriverManager.getConnection(
- String.valueOf(<xsl:copy-of
select="$dburl"/>).trim()
- );
+ <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:otherwise>
- </xsl:choose>
-
- <xsl:choose>
- <xsl:when test="esql:query">
- esqlSession.query = String.valueOf(<xsl:copy-of
select="$query"/>).trim();
- esqlSession.statement =
esqlSession.connection.createStatement();
- esqlSession.hasResultset =
esqlSession.statement.execute(esqlSession.query);
- </xsl:when>
- <xsl:when test="esql:statement">
- esqlSession.preparedStatement =
esqlSession.connection.prepareStatement(String.valueOf(<xsl:copy-of
select="$statement"/>).trim());
- esqlSession.statement = esqlSession.preparedStatement;
-
- <xsl:for-each select=".//esql:parameter">
- <xsl:text>esqlSession.preparedStatement.</xsl:text>
-
- <xsl:choose>
- <xsl:when test="@type">
- <xsl:variable name="type"><xsl:value-of
select="concat(translate(substring(@type,0,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'),substring(@type,1))"/></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: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>).trim());
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
-
- esqlSession.hasResultset =
esqlSession.preparedStatement.execute();
- </xsl:when>
- </xsl:choose>
-
- if (esqlSession.hasResultset) {
- esqlSession.resultset = esqlSession.statement.getResultSet();
- esqlSession.resultsetMetadata =
esqlSession.resultset.getMetaData();
- esqlSession.updateCount = -1;
- esqlSession.count = 0;
-
- if (esqlSession.skipRows > 0) {
- while (esqlSession.resultset.next()) {
- esqlSession.count++;
-
- if (esqlSession.count == esqlSession.skipRows) {
- break;
- }
- }
- }
-
- boolean esqlResults_<xsl:value-of select="generate-id(.)"/> =
false;
-
- while (esqlSession.resultset.next()) {
- esqlResults_<xsl:value-of select="generate-id(.)"/> = true;
- <xsl:apply-templates select="esql:results/*"/>
-
- if ((esqlSession.maxRows != -1) &&
((esqlSession.count - esqlSession.skipRows) == (esqlSession.maxRows - 1))) {
- break;
- }
-
- esqlSession.count++;
- }
-
- esqlSession.resultset.close();
-
- if (!esqlResults_<xsl:value-of select="generate-id(.)"/>) {
- <xsl:apply-templates select="esql:no-results/*"/>
- }
- } else {
- esqlSession.updateCount =
esqlSession.statement.getUpdateCount();
- <xsl:apply-templates select="esql:count-results/*"/>
- }
-
- esqlSession.statement.close();
- } catch (Exception esqlException) {
- cocoonLogger.error("esql XSP exception", esqlException);
-
- <xsl:if test="esql:error-results//esql:get-stacktrace">
- StringWriter esqlException_writer = new StringWriter();
- esqlException.printStackTrace(new
PrintWriter(esqlException_writer));
- </xsl:if>
-
- <xsl:apply-templates select="esql:error-results/*"/>
- } finally {
- if (esqlSession.connection != null) {
- try {
- esqlSession.connection.close();
- } catch (SQLException esqlException) {
- cocoonLogger.debug("Could not close DB connection",
esqlException);
- }
+ } catch (SQLException _esql_exception_<xsl:value-of
select="generate-id(.)"/>) {
+ throw new RuntimeException("Error setting parameter on
statement: "+_esql_query.query);
+ }
+ </xsl:for-each>
+ try {
+ _esql_query.results = _esql_query.prepared_statement.execute();
+ } catch (SQLException _esql_exception_<xsl:value-of
select="generate-id(.)"/>) {
+ throw new RuntimeException("Error executed prepared statement:
"+_esql_query.query);
}
-
- if (esqlSessions.empty()) {
- esqlSession = null;
- } else {
- esqlSession = (EsqlSession)esqlSessions.pop();
+ </xsl:when>
+ <!-- this is a normal query -->
+ <xsl:otherwise>
+ _esql_query.statement =
_esql_connection.connection.createStatement();
+ _esql_query.results =
_esql_query.statement.execute(_esql_query.query);
+ </xsl:otherwise>
+ </xsl:choose>
+ if (_esql_query.results) {
+ _esql_query.resultset = _esql_query.statement.getResultSet();
+ _esql_query.resultset_metadata = _esql_query.resultset.getMetaData();
+ _esql_query.position = 0;
+ if (_esql_query.skip_rows > 0) {
+ while (_esql_query.resultset.next()) {
+ _esql_query.position++;
+ if (_esql_query.position == _esql_query.skip_rows) {
+ break;
+ }
}
+ }
+ <xsl:apply-templates select="esql:results"/>
+ <xsl:apply-templates select="esql:no-results"/>
+ _esql_query.resultset.close();
+ } else {
+ _esql_query.position = _esql_query.statement.getUpdateCount();
+ if (_esql_query.position >= 0) {
+ <xsl:apply-templates select="esql:update-results/*"/>
+ }
}
- } // Where does this match?
- </xsp:logic>
- </xsl:template>
-
- <xsl:template match="esql:statement//esql:parameter">"?"</xsl:template>
-
- <!-- =========================================================== -->
-
- <xspdoc:desc>
- If the query has results, this element's children will be
- instantiated for each row in the result set
- </xspdoc:desc>
-
- <xsl:template match="esql:execute-query/esql:results">
- <xsl:apply-templates/>
- </xsl:template>
-
- <!-- =========================================================== -->
-
- <xspdoc:desc>
- If the query has no results, this element's children will be
- instantiated once
- </xspdoc:desc>
-
- <xsl:template match="esql:execute-query/esql:no-results">
- <xsl:apply-templates/>
- </xsl:template>
-
- <!-- =========================================================== -->
-
- <xspdoc:desc>
- If the query results in an error, this element's children will be
- instantiated once
- </xspdoc:desc>
-
- <xsl:template match="esql:execute-query/esql:error-results">
- <xsl:apply-templates/>
- </xsl:template>
-
- <!-- =========================================================== -->
-
- <xspdoc:desc>
- Results in a set of elements whose names are the names of the
- columns. the elements each have one text child, whose value is the
- value of the column interpreted as a string. No special formatting
- is allowed here. If you want to mess around with the names of the
- elements or the value of the text field, use the type-specific get
- methods and write out the result fragment yourself.
- </xspdoc:desc>
-
- <xsl:template match="esql:results//esql:get-columns">
- <xsp:logic>
- for (int esqlI=1; esqlI <=
esqlSession.resultsetMetadata.getColumnCount(); esqlI++) {
- String tagName =
esqlSession.resultsetMetadata.getColumnName(esqlI);
-
- <xsp:element>
- <xsp:param name="name"><xsp:expr>tagName</xsp:expr></xsp:param>
- <xsp:expr>esqlSession.resultset.getString(esqlI)</xsp:expr>
- </xsp:element>
+ _esql_query.statement.close();
+ } catch (SQLException _esql_exception_<xsl:value-of
select="generate-id(.)"/>) {
+ try {
+ <xsl:choose>
+ <xsl:when test="esql:error-results">
+ _esql_exception = _esql_exception_<xsl:value-of
select="generate-id(.)"/>;
+ _esql_exception_writer = new StringWriter();
+ _esql_exception.printStackTrace(new
PrintWriter(_esql_exception_writer));
+ <xsl:apply-templates select="esql:error-results"/>
+ if (!_esql_connection.connection.getAutoCommit()) {
+ _esql_connection.connection.rollback();
+ }
+ </xsl:when>
+ <xsl:otherwise>
+ if (!_esql_connection.connection.getAutoCommit()) {
+ _esql_connection.connection.rollback();
+ }
+ </xsl:otherwise>
+ </xsl:choose>
+ } catch (Exception _esql_exception_<xsl:value-of
select="generate-id(.)"/>_2) {}
+ }
+ if (_esql_queries.empty()) {
+ _esql_query = null;
+ } else {
+ _esql_query = (EsqlQuery)_esql_queries.pop();
+ }
+ </xsp:logic>
+</xsl:template>
+
+<xsl:template match="esql:query//esql:parameter">"?"</xsl:template>
+
+<xsl:template match="esql:execute-query//esql:results">
+ <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="esql:execute-query//esql:error-results">
+ <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="esql:execute-query//esql:no-results">
+ <xsp:logic>
+ if (_esql_query.position == _esql_query.skip_rows) {
+ <xsl:apply-templates/>
+ }
+ </xsp:logic>
+</xsl:template>
+
+<xsl:template match="esql:update-results//esql:get-update-count">
+ <xsp:expr>_esql_query.position</xsp:expr>
+</xsl:template>
+
+<xsl:template match="esql:results//esql:row-results">
+ <xsp:logic>
+ while (_esql_query.resultset.next()) {
+ <xsl:apply-templates/>
+ if (_esql_query.max_rows != -1 && _esql_query.position -
_esql_query.skip_rows == _esql_query.max_rows-1) {
+ break;
}
-
- this.characters("\n");
- </xsp:logic>
- </xsl:template>
-
- <!-- =========================================================== -->
-
- <xspdoc:desc>
- Returns the value of the given column as a string
- </xspdoc:desc>
-
- <xsl:template match="esql:results//esql:get-string" name="get-string">
- <xsp:expr><xsl:call-template
name="get-resultset"/>.getString(<xsl:call-template
name="get-column"/>)</xsp:expr>
- </xsl:template>
-
- <!-- =========================================================== -->
-
- <xspdoc:desc>
- Returns the value of the given column as a date. if a format
- attribute exists, its value is taken to be a date format string as
- defined in java.text.SimpleDateFormat, and the result is formatted
- accordingly.
- </xspdoc:desc>
-
- <xsl:template match="esql:results//esql:get-date">
- <xsl:choose>
- <xsl:when test="@format">
- <xsp:expr>new SimpleDateFormat("<xsl:value-of
select="@format"/>").format(<xsl:call-template
name="get-resultset"/>.getDate(<xsl:call-template
name="get-column"/>))</xsp:expr>
- </xsl:when>
- <xsl:otherwise>
- <xsp:expr><xsl:call-template
name="get-resultset"/>.getDate(<xsl:call-template
name="get-column"/>)</xsp:expr>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
-
- <!-- =========================================================== -->
-
- <xspdoc:desc>
- Returns the value of the given column as a time. if a format
- attribute exists, its value is taken to be a date format string as
- defined in java.text.SimpleDateFormat, and the result is formatted
- accordingly.
- </xspdoc:desc>
-
- <xsl:template match="esql:results//esql:get-time">
- <xsl:choose>
- <xsl:when test="@format">
- <xsp:expr>new SimpleDateFormat("<xsl:value-of
select="@format"/>").format(<xsl:call-template
name="get-resultset"/>.getTime(<xsl:call-template
name="get-column"/>))</xsp:expr>
- </xsl:when>
- <xsl:otherwise>
- <xsp:expr><xsl:call-template
name="get-resultset"/>.getTime(<xsl:call-template
name="get-column"/>)</xsp:expr>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
-
- <!-- =========================================================== -->
-
- <xspdoc:desc>
- Returns the value of the given column as a timestamp. if a format
- attribute exists, its value is taken to be a date format string as
- defined in java.text.SimpleDateFormat, and the result is formatted
- accordingly.
- </xspdoc:desc>
-
- <xsl:template match="esql:results//esql:get-timestamp">
- <xsl:choose>
- <xsl:when test="@format">
- <xsp:expr>new SimpleDateFormat("<xsl:value-of
select="@format"/>").format(<xsl:call-template
name="get-resultset"/>.getTimestamp(<xsl:call-template
name="get-column"/>))</xsp:expr>
- </xsl:when>
- <xsl:otherwise>
- <xsp:expr><xsl:call-template
name="get-resultset"/>.getTimestamp(<xsl:call-template
name="get-column"/>)</xsp:expr>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
-
- <!-- =========================================================== -->
-
- <xspdoc:desc>
- Returns the value of the given column as true or false
- </xspdoc:desc>
-
- <xsl:template match="esql:results//esql:get-boolean">
- <xsl:choose>
- <xsl:when test="@string='true'">
- <xsp:expr><xsl:call-template
name="get-resultset"/>.getBoolean(<xsl:call-template name="get-column"/>) ?
"true" : "false"</xsp:expr>
- </xsl:when>
- <xsl:otherwise>
- <xsp:expr><xsl:call-template
name="get-resultset"/>.getBoolean(<xsl:call-template
name="get-column"/>)</xsp:expr>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
-
- <!-- =========================================================== -->
-
- <xspdoc:desc>
- Returns the value of the given column as a double. if a format
- attribute exists, its value is taken to be a decimal format string
- as defined in java.text.DecimalFormat, and the result is formatted
- accordingly.
- </xspdoc:desc>
-
- <xsl:template match="esql:results//esql:get-double">
- <xsl:choose>
- <xsl:when test="@format">
- <xsp:expr>new DecimalFormat("<xsl:value-of
select="@format"/>").format(new Double(<xsl:call-template
name="get-resultset"/>.getDouble(<xsl:call-template
name="get-column"/>)))</xsp:expr>
- </xsl:when>
- <xsl:otherwise>
- <xsp:expr><xsl:call-template
name="get-resultset"/>.getDouble(<xsl:call-template
name="get-column"/>)</xsp:expr>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
-
- <!-- =========================================================== -->
-
- <xspdoc:desc>
- Returns the value of the given column as a float. if a format
- attribute exists, its value is taken to be a decimal format string
- as defined in java.text.DecimalFormat, and the result is formatted
- accordingly.
- </xspdoc:desc>
-
- <xsl:template match="esql:results//esql:get-float">
- <xsl:choose>
- <xsl:when test="@format">
- <xsp:expr>new DecimalFormat("<xsl:value-of
select="@format"/>").format(new Float(<xsl:call-template
name="get-resultset"/>.getFloat(<xsl:call-template
name="get-column"/>)))</xsp:expr>
+ _esql_query.position++;
+ }
+ </xsp:logic>
+</xsl:template>
+
+<xspdoc:desc>results in a set of elements whose names are the names of the
columns. the elements each have one text child, whose value is the value of the
column interpreted as a string. No special formatting is allowed here. If you
want to mess around with the names of the elements or the value of the text
field, use the type-specific get methods and write out the result fragment
yourself.</xspdoc:desc>
+<xsl:template match="esql:row-results//esql:get-columns">
+ <xsl:choose>
+ <xsl:when test="$environment = 'cocoon1'">
+ <xsp:logic>
+ for (int _esql_i=1; _esql_i <=
_esql_query.resultset_metadata.getColumnCount(); _esql_i++) {
+ Node _esql_node =
document.createElement(_esql_query.resultset_metadata.getColumnName(_esql_i));
+ _esql_node.appendChild(document.createTextNode(
+ <xsl:call-template name="get-string-encoded">
+ <xsl:with-param name="column-spec">_esql_i</xsl:with-param>
+ <xsl:with-param
name="resultset">_esql_query.resultset</xsl:with-param>
+ </xsl:call-template>
+ ));
+ xspCurrentNode.appendChild(_esql_node);
+ }
+ </xsp:logic>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsp:logic>
+ throw new RuntimeException("esql:get-columns is not supported in
this environment: "+<xsl:value-of select="$environment"/>);
+ </xsp:logic>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xspdoc:desc>returns the value of the given column as a string</xspdoc:desc>
+<xsl:template match="esql:row-results//esql:get-string" name="get-string">
+ <xsp:expr>
+ <xsl:call-template name="get-string-encoded">
+ <xsl:with-param name="column-spec"><xsl:call-template
name="get-column"/></xsl:with-param>
+ <xsl:with-param name="resultset"><xsl:call-template
name="get-resultset"/></xsl:with-param>
+ </xsl:call-template>
+ </xsp:expr>
+</xsl:template>
+
+<xspdoc:desc>returns the value of the given column as a date. if a format
attribute exists, its value is taken to be a date format string as defined in
java.text.SimpleDateFormat, and the result is formatted
accordingly.</xspdoc:desc>
+<xsl:template match="esql:row-results//esql:get-date">
+ <xsl:choose>
+ <xsl:when test="@format">
+ <xsp:expr>new SimpleDateFormat("<xsl:value-of
select="@format"/>").format(<xsl:call-template
name="get-resultset"/>.getDate(<xsl:call-template
name="get-column"/>))</xsp:expr>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsp:expr><xsl:call-template
name="get-resultset"/>.getDate(<xsl:call-template
name="get-column"/>)</xsp:expr>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xspdoc:desc>returns the value of the given column as a time. if a format
attribute exists, its value is taken to be a date format string as defined in
java.text.SimpleDateFormat, and the result is formatted
accordingly.</xspdoc:desc>
+<xsl:template match="esql:row-results//esql:get-time">
+ <xsl:choose>
+ <xsl:when test="@format">
+ <xsp:expr>new SimpleDateFormat("<xsl:value-of
select="@format"/>").format(<xsl:call-template
name="get-resultset"/>.getTime(<xsl:call-template
name="get-column"/>))</xsp:expr>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsp:expr><xsl:call-template
name="get-resultset"/>.getTime(<xsl:call-template
name="get-column"/>)</xsp:expr>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xspdoc:desc>returns the value of the given column as a timestamp. if a
format attribute exists, its value is taken to be a date format string as
defined in java.text.SimpleDateFormat, and the result is formatted
accordingly.</xspdoc:desc>
+<xsl:template match="esql:row-results//esql:get-timestamp">
+ <xsl:choose>
+ <xsl:when test="@format">
+ <xsp:expr>new SimpleDateFormat("<xsl:value-of
select="@format"/>").format(<xsl:call-template
name="get-resultset"/>.getTimestamp(<xsl:call-template
name="get-column"/>))</xsp:expr>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsp:expr><xsl:call-template
name="get-resultset"/>.getTimestamp(<xsl:call-template
name="get-column"/>)</xsp:expr>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xspdoc:desc>returns the value of the given column as true or
false</xspdoc:desc>
+<xsl:template match="esql:row-results//esql:get-boolean">
+ <xsp:expr><xsl:call-template
name="get-resultset"/>.getBoolean(<xsl:call-template
name="get-column"/>)</xsp:expr>
+</xsl:template>
+
+<xspdoc:desc>returns the value of the given column as a double. if a format
attribute exists, its value is taken to be a decimal format string as defined
in java.text.DecimalFormat, and the result is formatted
accordingly.</xspdoc:desc>
+<xsl:template match="esql:row-results//esql:get-double">
+ <xsl:choose>
+ <xsl:when test="@format">
+ <xsp:expr>new DecimalFormat("<xsl:value-of
select="@format"/>").format(new Double(<xsl:call-template
name="get-resultset"/>.getDouble(<xsl:call-template
name="get-column"/>)))</xsp:expr>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsp:expr><xsl:call-template
name="get-resultset"/>.getDouble(<xsl:call-template
name="get-column"/>)</xsp:expr>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xspdoc:desc>returns the value of the given column as a float. if a format
attribute exists, its value is taken to be a decimal format string as defined
in java.text.DecimalFormat, and the result is formatted
accordingly.</xspdoc:desc>
+<xsl:template match="esql:row-results//esql:get-float">
+ <xsl:choose>
+ <xsl:when test="@format">
+ <xsp:expr>new DecimalFormat("<xsl:value-of
select="@format"/>").format(new Float(<xsl:call-template
name="get-resultset"/>.getFloat(<xsl:call-template
name="get-column"/>)))</xsp:expr>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsp:expr><xsl:call-template
name="get-resultset"/>.getFloat(<xsl:call-template
name="get-column"/>)</xsp:expr>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xspdoc:desc>returns the value of the given column as an
integer</xspdoc:desc>
+<xsl:template match="esql:row-results//esql:get-int">
+ <xsp:expr><xsl:call-template
name="get-resultset"/>.getInt(<xsl:call-template name="get-column"/>)</xsp:expr>
+</xsl:template>
+
+<xspdoc:desc>returns the value of the given column as a long</xspdoc:desc>
+<xsl:template match="esql:row-results//esql:get-long">
+ <xsp:expr><xsl:call-template
name="get-resultset"/>.getLong(<xsl:call-template
name="get-column"/>)</xsp:expr>
+</xsl:template>
+
+<xspdoc:desc>returns the value of the given column as a short</xspdoc:desc>
+<xsl:template match="esql:row-results//esql:get-short">
+ <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 interpeted as an xml
fragment.
+ The fragment is parsed by the default xsp parser and the document element
is returned.
+ If a root attribute exists, its value is taken to be the name of an element
to wrap around the contents of
+ the fragment before parsing.</xspdoc:desc>
+<xsl:template match="esql:row-results//esql:get-xml">
+ <xsl:variable name="content">
+ <xsl:choose>
+ <xsl:when test="@root">
+ <!-- <xsl:call-template name="add-xml-decl"> not needed -->
+ <xsl:text>"<</xsl:text>
+ <xsl:value-of select="@root"/>
+ <xsl:text>>"+</xsl:text>
+ <xsl:call-template name="get-string"/>
+ <xsl:text>+"</</xsl:text>
+ <xsl:value-of select="@root"/>
+ <xsl:text>>"</xsl:text>
</xsl:when>
<xsl:otherwise>
- <xsp:expr><xsl:call-template
name="get-resultset"/>.getFloat(<xsl:call-template
name="get-column"/>)</xsp:expr>
+ <!-- <xsl:call-template name="add-xml-decl"> not needed -->
+ <xsl:call-template name="get-string"/>
</xsl:otherwise>
</xsl:choose>
- </xsl:template>
-
- <!-- =========================================================== -->
-
- <xspdoc:desc>
- Returns the value of the given column as an integer
- </xspdoc:desc>
-
- <xsl:template match="esql:results//esql:get-int">
- <xsp:expr><xsl:call-template
name="get-resultset"/>.getInt(<xsl:call-template name="get-column"/>)</xsp:expr>
- </xsl:template>
-
- <!-- =========================================================== -->
-
- <xspdoc:desc>
- Returns the value of the given column as a long
- </xspdoc:desc>
-
- <xsl:template match="esql:results//esql:get-long">
- <xsp:expr><xsl:call-template
name="get-resultset"/>.getLong(<xsl:call-template
name="get-column"/>)</xsp:expr>
- </xsl:template>
-
- <!-- =========================================================== -->
-
- <xspdoc:desc>
- Returns the value of the given column as a short
- </xspdoc:desc>
-
- <xsl:template match="esql:results//esql:get-short">
- <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 interpeted as an xml
- fragment. the fragment is parsed by the default xsp parser and the
- document element is returned. if a root attribute exists, its
- value is taken to be the name of an element to wrap around the
- contents of the fragment before parsing.
- </xspdoc:desc>
-
- <xsl:template match="esql:results//esql:get-xml">
- <xsl:variable name="content">
+ </xsl:variable>
+ <xsl:choose>
+ <xsl:when test="$environment = 'cocoon1'">
+ <xsp:expr>this.xspParser.parse(new InputSource(new
StringReader(<xsl:copy-of select="$content"/>))).getDocumentElement()</xsp:expr>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsp:logic>
+ throw new RuntimeException("esql:get-xml is not supported in this
environment: "+<xsl:value-of select="$environment"/>);
+ </xsp:logic>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xspdoc:desc>returns the position of the current row in the result
set</xspdoc:desc>
+<xsl:template
match="esql:row-results//esql:get-row-position|esql:results//esql:get-row-position">
+ <xsp:expr>_esql_query.position</xsp:expr>
+</xsl:template>
+
+<xspdoc:desc>returns the name of the given column. the column mus tbe
specified by number, not name.</xspdoc:desc>
+<xsl:template match="esql:row-results//esql:get-column-name">
+ <xsp:expr><xsl:call-template
name="get-resultset"/>.getMetaData().getColumnName(<xsl:value-of
select="@column"/>)</xsp:expr>
+</xsl:template>
+
+<xspdoc:desc>returns the label of the given column. the column mus tbe
specified by number, not name.</xspdoc:desc>
+<xsl:template match="esql:row-results//esql:get-column-label">
+ <xsp:expr><xsl:call-template
name="get-resultset"/>.getMetaData().getColumnLabel(<xsl:value-of
select="@column"/>)</xsp:expr>
+</xsl:template>
+
+<xspdoc:desc>returns the name of the type of the given column. the column
must be specified by number, not name.</xspdoc:desc>
+<xsl:template match="esql:row-results//esql:get-column-type-name">
+ <xsp:expr><xsl:call-template
name="get-resultset"/>.getMetaData().getColumnTypeName(<xsl:value-of
select="@column"/>)</xsp:expr>
+</xsl:template>
+
+<xspdoc:desc>returns the message of the current exception</xspdoc:desc>
+<xsl:template match="esql:error-results//esql:get-message">
+ <xsp:expr>_esql_exception.getMessage()</xsp:expr>
+</xsl:template>
+
+<xspdoc:desc>returns the current exception as a string</xspdoc:desc>
+<xsl:template match="esql:error-results//esql:to-string">
+ <xsp:expr>_esql_exception.toString()</xsp:expr>
+</xsl:template>
+
+<xspdoc:desc>returns the stacktrace of the current exception</xspdoc:desc>
+<xsl:template match="esql:error-results//esql:get-stacktrace">
+ <xsp:expr>_esql_exception_writer.toString()</xsp:expr>
+</xsl:template>
+
+<xsl:template name="get-resultset">
+ <xsl:call-template name="get-query"/><xsl:text>.resultset</xsl:text>
+</xsl:template>
+
+<xsl:template name="get-query">
+ <xsl:choose>
+ <xsl:when test="@ancestor">
+
<xsl:text>((EsqlQuery)_esql_queries.elementAt(_esql_queries.size()-</xsl:text>
+ <xsl:value-of select="@ancestor"/>
+ <xsl:text>))</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>_esql_query</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<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:choose>
+ <xsl:when test="@column">
<xsl:choose>
- <xsl:when test="@root">
- <xsl:text>"<</xsl:text>
- <xsl:value-of select="@root"/>
- <xsl:text>>"+</xsl:text>
- <xsl:call-template name="get-string"/>
- <xsl:text>+"</</xsl:text>
- <xsl:value-of select="@root"/>
- <xsl:text>>"</xsl:text>
+ <xsl:when test="not(string(number(@column))='NaN')">
+ <xsl:value-of select="@column"/>
</xsl:when>
<xsl:otherwise>
- <xsl:call-template name="get-string"/>
+ <xsl:text>"</xsl:text>
+ <xsl:value-of select="@column"/>
+ <xsl:text>"</xsl:text>
</xsl:otherwise>
</xsl:choose>
- </xsl:variable>
-
- <xsp:expr>this.xspParser.parse(new InputSource(new
StringReader(<xsl:copy-of select="$content"/>))).getDocumentElement()</xsp:expr>
- </xsl:template>
-
- <!-- =========================================================== -->
-
- <xspdoc:desc>
- Returns the position of the current row in the result set
- </xspdoc:desc>
-
- <xsl:template match="esql:results//esql:get-row-number">
- <xsp:expr>esqlSession.count</xsp:expr>
- </xsl:template>
-
- <!-- =========================================================== -->
-
- <xspdoc:desc>
- Returns the name of the given column. the column mus tbe specified
- by number, not name.
- </xspdoc:desc>
-
- <xsl:template match="esql:results//esql:get-column-name">
- <xsp:expr><xsl:call-template
name="get-resultset"/>.getMetaData().getColumnName(<xsl:value-of
select="@column"/>)</xsp:expr>
- </xsl:template>
-
- <!-- =========================================================== -->
-
- <xspdoc:desc>
- Returns the label of the given column. the column mus the
- specified by number, not name.
- </xspdoc:desc>
-
- <xsl:template match="esql:results//esql:get-column-label">
- <xsp:expr><xsl:call-template
name="get-resultset"/>.getMetaData().getColumnLabel(<xsl:value-of
select="@column"/>)</xsp:expr>
- </xsl:template>
-
- <!-- =========================================================== -->
-
- <xspdoc:desc>
- Returns the name of the type of the given column. the column must
- be specified by number, not name.
- </xspdoc:desc>
-
- <xsl:template match="esql:results//esql:get-column-type-name">
- <xsp:expr><xsl:call-template
name="get-resultset"/>.getMetaData().getColumnTypeName(<xsl:value-of
select="@column"/>)</xsp:expr>
- </xsl:template>
-
- <!-- =========================================================== -->
-
- <xspdoc:desc>
- Returns the message of the current exception
- </xspdoc:desc>
-
- <xsl:template match="esql:error-results//esql:get-message">
- <xsp:expr>esqlException.getMessage()</xsp:expr>
- </xsl:template>
-
- <!-- =========================================================== -->
-
- <xspdoc:desc>
- Returns the current exception as a string
- </xspdoc:desc>
-
- <xsl:template match="esql:error-results//esql:to-string">
- <xsp:expr>esqlException.toString()</xsp:expr>
- </xsl:template>
-
- <!-- =========================================================== -->
-
- <xspdoc:desc>
- Returns the stacktrace of the current exception
- </xspdoc:desc>
-
- <xsl:template match="esql:error-results//esql:get-stacktrace">
- <xsp:expr>esqlException_writer.toString()</xsp:expr>
- </xsl:template>
-
- <xsl:template name="get-resultset">
- <xsl:choose>
- <xsl:when test="@ancestor">
-
<xsl:text>((EsqlSession)esqlSessions.elementAt(esqlSessions.size()-</xsl:text>
- <xsl:value-of select="@ancestor"/>
- <xsl:text>)).resultset</xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text>esqlSession.resultset</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
-
- <!-- =========================================================== -->
-
- <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:choose>
- <xsl:when test="@column">
- <xsl:choose>
- <xsl:when test="not(string(number(@column))='NaN')">
- <xsl:value-of select="@column"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text>"</xsl:text>
- <xsl:value-of select="@column"/>
- <xsl:text>"</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:when test="esql:column">
- <xsl:call-template name="get-nested-string">
- <xsl:with-param name="content" select="esql:column"/>
- </xsl:call-template>
- </xsl:when>
- </xsl:choose>
- </xsl:template>
+ </xsl:when>
+ <xsl:when test="esql:column">
+ <xsl:call-template name="get-nested-string">
+ <xsl:with-param name="content" select="esql:column"/>
+ </xsl:call-template>
+ </xsl:when>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="get-string-encoded">
+ <xsl:param name="column-spec"/>
+ <xsl:param name="resultset"/>
+ <xsl:choose>
+ <xsl:when test="@encoding">
+ new String (<xsl:value-of select="$resultset"/>.getBytes
+ (<xsl:value-of select="$column-spec"/>), <xsl:value-of
select="@encoding"/>)
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$resultset"/>.getString(<xsl:value-of
select="$column-spec"/>)
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<!-- added by mistake. Not needed, I think - RDG
+<xsl:template name="add-xml-decl">
+ <xsl:choose>
+ <xsl:when test="@encoding">
+ "<?xml version=\"1.0\" encoding=\"<xsl:value-of
select="@encoding"/>\"?>"
+ </xsl:when>
+ <xsl:otherwise>
+ "<?xml version=\"1.0\"?>"
+ </xsl:otherwise>
+ </xsl:choose>
+ +
+</xsl:template>
+-->
- <xsl:template match="@*|*|text()|processing-instruction()">
- <xsl:copy>
- <xsl:apply-templates select="@*|*|text()|processing-instruction()"/>
- </xsl:copy>
- </xsl:template>
+<xsl:template match="@*|node()" priority="-1">
+ <xsl:copy>
+ <xsl:apply-templates select="@*|node()"/>
+ </xsl:copy>
+</xsl:template>
</xsl:stylesheet>