Skip to content

Commit 1d7e02b

Browse files
committed
Remove CountDSL Generic
1 parent daa4d60 commit 1d7e02b

File tree

6 files changed

+30
-50
lines changed

6 files changed

+30
-50
lines changed

src/main/java/org/mybatis/dynamic/sql/SqlBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public interface SqlBuilder {
109109
*
110110
* @return the next step in the DSL
111111
*/
112-
static CountDSL.FromGatherer<SelectModel> countDistinctColumn(BasicColumn column) {
112+
static CountDSL.FromGatherer countDistinctColumn(BasicColumn column) {
113113
return CountDSL.countDistinct(column);
114114
}
115115

@@ -121,7 +121,7 @@ static CountDSL.FromGatherer<SelectModel> countDistinctColumn(BasicColumn column
121121
*
122122
* @return the next step in the DSL
123123
*/
124-
static CountDSL.FromGatherer<SelectModel> countColumn(BasicColumn column) {
124+
static CountDSL.FromGatherer countColumn(BasicColumn column) {
125125
return CountDSL.count(column);
126126
}
127127

@@ -133,7 +133,7 @@ static CountDSL.FromGatherer<SelectModel> countColumn(BasicColumn column) {
133133
*
134134
* @return the next step in the DSL
135135
*/
136-
static CountDSL<SelectModel> countFrom(SqlTable table) {
136+
static CountDSL countFrom(SqlTable table) {
137137
return CountDSL.countFrom(table);
138138
}
139139

src/main/java/org/mybatis/dynamic/sql/select/CountDSL.java

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import java.util.Objects;
1919
import java.util.function.Consumer;
20-
import java.util.function.Function;
2120

2221
import org.jspecify.annotations.Nullable;
2322
import org.mybatis.dynamic.sql.BasicColumn;
@@ -34,22 +33,18 @@
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

src/main/java/org/mybatis/dynamic/sql/select/CountDSLCompleter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@
6262
* @author Jeff Butler
6363
*/
6464
@FunctionalInterface
65-
public interface CountDSLCompleter extends
66-
Function<CountDSL<SelectModel>, Buildable<SelectModel>> {
65+
public interface CountDSLCompleter extends Function<CountDSL, Buildable<SelectModel>> {
6766

6867
/**
6968
* Returns a completer that can be used to count every row in a table.

src/main/java/org/mybatis/dynamic/sql/util/mybatis3/MyBatis3Utils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ public static long countFrom(ToLongFunction<SelectStatementProvider> mapper,
8080
return mapper.applyAsLong(countFrom(table, completer));
8181
}
8282

83-
public static SelectStatementProvider countFrom(CountDSL<SelectModel> start, CountDSLCompleter completer) {
83+
public static SelectStatementProvider countFrom(CountDSL start, CountDSLCompleter completer) {
8484
return completer.apply(start)
8585
.build()
8686
.render(RenderingStrategies.MYBATIS3);
8787
}
8888

8989
public static long countFrom(ToLongFunction<SelectStatementProvider> mapper,
90-
CountDSL<SelectModel> start, CountDSLCompleter completer) {
90+
CountDSL start, CountDSLCompleter completer) {
9191
return mapper.applyAsLong(countFrom(start, completer));
9292
}
9393

src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinCountBuilder.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import org.mybatis.dynamic.sql.util.Buildable
2222

2323
typealias CountCompleter = KotlinCountBuilder.() -> Unit
2424

25-
class KotlinCountBuilder(private val fromGatherer: CountDSL.FromGatherer<SelectModel>) :
26-
KotlinBaseJoiningBuilder<CountDSL<SelectModel>>(),
25+
class KotlinCountBuilder(private val fromGatherer: CountDSL.FromGatherer) :
26+
KotlinBaseJoiningBuilder<CountDSL>(),
2727
Buildable<SelectModel> {
2828

29-
private var dsl: CountDSL<SelectModel>? = null
29+
private var dsl: CountDSL? = null
3030

3131
fun from(table: SqlTable): KotlinCountBuilder =
3232
apply {
@@ -35,5 +35,5 @@ class KotlinCountBuilder(private val fromGatherer: CountDSL.FromGatherer<SelectM
3535

3636
override fun build(): SelectModel = getDsl().build()
3737

38-
override fun getDsl(): CountDSL<SelectModel> = invalidIfNull(dsl, "ERROR.24") //$NON-NLS-1$
38+
override fun getDsl(): CountDSL = invalidIfNull(dsl, "ERROR.24") //$NON-NLS-1$
3939
}

src/test/java/examples/simple/PersonWithAddressMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ default Optional<PersonWithAddress> selectByPrimaryKey(Integer recordId) {
9797
}
9898

9999
default long count(CountDSLCompleter completer) {
100-
CountDSL<SelectModel> start = countFrom(person)
100+
CountDSL start = countFrom(person)
101101
.join(address, on(person.addressId, isEqualTo(address.id)));
102102
return MyBatis3Utils.countFrom(this::count, start, completer);
103103
}

0 commit comments

Comments
 (0)