db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Fox <thomas....@seitenbau.com>
Subject Re: svn commit: r1839284 - in /db/torque/torque4/trunk: torque-runtime/src/main/java/org/apache/torque/ torque-runtime/src/main/java/org/apache/torque/oid/ torque-runtime/src/main/java/org/apache/torque/util/ torque-runtime/src/test/java/org/apache/torque/...
Date Mon, 03 Sep 2018 03:32:05 GMT

I'm sorry but I do not understand the state kept in TorqueConnectionImpl. 
As I understand it, TorqueConnectionImpl.committed and TorqueConnectionImpl.rolledBack keep
track of whether there could be outstanding operations in a transaction. So when one calls
close() on a connection with uncommitted changes these get rolled back. But what if one calls
commit() and then does other operations on the connection? As I understand the javadoc of
java.sql.Connection, this is legal (maybe I'm wrong). But the current logic in TorqueConnectionImpl
would not do any rollback on close() then.

And what id autocommit is true? Should there be any rollback attempt in this case? And what
if the user switches from autoaommit to non autocommit in the midst of doing database operation?

These are just some random questions, in no way complete. In short, I am not sure whether
one wants to get involved in the (perhaps complicated) state keeping logic of java.sql.Connection.

And does TorqueCoonnectionImpl keep the contract of java.sql.Connection.close()? It says in
https://docs.oracle.com/javase/7/docs/api/java/sql/Connection.html#close()that close() would
release all resources, but TorqueConnectionImpl  does more than that. However, I know other
frameworks, e.g. Connection pools, which do other stuff on close() to guarantee a clean connection,
but personally I'm not happy about that either.

Just a not-well-thought-through idea: Perhaps one can solve some of these issues if TorqueConnection
would not inherit from java.sql.Connection, but would be a different object wrapping a java.sql.Connection,
with a different contract, like:

public class TorqueTransactionConnection implements AutoCloseable
  private java.sql.Connection connection;

  public TorqueTransactionConnectionImpl()
    connection = TransactionManagerImpl.begin();

  public void commit()
    if (connection == null)
      throw new IllegalStateException("already closed");
    connection = null;
  public void rollback()
    // analogous to close

  public void close()

Not sure if that idea works through, though.


View raw message