While looking through in Castor's source code the following question
hit me one more time: Why is it made so difficult to retrieve the
underlying JDBC connections from Castor?
Yes, I saw the warning "Only for internal / advanced use !" in
But some applications need access to the JDBC connection for example
to set some DB parameters at session initialization.
I see everywhere this construct:
Database db = jdo.getDatabase();
Connection conn = (Connection) ((DatabaseImpl)db).getConnection();
A bit complicated just to get a connection object, if you ask me.
First: Why is the cast to DatabaseImpl necessary?
Well, it's needed because getConnection() is only present in DatabaseImpl,
not in the Database interface. What about declaring it in the Database
interface, perhaps with ajusted name getJdbcConnection() and
the return type java.sql.Connection ?
Any other derived database implementation could just return null,
if it doesn't use a JDBC connection. Well - will there ever be a database
implementation in Java, which doesn't use JDBC? I doubt.
Second: Why is the cast to Connection necessary?
DatabaseImpl.getConnection() simply calls TransactionContextImpl.getConnection
which in any case returns a JDBC Connection object. Is there the
possibility to return any another type?
I would propose to change the return type of the getConnection() functions
from Object to java.sql.Connection.
What do you think?