morgand 01/03/06 13:19:42
Modified: jdbc/conf jdbc.tld
jdbc/doc/web index.html
jdbc/examples/web jdbc.jsp jndijdbc.jsp
jdbc/src/org/apache/taglibs/jdbc/connection JndiNameTag.java
jdbc/src/org/apache/taglibs/jdbc/preparedstatement
PreparedStatementImplTag.java
jdbc/src/org/apache/taglibs/jdbc/resultset ResultSetTag.java
jdbc/src/org/apache/taglibs/jdbc/statement
StatementImplTag.java StatementTag.java
Log:
added wasEmpty, wasNotEmpty and rowCount tags, fixed
capitalization of jndiName tag, updated docs and examples
Revision Changes Path
1.9 +34 -1 jakarta-taglibs/jdbc/conf/jdbc.tld
Index: jdbc.tld
===================================================================
RCS file: /home/cvs/jakarta-taglibs/jdbc/conf/jdbc.tld,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- jdbc.tld 2001/03/04 18:58:22 1.8
+++ jdbc.tld 2001/03/06 21:19:27 1.9
@@ -89,7 +89,7 @@
</tag>
<tag>
- <name>jndiname</name>
+ <name>jndiName</name>
<tagclass>org.apache.taglibs.jdbc.connection.JndiNameTag</tagclass>
<bodycontent>JSP</bodycontent>
<info>Sets the jndi named javax.sql.DataSource for the enclosing
@@ -202,6 +202,39 @@
</attribute>
</tag>
+ <tag>
+ <name>wasEmpty</name>
+ <tagclass>org.apache.taglibs.jdbc.statement.WasEmptyTag</tagclass>
+ <bodycontent>JSP</bodycontent>
+ <info>
+ Executes its body if the last ResultSet tag received 0 rows
+ from the database. You must be after a ResultSet tag and inside
+ a StatementTag or PreparedStatementTag, or an error will be generated.
+ </info>
+ </tag>
+
+ <tag>
+ <name>wasNotEmpty</name>
+ <tagclass>org.apache.taglibs.jdbc.statement.WasNotEmptyTag</tagclass>
+ <bodycontent>JSP</bodycontent>
+ <info>
+ Executes its body if the last ResultSet tag received more than 0 rows
+ from the database. You must be after a ResultSet tag and inside
+ a StatementTag or PreparedStatementTag, or an error will be generated.
+ </info>
+ </tag>
+
+ <tag>
+ <name>rowCount</name>
+ <tagclass>org.apache.taglibs.jdbc.statement.RowCountTag</tagclass>
+ <bodycontent>empty</bodycontent>
+ <info>Prints out the number of rows retrieved from the database.
+It can be used inside a ResultSet tag to provide a running
+count of rows retreived, or after the ResultSet tag to
+display the total number. Using the tag before the ResultSet
+or outside of a Statement or PreparedStatement will
+produce an error.</info>
+ </tag>
<!-- prepared statement only tags -->
<tag>
1.8 +272 -7 jakarta-taglibs/jdbc/doc/web/index.html
Index: index.html
===================================================================
RCS file: /home/cvs/jakarta-taglibs/jdbc/doc/web/index.html,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- index.html 2001/03/04 18:58:38 1.7
+++ index.html 2001/03/06 21:19:30 1.8
@@ -143,7 +143,7 @@
<p>The Connection tag also accepts a JNDI named JDBC DataSource.</p>
<pre><%-- open a database connection --%>
-<sql:connection id="conn1" jndiName="java:/comp/jdbc/test"/>
+<sql:connection id="conn1" jndiName="java:/comp/jdbc/test"/></pre>
<P><B>Closing connections</B></P>
@@ -202,6 +202,25 @@
<p>All statements and preparedStatements automatically trim whitespace from the
body.</p>
+<p><b>"wasEmpty" and "wasNotEmpty" tags</b></p>
+
+<p>The "wasEmpty" tag only executes its body if the last ResultSet
+tag received 0 rows from the database. You must be after a ResultSet tag and
+inside a StatementTag or PreparedStatementTag, or an error will be generated.
+The "wasNotEmpty" tag executes its body if the last ResultSet
+received <i>more than</i> 0 rows from the database.
+See the <A HREF="#summary">Tag Reference</A> for examples.</p>
+
+<p><b>"rowCount" tag</b></p>
+
+<p>The "rowCount" tag prints out the number of rows retrieved from the database.
+It can be used inside a ResultSet tag to provide a running
+count of rows retreived, or after the ResultSet tag to
+display the total number. See the <A HREF="#summary">Tag Reference</A> for
examples.
+Using the tag before the ResultSet
+or outside of a Statement or PreparedStatement will
+produce an error.</p>
+
<A NAME="overview.tags.preparedstatement"><h3>PreparedStatement Tags</h3></A>
<P>"Prepared statements" are a somewhat more advanced format for generating SQL
@@ -272,9 +291,12 @@
<p>The "wasNull" tag only executes its body if the previous "getColumn" tag
encountered a
null value in the database. You can only use the "wasNull" tag if you are
-inside a resultset and if a "getColumn" tag has already been executed. wasNotNull
-executes its body if the previous getColumn tag did <i>not</i> produce a null.</p>
+inside a resultset and if a "getColumn" tag has already been executed. The
+"wasNotNull" tag
+executes its body if the previous getColumn tag did <i>not</i> produce a null.
+See the <A HREF="#summary">Tag Reference</A> for examples.</p>
+
<p><b>"getColumn" tag</b></p>
<p>The getColumn tag performs one of two functions. You may either:</p>
@@ -431,7 +453,7 @@
<TD>JDBC driver for the database</TD>
</TR>
<TR>
- <TD><A HREF="#jndiname">jndiname</A></TD>
+ <TD><A HREF="#jndiName">jndiName</A></TD>
<TD>name of a JNDI JDBC DataSource</TD>
</TR>
<TR>
@@ -473,6 +495,18 @@
<TR>
<TD><A HREF="#execute">execute</A></TD>
<TD>execute an insert, update or delete statement</TD>
+ </TR>
+ <TR>
+ <TD><A HREF="#wasEmpty">wasEmpty</A></TD>
+ <TD>executes its body if the last ResultSet tag returned no rows</TD>
+ </TR>
+ <TR>
+ <TD><A HREF="#wasNotEmpty">wasNotEmpty</A></TD>
+ <TD>executes its body if the last ResultSet tag returned some rows</TD>
+ </TR>
+ <TR>
+ <TD><A HREF="#rowCount">rowCount</A></TD>
+ <TD>prints the number of rows retrieved from the database</TD>
</TR>
<TR>
<TD COLSPAN="2"> </TD>
@@ -762,7 +796,7 @@
<TD COLSPAN="2">
<TABLE BORDER="0" BGCOLOR="#CCCCCC" WIDTH="100%" CELLSPACING="0">
<TR>
- <TD><B><FONT SIZE="+1"><A NAME="jndiname"> jndiname</A></FONT></B></TD>
+ <TD><B><FONT SIZE="+1"><A NAME="jndiName"> jndiName</A></FONT></B></TD>
<TD ALIGN="RIGHT">Availability: version 1.0 </TD>
</TR>
</TABLE>
@@ -820,12 +854,12 @@
<TD WIDTH="80%"><BR>
<PRE><%-- example 1: using the tag body --%>
<sql:connection id="conn1">
- <sql:jndiname>java:/comp/jdbc/test</sql:jndiname>
+ <sql:jndiName>java:/comp/jdbc/test</sql:jndiName>
</sql:connection>
<%-- example 2: using an init parameter --%>
<sql:connection id="conn1">
- <sql:jndiname initParameter="jndiDataSource"/>
+ <sql:jndiName initParameter="jndiDataSource"/>
</sql:connection></PRE>
</TD>
</TR>
@@ -1450,6 +1484,237 @@
<%-- execute the query --%>
<sql:execute/>
</sql:statement></pre>
+ </TD>
+ </TR>
+ </TABLE>
+ </TD>
+ </TR>
+</TABLE>
+
+<TABLE BORDER="0" WIDTH="90%" CELLPADDING="3" CELLSPACING="0">
+ <TR>
+ <TD COLSPAN="2">
+ <TABLE BORDER="0" BGCOLOR="#CCCCCC" WIDTH="100%" CELLSPACING="0">
+ <TR>
+ <TD><B><FONT SIZE="+1"><A NAME="wasEmpty"> wasEmpty</A></FONT></B></TD>
+ <TD ALIGN="RIGHT">Availability: version 1.0 </TD>
+ </TR>
+ </TABLE>
+ </TD>
+ </TR>
+ <TR>
+ <TD COLSPAN="3">Executes its body if the last ResultSet tag received 0 rows
+ from the database. You must be after a ResultSet tag and inside
+ a StatementTag or PreparedStatementTag, or an error will be generated.
+ </TD>
+ </TR>
+ <TR>
+ <TD WIDTH="2%"> </TD>
+ <TD WIDTH="98%">
+ <TABLE BORDER="0" WIDTH="100%">
+ <TR>
+ <TD WIDTH="20%"><B>Tag Body</B></TD>
+ <TD WIDTH="80%">JSP</TD>
+ </TR>
+ <TR>
+ <TD WIDTH="20%"><B>Script Variable</B></TD>
+ <TD WIDTH="80%">No</TD>
+ </TR>
+ <TR>
+ <TD WIDTH="20%"><B>Restrictions</B></TD>
+ <TD WIDTH="80%">Use inside a statement or preparedStatement tag and
+ after a ResultSet tag.</TD>
+ </TR>
+ <TR>
+ <TD WIDTH="20%"><B>Attributes</B></TD>
+ <TD WIDTH="80%">None</TD>
+ </TR>
+ <TR>
+ <TD WIDTH="20%"><B>Properties</B></TD>
+ <TD>None</TD>
+ </TR>
+ <TR>
+ <TD WIDTH="20%" VALIGN="TOP"><B>Example</B></TD>
+ <TD WIDTH="80%"><BR>
+<pre><%-- showing the contents of the table --%>
+<table>
+<tr><th>id</th><th>name</th><th>description</th></tr>
+<sql:preparedStatement id="stmt6" conn="conn1">
+ <sql:query>
+ select id, name, description from test_books
+ </sql:query>
+ <sql:resultSet id="rset4">
+ <tr>
+ <td><sql:getColumn position="1"/></td>
+ <td><sql:getColumn position="2"/></td>
+ <td><sql:getColumn position="3" to="description"/></td>
+ </tr>
+ </sql:resultSet>
+ <tr>
+ <td colspan="3">
+ <%-- show different text, depending on whether or not
+ any rows were retrieved --%>
+ <sql:wasEmpty>No rows retrieved.</sql:wasEmpty>
+ <sql:wasNotEmpty><sql:rowCount/> rows retrieved.</sql:wasNotEmpty>
+ </td>
+ </tr>
+</sql:preparedStatement>
+</table></pre>
+ </TD>
+ </TR>
+ </TABLE>
+ </TD>
+ </TR>
+</TABLE>
+
+<TABLE BORDER="0" WIDTH="90%" CELLPADDING="3" CELLSPACING="0">
+ <TR>
+ <TD COLSPAN="2">
+ <TABLE BORDER="0" BGCOLOR="#CCCCCC" WIDTH="100%" CELLSPACING="0">
+ <TR>
+ <TD><B><FONT SIZE="+1"><A
NAME="wasNotEmpty"> wasNotEmpty</A></FONT></B></TD>
+ <TD ALIGN="RIGHT">Availability: version 1.0 </TD>
+ </TR>
+ </TABLE>
+ </TD>
+ </TR>
+ <TR>
+ <TD COLSPAN="3">Executes its body if the last ResultSet tag received more than 0
rows
+ from the database. You must be after a ResultSet tag and inside
+ a StatementTag or PreparedStatementTag, or an error will be generated.
+ </TD>
+ </TR>
+ <TR>
+ <TD WIDTH="2%"> </TD>
+ <TD WIDTH="98%">
+ <TABLE BORDER="0" WIDTH="100%">
+ <TR>
+ <TD WIDTH="20%"><B>Tag Body</B></TD>
+ <TD WIDTH="80%">JSP</TD>
+ </TR>
+ <TR>
+ <TD WIDTH="20%"><B>Script Variable</B></TD>
+ <TD WIDTH="80%">No</TD>
+ </TR>
+ <TR>
+ <TD WIDTH="20%"><B>Restrictions</B></TD>
+ <TD WIDTH="80%">Use inside a statement or preparedStatement tag and
+ after a ResultSet tag.</TD>
+ </TR>
+ <TR>
+ <TD WIDTH="20%"><B>Attributes</B></TD>
+ <TD WIDTH="80%">None</TD>
+ </TR>
+ <TR>
+ <TD WIDTH="20%"><B>Properties</B></TD>
+ <TD>None</TD>
+ </TR>
+ <TR>
+ <TD WIDTH="20%" VALIGN="TOP"><B>Example</B></TD>
+ <TD WIDTH="80%"><BR>
+<pre><%-- showing the contents of the table --%>
+<table>
+<tr><th>id</th><th>name</th><th>description</th></tr>
+<sql:preparedStatement id="stmt6" conn="conn1">
+ <sql:query>
+ select id, name, description from test_books
+ </sql:query>
+ <sql:resultSet id="rset4">
+ <tr>
+ <td><sql:getColumn position="1"/></td>
+ <td><sql:getColumn position="2"/></td>
+ <td><sql:getColumn position="3" to="description"/></td>
+ </tr>
+ </sql:resultSet>
+ <tr>
+ <td colspan="3">
+ <%-- show different text, depending on whether or not
+ any rows were retrieved --%>
+ <sql:wasEmpty>No rows retrieved.</sql:wasEmpty>
+ <sql:wasNotEmpty><sql:rowCount/> rows retrieved.</sql:wasNotEmpty>
+ </td>
+ </tr>
+</sql:preparedStatement>
+</table></pre>
+ </TD>
+ </TR>
+ </TABLE>
+ </TD>
+ </TR>
+</TABLE>
+
+<TABLE BORDER="0" WIDTH="90%" CELLPADDING="3" CELLSPACING="0">
+ <TR>
+ <TD COLSPAN="2">
+ <TABLE BORDER="0" BGCOLOR="#CCCCCC" WIDTH="100%" CELLSPACING="0">
+ <TR>
+ <TD><B><FONT SIZE="+1"><A NAME="rowCount"> rowCount</A></FONT></B></TD>
+ <TD ALIGN="RIGHT">Availability: version 1.0 </TD>
+ </TR>
+ </TABLE>
+ </TD>
+ </TR>
+ <TR>
+ <TD COLSPAN="3">Prints out the number of rows retrieved from the database.
+It can be used inside a ResultSet tag to provide a running
+count of rows retreived, or after the ResultSet tag to
+display the total number. Using the tag before the ResultSet
+or outside of a Statement or PreparedStatement will
+produce an error.
+ </TD>
+ </TR>
+ <TR>
+ <TD WIDTH="2%"> </TD>
+ <TD WIDTH="98%">
+ <TABLE BORDER="0" WIDTH="100%">
+ <TR>
+ <TD WIDTH="20%"><B>Tag Body</B></TD>
+ <TD WIDTH="80%">empty</TD>
+ </TR>
+ <TR>
+ <TD WIDTH="20%"><B>Script Variable</B></TD>
+ <TD WIDTH="80%">No</TD>
+ </TR>
+ <TR>
+ <TD WIDTH="20%"><B>Restrictions</B></TD>
+ <TD WIDTH="80%">Use inside a statement or preparedStatement tag and not
+ before a ResultSet tag.</TD>
+ </TR>
+ <TR>
+ <TD WIDTH="20%"><B>Attributes</B></TD>
+ <TD WIDTH="80%">None</TD>
+ </TR>
+ <TR>
+ <TD WIDTH="20%"><B>Properties</B></TD>
+ <TD>None</TD>
+ </TR>
+ <TR>
+ <TD WIDTH="20%" VALIGN="TOP"><B>Example</B></TD>
+ <TD WIDTH="80%"><BR>
+<pre><%-- showing the contents of the table --%>
+<table>
+<tr><th>id</th><th>name</th><th>description</th></tr>
+<sql:preparedStatement id="stmt6" conn="conn1">
+ <sql:query>
+ select id, name, description from test_books
+ </sql:query>
+ <sql:resultSet id="rset4">
+ <tr>
+ <td><sql:getColumn position="1"/></td>
+ <td><sql:getColumn position="2"/></td>
+ <td><sql:getColumn position="3" to="description"/></td>
+ </tr>
+ </sql:resultSet>
+ <tr>
+ <td colspan="3">
+ <%-- show different text, depending on whether or not
+ any rows were retrieved --%>
+ <sql:wasEmpty>No rows retrieved.</sql:wasEmpty>
+ <sql:wasNotEmpty><sql:rowCount/> rows retrieved.</sql:wasNotEmpty>
+ </td>
+ </tr>
+</sql:preparedStatement>
+</table></pre>
</TD>
</TR>
</TABLE>
1.5 +61 -2 jakarta-taglibs/jdbc/examples/web/jdbc.jsp
Index: jdbc.jsp
===================================================================
RCS file: /home/cvs/jakarta-taglibs/jdbc/examples/web/jdbc.jsp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- jdbc.jsp 2001/02/09 01:08:15 1.4
+++ jdbc.jsp 2001/03/06 21:19:32 1.5
@@ -20,8 +20,9 @@
<P><B>Showing current contents of the "test_books" table</B></P>
+<!-- should be empty -->
<table>
-<tr><th>id</th><th>name</th><th>description</th></tr>
+<tr><th>id</th><th>name</th><th>description</th><th>rowCount</th></tr>
<sql:preparedStatement id="stmt2" conn="conn1">
<sql:query>
select id, name, description from test_books
@@ -32,8 +33,15 @@
<td><sql:getColumn position="1"/></td>
<td><sql:getColumn position="2"/></td>
<td><sql:getColumn position="3"/><sql:wasNull>[no
description]</sql:wasNull></td>
+ <td><sql:rowCount/></td>
</tr>
</sql:resultSet>
+ <tr>
+ <td colspan="4">
+ <sql:wasEmpty>No rows retrieved.</sql:wasEmpty>
+ <sql:wasNotEmpty><sql:rowCount/> rows retrieved.</sql:wasNotEmpty>
+ </td>
+ </tr>
</sql:preparedStatement>
</table>
@@ -63,6 +71,12 @@
<td><sql:getColumn position="3"/><sql:wasNull>[no
description]</sql:wasNull></td>
</tr>
</sql:resultSet>
+ <tr>
+ <td colspan="3">
+ <sql:wasEmpty>No rows retrieved.</sql:wasEmpty>
+ <sql:wasNotEmpty><sql:rowCount/> rows retrieved.</sql:wasNotEmpty>
+ </td>
+ </tr>
</sql:preparedStatement>
</table>
@@ -76,7 +90,13 @@
</sql:query>
<sql:resultSet id="rset3">
<sql:getColumn position="1" to="bookName"/>
+ <!-- show that rowCount works for a single row -->
+ retrieved row <sql:rowCount/>
</sql:resultSet>
+ <p>
+ <sql:wasEmpty>No rows retrieved.</sql:wasEmpty>
+ <sql:wasNotEmpty><sql:rowCount/> rows retrieved.</sql:wasNotEmpty>
+ </p>
</sql:preparedStatement>
<P><B>Inserting that title into a new row with a "preparedStatement" tag, adding
@@ -113,6 +133,12 @@
<sql:wasNull>[no description]</sql:wasNull></td>
</tr>
</sql:resultSet>
+ <tr>
+ <td colspan="3">
+ <sql:wasEmpty>No rows retrieved.</sql:wasEmpty>
+ <sql:wasNotEmpty><sql:rowCount/> rows retrieved.</sql:wasNotEmpty>
+ </td>
+ </tr>
</sql:preparedStatement>
</table>
@@ -129,8 +155,41 @@
<td><sql:getNumber colName="id" format="CURRENCY" locale="en_GB"/></td>
</tr>
</sql:resultSet>
+ <tr>
+ <td>
+ <sql:wasEmpty>No rows retrieved.</sql:wasEmpty>
+ <sql:wasNotEmpty><sql:rowCount/> rows retrieved.</sql:wasNotEmpty>
+ </td>
+ </tr>
</sql:preparedStatement>
-</table>
+</table>
+
+<P><B>Prove that an empty resultset executes the wasEmpty tag</B></P>
+
+<sql:preparedStatement id="stmt6" conn="conn1">
+ <!-- impossible statement -->
+ <sql:query>
+ select id, name, description from test_books
+ where id > 1000
+ </sql:query>
+ <sql:resultSet id="rset4">
+ <p>
+
+ <!-- show that rowCount works for a no rows -->
+ retrieved row <sql:rowCount/>
+
+ <sql:getColumn position="1"/>
+ <sql:getColumn position="2"/>
+ <sql:getColumn position="3" to="description"/>
+ <sql:wasNotNull>Description: <%= pageContext.getAttribute("description")
%></sql:wasNotNull>
+ <sql:wasNull>[no description]</sql:wasNull>
+ </p>
+ </sql:resultSet>
+ <p>
+ <sql:wasEmpty>No rows retrieved.</sql:wasEmpty>
+ <sql:wasNotEmpty><sql:rowCount/> rows retrieved.</sql:wasNotEmpty>
+ </p>
+</sql:preparedStatement>
<P><B>Closing the database connection</B></P>
1.2 +1 -1 jakarta-taglibs/jdbc/examples/web/jndijdbc.jsp
Index: jndijdbc.jsp
===================================================================
RCS file: /home/cvs/jakarta-taglibs/jdbc/examples/web/jndijdbc.jsp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- jndijdbc.jsp 2001/03/04 18:57:10 1.1
+++ jndijdbc.jsp 2001/03/06 21:19:32 1.2
@@ -3,7 +3,7 @@
<P><B>Opening connection</B></P>
<sql:connection id="conn1">
- <sql:jndiname><%=request.getParameter("jndiname")%></sql:jndiname>
+ <sql:jndiName><%=request.getParameter("jndiname")%></sql:jndiName>
</sql:connection>
<P><B>Connection is closed?</B></P>
1.2 +1 -1
jakarta-taglibs/jdbc/src/org/apache/taglibs/jdbc/connection/JndiNameTag.java
Index: JndiNameTag.java
===================================================================
RCS file:
/home/cvs/jakarta-taglibs/jdbc/src/org/apache/taglibs/jdbc/connection/JndiNameTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JndiNameTag.java 2001/03/04 18:57:56 1.1
+++ JndiNameTag.java 2001/03/06 21:19:35 1.2
@@ -68,7 +68,7 @@
*
* <p>JSP Tag Lib Descriptor
* <pre>
- * <name>jndiname</name>
+ * <name>jndiName</name>
* <tagclass>org.apache.taglibs.jdbc.connection.JndiNameTag</tagclass>
* <bodycontent>JSP</bodycontent>
* <info>Sets the jndi named javax.sql.DataSource for the enclosing
1.3 +9 -0
jakarta-taglibs/jdbc/src/org/apache/taglibs/jdbc/preparedstatement/PreparedStatementImplTag.java
Index: PreparedStatementImplTag.java
===================================================================
RCS file:
/home/cvs/jakarta-taglibs/jdbc/src/org/apache/taglibs/jdbc/preparedstatement/PreparedStatementImplTag.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PreparedStatementImplTag.java 2001/01/31 00:53:44 1.2
+++ PreparedStatementImplTag.java 2001/03/06 21:19:36 1.3
@@ -103,6 +103,7 @@
private String _connId = null;
private PreparedStatement _statement = null;
+ private int _rowCount = -1;
public void setQuery(String query) throws SQLException{
Connection conn = (Connection)pageContext.getAttribute(_connId);
@@ -133,6 +134,14 @@
public ResultSet executeQuery() throws SQLException {
return _statement.executeQuery();
+ }
+
+ public int getTotalRowCount() {
+ return _rowCount;
+ }
+
+ public void setTotalRowCount(int rowCount) {
+ _rowCount = rowCount;
}
public int doStartTag() throws JspTagException {
1.4 +21 -5
jakarta-taglibs/jdbc/src/org/apache/taglibs/jdbc/resultset/ResultSetTag.java
Index: ResultSetTag.java
===================================================================
RCS file:
/home/cvs/jakarta-taglibs/jdbc/src/org/apache/taglibs/jdbc/resultset/ResultSetTag.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ResultSetTag.java 2001/02/09 01:10:17 1.3
+++ ResultSetTag.java 2001/03/06 21:19:38 1.4
@@ -110,6 +110,8 @@
private Statement _statement = null;
private ResultSet _rset = null;
private boolean _shouldLoop = true;
+ private int _rowCount = 0;
+ private StatementTag _stmtTag = null;
public void setLoop(boolean shouldLoop) {
_shouldLoop = shouldLoop;
@@ -121,16 +123,22 @@
public int doStartTag() throws JspTagException {
try {
- StatementTag stmtTag =
+ _stmtTag =
(StatementTag) findAncestorWithClass(this,
Class.forName("org.apache.taglibs.jdbc.statement.StatementTag"));
- _rset = stmtTag.executeQuery();
+ _rset = _stmtTag.executeQuery();
pageContext.setAttribute(getId(), _rset);
if (_shouldLoop == false) {
return EVAL_BODY_TAG;
}
- if (_rset.next() == false) { return SKIP_BODY; }
+ if (_rset.next() == false) {
+ _stmtTag.setTotalRowCount(_rowCount);
+ return SKIP_BODY;
+ }
+
+ ++_rowCount;
+ _stmtTag.setTotalRowCount(_rowCount);
} catch (ClassNotFoundException e) {
throw new JspTagException(e.toString());
@@ -168,10 +176,16 @@
}
try {
- if (_rset.next() == true) { return EVAL_BODY_TAG; }
+ if (_rset.next() == true) {
+ ++_rowCount;
+ _stmtTag.setTotalRowCount(_rowCount);
+ return EVAL_BODY_TAG;
+ }
} catch (SQLException e) {
throw new JspTagException(e.toString());
- }
+ }
+
+ _stmtTag.setTotalRowCount(_rowCount);
return EVAL_PAGE;
}
@@ -179,6 +193,8 @@
_statement = null;
_rset = null;
_shouldLoop = true;
+ _rowCount = 0;
+ _stmtTag = null;
}
}
1.3 +9 -0
jakarta-taglibs/jdbc/src/org/apache/taglibs/jdbc/statement/StatementImplTag.java
Index: StatementImplTag.java
===================================================================
RCS file:
/home/cvs/jakarta-taglibs/jdbc/src/org/apache/taglibs/jdbc/statement/StatementImplTag.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StatementImplTag.java 2001/01/31 01:00:14 1.2
+++ StatementImplTag.java 2001/03/06 21:19:39 1.3
@@ -98,6 +98,7 @@
private Statement _statement = null;
private String _query = null;
private String _connId = null;
+ private int _rowCount = -1;
// all the public methods are Javadoced
// in their interfaces
@@ -116,6 +117,14 @@
public ResultSet executeQuery() throws SQLException {
return _statement.executeQuery(_query);
+ }
+
+ public int getTotalRowCount() {
+ return _rowCount;
+ }
+
+ public void setTotalRowCount(int rowCount) {
+ _rowCount = rowCount;
}
public int doStartTag() throws JspTagException {
1.3 +17 -0
jakarta-taglibs/jdbc/src/org/apache/taglibs/jdbc/statement/StatementTag.java
Index: StatementTag.java
===================================================================
RCS file:
/home/cvs/jakarta-taglibs/jdbc/src/org/apache/taglibs/jdbc/statement/StatementTag.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StatementTag.java 2001/01/31 01:00:15 1.2
+++ StatementTag.java 2001/03/06 21:19:40 1.3
@@ -105,5 +105,22 @@
* @exception SQLException
*/
public ResultSet executeQuery() throws SQLException;
+
+ /**
+ * Get the total number of rows returned by the previous
+ * ResultSet
+ *
+ * @return count of rows in the previous ResultSet, or -1
+ * if no ResultSet has been retrieved
+ */
+ public int getTotalRowCount();
+
+ /**
+ * Allows an enclosed ResultSet tag to indicate
+ * how many rows it retrieved
+ *
+ * @param rowCount number of rows retrieved
+ */
+ public void setTotalRowCount(int rowCount);
}