Skip to content

Commit 50cea17

Browse files
authored
Merge pull request #394 from domaframework/enhance-processors-for-criteira-api
Enhance annotation processors for the Criteria API
2 parents 37858b8 + 679cffe commit 50cea17

File tree

69 files changed

+574
-131
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+574
-131
lines changed

docs/annotation-processing.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ and show you how to pass them to build tools.
1313
Options
1414
=======
1515

16+
doma.criteria.enabled
17+
Whether to generate meta classes for the Criteria API.
18+
The default value is ``true``.
19+
20+
doma.criteria.prefix
21+
The name prefix of the meta classes for the Criteria API.
22+
The default value is an empty string.
23+
24+
doma.criteria.suffix
25+
The name suffix of the meta classes for the Criteria API.
26+
The default value is ``_``.
27+
1628
doma.dao.package
1729
The package that the generated implementation classes of interfaces annotated with ``@Dao`` belong to.
1830
The specified value overrides the value of doma.dao.subpackage.

docs/criteria-api.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ We use the following Entity classes to show you some examples:
6161
Each of the above classes has a corresponding meta class - ``Employee_`` and ``Department_``.
6262
These meta classes allow you to make your query typesafe.
6363

64+
You can customize the name of the meta classes by specifying annotation processor options.
65+
See :doc:`annotation-processing` and check the `doma.criteria.prefix`
66+
and the `doma.criteria.suffix` options.
67+
6468
Entityql DSL
6569
============
6670

@@ -294,6 +298,8 @@ The above query issues the following SQL statement:
294298
from EMPLOYEE t0_
295299
left outer join DEPARTMENT t1_ on (t0_.DEPARTMENT_ID = t1_.DEPARTMENT_ID)
296300
301+
.. _criteria_associate:
302+
297303
associate (Entityql)
298304
--------------------
299305

@@ -653,8 +659,9 @@ The use of the select method (NativeSql)
653659

654660
Be careful of the following points when you use the ``select`` method:
655661

656-
* Specify a type argument to the select method.
657-
* Use the select method in combination with the following map method.
662+
* Specify a type argument to the ``select`` method.
663+
* Use the ``select`` method in combination with the ``map`` method.
664+
The object returned by the ``select`` method doesn't have any ``execute`` methods.
658665

659666
.. code-block:: java
660667

docs/faq.rst

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Runtime environment
3131
Which version of JRE does Doma support?
3232
---------------------------------------
3333

34-
JRE 8, 9, 10, 11, 12, 13 and 14.
34+
JRE 8 and above.
3535

3636
Which libraries are required for Doma to work?
3737
----------------------------------------------
@@ -48,7 +48,7 @@ Development environment
4848
Which version of JDK does Doma support?
4949
---------------------------------------
5050

51-
JDK 8, 9, 10, 11, 12, 13 and 14.
51+
JDK 8 and above.
5252

5353
Which IDE do you recommend?
5454
---------------------------
@@ -105,30 +105,31 @@ Does Doma generate SQL statements?
105105

106106
Yes, Doma generates the following statements:
107107

108+
- SELECT
108109
- INSERT
109110
- DELETE
110111
- UPDATE
111112
- Stored procedure call
112113
- Stored function call
113114

114-
Doma doesn't generate SELECT statements
115-
but executes arbitrary SELECT statements and maps the results to the Java objects.
116-
117-
See also :doc:`query/index` for detailed information.
118-
119115
How are dynamic SQL statements executed?
120116
----------------------------------------
121117

122-
Dynamic SQL statements are built by directives that are represented by the SQL comments.
118+
There are two ways:
119+
120+
* The SQL Templates.
121+
* The Criteria API.
123122

124-
See also :doc:`sql` for detail information.
123+
See :doc:`sql` and :doc:`criteria-api` for detail information.
125124

126125
Does Doma map database relationships such as one-to-one and one-to-many to Java objects?
127126
----------------------------------------------------------------------------------------
128127

129-
No.
128+
Yes.
129+
130+
Doma provides the Criteria API to map database relationships to Java entities.
130131

131-
Doma only maps each row of the SQL result set to a Java entity instance.
132+
See :ref:`criteria_associate` for detail information.
132133

133134
Does Doma provide a JDBC connection pooling feature?
134135
----------------------------------------------------

doma-core/src/main/java/org/seasar/doma/internal/ClassNames.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ public static ClassName newExternalDomainTypeClassName(CharSequence externalDoma
4343
return new ExternalDomainClassNameBuilder(externalDomainClassName).build();
4444
}
4545

46+
public static ClassName newEntityDefClassNameBuilder(
47+
CharSequence entityClassName, String criteriaPrefix, String criteriaSuffix) {
48+
assertNotNull(entityClassName, criteriaPrefix, criteriaSuffix);
49+
return new DefClassNameBuilder(entityClassName, criteriaPrefix, criteriaSuffix).build();
50+
}
51+
52+
public static ClassName newEmbeddableDefClassNameBuilder(
53+
CharSequence entityClassName, String criteriaPrefix, String criteriaSuffix) {
54+
assertNotNull(entityClassName, criteriaPrefix, criteriaSuffix);
55+
return new DefClassNameBuilder(entityClassName, criteriaPrefix, criteriaSuffix).build();
56+
}
57+
4658
private static class ClassNameBuilder {
4759

4860
final String binaryName;
@@ -88,4 +100,26 @@ protected String prefix() {
88100
+ ".";
89101
}
90102
}
103+
104+
private static class DefClassNameBuilder extends ClassNameBuilder {
105+
private final String criteriaPrefix;
106+
private final String criteriaSuffix;
107+
108+
public DefClassNameBuilder(
109+
CharSequence binaryName, String criteriaPrefix, String criteriaSuffix) {
110+
super(binaryName);
111+
this.criteriaPrefix = criteriaPrefix;
112+
this.criteriaSuffix = criteriaSuffix;
113+
}
114+
115+
@Override
116+
protected String infix() {
117+
return criteriaPrefix;
118+
}
119+
120+
@Override
121+
protected String suffix() {
122+
return super.suffix() + criteriaSuffix;
123+
}
124+
}
91125
}

doma-core/src/main/java/org/seasar/doma/jdbc/criteria/AggregateFunctions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.seasar.doma.jdbc.criteria;
22

3-
import org.seasar.doma.def.PropertyDef;
43
import org.seasar.doma.jdbc.criteria.declaration.AggregateFunction;
4+
import org.seasar.doma.jdbc.criteria.def.PropertyDef;
55

66
public final class AggregateFunctions {
77

doma-core/src/main/java/org/seasar/doma/jdbc/criteria/Entityql.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package org.seasar.doma.jdbc.criteria;
22

33
import java.util.Objects;
4-
import org.seasar.doma.def.EntityDef;
54
import org.seasar.doma.jdbc.criteria.context.SelectContext;
65
import org.seasar.doma.jdbc.criteria.declaration.SelectFromDeclaration;
6+
import org.seasar.doma.jdbc.criteria.def.EntityDef;
77
import org.seasar.doma.jdbc.criteria.statement.EntityqlSelectStatement;
88

99
public final class Entityql {

doma-core/src/main/java/org/seasar/doma/jdbc/criteria/NativeSql.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.seasar.doma.jdbc.criteria;
22

33
import java.util.Objects;
4-
import org.seasar.doma.def.EntityDef;
54
import org.seasar.doma.jdbc.criteria.context.DeleteContext;
65
import org.seasar.doma.jdbc.criteria.context.InsertContext;
76
import org.seasar.doma.jdbc.criteria.context.SelectContext;
@@ -10,6 +9,7 @@
109
import org.seasar.doma.jdbc.criteria.declaration.InsertIntoDeclaration;
1110
import org.seasar.doma.jdbc.criteria.declaration.SelectFromDeclaration;
1211
import org.seasar.doma.jdbc.criteria.declaration.UpdateDeclaration;
12+
import org.seasar.doma.jdbc.criteria.def.EntityDef;
1313
import org.seasar.doma.jdbc.criteria.statement.NativeSqlDeleteStarting;
1414
import org.seasar.doma.jdbc.criteria.statement.NativeSqlInsertStarting;
1515
import org.seasar.doma.jdbc.criteria.statement.NativeSqlSelectStarting;

doma-core/src/main/java/org/seasar/doma/jdbc/criteria/command/AssociateCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
import java.util.Map;
88
import java.util.Objects;
99
import java.util.function.BiConsumer;
10-
import org.seasar.doma.def.EntityDef;
1110
import org.seasar.doma.internal.util.Pair;
1211
import org.seasar.doma.jdbc.command.Command;
1312
import org.seasar.doma.jdbc.command.SelectCommand;
1413
import org.seasar.doma.jdbc.criteria.context.SelectContext;
14+
import org.seasar.doma.jdbc.criteria.def.EntityDef;
1515
import org.seasar.doma.jdbc.entity.EntityType;
1616
import org.seasar.doma.jdbc.query.Query;
1717
import org.seasar.doma.jdbc.query.SelectQuery;

doma-core/src/main/java/org/seasar/doma/jdbc/criteria/command/EntityKey.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.util.Collections;
44
import java.util.List;
55
import java.util.Objects;
6-
import org.seasar.doma.def.EntityDef;
6+
import org.seasar.doma.jdbc.criteria.def.EntityDef;
77

88
public final class EntityKey {
99
private final EntityDef<?> entityDef;

doma-core/src/main/java/org/seasar/doma/jdbc/criteria/command/EntityPoolIterationHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import java.util.List;
44
import java.util.Objects;
5-
import org.seasar.doma.def.EntityDef;
65
import org.seasar.doma.internal.jdbc.command.AbstractIterationHandler;
76
import org.seasar.doma.internal.jdbc.command.ResultListCallback;
87
import org.seasar.doma.jdbc.ObjectProvider;
8+
import org.seasar.doma.jdbc.criteria.def.EntityDef;
99
import org.seasar.doma.jdbc.query.SelectQuery;
1010

1111
public class EntityPoolIterationHandler

0 commit comments

Comments
 (0)