|
4 | 4 |
|
5 | 5 | import java.util.function.Supplier; |
6 | 6 | import org.seasar.doma.DomaNullPointerException; |
| 7 | +import org.seasar.doma.jdbc.JdbcLogger; |
7 | 8 |
|
8 | | -/** A transaction manager for local transactions. */ |
| 9 | +/** |
| 10 | + * A transaction manager for local transactions. |
| 11 | + * |
| 12 | + * <p>This instance is thread safe. |
| 13 | + */ |
9 | 14 | public class LocalTransactionManager implements TransactionManager { |
10 | 15 |
|
11 | 16 | protected final LocalTransaction transaction; |
12 | 17 |
|
| 18 | + /** |
| 19 | + * Create an instance. |
| 20 | + * |
| 21 | + * @param transaction the transaction |
| 22 | + * @throws DomaNullPointerException if the {@code transaction} is {@code null} |
| 23 | + */ |
13 | 24 | public LocalTransactionManager(LocalTransaction transaction) { |
14 | 25 | if (transaction == null) { |
15 | 26 | throw new DomaNullPointerException("transaction"); |
16 | 27 | } |
17 | 28 | this.transaction = transaction; |
18 | 29 | } |
19 | 30 |
|
| 31 | + /** |
| 32 | + * Create an instance. |
| 33 | + * |
| 34 | + * @param dataSource the data source |
| 35 | + * @param jdbcLogger the logger |
| 36 | + * @throws DomaNullPointerException if any of the parameters are {@code null} |
| 37 | + */ |
| 38 | + public LocalTransactionManager(LocalTransactionDataSource dataSource, JdbcLogger jdbcLogger) { |
| 39 | + if (dataSource == null) { |
| 40 | + throw new DomaNullPointerException("dataSource"); |
| 41 | + } |
| 42 | + if (jdbcLogger == null) { |
| 43 | + throw new DomaNullPointerException("jdbcLogger"); |
| 44 | + } |
| 45 | + this.transaction = dataSource.getLocalTransaction(jdbcLogger); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Create an instance. |
| 50 | + * |
| 51 | + * @param dataSource the data source |
| 52 | + * @param jdbcLogger the logger |
| 53 | + * @param isolationLevel the default transaction isolation level |
| 54 | + * @throws DomaNullPointerException if any of the parameters are {@code null} |
| 55 | + */ |
| 56 | + public LocalTransactionManager( |
| 57 | + LocalTransactionDataSource dataSource, |
| 58 | + JdbcLogger jdbcLogger, |
| 59 | + TransactionIsolationLevel isolationLevel) { |
| 60 | + if (dataSource == null) { |
| 61 | + throw new DomaNullPointerException("dataSource"); |
| 62 | + } |
| 63 | + if (jdbcLogger == null) { |
| 64 | + throw new DomaNullPointerException("jdbcLogger"); |
| 65 | + } |
| 66 | + if (isolationLevel == null) { |
| 67 | + throw new DomaNullPointerException("isolationLevel"); |
| 68 | + } |
| 69 | + this.transaction = dataSource.getLocalTransaction(jdbcLogger, isolationLevel); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Returns the transaction. |
| 74 | + * |
| 75 | + * <p>This method is mainly used in test code. |
| 76 | + * |
| 77 | + * @return the transaction |
| 78 | + */ |
| 79 | + public LocalTransaction getTransaction() { |
| 80 | + return transaction; |
| 81 | + } |
| 82 | + |
20 | 83 | @Override |
21 | 84 | public void required(Runnable block) { |
22 | 85 | if (block == null) { |
|
0 commit comments