ORMLite + transactions
I have a problem understanding the default DaoManager behavior.
DaoManager.createDao(connectionSource, theClass);
This accepts a connectionSource - not a connection. Therefore, if I do the following:
TransactionManager.callInTransaction(
localConnection,
connectionSource.getDatabaseType(),
new Callable<Void>() {
public Void call() throws Exception {
dao.create(user);
dao.create(player);
return null;
}
});
The transaction must be limited to one connection (localConnection). How does the DAO handle this? Or is he not doing it at all?
thank!
source to share
The transaction must be limited to one connection (localConnection). How does the DAO handle this? Or is he not doing it at all?
Hmm. I'm not 100% sure why the connection method is open. I will condemn this.
You should really use the method dao.callBatchTasks(...)
. If you need to use directly TransactionManager
, I would use a method that acceptsConnectionSource
, not a connection.
You can look at the sourceTransactionManager.callInTransaction(...)
to see that it saves the connection, which is then used by DAO later through some ORMLite magic. So auto-commit is turned off on the saved connection and then restored after the batch tasks are completed.
source to share
I have analyzed the codebase and it seems that if I use the same ConnectionSource when the dao is initially requested internally, a "savedConnection" is set, which is then forced into use.
If anyone can confirm / disprove this - or just knows how to do it in perfect order - please tell me!
source to share