dlr 01/11/03 10:34:29
Modified: src/java/org/apache/torque/task TorqueDataDumpTask.java
Log:
o Added conn and stmt instance members to hold onto the database
Connection and Statement objects used to dump the data.
o Overrode the new TexenTask cleanup() method to properly release the
Statement and Connection members.
o Addded some FIXME notes where the Ant log() method should be used
instead of System.err.
Revision Changes Path
1.4 +44 -9
jakarta-turbine-torque/src/java/org/apache/torque/task/TorqueDataDumpTask.java
Index: TorqueDataDumpTask.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/task/TorqueDataDumpTask.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -u -r1.3 -r1.4
--- TorqueDataDumpTask.java 2001/10/27 19:04:38 1.3
+++ TorqueDataDumpTask.java 2001/11/03 18:34:29 1.4
@@ -62,6 +62,7 @@
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.sql.SQLException;
+import java.sql.Statement;
import org.apache.velocity.context.Context;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.texen.ant.TexenTask;
@@ -74,7 +75,8 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]"> Fedor Karpelevitch </a>
* @author <a href="[EMAIL PROTECTED]">Jason van Zyl</a>
- * @version $Id: TorqueDataDumpTask.java,v 1.3 2001/10/27 19:04:38 jvanzyl Exp $
+ * @author <a href="[EMAIL PROTECTED]">Daniel Rall</a>
+ * @version $Id: TorqueDataDumpTask.java,v 1.4 2001/11/03 18:34:29 dlr Exp $
*/
public class TorqueDataDumpTask
extends TorqueDataModelTask
@@ -105,6 +107,16 @@
private String databasePassword;
/**
+ * The database connection used to retrieve the data to dump.
+ */
+ private Connection conn;
+
+ /**
+ * The statement used to acquire the data to dump.
+ */
+ private Statement stmt;
+
+ /**
* Get the database name to dump
*
* @return The DatabaseName value
@@ -216,6 +228,7 @@
context.put("dataset", "all");
+ // FIXME: Use Ant log() method
System.err.println("Your DB settings are:");
System.err.println("driver : " + databaseDriver);
System.err.println("URL : " + databaseUrl);
@@ -225,13 +238,13 @@
try
{
Class.forName(databaseDriver);
+ // FIXME: Use Ant log() method
System.err.println("DB driver sucessfuly instantiated");
- // Attemtp to connect to a database.
-
- Connection conn = DriverManager.getConnection(
+ conn = DriverManager.getConnection(
databaseUrl, databaseUser, databasePassword);
+ // FIXME: Use Ant log() method
System.err.println("DB connection established");
context.put("tableTool", new TableTool(conn));
}
@@ -250,6 +263,26 @@
}
/**
+ * Closes <code>rs</code> and <code>conn</code>, overriding the
+ * <code>cleanup()</code> hook method in <code>TexenTask</code>.
+ *
+ * @exception Exception Database problem while closing resource.
+ */
+ protected void cleanup()
+ throws Exception
+ {
+ if (stmt != null)
+ {
+ stmt.close();
+ }
+
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
+
+ /**
* A nasty do-it-all tool class. It serves as:
* <ul>
* <li>context tool to fetch a table iterator</li>
@@ -291,7 +324,8 @@
/**
- * Description of the Method
+ * Fetches an <code>Iterator</code> for the data in the named
+ * table.
*
* @param tableName Description of Parameter
* @return Description of the Returned Value
@@ -301,9 +335,11 @@
{
System.err.println();
System.err.print("fetching table " + tableName);
- return
- new TableTool(conn.createStatement()
- .executeQuery("SELECT * FROM " + tableName));
+ // Set Statement object in associated TorqueDataDump
+ // instance
+ stmt = conn.createStatement();
+ return new TableTool
+ (stmt.executeQuery("SELECT * FROM " + tableName));
}
@@ -382,4 +418,3 @@
}
}
}
-
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>