|
From: Brandon G. <ma...@ph...> - 2004-05-29 00:50:50
|
Greetings,
My name is Brandon Goodin. I am committer on the iBatis project. As I've had
time recently I've become increasingly more familiar with the Spring product
and began to explore the code base. I specifically have examined the iBatis
integration and noticed a problem in how the datasource is being set.
In the SqlMapClientTemplate the execute method is using
session.setUserConnection(con);. Setting the connection using
setUserConnection on the SqlMapSession will not take full advantage of
ibatis functionality (i.e. lazy loading will not work).
The short explanation is that Spring needs to set the the Datasource via the
TransactionConfig which is stored in the TransactionManager. The
TransactionManager needs to be set via the SqlMapExecutorDelegate of the
SqlMapClient. The TransactionManager contains the TransactionConfig which
contains the datasource and various other pertinent config info for
transactions.
Following is a chunk from the XmlSqlMapClientBuilder that demonstrates how
the datasource should be configured in ibatis:
---- start code ---
TransactionManager txManager = null;
try {
errorCtx.setMoreInfo("Check the transaction manager type or class.");
TransactionConfig config = (TransactionConfig) Resources.instantiate(type);
config.setDataSource(dataSource);
config.setMaximumConcurrentTransactions(client.getDelegate().getMaxTransacti
ons());
errorCtx.setMoreInfo("Check the transactio nmanager properties or
configuration.");
config.initialize(initProperties);
errorCtx.setMoreInfo(null);
txManager = new TransactionManager(config);
} catch (Exception e) {
if (e instanceof SqlMapException) {
throw (SqlMapException) e;
} else {
throw new SqlMapException("Error initializing TransactionManager. Could not
instantiate TransactionConfig. Cause: " + e, e);
}
}
client.getDelegate().setTxManager(txManager);
--- end code ---
From what I can tell Spring allows for iBatis users to take advantage of the
iBatis transaction facilities if they choose (i.e. avoid using spring
transaction management if they so choose). So, the only thing that is left
is for Spring to use the proper implementation of the TransactionConfig
(com.ibatis.sqlmap.engine.transaction.external.ExternalTransactionConfig)
for the configuration of the datasource. The ExternalTransactionConfig will
allow for Spring to manage the commit and rollback functionality without
losing valuable functionality in iBatis (lazy loading).
I'd be happy to work on the Spring code base if you would like or provide
you with more insight if you need. Let me know.
Thanks,
Brandon Goodin
http://www.ibatis.com <http://www.ibatis.com/>
|