Last active
May 29, 2019 21:09
-
-
Save bufferings/5145468 to your computer and use it in GitHub Desktop.
http://d.hatena.ne.jp/taedium/20100314/p2
を読んで。自分だったらどうかくかなーと思って。こんな感じかな。のメモ。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Integer result = tx(new UnitWork<Integer>() { | |
@Override | |
public Integer run() { | |
Employee employee = dao.selectById(1); | |
employee.setName("hoge"); | |
employee.setJobType(JobType.PRESIDENT); | |
return dao.update(employee); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TxHandler { | |
public interface UnitWork<S> { | |
S run(); | |
} | |
public static <T> T tx(UnitWork<T> unitWork) { | |
LocalTransaction tx = AppConfig.getLocalTransaction(); | |
try{ | |
tx.begin(); | |
T result = unitWork.run(); | |
tx.commit(); | |
return result; | |
} finally { | |
tx.rollback(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment