DBStatements in Forte exist in single-threaded partitions, and can maintain their values across transactions. In Java, a PreparedStatement is single-threaded (as evidenced by the fact it stores the variables for that thread) and cannot exist across a transaction boundary, as the commit (especially in Spring) calls connection.close() which removes all the statements.
This class solved both of these problems by maintaining enough state to be able to re-create a statement if it's created by a different thread or exists on a closed connection. This means that if the pattern in Forte is:
conn = myDataSource.getConnection(); statement1 = conn.createStatement(someSQL1); statement2 = conn.createStatement(someSQL2); begin transaction statement1.execute(); end transaction begin transaction statement1.execute(); end transaction
then this should still work in Java
Debugging note: This class provides some level of tracing into the execution of dynamic SQL statements. To used it, set one of the following levels of tracing:
Level set | Effect |
CloseTolerantStatement.info log4j leveltrc:db:2:1 | Traces all instances of the execute methods (execute, executeQuery, etc) including parameters |
CloseTolerantStatement.debug log4j leveltrc:db:2:50 | Traces all setter and execute methods |
@author tfaulkes