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

Commit 1698c90

Browse files
authored
Merge pull request #27 from domaframework/feat/query-dsl
Use QueryDsl instead of Entityql and NativeSql
2 parents bfc34b5 + 455c776 commit 1698c90

File tree

10 files changed

+700
-736
lines changed

10 files changed

+700
-736
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/faq.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ There are two ways:
129129
* The SQL Templates.
130130
* The Criteria API.
131131

132-
See :doc:`sql` and :doc:`criteria-api` for detail information.
132+
See :doc:`sql` and :doc:`query-dsl` for detail information.
133133

134134
Does Doma support fetching relationships like one-to-one or one-to-many?
135135
----------------------------------------------------------------------------------------
@@ -138,7 +138,7 @@ Yes.
138138

139139
Doma provides the Criteria API to map database relationships to Java entities.
140140

141-
See :ref:`criteria_associate` for detail information.
141+
See :ref:`query_dsl_associate` for detail information.
142142

143143
Does Doma provide a JDBC connection pooling feature?
144144
----------------------------------------------------

docs/getting-started.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ To execute a SELECT query and retrieve Java object results, follow this example:
9494
9595
public Employee selectById(Integer id) {
9696
var e = new Employee_();
97-
return entityql.from(e).where(c -> c.eq(e.id, id)).fetchOne();
97+
return queryDsl.from(e).where(c -> c.eq(e.id, id)).fetchOne();
9898
}
9999
100100
You'll use a metamodel class, like ``Employee_`` for ``Employee``, which is auto-generated through annotation processing.
101101

102-
The ``entityql`` instance from the ``Entityql`` class serves as the Criteria API's starting point.
102+
The ``queryDsl`` instance from the ``QueryDsl`` class serves as the Criteria API's starting point.
103103

104104
The above code generates the following SQL statement:
105105

@@ -116,7 +116,7 @@ To issue a DELETE statement, write as follows:
116116
117117
public void delete(Employee employee) {
118118
var e = new Employee_();
119-
entityql.delete(e, employee).execute();
119+
queryDsl.delete(e).single(employee).execute();
120120
}
121121
122122
INSERT
@@ -128,7 +128,7 @@ To issue an INSERT statement, write as follows:
128128
129129
public void insert(Employee employee) {
130130
var e = new Employee_();
131-
entityql.insert(e, employee).execute();
131+
queryDsl.insert(e).single(employee).execute();
132132
}
133133
134134
UPDATE
@@ -140,7 +140,7 @@ To issue an UPDATE statement, write as follows:
140140
141141
public void update(Employee employee) {
142142
var e = new Employee_();
143-
entityql.update(e, employee).execute();
143+
queryDsl.update(e).single(employee).execute();
144144
}
145145
146146
DAO style

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)