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!

+3


source to share


2 answers


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.

+5


source


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!

0


source







All Articles