balld 00/09/28 21:25:20
Modified: . changes.xml
src/org/apache/cocoon/processor/xsp/library/sql esql.xsl
samples/sql esql.xml
Log:
a doozy of a patch to esql - i made it so that you can execute queries
eitherin their own special methods or inlined code - both on the same page even
(can't imagine why you'd want to tho).
syntax is documented in sample - all you do is add a inner-method attribute
valued 'no'. default is 'yes', but i'm definitely considering switching it.
Revision Changes Path
1.118 +4 -1 xml-cocoon/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/xml-cocoon/changes.xml,v
retrieving revision 1.117
retrieving revision 1.118
diff -u -r1.117 -r1.118
--- changes.xml 2000/09/28 01:52:32 1.117
+++ changes.xml 2000/09/29 04:25:19 1.118
@@ -4,7 +4,7 @@
<!--
History of Cocoon changes
- $Id: changes.xml,v 1.117 2000/09/28 01:52:32 balld Exp $
+ $Id: changes.xml,v 1.118 2000/09/29 04:25:19 balld Exp $
-->
<changes title="History of Changes">
@@ -17,6 +17,9 @@
</devs>
<release version="@version@" date="@date@">
+ <action dev="DB" type="update">
+ a doozy of a patch to esql - i made it so that you can execute queries
either in their own special methods or inlined code - both on the same page
even (can't imagine why you'd want to tho)
+ </action>
<action dev="DB" type="update">
a couple of bugs fixed in esql, plus i added the first bit of prepared
statement support. nothing but strings yet, but it works.
</action>
1.17 +28 -7
xml-cocoon/src/org/apache/cocoon/processor/xsp/library/sql/esql.xsl
Index: esql.xsl
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/processor/xsp/library/sql/esql.xsl,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- esql.xsl 2000/09/28 01:52:35 1.16
+++ esql.xsl 2000/09/29 04:25:19 1.17
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
-<!-- $Id: esql.xsl,v 1.16 2000/09/28 01:52:35 balld Exp $-->
+<!-- $Id: esql.xsl,v 1.17 2000/09/29 04:25:19 balld Exp $-->
<!--
============================================================================
@@ -121,7 +121,11 @@
int skip_rows;
}
</xsp:logic>
- <xsl:apply-templates select=".//esql:execute-query"
mode="generate-method"/>
+ <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>
@@ -145,10 +149,20 @@
<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">
- <xsp:logic>_esql_execute_query_<xsl:value-of
select="generate-id(.)"/>(request,response,document,xspParentNode,xspCurrentNode,xspNodeStack,session,_esql_sessions,_esql_session);</xsp:logic>
+ <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>_esql_execute_query_<xsl:value-of
select="generate-id(.)"/>(request,response,document,xspParentNode,xspCurrentNode,xspNodeStack,session,_esql_sessions,_esql_session);</xsp:logic>
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:template>
-<xsl:template match="esql:execute-query" mode="generate-method">
+<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"/>
@@ -195,6 +209,8 @@
</xsl:call-template>
</xsl:variable>
<xsp:logic>
+ <xsl:choose>
+ <xsl:when test="$inner-method='yes'">
void _esql_execute_query_<xsl:value-of select="generate-id(.)"/>(
HttpServletRequest request,
HttpServletResponse response,
@@ -205,6 +221,11 @@
HttpSession session,
Stack _esql_sessions,
EsqlSession _esql_session) throws Exception {
+ </xsl:when>
+ <xsl:when test="$inner-method='no'">
+ {
+ </xsl:when>
+ </xsl:choose>
if (_esql_session != null) {
_esql_sessions.push(_esql_session);
}
@@ -271,9 +292,9 @@
}
}
}
- boolean _esql_results = false;
+ boolean _esql_results_<xsl:value-of select="generate-id(.)"/> =
false;
while (_esql_session.resultset.next()) {
- _esql_results = true;
+ _esql_results_<xsl:value-of select="generate-id(.)"/> = true;
<xsl:apply-templates select="esql:results/*"/>
if (_esql_session.max_rows != -1 && _esql_session.count
- _esql_session.skip_rows == _esql_session.max_rows-1) {
break;
@@ -286,7 +307,7 @@
} else if (_esql_session.prepared_statement != null) {
_esql_session.prepared_statement.close();
}
- if (!_esql_results) {
+ if (!_esql_results_<xsl:value-of select="generate-id(.)"/>) {
<xsl:apply-templates select="esql:no-results/*"/>
}
} catch (Exception _esql_exception) {
1.4 +2 -2 xml-cocoon/samples/sql/esql.xml
Index: esql.xml
===================================================================
RCS file: /home/cvs/xml-cocoon/samples/sql/esql.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- esql.xml 2000/09/28 01:52:34 1.3
+++ esql.xml 2000/09/29 04:25:20 1.4
@@ -12,7 +12,7 @@
<page>
-<esql:execute-query>
+<esql:execute-query inner-method="no">
<esql:driver>postgresql.Driver</esql:driver>
<esql:dburl>jdbc:postgresql://localhost/test</esql:dburl>
<esql:username>test</esql:username>
@@ -23,7 +23,7 @@
<id><esql:get-string column="id"/></id>
<name><esql:get-string column="name"/></name>
<employees>
- <esql:execute-query>
+ <esql:execute-query inner-method="no">
<esql:query>select * from employee_table where department_id =
<esql:get-string column="id" ancestor="1"/></esql:query>
<esql:results>
<employee>