You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by ha...@apache.org on 2002/06/04 11:06:54 UTC
cvs commit: xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java esql.xsl
haul 2002/06/04 02:06:54
Modified: src/java/org/apache/cocoon/components/language/markup/xsp
EsqlQuery.java
src/java/org/apache/cocoon/components/language/markup/xsp/java
esql.xsl
Log:
Improvements on nested groups.
Renamed tag (special case only) to esql:use-results
Revision Changes Path
1.17 +46 -14 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/EsqlQuery.java
Index: EsqlQuery.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/EsqlQuery.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- EsqlQuery.java 17 May 2002 14:30:53 -0000 1.16
+++ EsqlQuery.java 4 Jun 2002 09:06:53 -0000 1.17
@@ -66,7 +66,7 @@
*
* based on the orginal esql.xsl
* @author <a href="mailto:tcurdt@dff.st">Torsten Curdt</a>
- * @version CVS $Id: EsqlQuery.java,v 1.16 2002/05/17 14:30:53 haul Exp $
+ * @version CVS $Id: EsqlQuery.java,v 1.17 2002/06/04 09:06:53 haul Exp $
*/
public class EsqlQuery {
@@ -78,7 +78,8 @@
private ResultSet resultSet = null;
private ResultSetMetaData resultSetMetaData = null;
private int updateCount = EsqlQuery.UPDATE_COUNT_UNSET;
- private int resultCount = 1;
+ private int updateCountCount = 0;
+ private int resultCount = 0;
private boolean hasResultSet = false;
private boolean resultSetValid = false;
private int position = -1;
@@ -88,6 +89,7 @@
private ArrayList groups = null;
private int groupLevel = -1;
+ private int changeLevel = -1;
private String query;
private int limitMethod;
@@ -229,7 +231,6 @@
keepgoing = still;
}
-
public void groupLevelPlusPlus() {
this.groupLevel++;
}
@@ -250,12 +251,26 @@
}
public boolean hasGroupingVarChanged() throws SQLException {
- Object tmp = this.getResultSet().getObject(((EsqlGroup)this.groups.get(this.groupLevel)).var);
- if (tmp.equals(((EsqlGroup)this.groups.get(groupLevel)).value)) {
- return false;
+ if (this.changeLevel != -1) {
+ if (this.changeLevel < this.groupLevel) {
+ return true;
+ } else {
+ this.changeLevel = -1;
+ return true;
+ }
} else {
- ((EsqlGroup)this.groups.get(groupLevel)).value = tmp;
- return true;
+ boolean result = false;
+ // need to check the complete hierarchy of nested groups for changes
+ for (int i = 0; i <= this.groupLevel; i++) {
+ Object tmp = this.getResultSet().getObject(((EsqlGroup)this.groups.get(i)).var);
+ if (!tmp.equals(((EsqlGroup)this.groups.get(i)).value)) {
+ ((EsqlGroup)this.groups.get(i)).value = tmp;
+ result = true;
+ if (this.changeLevel == -1 && this.groupLevel != i)
+ this.changeLevel = i;
+ }
+ }
+ return result;
}
}
@@ -279,26 +294,43 @@
}
public int getUpdateCount() throws SQLException {
- if (this.updateCount == EsqlQuery.UPDATE_COUNT_UNSET) {
- this.updateCount = this.statement.getUpdateCount();
- }
return this.updateCount;
}
+ public int getUpdateCountCount() {
+ return this.updateCountCount;
+ }
+
public int getResultCount() {
return this.resultCount;
}
+ /**
+ * retrieve next result, check whether it is an result set or an
+ * update count. Set instance vars accordingly and update
+ * counters.
+ */
public boolean getMoreResults() throws SQLException {
- this.updateCount=EsqlQuery.UPDATE_COUNT_UNSET;
if (this.statement==null)
return false;
this.hasResultSet = this.statement.getMoreResults();
- this.updateCount=this.getUpdateCount();
- this.resultCount++;
this.resultSetValid=false;
+ this.adjustCounts();
return (this.hasResultSet || (this.updateCount>-1));
}
+
+
+ /**
+ * update counters for result sets and update counts
+ */
+ protected void adjustCounts() throws SQLException {
+ this.updateCount=this.statement.getUpdateCount();
+ if (this.hasResultSet) {
+ this.resultCount++;
+ } else {
+ this.updateCountCount++;
+ }
+ };
public boolean execute() throws SQLException {
return this.execute(false);
1.27 +15 -11 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.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- esql.xsl 24 May 2002 12:40:23 -0000 1.26
+++ esql.xsl 4 Jun 2002 09:06:53 -0000 1.27
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
-<!-- $Id: esql.xsl,v 1.26 2002/05/24 12:40:23 haul Exp $-->
+<!-- $Id: esql.xsl,v 1.27 2002/06/04 09:06:53 haul Exp $-->
<!--
============================================================================
@@ -56,7 +56,7 @@
* ESQL Logicsheet
*
* @author ?
- * @version CVS $Revision: 1.26 $ $Date: 2002/05/24 12:40:23 $
+ * @version CVS $Revision: 1.27 $ $Date: 2002/06/04 09:06:53 $
-->
<xsl:stylesheet version="1.0"
@@ -406,9 +406,8 @@
break;
</xsl:for-each>
}
- }
- else {
- switch (_esql_query.getResultCount()) {
+ } else {
+ switch (_esql_query.getUpdateCountCount()) {
<xsl:for-each select="esql:no-results">
case <xsl:value-of select="position()"/>: <xsl:if test="position()=last()"><xsl:text>
default: </xsl:text></xsl:if><xsl:apply-templates select="."/>
@@ -419,7 +418,7 @@
_esql_query.getResultSet().close();
} else {
if (_esql_query.getUpdateCount() >= 0) {
- switch (_esql_query.getResultCount()) {
+ switch (_esql_query.getUpdateCountCount()) {
<xsl:for-each select="esql:update-results">
case <xsl:value-of select="position()"/>: <xsl:if test="position()=last()"><xsl:text>
default: </xsl:text></xsl:if><xsl:apply-templates select="."/>
@@ -427,7 +426,7 @@
</xsl:for-each>
}
} else {
- switch (_esql_query.getResultCount()) {
+ switch (_esql_query.getUpdateCountCount()) {
<xsl:for-each select="esql:no-results">
case <xsl:value-of select="position()"/>: <xsl:if test="position()=last()"><xsl:text>
default: </xsl:text></xsl:if><xsl:apply-templates select="."/>
@@ -623,7 +622,7 @@
-<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>
+<xspdoc:desc>Allows header 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:member">
<xsp:logic>
do {
@@ -636,7 +635,7 @@
</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>
+<xspdoc:desc>Used in conjunction with and nested inside esql:group. Formatting for individual records goes within esql:member. Header stuff goes in between group and member.</xspdoc:desc>
<xsl:template match="esql:group">
<xsl:variable name="group">
<xsl:call-template name="get-column">
@@ -947,14 +946,19 @@
<xsl:template match="esql:result"/>
-<xspdoc:desc>creates a nested query like block that uses the result set obtained from a column as current result set. Only row-results and no-results are supported as nested elements (i.e. more-results is not supported).</xspdoc:desc>
+<xspdoc:desc>creates a nested query like block that uses the result set obtained from a column as current result set. This version is deprecated, please use <esql:use-result> instead.</xspdoc:desc>
<xsl:template match="esql:row-results//esql:results[child::esql:result]|esql:call-results//esql:results[child::esql:result]">
+ <xsl:call-template name="use-results"/>
+</xsl:template>
+
+<xspdoc:desc>creates a nested query like block that uses the result set obtained from a column as current result set.</xspdoc:desc>
+<xsl:template name="use-results" match="esql:use-results[child::esql:result]">
<xsp:logic>
// nested result set
if (_esql_query != null) {
_esql_queries.push(_esql_query);
}
- _esql_query = new EsqlQuery((ResultSet) <xsl:apply-templates select="esql:result/*"/>);
+ _esql_query = new EsqlQuery((ResultSet) <xsl:apply-templates select="esql:result/*"/>);
{
<xsl:call-template name="do-results"/>
}
----------------------------------------------------------------------
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