Skip to content

Commit f235b5f

Browse files
authored
Merge pull request #273 from domaframework/translate
Translate lombok-support.rst and kotlin-support.rst from Japanese into English
2 parents a6ba81c + c63e5b3 commit f235b5f

File tree

2 files changed

+118
-114
lines changed

2 files changed

+118
-114
lines changed

docs/kotlin-support.rst

Lines changed: 80 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,142 @@
1-
==================
2-
Kotlin サポート
3-
==================
1+
==============
2+
Kotlin support
3+
==============
44

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

8-
Doma `Kotlin <https://kotlinlang.org/>`_ 1.1.2を実験的にサポートしています。
8+
Doma supports `Kotlin <https://kotlinlang.org/>`_ 1.3.11 or above **experimentally**.
99

10-
Kotlin利用のベストプラクティス
11-
================================
10+
Best practices
11+
==============
1212

13-
クラスの定義やビルドに関する事柄について推奨する方法を記載します。
13+
We show you recommended ways to define classes and build them with Kotlin.
1414

15-
エンティティクラス
16-
-------------------
15+
Entity classes
16+
--------------
1717

18-
* Data Classで定義する
19-
* イミュータブルで定義する( `@Entity` の `immutable` 要素に `true` を設定する)
20-
* コンストラクタは1つだけ定義する
21-
* コンストラクタ以外でプロパティを定義しない
22-
* コンストラクタで定義するプロパティには `val` を使用する
18+
* Define as a data class
19+
* Specify ``true`` to the ``immutable`` element of ``@Entity``
20+
* Define only one constructor
21+
* Define properties only in the constructor
22+
* Use `val` for the property definitions
2323

2424
.. code-block:: java
2525
2626
@Entity(immutable = true)
2727
data class Person(
2828
@Id
29-
@GeneratedValue(strategy = org.seasar.doma.GenerationType.IDENTITY)
29+
@GeneratedValue(strategy = GenerationType.IDENTITY)
3030
val id: Int? = null,
3131
val name: Name,
3232
val address: Address)
3333
34-
ドメインクラス
35-
-------------------
34+
Domain classes
35+
--------------
3636
37-
* Data Classで定義する
38-
* コンストラクタは1つだけ定義する
39-
* コンストラクタで定義するプロパティの名前は `value` にする
40-
* コンストラクタで定義するプロパティには `val` を使用する
37+
* Define as a data class
38+
* Define only one constructor
39+
* Define only one property whose name is ``value`` in the constructor
40+
* Use `val` for the property definition
4141
4242
.. code-block:: java
4343
4444
@Domain(valueType = String::class)
4545
data class Name(val value: String)
4646
47-
エンベッダブルクラス
48-
----------------------
47+
Embeddable classes
48+
------------------
4949
50-
* Data Classで定義する
51-
* コンストラクタは1つだけ定義する
52-
* コンストラクタ以外でプロパティを定義しない
53-
* コンストラクタで定義するプロパティには `val` を使用する
50+
* Define as a data class
51+
* Define only one constructor
52+
* Define properties only in the constructor
53+
* Use `val` for the property definitions
5454
5555
.. code-block:: java
5656
5757
@Embeddable
5858
data class Address(val city: String, val street: String)
5959
60-
Daoインタフェース
61-
-------------------
60+
Dao interfaces
61+
--------------
6262
63-
* KotlinではなくJavaで定義する
64-
* 更新処理の戻り値の型は `org.seasar.doma.jdbc.Result` や `org.seasar.doma.jdbc.BatchResult` を使う
63+
* Specify a SQL template to ``@org.seasar.doma.experimental.Sql``
64+
* Use ``org.seasar.doma.jdbc.Result`` as the return type of ``@Delete``, ``@Insert`` and ``@Update``
65+
* Use ``org.seasar.doma.jdbc.BatchResult`` as the return type of
66+
``@BatchDelete``, ``@BatchInsert`` and ``@BatchUpdate``
6567
6668
.. code-block:: java
6769
68-
@Dao(config = AppConfig.class)
69-
public interface PersonDao {
70+
@Dao(config = AppConfig::class)
71+
interface PersonDao {
72+
@Sql("""
73+
select * from person where id = /*id*/0
74+
""")
7075
@Select
71-
Person selectById(Integer id);
76+
fun selectById(id: Int): Person
77+
7278
@Insert
7379
Result<Person> insert(Person person);
7480
}
7581
76-
* 更新処理の戻り値を扱う際は `Destructuring Declarations <https://kotlinlang.org/docs/reference/multi-declarations.html>`_ を使う
82+
* Use `Destructuring Declarations <https://kotlinlang.org/docs/reference/multi-declarations.html>`_
83+
for ``org.seasar.doma.jdbc.Result`` and ``org.seasar.doma.jdbc.BatchResult``
7784

7885
.. code-block:: java
7986
8087
val dao: PersonDao = ...
8188
val person = Person(name = Name("Jhon"), address = Address(city = "Tokyo", street = "Yaesu"))
8289
val (newPerson, count) = dao.insert(person)
8390
91+
Using kapt in Gradle
92+
--------------------
8493

85-
kaptによるビルド
86-
-------------------
87-
88-
Kotlinで記述されたクラスやインタフェースに対して注釈処理をするには `kapt <https://blog.jetbrains.com/kotlin/2016/12/kotlin-1-0-6-is-here/>`_ を実行する必要があります。
89-
kaptは実験的な位置付けにありドキュメントがありません。
90-
Gradleでビルドする際は、確実な注釈処理が行われるように常に `clean build` を実行することを推奨します。
94+
Annotation processors are supported in Kotlin with the
95+
`kapt <https://kotlinlang.org/docs/reference/kapt.html>`_ compiler plugin.
9196

92-
.. code-block:: sh
97+
Add the dependencies using the `kapt` and `implementation` configuration in your dependencies block:
9398

94-
./gradlew clean build
99+
.. code-block:: groovy
95100
96-
Eclispeを利用する場合設定を適切に行えばJavaの注釈処理は自動で行われますが、kapt(Kotlinの注釈処理)はGradleを実行しない限り行われないことに注意してください。
101+
dependencies {
102+
kapt "org.seasar.doma:doma:2.21.1-SNAPSHOT"
103+
implementation "org.seasar.doma:doma:2.21.1-SNAPSHOT"
104+
}
97105
98-
下記はbuild.gradleの抜粋です。コンパイル時にSQLファイルを参照するために下記の設定に特に注意してください。
106+
If you use resource files such as SQL files, make the kapt find them:
99107

100108
.. code-block:: groovy
101109
102-
// コンパイルより前にSQLファイルを出力先ディレクトリにコピーするために依存関係を逆転する
103-
compileJava.dependsOn processResources
104-
105-
// SQLファイルなどリソースファイルの出力先ディレクトリをkaptに伝える
106-
kapt {
107-
arguments {
108-
arg("doma.resources.dir", processResources.destinationDir)
109-
}
110-
}
110+
kapt {
111+
arguments {
112+
arg("doma.resources.dir", compileKotlin.destinationDir)
113+
}
114+
}
115+
116+
task copyDomaResources(type: Sync) {
117+
from sourceSets.main.resources.srcDirs
118+
into compileKotlin.destinationDir
119+
include 'doma.compile.config'
120+
include 'META-INF/**/*.sql'
121+
include 'META-INF/**/*.script'
122+
}
123+
124+
compileKotlin {
125+
dependsOn copyDomaResources
126+
}
127+
111128
129+
.. note::
112130

113-
JavaとKotlinの混在
114-
-------------------------
131+
Remember that you always have options as follows:
115132

116-
kaptの不確実な挙動を避けるため、Domaに関するコードの全てをJavaで書くことは検討に値します。
117-
Domaの利用において、JavaとKotlinの混在は問題ありません。
133+
- Write all codes with Kotlin
134+
- Write all codes with Java
135+
- Write codes annotated with Doma's annotations in Java and others in Kotlin
118136

119-
サンプルプロジェクト
120-
=====================
137+
The third option is worth considering, because it can avoid some troubles with the kapt.
121138

122-
サンプルコードについては下記のプロジェクトを参照ください。
139+
Sample project
140+
==============
123141

124142
* `kotlin-sample <https://github.com/domaframework/kotlin-sample>`_

docs/lombok-support.rst

Lines changed: 38 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,43 @@
1-
==================
2-
Lombok サポート
3-
==================
1+
==============
2+
Lombok support
3+
==============
44

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

8-
Doma `Lombok <https://projectlombok.org/>`_ のバージョン 1.16.12 以上をサポートしています。
8+
Doma supports `Lombok <https://projectlombok.org/>`_ 1.16.12 or above.
99

1010
.. note::
1111

12-
IDE として Eclipse を利用する場合はバージョン 4.5 以上を使ってください。
13-
4.5 未満ではアノテーションプロッサで取得されるクラスに定義されたフィールドなどの並びがソースコードに記載されている順序と異なり、
14-
正しく動作しないためです。
12+
If you intend to use Eclipse, use version 4.5 or above.
1513

16-
Lombok サポートの概要
17-
================================
14+
Overview
15+
========
1816

19-
Lombok と Doma は共に JSR 269 で規定されたアノテーションプロセッサを提供していますが、
20-
Lombok と Doma を同時に利用する場合はアノテーションプロセッサの処理順序が問題になることがあります。
21-
例えば、 Lombok のアノテーションプロセッサがコンストラクタを生成し、
22-
Doma のアノテーションプロセッサがそのコンストラクタを読み取る場合などです。
23-
仮に、Doma のアノテーションプロセッサが先に実行されると単にコンストラクタが定義されていないものとして動作し、
24-
コンパイルに失敗します。
17+
Both Lombok and Doma provide their own annotation processors.
18+
Because the execution order of annotation processors is not determined in Java,
19+
the Doma's annotation processors are not always aware of the class modifications made by
20+
the Lombok annotation processors.
2521

26-
アノテーションプロセッサの処理順序を指定できればこの問題は解決するのですが、
27-
残念ながら処理順序が保証されないことが仕様に記載されており、実際に問題解決の仕組みは提供されていません。
22+
To resolve the issue, the Doma's annotation processors recognise several Lombok's annotations
23+
and change their own behavior.
24+
For example, if the Doma's annotation processors find a class annotated with ``@lombok.Value``,
25+
they supposes that the class has a constructor whose arguments covers all instance fields.
2826

29-
Doma では、この問題に対応するために、Lombok のアノテーションの有無を認識して処理順序に依存にしない振る舞いをするようにしています。
30-
先ほどの例で言えば、 ``@lombok.Value`` などコンストラクタを生成するLombokのアノテーションが存在する場合は
31-
実際にはコンストラクタを読み取らなくてもコンストラクタが存在するものとして動作するということです。
27+
Best practices
28+
==============
3229

33-
Lombok 利用のベストプラクティス
34-
================================
30+
We show you recommended ways to define classes with Lombok annotations.
3531

36-
Lombok のアノテーションを用いたクラスの定義について推奨する方法を記載します。
32+
Entity class definition
33+
-----------------------
3734

38-
エンティティクラス
39-
-------------------
35+
immutable entity classes
36+
~~~~~~~~~~~~~~~~~~~~~~~~
4037

41-
immutable(イミュータブル)
42-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43-
44-
イミュータブルなエンティティクラスを定義する場合は下記の点に注意します。
45-
46-
* ``@Entity`` の ``immutable`` 要素に ``true`` を設定する
47-
* ``@lombok.Value`` もしくは ``@lombok.AllArgsConstructor`` を注釈する
48-
* ``@lombok.AllArgsConstructor`` を選んだ場合、getterを生成するためには ``@lombok.Getter`` を注釈する
38+
* Specify ``true`` to the ``immutable`` element of ``@Entity``
39+
* Specify either ``@lombok.Value`` or ``@lombok.AllArgsConstructor``
40+
* Specify ``@lombok.Getter`` to generate getters, in case of ``@lombok.AllArgsConstructor``
4941

5042
.. code-block:: java
5143
@@ -70,13 +62,11 @@ immutable(イミュータブル)
7062
private final Age age;
7163
}
7264
73-
mutable(ミュータブル)
74-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75-
76-
ミュータブルなエンティティクラスを定義する場合は下記の点に注意します。
65+
mutable entity classes
66+
~~~~~~~~~~~~~~~~~~~~~~
7767

78-
* デフォルトコンストラクタを定義する(デフォルトコンストラクタの生成を抑制しない)
79-
* getter/setterを生成する場合は ``@lombok.Data`` もしくは ``@lombok.Getter`` / ``@lombok.Setter`` を注釈する
68+
* Define a default constructor
69+
* Specify ``@lombok.Data`` or ``@lombok.Getter``/``@lombok.Setter`` to generate getters/setters
8070

8171
.. code-block:: java
8272
@@ -101,13 +91,11 @@ mutable(ミュータブル)
10191
private Age age;
10292
}
10393
104-
ドメインクラス
105-
-------------------
94+
Domain class definition
95+
-----------------------
10696

107-
ドメインクラスを定義する場合は下記の点に注意します。
108-
109-
* ``@lombok.Value`` を注釈する
110-
* インスタンスフィールドは1つだけ定義し名前は ``value`` にする
97+
* Specify ``@lombok.Value``
98+
* Define only one instance field whose name is ``value``
11199

112100
.. code-block:: java
113101
@@ -117,13 +105,11 @@ mutable(ミュータブル)
117105
Integer value;
118106
}
119107
120-
エンベッダブルクラス
121-
----------------------
122-
123-
エンベッダブルクラスを定義する場合は下記の点に注意します。
108+
Embeddable class definition
109+
---------------------------
124110

125-
* ``@lombok.Value`` もしくは ``@lombok.AllArgsConstructor`` を注釈する
126-
* ``@lombok.AllArgsConstructor`` を選んだ場合、getterを生成するためには ``@lombok.Getter`` を注釈する
111+
* Specify either ``@lombok.Value`` or ``@lombok.AllArgsConstructor``
112+
* Specify ``@lombok.Getter`` to generate getters, in case of ``@lombok.AllArgsConstructor``
127113

128114
.. code-block:: java
129115

0 commit comments

Comments
 (0)