Skip to content

Commit 77d971a

Browse files
bufferingsnakamura-to
authored andcommitted
Translate transaction.rst
1 parent e3e06e2 commit 77d971a

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

docs/transaction.rst

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
==================
2-
トランザクション
2+
Transaction
33
==================
44

5-
.. contents:: 目次
5+
.. contents:: Contents
66
:depth: 3
77

8-
Domaは、ローカルトランザクションをサポートします。
9-
このドキュメントでは、ローカルトランザクションの設定方法と利用方法について説明します。
8+
Doma supports local transaction.
9+
This document explains how to configure and use the local transaction.
1010

11-
グローバルトランザクションを使用したい場合は、JTA(Java Transaction API)
12-
の実装をもつフレームワークやアプリケーションサーバーの機能を利用してください。
11+
If you want to use global transaction, use frameworks or application servers
12+
which support JTA (Java Transaction API).
1313

14-
設定
15-
====
14+
Configuration
15+
=============
1616

17-
ローカルトランザクションを実行するには次の条件を満たす必要があります。
17+
To use local transaction, these conditions are required:
1818

19-
* ``Config`` ``getDataSource`` ``LocalTransactionDataSource`` を返す
20-
* 上記の ``LocalTransactionDataSource`` をコンストラクタで受けて ``LocalTransactionManager`` を生成する
21-
* 上記の ``LocalTransactionManager`` の管理下でデータベースアクセスを行う
19+
* Return ``LocalTransactionDataSource`` from ``getDataSource`` in ``Config``
20+
* Generate ``LocalTransactionManager`` using the ``LocalTransactionDataSource`` above in the constructor
21+
* Use the ``LocalTransactionManager`` above to control database access
2222

23-
``LocalTransactionManager`` の生成と取得方法はいくつかありますが、最も単純な方法は、
24-
``Config`` の実装クラスのコンストラクタで生成し ``Config`` の実装クラスをシングルトンとすることです。
23+
There are several ways to generate and get the ``LocalTransactionManager``,
24+
but the simplest way is to generate it in the constructor of ``Config`` implementaion class
25+
and make the ``Config`` implementaiton class singleton.
2526

26-
実装例です。
27+
Here is an example:
2728

2829
.. code-block:: java
2930
@@ -68,12 +69,13 @@ Domaは、ローカルトランザクションをサポートします。
6869
6970
.. note::
7071

71-
クラスに ``@SingletonConfig`` を指定することでシングルトンであることを表しています
72+
The ``@SingletonConfig`` shows that this class is a singleton class.
7273

73-
利用例
74+
Usage
7475
======
7576

76-
`設定`_ で示した ``AppConfig`` クラスを以下のようにDaoインタフェースに注釈するものとして例を示します。
77+
Let's see examples on the condition that we use the following Dao interface annotated with
78+
the ``AppConfig`` class which we saw in the `Configuration`_.
7779

7880
.. code-block:: java
7981
@@ -82,18 +84,18 @@ Domaは、ローカルトランザクションをサポートします。
8284
...
8385
}
8486
85-
以降のコード例に登場する ``dao`` は上記クラスのインスタンスです。
87+
The ``dao`` used in the code examples below are instances of this class.
8688

87-
トランザクションの開始と終了
88-
----------------------------
89+
Start and finish transactions
90+
-----------------------------
8991

90-
トランザクションは ``TransactionManager`` の以下のメソッドのいずれかを使って開始します。
92+
You can start a transaction with one of following methods of ``TransactionManager``:
9193

9294
* required
9395
* requiresNew
9496
* notSupported
9597

96-
トランザクション内で行う処理はラムダ式として渡します。
98+
Use a lambda expression to write a process which you want to run in a transaction.
9799

98100
.. code-block:: java
99101
@@ -106,13 +108,13 @@ Domaは、ローカルトランザクションをサポートします。
106108
dao.update(employee);
107109
});
108110
109-
ラムダ式が正常に終了すればトランザクションはコミットされます。
110-
ラムダ式が例外をスローした場合はトランザクションはロールバックされます。
111+
The transaction is committed if the lambda expression finishes successfully.
112+
The transaction is rolled back if the lambda expression throws an exception.
111113

112-
明示的なロールバック
114+
Explicit rollback
113115
--------------------
114116

115-
例外をスローする方法以外でトランザクションをロールバックするには ``setRollbackOnly`` メソッドを呼び出します。
117+
Besides throwing an exception, you can use ``setRollbackOnly`` method to rollback a transaction.
116118

117119
.. code-block:: java
118120
@@ -123,32 +125,32 @@ Domaは、ローカルトランザクションをサポートします。
123125
employee.setName("hoge");
124126
employee.setJobType(JobType.PRESIDENT);
125127
dao.update(employee);
126-
// ロールバックするものとしてマークする
128+
// Mark as rollback
127129
tm.setRollbackOnly();
128130
});
129131
130-
セーブポイント
132+
Savepoint
131133
--------------
132134

133-
セーブポイントを使用することで、トランザクション中の特定の変更を取り消すことができます。
135+
With a savepoint, you can cancel specific changes in a transaction.
134136

135137
.. code-block:: java
136138
137139
TransactionManager tm = AppConfig.singleton().getTransactionManager();
138140
139141
tm.required(() -> {
140-
// 検索して更新
142+
// Search and update
141143
Employee employee = dao.selectById(1);
142144
employee.setName("hoge");
143145
dao.update(employee);
144146
145-
// セーブポイントを作成
147+
// Create a savepoint
146148
tm.setSavepoint("beforeDelete");
147149
148-
// 削除
150+
// Delete
149151
dao.delete(employee);
150152
151-
// セーブポイントへ戻る(上で行った削除を取り消す)
153+
// Rollback to the savepoint (cancel the deletion above)
152154
tm.rollback("beforeDelete");
153155
});
154156

0 commit comments

Comments
 (0)