vgritsenko 01/06/22 20:37:55
Modified: src/org/apache/cocoon/transformation Tag: cocoon_20_branch
SQLTransformer.java
Log:
Fix SQLTransformer (query should be closed AFTER info obtained, not before);
sql-page works now.
Revision Changes Path
No revision
No revision
1.5.2.2 +26 -27
xml-cocoon2/src/org/apache/cocoon/transformation/SQLTransformer.java
Index: SQLTransformer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/transformation/SQLTransformer.java,v
retrieving revision 1.5.2.1
retrieving revision 1.5.2.2
diff -u -r1.5.2.1 -r1.5.2.2
--- SQLTransformer.java 2001/06/07 06:16:38 1.5.2.1
+++ SQLTransformer.java 2001/06/23 03:37:54 1.5.2.2
@@ -46,7 +46,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Donald Ball</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
* (PWR Organisation & Entwicklung)
- * @version CVS $Revision: 1.5.2.1 $ $Date: 2001/06/07 06:16:38 $ $Author:
cziegeler $
+ * @version CVS $Revision: 1.5.2.2 $ $Date: 2001/06/23 03:37:54 $ $Author:
vgritsenko $
*/
public class SQLTransformer extends AbstractTransformer
@@ -185,12 +185,9 @@
Query query = (Query) queries.elementAt(index);
try {
query.execute();
- } catch (SQLException e) {
- getLogger().debug("SQLTransformer.executeQuery()", e);
- throw new SAXException(e);
- }
- this.start(query.rowset_name, attr);
- try {
+
+ this.start(query.rowset_name, attr);
+
while (query.next()) {
this.start(query.row_name, attr);
query.serializeRow();
@@ -202,6 +199,12 @@
} catch (SQLException e) {
getLogger().debug("SQLTransformer.executeQuery()", e);
throw new SAXException(e);
+ } finally {
+ try{
+ query.close();
+ }catch(SQLException e){
+ getLogger().warn("Could not close JDBC Connection", e);
+ }
}
this.end(query.rowset_name);
this.contentHandler.endPrefixMapping("");
@@ -482,11 +485,11 @@
/** And the results' metadata **/
protected ResultSetMetaData md = null;
- /** If this query is actually an update (insert, update, delete) **/
- protected boolean isupdate = false;
+ /** If this query is actually an update (insert, update, delete) **/
+ protected boolean isupdate = false;
- /** If it is an update/etc, the return value (num rows modified) **/
- protected int rv = -1;
+ /** If it is an update/etc, the return value (num rows modified) **/
+ protected int rv = -1;
/** The parts of the query **/
protected Vector query_parts = new Vector();
@@ -516,6 +519,7 @@
String dburl = properties.getProperty(SQLTransformer.MAGIC_DBURL);
String username = properties.getProperty(SQLTransformer.MAGIC_USERNAME);
String password = properties.getProperty(SQLTransformer.MAGIC_PASSWORD);
+
Enumeration enum = query_parts.elements();
StringBuffer sb = new StringBuffer();
while (enum.hasMoreElements()) {
@@ -535,6 +539,7 @@
}
}
}
+
String query = sb.toString();
DataSourceComponent datasource = null;
try {
@@ -550,11 +555,11 @@
}
}
st = conn.createStatement();
- if (isupdate)
- rv = st.executeUpdate(query);
- else {
- rs = st.executeQuery(query);
- md = rs.getMetaData();
+ if (isupdate) {
+ rv = st.executeUpdate(query);
+ } else {
+ rs = st.executeQuery(query);
+ md = rs.getMetaData();
}
} catch (SQLException e) {
transformer.getTheLogger().error("Caught a SQLException", e);
@@ -562,7 +567,6 @@
} catch (ComponentException cme) {
transformer.getTheLogger().error("Could not use connection: " +
connection, cme);
} finally {
- close();
if (datasource != null) dbSelector.release(datasource);
}
}
@@ -590,9 +594,9 @@
protected boolean next() throws SQLException {
try {
// if rv is not -1, then an SQL insert, update, etc, has
- // happened (see JDBC docs - return codes for executeUpdate)
- if (rv != -1)
- return true;
+ // happened (see JDBC docs - return codes for executeUpdate)
+ if (rv != -1)
+ return true;
if (rs == null || !rs.next()) {
close();
return false;
@@ -626,8 +630,7 @@
protected void serializeRow() throws SQLException, SAXException {
AttributesImpl attr = new AttributesImpl();
-
- if (!isupdate) {
+ if (!isupdate) {
for (int i = 1; i <= md.getColumnCount(); i++) {
transformer.start(md.getColumnName(i).toLowerCase(), attr);
try {
@@ -644,13 +647,11 @@
transformer.data(String.valueOf(rv));
transformer.end("returncode");
rv = -1; // we only want the return code shown once.
+ }
}
- }
-
}
private class AncestorValue {
-
protected int level;
protected String name;
@@ -658,7 +659,5 @@
this.level = level;
this.name = name;
}
-
}
-
}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]