Skip to content

Commit daa4d60

Browse files
committed
Remove DeleteDSL Generic
1 parent eeeba22 commit daa4d60

File tree

5 files changed

+28
-41
lines changed

5 files changed

+28
-41
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import org.jspecify.annotations.Nullable;
2525
import org.mybatis.dynamic.sql.delete.DeleteDSL;
26-
import org.mybatis.dynamic.sql.delete.DeleteModel;
2726
import org.mybatis.dynamic.sql.insert.BatchInsertDSL;
2827
import org.mybatis.dynamic.sql.insert.GeneralInsertDSL;
2928
import org.mybatis.dynamic.sql.insert.InsertDSL;
@@ -138,11 +137,11 @@ static CountDSL<SelectModel> countFrom(SqlTable table) {
138137
return CountDSL.countFrom(table);
139138
}
140139

141-
static DeleteDSL<DeleteModel> deleteFrom(SqlTable table) {
140+
static DeleteDSL deleteFrom(SqlTable table) {
142141
return DeleteDSL.deleteFrom(table);
143142
}
144143

145-
static DeleteDSL<DeleteModel> deleteFrom(SqlTable table, String tableAlias) {
144+
static DeleteDSL deleteFrom(SqlTable table, String tableAlias) {
146145
return DeleteDSL.deleteFrom(table, tableAlias);
147146
}
148147

src/main/java/org/mybatis/dynamic/sql/delete/DeleteDSL.java

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.Collection;
2020
import java.util.Objects;
2121
import java.util.function.Consumer;
22-
import java.util.function.Function;
2322

2423
import org.jspecify.annotations.Nullable;
2524
import org.mybatis.dynamic.sql.SortSpecification;
@@ -32,21 +31,19 @@
3231
import org.mybatis.dynamic.sql.where.AbstractWhereStarter;
3332
import org.mybatis.dynamic.sql.where.EmbeddedWhereModel;
3433

35-
public class DeleteDSL<R> implements AbstractWhereStarter<DeleteDSL<R>.DeleteWhereBuilder, DeleteDSL<R>>,
36-
Buildable<R> {
34+
public class DeleteDSL implements AbstractWhereStarter<DeleteDSL.DeleteWhereBuilder, DeleteDSL>,
35+
Buildable<DeleteModel> {
3736

38-
private final Function<DeleteModel, R> adapterFunction;
3937
private final SqlTable table;
4038
private final @Nullable String tableAlias;
4139
private @Nullable DeleteWhereBuilder whereBuilder;
4240
private final StatementConfiguration statementConfiguration = new StatementConfiguration();
4341
private @Nullable Long limit;
4442
private @Nullable OrderByModel orderByModel;
4543

46-
private DeleteDSL(SqlTable table, @Nullable String tableAlias, Function<DeleteModel, R> adapterFunction) {
44+
private DeleteDSL(SqlTable table, @Nullable String tableAlias) {
4745
this.table = Objects.requireNonNull(table);
4846
this.tableAlias = tableAlias;
49-
this.adapterFunction = Objects.requireNonNull(adapterFunction);
5047
}
5148

5249
@Override
@@ -55,20 +52,20 @@ public DeleteWhereBuilder where() {
5552
return whereBuilder;
5653
}
5754

58-
public DeleteDSL<R> limit(long limit) {
55+
public DeleteDSL limit(long limit) {
5956
return limitWhenPresent(limit);
6057
}
6158

62-
public DeleteDSL<R> limitWhenPresent(@Nullable Long limit) {
59+
public DeleteDSL limitWhenPresent(@Nullable Long limit) {
6360
this.limit = limit;
6461
return this;
6562
}
6663

67-
public DeleteDSL<R> orderBy(SortSpecification... columns) {
64+
public DeleteDSL orderBy(SortSpecification... columns) {
6865
return orderBy(Arrays.asList(columns));
6966
}
7067

71-
public DeleteDSL<R> orderBy(Collection<? extends SortSpecification> columns) {
68+
public DeleteDSL orderBy(Collection<? extends SortSpecification> columns) {
7269
orderByModel = OrderByModel.of(columns);
7370
return this;
7471
}
@@ -80,62 +77,55 @@ public DeleteDSL<R> orderBy(Collection<? extends SortSpecification> columns) {
8077
* @return the model class
8178
*/
8279
@Override
83-
public R build() {
84-
DeleteModel deleteModel = DeleteModel.withTable(table)
80+
public DeleteModel build() {
81+
return DeleteModel.withTable(table)
8582
.withTableAlias(tableAlias)
8683
.withLimit(limit)
8784
.withOrderByModel(orderByModel)
8885
.withWhereModel(whereBuilder == null ? null : whereBuilder.buildWhereModel())
8986
.withStatementConfiguration(statementConfiguration)
9087
.build();
91-
92-
return adapterFunction.apply(deleteModel);
9388
}
9489

9590
@Override
96-
public DeleteDSL<R> configureStatement(Consumer<StatementConfiguration> consumer) {
91+
public DeleteDSL configureStatement(Consumer<StatementConfiguration> consumer) {
9792
consumer.accept(statementConfiguration);
9893
return this;
9994
}
10095

101-
public static <R> DeleteDSL<R> deleteFrom(Function<DeleteModel, R> adapterFunction, SqlTable table,
102-
@Nullable String tableAlias) {
103-
return new DeleteDSL<>(table, tableAlias, adapterFunction);
104-
}
105-
106-
public static DeleteDSL<DeleteModel> deleteFrom(SqlTable table) {
107-
return deleteFrom(Function.identity(), table, null);
96+
public static DeleteDSL deleteFrom(SqlTable table) {
97+
return deleteFrom(table, null);
10898
}
10999

110-
public static DeleteDSL<DeleteModel> deleteFrom(SqlTable table, String tableAlias) {
111-
return deleteFrom(Function.identity(), table, tableAlias);
100+
public static DeleteDSL deleteFrom(SqlTable table, @Nullable String tableAlias) {
101+
return new DeleteDSL(table, tableAlias);
112102
}
113103

114-
public class DeleteWhereBuilder extends AbstractWhereFinisher<DeleteWhereBuilder> implements Buildable<R> {
104+
public class DeleteWhereBuilder extends AbstractWhereFinisher<DeleteWhereBuilder> implements Buildable<DeleteModel> {
115105

116106
private DeleteWhereBuilder() {
117107
super(DeleteDSL.this);
118108
}
119109

120-
public DeleteDSL<R> limit(long limit) {
110+
public DeleteDSL limit(long limit) {
121111
return limitWhenPresent(limit);
122112
}
123113

124-
public DeleteDSL<R> limitWhenPresent(Long limit) {
114+
public DeleteDSL limitWhenPresent(Long limit) {
125115
return DeleteDSL.this.limitWhenPresent(limit);
126116
}
127117

128-
public DeleteDSL<R> orderBy(SortSpecification... columns) {
118+
public DeleteDSL orderBy(SortSpecification... columns) {
129119
return orderBy(Arrays.asList(columns));
130120
}
131121

132-
public DeleteDSL<R> orderBy(Collection<? extends SortSpecification> columns) {
122+
public DeleteDSL orderBy(Collection<? extends SortSpecification> columns) {
133123
orderByModel = OrderByModel.of(columns);
134124
return DeleteDSL.this;
135125
}
136126

137127
@Override
138-
public R build() {
128+
public DeleteModel build() {
139129
return DeleteDSL.this.build();
140130
}
141131

src/main/java/org/mybatis/dynamic/sql/delete/DeleteDSLCompleter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@
6363
* @author Jeff Butler
6464
*/
6565
@FunctionalInterface
66-
public interface DeleteDSLCompleter extends
67-
Function<DeleteDSL<DeleteModel>, Buildable<DeleteModel>> {
66+
public interface DeleteDSLCompleter extends Function<DeleteDSL, Buildable<DeleteModel>> {
6867

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

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

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

2323
typealias DeleteCompleter = KotlinDeleteBuilder.() -> Unit
2424

25-
class KotlinDeleteBuilder(private val dsl: DeleteDSL<DeleteModel>) :
26-
KotlinBaseBuilder<DeleteDSL<DeleteModel>>(), Buildable<DeleteModel> {
25+
class KotlinDeleteBuilder(private val dsl: DeleteDSL) :
26+
KotlinBaseBuilder<DeleteDSL>(), Buildable<DeleteModel> {
2727

2828
fun orderBy(vararg columns: SortSpecification) {
2929
dsl.orderBy(columns.toList())
@@ -39,5 +39,5 @@ class KotlinDeleteBuilder(private val dsl: DeleteDSL<DeleteModel>) :
3939

4040
override fun build(): DeleteModel = dsl.build()
4141

42-
override fun getDsl(): DeleteDSL<DeleteModel> = dsl
42+
override fun getDsl(): DeleteDSL = dsl
4343
}

src/test/java/examples/emptywhere/EmptyWhereTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.junit.jupiter.params.ParameterizedTest;
2828
import org.junit.jupiter.params.provider.MethodSource;
2929
import org.mybatis.dynamic.sql.delete.DeleteDSL;
30-
import org.mybatis.dynamic.sql.delete.DeleteModel;
3130
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
3231
import org.mybatis.dynamic.sql.render.RenderingStrategies;
3332
import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
@@ -90,7 +89,7 @@ void testDeleteThreeConditions() {
9089
String fName = "Fred";
9190
String lName = "Flintstone";
9291

93-
DeleteDSL<DeleteModel>.DeleteWhereBuilder builder = deleteFrom(person)
92+
DeleteDSL.DeleteWhereBuilder builder = deleteFrom(person)
9493
.where(id, isEqualTo(3));
9594

9695
builder.and(firstName, isEqualTo(fName).filter(Objects::nonNull));
@@ -109,7 +108,7 @@ void testDeleteThreeConditions() {
109108
@ParameterizedTest
110109
@MethodSource("whereVariations")
111110
void testDeleteVariations(Variation variation) {
112-
DeleteDSL<DeleteModel>.DeleteWhereBuilder builder = deleteFrom(person)
111+
DeleteDSL.DeleteWhereBuilder builder = deleteFrom(person)
113112
.where();
114113

115114
builder.and(firstName, isEqualTo(variation.firstName).filter(Objects::nonNull));

0 commit comments

Comments
 (0)