Class KeepAliveLocalTransaction

java.lang.Object
org.seasar.doma.jdbc.tx.LocalTransaction
org.seasar.doma.jdbc.tx.KeepAliveLocalTransaction

public class KeepAliveLocalTransaction extends LocalTransaction
A local transaction that keeps a JDBC connection open until the transaction is explicitly destroyed.

But the connection is closed, if any exceptions are thrown.

This instance is thread safe.

 KeepAliveLocalTransaction tx = DbConfig.singleton().getKeepAliveLocalTransaction();
 tx.init();
 try {
     try {
         tx.begin();
         Employee employee = dao.selectById(1);
         employee.setName("SMITH");
         employee.setJobType(JobType.PRESIDENT);
         dao.update(employee);
         tx.commit();
     } finally {
         tx.rollback();
     }
     try {
         tx.begin();
         Employee employee = dao.selectById(2);
         employee.setName("foo");
         employee.setJobType(JobType.SALESMAN);
         dao.update(employee);
         tx.commit();
     } finally {
         tx.rollback();
     }
 } finally {
     tx.destroy();
 }