Skip to content

Commit e0f799f

Browse files
committed
Remove UpdateDSL Generics
1 parent 32fb3f7 commit e0f799f

File tree

7 files changed

+44
-59
lines changed

7 files changed

+44
-59
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
@@ -57,7 +57,6 @@
5757
import org.mybatis.dynamic.sql.select.function.Subtract;
5858
import org.mybatis.dynamic.sql.select.function.Upper;
5959
import org.mybatis.dynamic.sql.update.UpdateDSL;
60-
import org.mybatis.dynamic.sql.update.UpdateModel;
6160
import org.mybatis.dynamic.sql.util.Buildable;
6261
import org.mybatis.dynamic.sql.where.WhereDSL;
6362
import org.mybatis.dynamic.sql.where.condition.IsBetween;
@@ -237,11 +236,11 @@ static MultiSelectDSL multiSelect(Buildable<SelectModel> selectModelBuilder) {
237236
return new MultiSelectDSL(selectModelBuilder);
238237
}
239238

240-
static UpdateDSL<UpdateModel> update(SqlTable table) {
239+
static UpdateDSL update(SqlTable table) {
241240
return UpdateDSL.update(table);
242241
}
243242

244-
static UpdateDSL<UpdateModel> update(SqlTable table, String tableAlias) {
243+
static UpdateDSL update(SqlTable table, String tableAlias) {
245244
return UpdateDSL.update(table, tableAlias);
246245
}
247246

src/main/java/org/mybatis/dynamic/sql/update/UpdateDSL.java

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.List;
2222
import java.util.Objects;
2323
import java.util.function.Consumer;
24-
import java.util.function.Function;
2524
import java.util.function.Supplier;
2625

2726
import org.jspecify.annotations.Nullable;
@@ -47,10 +46,9 @@
4746
import org.mybatis.dynamic.sql.where.AbstractWhereStarter;
4847
import org.mybatis.dynamic.sql.where.EmbeddedWhereModel;
4948

50-
public class UpdateDSL<R> implements AbstractWhereStarter<UpdateDSL<R>.UpdateWhereBuilder, UpdateDSL<R>>,
51-
Buildable<R> {
49+
public class UpdateDSL implements AbstractWhereStarter<UpdateDSL.UpdateWhereBuilder, UpdateDSL>,
50+
Buildable<UpdateModel> {
5251

53-
private final Function<UpdateModel, R> adapterFunction;
5452
private final List<AbstractColumnMapping> columnMappings = new ArrayList<>();
5553
private final SqlTable table;
5654
private final @Nullable String tableAlias;
@@ -59,10 +57,9 @@ public class UpdateDSL<R> implements AbstractWhereStarter<UpdateDSL<R>.UpdateWhe
5957
private @Nullable Long limit;
6058
private @Nullable OrderByModel orderByModel;
6159

62-
private UpdateDSL(SqlTable table, @Nullable String tableAlias, Function<UpdateModel, R> adapterFunction) {
60+
private UpdateDSL(SqlTable table, @Nullable String tableAlias) {
6361
this.table = Objects.requireNonNull(table);
6462
this.tableAlias = tableAlias;
65-
this.adapterFunction = Objects.requireNonNull(adapterFunction);
6663
}
6764

6865
public <T> SetClauseFinisher<T> set(SqlColumn<T> column) {
@@ -75,20 +72,20 @@ public UpdateWhereBuilder where() {
7572
return whereBuilder;
7673
}
7774

78-
public UpdateDSL<R> limit(long limit) {
75+
public UpdateDSL limit(long limit) {
7976
return limitWhenPresent(limit);
8077
}
8178

82-
public UpdateDSL<R> limitWhenPresent(@Nullable Long limit) {
79+
public UpdateDSL limitWhenPresent(@Nullable Long limit) {
8380
this.limit = limit;
8481
return this;
8582
}
8683

87-
public UpdateDSL<R> orderBy(SortSpecification... columns) {
84+
public UpdateDSL orderBy(SortSpecification... columns) {
8885
return orderBy(Arrays.asList(columns));
8986
}
9087

91-
public UpdateDSL<R> orderBy(Collection<? extends SortSpecification> columns) {
88+
public UpdateDSL orderBy(Collection<? extends SortSpecification> columns) {
9289
orderByModel = OrderByModel.of(columns);
9390
return this;
9491
}
@@ -100,36 +97,29 @@ public UpdateDSL<R> orderBy(Collection<? extends SortSpecification> columns) {
10097
* @return the update model
10198
*/
10299
@Override
103-
public R build() {
104-
UpdateModel updateModel = UpdateModel.withTable(table)
100+
public UpdateModel build() {
101+
return UpdateModel.withTable(table)
105102
.withTableAlias(tableAlias)
106103
.withColumnMappings(columnMappings)
107104
.withLimit(limit)
108105
.withOrderByModel(orderByModel)
109106
.withWhereModel(whereBuilder == null ? null : whereBuilder.buildWhereModel())
110107
.withStatementConfiguration(statementConfiguration)
111108
.build();
112-
113-
return adapterFunction.apply(updateModel);
114109
}
115110

116111
@Override
117-
public UpdateDSL<R> configureStatement(Consumer<StatementConfiguration> consumer) {
112+
public UpdateDSL configureStatement(Consumer<StatementConfiguration> consumer) {
118113
consumer.accept(statementConfiguration);
119114
return this;
120115
}
121116

122-
public static <R> UpdateDSL<R> update(Function<UpdateModel, R> adapterFunction, SqlTable table,
123-
@Nullable String tableAlias) {
124-
return new UpdateDSL<>(table, tableAlias, adapterFunction);
125-
}
126-
127-
public static UpdateDSL<UpdateModel> update(SqlTable table) {
128-
return update(Function.identity(), table, null);
117+
public static UpdateDSL update(SqlTable table, @Nullable String tableAlias) {
118+
return new UpdateDSL(table, tableAlias);
129119
}
130120

131-
public static UpdateDSL<UpdateModel> update(SqlTable table, String tableAlias) {
132-
return update(Function.identity(), table, tableAlias);
121+
public static UpdateDSL update(SqlTable table) {
122+
return update(table, null);
133123
}
134124

135125
public class SetClauseFinisher<T> {
@@ -140,84 +130,85 @@ public SetClauseFinisher(SqlColumn<T> column) {
140130
this.column = column;
141131
}
142132

143-
public UpdateDSL<R> equalToNull() {
133+
public UpdateDSL equalToNull() {
144134
columnMappings.add(NullMapping.of(column));
145135
return UpdateDSL.this;
146136
}
147137

148-
public UpdateDSL<R> equalToConstant(String constant) {
138+
public UpdateDSL equalToConstant(String constant) {
149139
columnMappings.add(ConstantMapping.of(column, constant));
150140
return UpdateDSL.this;
151141
}
152142

153-
public UpdateDSL<R> equalToStringConstant(String constant) {
143+
public UpdateDSL equalToStringConstant(String constant) {
154144
columnMappings.add(StringConstantMapping.of(column, constant));
155145
return UpdateDSL.this;
156146
}
157147

158-
public UpdateDSL<R> equalTo(T value) {
148+
public UpdateDSL equalTo(T value) {
159149
return equalTo(() -> value);
160150
}
161151

162-
public UpdateDSL<R> equalTo(Supplier<T> valueSupplier) {
152+
public UpdateDSL equalTo(Supplier<T> valueSupplier) {
163153
columnMappings.add(ValueMapping.of(column, valueSupplier));
164154
return UpdateDSL.this;
165155
}
166156

167-
public UpdateDSL<R> equalTo(Buildable<SelectModel> buildable) {
157+
public UpdateDSL equalTo(Buildable<SelectModel> buildable) {
168158
columnMappings.add(SelectMapping.of(column, buildable));
169159
return UpdateDSL.this;
170160
}
171161

172-
public UpdateDSL<R> equalTo(BasicColumn rightColumn) {
162+
public UpdateDSL equalTo(BasicColumn rightColumn) {
173163
columnMappings.add(ColumnToColumnMapping.of(column, rightColumn));
174164
return UpdateDSL.this;
175165
}
176166

177-
public UpdateDSL<R> equalToOrNull(@Nullable T value) {
167+
public UpdateDSL equalToOrNull(@Nullable T value) {
178168
return equalToOrNull(() -> value);
179169
}
180170

181-
public UpdateDSL<R> equalToOrNull(Supplier<@Nullable T> valueSupplier) {
171+
public UpdateDSL equalToOrNull(Supplier<@Nullable T> valueSupplier) {
182172
columnMappings.add(ValueOrNullMapping.of(column, valueSupplier));
183173
return UpdateDSL.this;
184174
}
185175

186-
public UpdateDSL<R> equalToWhenPresent(@Nullable T value) {
176+
public UpdateDSL equalToWhenPresent(@Nullable T value) {
187177
return equalToWhenPresent(() -> value);
188178
}
189179

190-
public UpdateDSL<R> equalToWhenPresent(Supplier<@Nullable T> valueSupplier) {
180+
public UpdateDSL equalToWhenPresent(Supplier<@Nullable T> valueSupplier) {
191181
columnMappings.add(ValueWhenPresentMapping.of(column, valueSupplier));
192182
return UpdateDSL.this;
193183
}
194184
}
195185

196-
public class UpdateWhereBuilder extends AbstractWhereFinisher<UpdateWhereBuilder> implements Buildable<R> {
186+
public class UpdateWhereBuilder extends AbstractWhereFinisher<UpdateWhereBuilder>
187+
implements Buildable<UpdateModel> {
197188

198189
private UpdateWhereBuilder() {
199190
super(UpdateDSL.this);
200191
}
201192

202-
public UpdateDSL<R> limit(long limit) {
193+
public UpdateDSL limit(long limit) {
203194
return limitWhenPresent(limit);
204195
}
205196

206-
public UpdateDSL<R> limitWhenPresent(Long limit) {
197+
public UpdateDSL limitWhenPresent(Long limit) {
207198
return UpdateDSL.this.limitWhenPresent(limit);
208199
}
209200

210-
public UpdateDSL<R> orderBy(SortSpecification... columns) {
201+
public UpdateDSL orderBy(SortSpecification... columns) {
211202
return orderBy(Arrays.asList(columns));
212203
}
213204

214-
public UpdateDSL<R> orderBy(Collection<? extends SortSpecification> columns) {
205+
public UpdateDSL orderBy(Collection<? extends SortSpecification> columns) {
215206
orderByModel = OrderByModel.of(columns);
216207
return UpdateDSL.this;
217208
}
218209

219210
@Override
220-
public R build() {
211+
public UpdateModel build() {
221212
return UpdateDSL.this.build();
222213
}
223214

src/main/java/org/mybatis/dynamic/sql/update/UpdateDSLCompleter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,5 @@
8888
*/
8989
@FunctionalInterface
9090
public interface UpdateDSLCompleter extends
91-
Function<UpdateDSL<UpdateModel>, Buildable<UpdateModel>> {
91+
Function<UpdateDSL, Buildable<UpdateModel>> {
9292
}

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

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

2525
typealias UpdateCompleter = KotlinUpdateBuilder.() -> Unit
2626

27-
class KotlinUpdateBuilder(private val dsl: UpdateDSL<UpdateModel>) :
28-
KotlinBaseBuilder<UpdateDSL<UpdateModel>>(), Buildable<UpdateModel> {
27+
class KotlinUpdateBuilder(private val dsl: UpdateDSL) :
28+
KotlinBaseBuilder<UpdateDSL>(), Buildable<UpdateModel> {
2929

3030
fun <T : Any> set(column: SqlColumn<T>): KotlinSetClauseFinisher<T> = KotlinSetClauseFinisher(column)
3131

@@ -43,7 +43,7 @@ class KotlinUpdateBuilder(private val dsl: UpdateDSL<UpdateModel>) :
4343

4444
override fun build(): UpdateModel = dsl.build()
4545

46-
override fun getDsl(): UpdateDSL<UpdateModel> = dsl
46+
override fun getDsl(): UpdateDSL = dsl
4747

4848
@MyBatisDslMarker
4949
@Suppress("TooManyFunctions")
@@ -94,7 +94,7 @@ class KotlinUpdateBuilder(private val dsl: UpdateDSL<UpdateModel>) :
9494

9595
infix fun equalToWhenPresent(value: T?): Unit = equalToWhenPresent { value }
9696

97-
private fun applyToDsl(block: UpdateDSL<UpdateModel>.() -> Unit) {
97+
private fun applyToDsl(block: UpdateDSL.() -> Unit) {
9898
this@KotlinUpdateBuilder.dsl.apply(block)
9999
}
100100
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
3333
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
3434
import org.mybatis.dynamic.sql.update.UpdateDSL;
35-
import org.mybatis.dynamic.sql.update.UpdateModel;
3635
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
3736
import org.mybatis.dynamic.sql.where.WhereDSL;
3837
import org.mybatis.dynamic.sql.where.render.WhereClauseProvider;
@@ -212,7 +211,7 @@ void testUpdateThreeConditions() {
212211
String fName = "Fred";
213212
String lName = "Flintstone";
214213

215-
UpdateDSL<UpdateModel>.UpdateWhereBuilder builder = update(person)
214+
UpdateDSL.UpdateWhereBuilder builder = update(person)
216215
.set(id).equalTo(3)
217216
.where(id, isEqualTo(3));
218217

@@ -233,7 +232,7 @@ void testUpdateThreeConditions() {
233232
@ParameterizedTest
234233
@MethodSource("updateWhereVariations")
235234
void testUpdateVariations(Variation variation) {
236-
UpdateDSL<UpdateModel>.UpdateWhereBuilder builder = update(person)
235+
UpdateDSL.UpdateWhereBuilder builder = update(person)
237236
.set(id).equalTo(3)
238237
.where();
239238

src/test/java/examples/generated/always/mybatis/GeneratedAlwaysMapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
3737
import org.mybatis.dynamic.sql.update.UpdateDSL;
3838
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
39-
import org.mybatis.dynamic.sql.update.UpdateModel;
4039
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
4140
import org.mybatis.dynamic.sql.util.mybatis3.CommonUpdateMapper;
4241
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;
@@ -128,7 +127,7 @@ default int updateByPrimaryKeySelective(GeneratedAlwaysRecord row) {
128127
);
129128
}
130129

131-
static UpdateDSL<UpdateModel> updateSelectiveColumns(GeneratedAlwaysRecord row, UpdateDSL<UpdateModel> dsl) {
130+
static UpdateDSL updateSelectiveColumns(GeneratedAlwaysRecord row, UpdateDSL dsl) {
132131
return dsl.set(id).equalToWhenPresent(row::getId)
133132
.set(firstName).equalToWhenPresent(row::getFirstName)
134133
.set(lastName).equalToWhenPresent(row::getLastName);

src/test/java/examples/simple/PersonMapper.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
3939
import org.mybatis.dynamic.sql.update.UpdateDSL;
4040
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
41-
import org.mybatis.dynamic.sql.update.UpdateModel;
4241
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
4342
import org.mybatis.dynamic.sql.util.mybatis3.CommonCountMapper;
4443
import org.mybatis.dynamic.sql.util.mybatis3.CommonDeleteMapper;
@@ -162,8 +161,7 @@ default int update(UpdateDSLCompleter completer) {
162161
return MyBatis3Utils.update(this::update, person, completer);
163162
}
164163

165-
static UpdateDSL<UpdateModel> updateAllColumns(PersonRecord row,
166-
UpdateDSL<UpdateModel> dsl) {
164+
static UpdateDSL updateAllColumns(PersonRecord row, UpdateDSL dsl) {
167165
return dsl.set(id).equalTo(row::getId)
168166
.set(firstName).equalTo(row::getFirstName)
169167
.set(lastName).equalTo(row::getLastName)
@@ -173,8 +171,7 @@ static UpdateDSL<UpdateModel> updateAllColumns(PersonRecord row,
173171
.set(addressId).equalTo(row::getAddressId);
174172
}
175173

176-
static UpdateDSL<UpdateModel> updateSelectiveColumns(PersonRecord row,
177-
UpdateDSL<UpdateModel> dsl) {
174+
static UpdateDSL updateSelectiveColumns(PersonRecord row, UpdateDSL dsl) {
178175
return dsl.set(id).equalToWhenPresent(row::getId)
179176
.set(firstName).equalToWhenPresent(row::getFirstName)
180177
.set(lastName).equalToWhenPresent(row::getLastName)

0 commit comments

Comments
 (0)