Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 455c776

Browse files
committed
Polish about the Unified Criteria API
1 parent e684fad commit 455c776

File tree

8 files changed

+691
-729
lines changed

8 files changed

+691
-729
lines changed

docs/criteria-api.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ Introduction
1414
DSLs explained here.
1515
The Query DSL is a new, unified interface that combines both Entityql and NativeSql DSLs.
1616

17-
.. note::
18-
19-
In Kotlin environment, use Kotlin specific DSLs instead of the following DSLs.
20-
See :ref:`kotlin-specific-criteria-api`.
21-
2217
There are two kinds of DSLs in the Criteria API:
2318

2419
* The Entityql DSL

docs/kotlin-support.rst

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -100,38 +100,16 @@ Kotlin specific Criteria API
100100
101101
Prefer the Kotlin specific Criteria API to DAO interfaces.
102102
103-
Doma provides Kotlin specific Criteria API, ``KEntityql`` and ``KNativeSql`` DSLs.
104-
They are very similar with the ``Entityql`` and ``NativeSql`` DSLs, which are described in :doc:`criteria-api`.
105-
The biggest feature of the ``KEntityql`` and ``KNativeSql`` DSLs is simplicity.
106-
107-
For example, when you use ``KEntityql``, you have to accept a lambda parameter in a WHERE expression as follows:
108-
109-
.. code-block:: kotlin
110-
111-
val entityql = Entityql(config)
112-
val e = Employee_()
113-
114-
val list = entityql
115-
.from(e)
116-
.where { c ->
117-
c.eq(e.departmentId, 2)
118-
c.isNotNull(e.managerId)
119-
c.or {
120-
c.gt(e.salary, Salary("1000"))
121-
c.lt(e.salary, Salary("2000"))
122-
}
123-
}
124-
.fetch()
125-
126-
The lambda parameter ``c`` is a bit annoying.
127-
On the other hand, when you use ``KEntityql``, the parameter is gone.
103+
Doma provides ``KQueryDsl``, a Criteria API specifically for Kotlin.
104+
It is very similar with the ``QueryDsl``, which is described in :doc:`query-dsl`.
105+
The biggest feature of the ``KQueryDsl`` is simplicity.
128106
129107
.. code-block:: kotlin
130108
131-
val entityql = KEntityql(config)
109+
val queryDsl = KQueryDsl(config)
132110
val e = Employee_()
133111
134-
val list = entityql
112+
val list = queryDsl
135113
.from(e)
136114
.where {
137115
eq(e.departmentId, 2)
@@ -143,9 +121,9 @@ On the other hand, when you use ``KEntityql``, the parameter is gone.
143121
}
144122
.fetch()
145123
146-
You can see a lot of sample code `here <https://github.com/domaframework/doma-it/tree/master/kotlin/src/test/kotlin/org/seasar/doma/it/criteria>`_.
124+
You can see mode sample code `here <https://github.com/domaframework/kotlin-sample>`_.
147125
148-
The ``KEntityql`` and ``KNativeSql`` DSLs are included in doma-kotlin.jar.
126+
The ``KQueryDsl`` is included in the doma-kotlin module.
149127
Note that you should depend on doma-kotlin instead of doma-core in your build script.
150128
You can write build.gradle.kts as follows:
151129

0 commit comments

Comments
 (0)