1717
1818import java .util .Objects ;
1919import java .util .function .Consumer ;
20- import java .util .function .Function ;
2120
2221import org .jspecify .annotations .Nullable ;
2322import org .mybatis .dynamic .sql .BasicColumn ;
3433 * clauses, but not the other parts of a select (group by, order by, etc.) Count queries always return
3534 * a long. If these restrictions are not acceptable, then use the Select DSL for an unrestricted select statement.
3635 *
37- * @param <R> the type of model built by this Builder. Typically, SelectModel.
38- *
3936 * @author Jeff Butler
4037 */
41- public class CountDSL < R > extends AbstractQueryExpressionDSL <CountDSL < R > .CountWhereBuilder , CountDSL < R > >
42- implements Buildable <R > {
38+ public class CountDSL extends AbstractQueryExpressionDSL <CountDSL .CountWhereBuilder , CountDSL >
39+ implements Buildable <SelectModel > {
4340
44- private final Function <SelectModel , R > adapterFunction ;
4541 private @ Nullable CountWhereBuilder whereBuilder ;
4642 private final BasicColumn countColumn ;
4743 private final StatementConfiguration statementConfiguration = new StatementConfiguration ();
4844
49- private CountDSL (BasicColumn countColumn , SqlTable table , Function < SelectModel , R > adapterFunction ) {
45+ private CountDSL (BasicColumn countColumn , SqlTable table ) {
5046 super (table );
5147 this .countColumn = Objects .requireNonNull (countColumn );
52- this .adapterFunction = Objects .requireNonNull (adapterFunction );
5348 }
5449
5550 @ Override
@@ -59,12 +54,12 @@ public CountWhereBuilder where() {
5954 }
6055
6156 @ Override
62- public R build () {
63- return adapterFunction . apply ( buildModel () );
57+ public SelectModel build () {
58+ return buildModel ();
6459 }
6560
6661 @ Override
67- public CountDSL < R > configureStatement (Consumer <StatementConfiguration > consumer ) {
62+ public CountDSL configureStatement (Consumer <StatementConfiguration > consumer ) {
6863 consumer .accept (statementConfiguration );
6964 return this ;
7065 }
@@ -84,57 +79,43 @@ private SelectModel buildModel() {
8479 .build ();
8580 }
8681
87- public static CountDSL <SelectModel > countFrom (SqlTable table ) {
88- return countFrom (Function .identity (), table );
89- }
90-
91- public static <R > CountDSL <R > countFrom (Function <SelectModel , R > adapterFunction , SqlTable table ) {
92- return new CountDSL <>(SqlBuilder .count (), table , adapterFunction );
93- }
94-
95- public static FromGatherer <SelectModel > count (BasicColumn column ) {
96- return count (Function .identity (), column );
97- }
98-
99- public static <R > FromGatherer <R > count (Function <SelectModel , R > adapterFunction , BasicColumn column ) {
100- return new FromGatherer <>(adapterFunction , SqlBuilder .count (column ));
82+ public static CountDSL countFrom (SqlTable table ) {
83+ return new CountDSL (SqlBuilder .count (), table );
10184 }
10285
103- public static FromGatherer < SelectModel > countDistinct (BasicColumn column ) {
104- return countDistinct ( Function . identity (), column );
86+ public static FromGatherer count (BasicColumn column ) {
87+ return new FromGatherer ( SqlBuilder . count ( column ) );
10588 }
10689
107- public static < R > FromGatherer < R > countDistinct (Function < SelectModel , R > adapterFunction , BasicColumn column ) {
108- return new FromGatherer <>( adapterFunction , SqlBuilder .countDistinct (column ));
90+ public static FromGatherer countDistinct (BasicColumn column ) {
91+ return new FromGatherer ( SqlBuilder .countDistinct (column ));
10992 }
11093
11194 @ Override
112- protected CountDSL < R > getThis () {
95+ protected CountDSL getThis () {
11396 return this ;
11497 }
11598
116- public static class FromGatherer < R > {
99+ public static class FromGatherer {
117100 private final BasicColumn column ;
118- private final Function <SelectModel , R > adapterFunction ;
119101
120- public FromGatherer (Function <SelectModel , R > adapterFunction , BasicColumn column ) {
121- this .adapterFunction = adapterFunction ;
102+ public FromGatherer (BasicColumn column ) {
122103 this .column = column ;
123104 }
124105
125- public CountDSL < R > from (SqlTable table ) {
126- return new CountDSL <> (column , table , adapterFunction );
106+ public CountDSL from (SqlTable table ) {
107+ return new CountDSL (column , table );
127108 }
128109 }
129110
130111 public class CountWhereBuilder extends AbstractWhereFinisher <CountWhereBuilder >
131- implements Buildable <R > {
112+ implements Buildable <SelectModel > {
132113 private CountWhereBuilder () {
133114 super (CountDSL .this );
134115 }
135116
136117 @ Override
137- public R build () {
118+ public SelectModel build () {
138119 return CountDSL .this .build ();
139120 }
140121
0 commit comments