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

Commit ac5373e

Browse files
committed
Add documentation for user-defined operators
1 parent e6f5908 commit ac5373e

File tree

2 files changed

+66
-10
lines changed

2 files changed

+66
-10
lines changed

docs/locale/ja/LC_MESSAGES/query-dsl.po

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ msgid ""
22
msgstr ""
33
"Project-Id-Version: doma-docs\n"
44
"Report-Msgid-Bugs-To: \n"
5-
"POT-Creation-Date: 2025-05-05 10:22+0900\n"
5+
"POT-Creation-Date: 2025-06-06 20:58+0900\n"
66
"Last-Translator: \n"
77
"Language-Team: Japanese\n"
88
"MIME-Version: 1.0\n"
@@ -1213,42 +1213,58 @@ msgid "This feature is useful for working with two tables that share the same st
12131213
msgstr "この機能は、同じ構造を共有する2つのテーブルを扱う場合に便利です。"
12141214

12151215
#: ../../query-dsl.rst:1983
1216+
msgid "User-Defined Operators"
1217+
msgstr "ユーザー定義演算子"
1218+
1219+
#: ../../query-dsl.rst:1985
1220+
msgid "User-defined operators can be implemented as methods in a class that accepts a ``UserDefinedCriteriaContext`` instance via its constructor."
1221+
msgstr "ユーザー定義の演算子は、 ``UserDefinedCriteriaContext`` インスタンスをコンストラクタを介して受け入れるクラスのメソッドとして実装することができます。"
1222+
1223+
#: ../../query-dsl.rst:2000
1224+
msgid "The class above can be used in the WHERE, JOIN, or HAVING clause of a query as follows:"
1225+
msgstr "上記のクラスは、クエリの WHERE、JOIN、または HAVING 句で次のように使用できます。"
1226+
1227+
#: ../../query-dsl.rst:2014
1228+
msgid "The query above is translated into the following SQL:"
1229+
msgstr "上記のクエリは次の SQL に変換されます。"
1230+
1231+
#: ../../query-dsl.rst:2023
12161232
msgid "Debugging"
12171233
msgstr "デバッグ"
12181234

1219-
#: ../../query-dsl.rst:1985
1235+
#: ../../query-dsl.rst:2025
12201236
msgid "To inspect the SQL statement generated by DSLs, use the ``asSql`` method:"
12211237
msgstr "DSL によって生成される SQL ステートメントを調べるには、``asSql`` メソッドを使用します。"
12221238

1223-
#: ../../query-dsl.rst:1997
1239+
#: ../../query-dsl.rst:2037
12241240
msgid "The code above outputs the following:"
12251241
msgstr "上記のコードは以下を出力します。"
12261242

1227-
#: ../../query-dsl.rst:2004
1243+
#: ../../query-dsl.rst:2044
12281244
msgid "The ``asSql`` method does not execute the SQL statement against the database; instead, it only constructs the SQL statement and returns it as an ``Sql`` object."
12291245
msgstr "``asSql`` メソッドはSQLステートメントをデータベースに対して実行しません。代わりに、SQLステートメントを構築し、``Sql`` オブジェクトとして返します。"
12301246

1231-
#: ../../query-dsl.rst:2006
1247+
#: ../../query-dsl.rst:2046
12321248
msgid "You can also obtain the ``Sql`` object by using the ``peek`` method:"
12331249
msgstr "``peek`` メソッドを使用して ``Sql`` オブジェクトを取得することもできます。"
12341250

1235-
#: ../../query-dsl.rst:2021
1251+
#: ../../query-dsl.rst:2061
12361252
msgid "The code above outputs SQL statements at various stages of the query:"
12371253
msgstr "上記のコードは、クエリの様々な段階で SQL ステートメントを出力します。"
12381254

1239-
#: ../../query-dsl.rst:2031
1255+
#: ../../query-dsl.rst:2071
12401256
msgid "Sample Projects"
12411257
msgstr "サンプルプロジェクト"
12421258

1243-
#: ../../query-dsl.rst:2033
1259+
#: ../../query-dsl.rst:2073
12441260
msgid "You can refer to the following sample projects for additional guidance:"
12451261
msgstr "追加のガイダンスについては、以下のサンプルプロジェクトを参照してください。"
12461262

1247-
#: ../../query-dsl.rst:2035
1263+
#: ../../query-dsl.rst:2075
12481264
msgid "`simple-examples <https://github.com/domaframework/simple-examples>`_"
12491265
msgstr ""
12501266

1251-
#: ../../query-dsl.rst:2036
1267+
#: ../../query-dsl.rst:2076
12521268
msgid "`kotlin-sample <https://github.com/domaframework/kotlin-sample>`_"
12531269
msgstr ""
12541270

docs/query-dsl.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,6 +1979,46 @@ This generates:
19791979
LOCATION, VERSION) select t0_.DEPARTMENT_ID, t0_.DEPARTMENT_NO, t0_.DEPARTMENT_NAME,
19801980
t0_.LOCATION, t0_.VERSION from DEPARTMENT t0_
19811981
1982+
User-Defined Operators
1983+
----------------------
1984+
1985+
User-defined operators can be implemented as methods in a class that accepts a ``UserDefinedCriteriaContext`` instance via its constructor.
1986+
1987+
.. code-block:: java
1988+
1989+
record MyExtension(UserDefinedCriteriaContext context) {
1990+
public void regexp(PropertyMetamodel<String> propertyMetamodel, String regexp) {
1991+
context.add(
1992+
(b) -> {
1993+
b.appendExpression(propertyMetamodel);
1994+
b.appendSql(" ~ ");
1995+
b.appendParameter(propertyMetamodel, regexp);
1996+
});
1997+
}
1998+
}
1999+
2000+
The class above can be used in the WHERE, JOIN, or HAVING clause of a query as follows:
2001+
2002+
.. code-block:: java
2003+
2004+
var d = new Department_();
2005+
var list =
2006+
queryDsl.from(d)
2007+
.where(c -> c.extension(MyExtension::new, (ext) -> {
2008+
ext.regexp(d.departmentName, "A");
2009+
}))
2010+
.orderBy(c -> c.asc(d.departmentId))
2011+
.select()
2012+
.fetch();
2013+
2014+
The query above is translated into the following SQL:
2015+
2016+
.. code-block:: sql
2017+
2018+
select t0_.DEPARTMENT_ID, t0_.DEPARTMENT_NO, t0_.DEPARTMENT_NAME, t0_.LOCATION, t0_.VERSION from DEPARTMENT t0_
2019+
where t0_.DEPARTMENT_NAME ~ ?
2020+
order by t0_.DEPARTMENT_ID asc
2021+
19822022
Debugging
19832023
=========
19842024

0 commit comments

Comments
 (0)