Skip to content

Commit 504ff0d

Browse files
committed
Renaming for clarity
1 parent ec437a0 commit 504ff0d

File tree

8 files changed

+86
-86
lines changed

8 files changed

+86
-86
lines changed

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

+11-14
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.mybatis.dynamic.sql.delete;
1717

18+
import java.util.Objects;
1819
import java.util.function.Function;
1920

2021
import org.mybatis.dynamic.sql.BindableColumn;
@@ -26,12 +27,12 @@
2627

2728
public class DeleteDSL<R> {
2829

29-
private Function<DeleteModel, R> decoratorFunction;
30+
private Function<DeleteModel, R> adapterFunction;
3031
private SqlTable table;
3132

32-
private DeleteDSL(SqlTable table, Function<DeleteModel, R> decoratorFunction) {
33-
this.table = table;
34-
this.decoratorFunction = decoratorFunction;
33+
private DeleteDSL(SqlTable table, Function<DeleteModel, R> adapterFunction) {
34+
this.table = Objects.requireNonNull(table);
35+
this.adapterFunction = Objects.requireNonNull(adapterFunction);
3536
}
3637

3738
public <T> DeleteWhereBuilder where(BindableColumn<T> column, VisitableCondition<T> condition) {
@@ -53,23 +54,19 @@ public R build() {
5354
DeleteModel deleteModel = new DeleteModel.Builder()
5455
.withTable(table)
5556
.build();
56-
return decoratorFunction.apply(deleteModel);
57+
return adapterFunction.apply(deleteModel);
5758
}
5859

59-
public static <R> DeleteDSL<R> genericDeleteFrom(SqlTable table, Function<DeleteModel, R> decoratorFunction) {
60-
return new DeleteDSL<>(table, decoratorFunction);
60+
public static <R> DeleteDSL<R> genericDeleteFrom(SqlTable table, Function<DeleteModel, R> adapterFunction) {
61+
return new DeleteDSL<>(table, adapterFunction);
6162
}
6263

6364
public static DeleteDSL<DeleteModel> deleteFrom(SqlTable table) {
6465
return genericDeleteFrom(table, Function.identity());
6566
}
6667

67-
public static DeleteDSL<MyBatis3DeleteModel> deleteFrom(SqlTable table, Function<DeleteStatement, Integer> mapperMethod) {
68-
return genericDeleteFrom(table, decorate(mapperMethod));
69-
}
70-
71-
private static Function<DeleteModel, MyBatis3DeleteModel> decorate(Function<DeleteStatement, Integer> mapperMethod) {
72-
return deleteModel -> MyBatis3DeleteModel.of(deleteModel, mapperMethod);
68+
public static <T> DeleteDSL<MyBatis3DeleteModelAdapter<T>> deleteFrom(SqlTable table, Function<DeleteStatement, T> mapperMethod) {
69+
return genericDeleteFrom(table, deleteModel -> MyBatis3DeleteModelAdapter.of(deleteModel, mapperMethod));
7370
}
7471

7572
public class DeleteWhereBuilder extends AbstractWhereDSL<DeleteWhereBuilder> {
@@ -88,7 +85,7 @@ public R build() {
8885
.withTable(table)
8986
.withWhereModel(buildWhereModel())
9087
.build();
91-
return decoratorFunction.apply(deleteModel);
88+
return adapterFunction.apply(deleteModel);
9289
}
9390

9491
@Override

src/main/java/org/mybatis/dynamic/sql/delete/MyBatis3DeleteModel.java src/main/java/org/mybatis/dynamic/sql/delete/MyBatis3DeleteModelAdapter.java

+15-10
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,37 @@
1515
*/
1616
package org.mybatis.dynamic.sql.delete;
1717

18+
import java.util.Objects;
1819
import java.util.function.Function;
1920

2021
import org.mybatis.dynamic.sql.delete.render.DeleteStatement;
2122
import org.mybatis.dynamic.sql.render.RenderingStrategy;
2223

2324
/**
24-
* This DeleteModel will render the underlying delete model for MyBatis3, and then call a MyBatis mapper method.
25+
* This adapter will render the underlying delete model for MyBatis3, and then call a MyBatis mapper method.
2526
*
2627
* @author Jeff Butler
2728
*
2829
*/
29-
public class MyBatis3DeleteModel {
30+
public class MyBatis3DeleteModelAdapter<R> {
3031

3132
private DeleteModel deleteModel;
32-
private Function<DeleteStatement, Integer> mapperMethod;
33+
private Function<DeleteStatement, R> mapperMethod;
3334

34-
private MyBatis3DeleteModel(DeleteModel deleteModel, Function<DeleteStatement, Integer> mapperMethod) {
35-
this.deleteModel = deleteModel;
36-
this.mapperMethod = mapperMethod;
35+
private MyBatis3DeleteModelAdapter(DeleteModel deleteModel, Function<DeleteStatement, R> mapperMethod) {
36+
this.deleteModel = Objects.requireNonNull(deleteModel);
37+
this.mapperMethod = Objects.requireNonNull(mapperMethod);
3738
}
3839

39-
public int execute() {
40-
return mapperMethod.apply(deleteModel.render(RenderingStrategy.MYBATIS3));
40+
public R execute() {
41+
return mapperMethod.apply(deleteStatement());
4142
}
4243

43-
public static MyBatis3DeleteModel of(DeleteModel deleteModel, Function<DeleteStatement, Integer> mapperMethod) {
44-
return new MyBatis3DeleteModel(deleteModel, mapperMethod);
44+
private DeleteStatement deleteStatement() {
45+
return deleteModel.render(RenderingStrategy.MYBATIS3);
46+
}
47+
48+
public static <R> MyBatis3DeleteModelAdapter<R> of(DeleteModel deleteModel, Function<DeleteStatement, R> mapperMethod) {
49+
return new MyBatis3DeleteModelAdapter<>(deleteModel, mapperMethod);
4550
}
4651
}

src/main/java/org/mybatis/dynamic/sql/select/MyBatis3SelectModel.java src/main/java/org/mybatis/dynamic/sql/select/MyBatis3SelectModelAdapter.java

+13-8
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,37 @@
1515
*/
1616
package org.mybatis.dynamic.sql.select;
1717

18+
import java.util.Objects;
1819
import java.util.function.Function;
1920

2021
import org.mybatis.dynamic.sql.render.RenderingStrategy;
2122
import org.mybatis.dynamic.sql.select.render.SelectStatement;
2223

2324
/**
24-
* This SelectModel will render the underlying select model for MyBatis3, and then call a MyBatis mapper method.
25+
* This adapter will render the underlying select model for MyBatis3, and then call a MyBatis mapper method.
2526
*
2627
* @author Jeff Butler
2728
*
2829
*/
29-
public class MyBatis3SelectModel<R> {
30+
public class MyBatis3SelectModelAdapter<R> {
3031

3132
private SelectModel selectModel;
3233
private Function<SelectStatement, R> mapperMethod;
3334

34-
private MyBatis3SelectModel(SelectModel selectModel, Function<SelectStatement, R> mapperMethod) {
35-
this.selectModel = selectModel;
36-
this.mapperMethod = mapperMethod;
35+
private MyBatis3SelectModelAdapter(SelectModel selectModel, Function<SelectStatement, R> mapperMethod) {
36+
this.selectModel = Objects.requireNonNull(selectModel);
37+
this.mapperMethod = Objects.requireNonNull(mapperMethod);
3738
}
3839

3940
public R execute() {
40-
return mapperMethod.apply(selectModel.render(RenderingStrategy.MYBATIS3));
41+
return mapperMethod.apply(selectStatement());
4142
}
4243

43-
public static <R> MyBatis3SelectModel<R> of(SelectModel selectModel, Function<SelectStatement, R> mapperMethod) {
44-
return new MyBatis3SelectModel<>(selectModel, mapperMethod);
44+
private SelectStatement selectStatement() {
45+
return selectModel.render(RenderingStrategy.MYBATIS3);
46+
}
47+
48+
public static <R> MyBatis3SelectModelAdapter<R> of(SelectModel selectModel, Function<SelectStatement, R> mapperMethod) {
49+
return new MyBatis3SelectModelAdapter<>(selectModel, mapperMethod);
4550
}
4651
}

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

+12-16
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
*/
3333
public class SelectDSL<R> {
3434

35-
private Function<SelectModel, R> decoratorFunction;
35+
private Function<SelectModel, R> adapterFunction;
3636
private List<QueryExpressionModel> queryExpressions = new ArrayList<>();
3737
private OrderByModel orderByModel;
3838

39-
private SelectDSL(Function<SelectModel, R> decoratorFunction) {
40-
this.decoratorFunction = Objects.requireNonNull(decoratorFunction);
39+
private SelectDSL(Function<SelectModel, R> adapterFunction) {
40+
this.adapterFunction = Objects.requireNonNull(adapterFunction);
4141
}
4242

4343
private QueryExpressionDSL<R> queryExpressionBuilder(BasicColumn...selectList) {
@@ -55,34 +55,30 @@ private QueryExpressionDSL<R> distinctQueryExpressionBuilder(BasicColumn...selec
5555
.build();
5656
}
5757

58-
public static <R> QueryExpressionDSL<R> genericSelect(Function<SelectModel, R> decoratorFunction, BasicColumn...selectList) {
59-
SelectDSL<R> selectModelBuilder = new SelectDSL<>(decoratorFunction);
58+
public static <R> QueryExpressionDSL<R> genericSelect(Function<SelectModel, R> adapterFunction, BasicColumn...selectList) {
59+
SelectDSL<R> selectModelBuilder = new SelectDSL<>(adapterFunction);
6060
return selectModelBuilder.queryExpressionBuilder(selectList);
6161
}
6262

63-
public static <R> QueryExpressionDSL<R> genericSelectDistinct(Function<SelectModel, R> decoratorFunction, BasicColumn...selectList) {
64-
SelectDSL<R> selectModelBuilder = new SelectDSL<>(decoratorFunction);
63+
public static <R> QueryExpressionDSL<R> genericSelectDistinct(Function<SelectModel, R> adapterFunction, BasicColumn...selectList) {
64+
SelectDSL<R> selectModelBuilder = new SelectDSL<>(adapterFunction);
6565
return selectModelBuilder.distinctQueryExpressionBuilder(selectList);
6666
}
6767

6868
public static QueryExpressionDSL<SelectModel> select(BasicColumn...selectList) {
6969
return genericSelect(Function.identity(), selectList);
7070
}
7171

72-
public static <T> QueryExpressionDSL<MyBatis3SelectModel<T>> select(Function<SelectStatement, T> mapperMethod, BasicColumn...selectList) {
73-
return genericSelect(decorate(mapperMethod), selectList);
72+
public static <T> QueryExpressionDSL<MyBatis3SelectModelAdapter<T>> select(Function<SelectStatement, T> mapperMethod, BasicColumn...selectList) {
73+
return genericSelect(selectModel -> MyBatis3SelectModelAdapter.of(selectModel, mapperMethod), selectList);
7474
}
7575

7676
public static QueryExpressionDSL<SelectModel> selectDistinct(BasicColumn...selectList) {
7777
return genericSelectDistinct(Function.identity(), selectList);
7878
}
7979

80-
public static <T> QueryExpressionDSL<MyBatis3SelectModel<T>> selectDistinct(Function<SelectStatement, T> mapperMethod, BasicColumn...selectList) {
81-
return genericSelectDistinct(decorate(mapperMethod), selectList);
82-
}
83-
84-
private static <T> Function<SelectModel, MyBatis3SelectModel<T>> decorate(Function<SelectStatement, T> mapperMethod) {
85-
return selectModel -> MyBatis3SelectModel.of(selectModel, mapperMethod);
80+
public static <T> QueryExpressionDSL<MyBatis3SelectModelAdapter<T>> selectDistinct(Function<SelectStatement, T> mapperMethod, BasicColumn...selectList) {
81+
return genericSelectDistinct(selectModel -> MyBatis3SelectModelAdapter.of(selectModel, mapperMethod), selectList);
8682
}
8783

8884
void addQueryExpression(QueryExpressionModel queryExpression) {
@@ -98,6 +94,6 @@ public R build() {
9894
.withQueryExpressions(queryExpressions)
9995
.withOrderByModel(orderByModel)
10096
.build();
101-
return decoratorFunction.apply(selectModel);
97+
return adapterFunction.apply(selectModel);
10298
}
10399
}

src/main/java/org/mybatis/dynamic/sql/update/MyBatis3UpdateModel.java src/main/java/org/mybatis/dynamic/sql/update/MyBatis3UpdateModelAdapter.java

+15-10
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,37 @@
1515
*/
1616
package org.mybatis.dynamic.sql.update;
1717

18+
import java.util.Objects;
1819
import java.util.function.Function;
1920

2021
import org.mybatis.dynamic.sql.render.RenderingStrategy;
2122
import org.mybatis.dynamic.sql.update.render.UpdateStatement;
2223

2324
/**
24-
* This UpdateModel will render the underlying update model for MyBatis3, and then call a MyBatis mapper method.
25+
* This adapter will render the underlying update model for MyBatis3, and then call a MyBatis mapper method.
2526
*
2627
* @author Jeff Butler
2728
*
2829
*/
29-
public class MyBatis3UpdateModel {
30+
public class MyBatis3UpdateModelAdapter<R> {
3031

3132
private UpdateModel updateModel;
32-
private Function<UpdateStatement, Integer> mapperMethod;
33+
private Function<UpdateStatement, R> mapperMethod;
3334

34-
private MyBatis3UpdateModel(UpdateModel updateModel, Function<UpdateStatement, Integer> mapperMethod) {
35-
this.updateModel = updateModel;
36-
this.mapperMethod = mapperMethod;
35+
private MyBatis3UpdateModelAdapter(UpdateModel updateModel, Function<UpdateStatement, R> mapperMethod) {
36+
this.updateModel = Objects.requireNonNull(updateModel);
37+
this.mapperMethod = Objects.requireNonNull(mapperMethod);
3738
}
3839

39-
public int execute() {
40-
return mapperMethod.apply(updateModel.render(RenderingStrategy.MYBATIS3));
40+
public R execute() {
41+
return mapperMethod.apply(updateStatement());
4142
}
4243

43-
public static MyBatis3UpdateModel of(UpdateModel updateModel, Function<UpdateStatement, Integer> mapperMethod) {
44-
return new MyBatis3UpdateModel(updateModel, mapperMethod);
44+
private UpdateStatement updateStatement() {
45+
return updateModel.render(RenderingStrategy.MYBATIS3);
46+
}
47+
48+
public static <R> MyBatis3UpdateModelAdapter<R> of(UpdateModel updateModel, Function<UpdateStatement, R> mapperMethod) {
49+
return new MyBatis3UpdateModelAdapter<>(updateModel, mapperMethod);
4550
}
4651
}

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

+9-13
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@
3535

3636
public class UpdateDSL<R> {
3737

38-
private Function<UpdateModel, R> decoratorFunction;
38+
private Function<UpdateModel, R> adapterFunction;
3939
private List<UpdateMapping> columnsAndValues = new ArrayList<>();
4040
private SqlTable table;
4141

42-
private UpdateDSL(SqlTable table, Function<UpdateModel, R> decoratorFunction) {
42+
private UpdateDSL(SqlTable table, Function<UpdateModel, R> adapterFunction) {
4343
this.table = Objects.requireNonNull(table);
44-
this.decoratorFunction = Objects.requireNonNull(decoratorFunction);
44+
this.adapterFunction = Objects.requireNonNull(adapterFunction);
4545
}
4646

4747
public <T> SetClauseFinisher<T> set(SqlColumn<T> column) {
@@ -68,23 +68,19 @@ public R build() {
6868
.withTable(table)
6969
.withColumnValues(columnsAndValues)
7070
.build();
71-
return decoratorFunction.apply(updateModel);
71+
return adapterFunction.apply(updateModel);
7272
}
7373

74-
public static <R> UpdateDSL<R> genericUpdate(Function<UpdateModel, R> decoratorFunction, SqlTable table) {
75-
return new UpdateDSL<>(table, decoratorFunction);
74+
public static <R> UpdateDSL<R> genericUpdate(Function<UpdateModel, R> adapterFunction, SqlTable table) {
75+
return new UpdateDSL<>(table, adapterFunction);
7676
}
7777

7878
public static UpdateDSL<UpdateModel> update(SqlTable table) {
7979
return genericUpdate(Function.identity(), table);
8080
}
8181

82-
public static UpdateDSL<MyBatis3UpdateModel> update(Function<UpdateStatement, Integer> mapperMethod, SqlTable table) {
83-
return genericUpdate(decorate(mapperMethod), table);
84-
}
85-
86-
private static Function<UpdateModel, MyBatis3UpdateModel> decorate(Function<UpdateStatement, Integer> mapperMethod) {
87-
return updateModel -> MyBatis3UpdateModel.of(updateModel, mapperMethod);
82+
public static <T> UpdateDSL<MyBatis3UpdateModelAdapter<T>> update(Function<UpdateStatement, T> mapperMethod, SqlTable table) {
83+
return genericUpdate(updateModel -> MyBatis3UpdateModelAdapter.of(updateModel, mapperMethod), table);
8884
}
8985

9086
public class SetClauseFinisher<T> {
@@ -140,7 +136,7 @@ public R build() {
140136
.withColumnValues(columnsAndValues)
141137
.withWhereModel(buildWhereModel())
142138
.build();
143-
return decoratorFunction.apply(updateModel);
139+
return adapterFunction.apply(updateModel);
144140
}
145141

146142
@Override

src/test/java/examples/simple/SimpleTableAnnotatedMapper.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@
3131
import org.apache.ibatis.type.JdbcType;
3232
import org.mybatis.dynamic.sql.SqlBuilder;
3333
import org.mybatis.dynamic.sql.delete.DeleteDSL;
34-
import org.mybatis.dynamic.sql.delete.MyBatis3DeleteModel;
34+
import org.mybatis.dynamic.sql.delete.MyBatis3DeleteModelAdapter;
3535
import org.mybatis.dynamic.sql.delete.render.DeleteStatement;
3636
import org.mybatis.dynamic.sql.insert.render.InsertStatement;
3737
import org.mybatis.dynamic.sql.render.RenderingStrategy;
38-
import org.mybatis.dynamic.sql.select.MyBatis3SelectModel;
38+
import org.mybatis.dynamic.sql.select.MyBatis3SelectModelAdapter;
3939
import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
4040
import org.mybatis.dynamic.sql.select.SelectDSL;
4141
import org.mybatis.dynamic.sql.select.render.SelectStatement;
42-
import org.mybatis.dynamic.sql.update.MyBatis3UpdateModel;
42+
import org.mybatis.dynamic.sql.update.MyBatis3UpdateModelAdapter;
4343
import org.mybatis.dynamic.sql.update.UpdateDSL;
4444
import org.mybatis.dynamic.sql.update.render.UpdateStatement;
4545
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
@@ -74,12 +74,12 @@ public interface SimpleTableAnnotatedMapper {
7474
@SelectProvider(type=SqlProviderAdapter.class, method="select")
7575
long count(SelectStatement selectStatement);
7676

77-
default QueryExpressionDSL<MyBatis3SelectModel<Long>>.QueryExpressionAfterFrom countByExample() {
77+
default QueryExpressionDSL<MyBatis3SelectModelAdapter<Long>>.QueryExpressionAfterFrom countByExample() {
7878
return SelectDSL.select(this::count, SqlBuilder.count())
7979
.from(simpleTable);
8080
}
8181

82-
default DeleteDSL<MyBatis3DeleteModel> deleteByExample() {
82+
default DeleteDSL<MyBatis3DeleteModelAdapter<Integer>> deleteByExample() {
8383
return DeleteDSL.deleteFrom(simpleTable, this::delete);
8484
}
8585

@@ -116,7 +116,7 @@ default int insertSelective(SimpleTableRecord record) {
116116
.render(RenderingStrategy.MYBATIS3));
117117
}
118118

119-
default QueryExpressionDSL<MyBatis3SelectModel<List<SimpleTableRecord>>>.QueryExpressionAfterFrom selectByExample() {
119+
default QueryExpressionDSL<MyBatis3SelectModelAdapter<List<SimpleTableRecord>>>.QueryExpressionAfterFrom selectByExample() {
120120
return SelectDSL.select(this::selectMany, id.as("A_ID"), firstName, lastName, birthDate, employed, occupation)
121121
.from(simpleTable);
122122
}
@@ -129,7 +129,7 @@ default SimpleTableRecord selectByPrimaryKey(Integer id_) {
129129
.render(RenderingStrategy.MYBATIS3));
130130
}
131131

132-
default UpdateDSL<MyBatis3UpdateModel> updateByExample(SimpleTableRecord record) {
132+
default UpdateDSL<MyBatis3UpdateModelAdapter<Integer>> updateByExample(SimpleTableRecord record) {
133133
return UpdateDSL.update(this::update, simpleTable)
134134
.set(id).equalTo(record.getId())
135135
.set(firstName).equalTo(record.getFirstName())
@@ -139,7 +139,7 @@ default UpdateDSL<MyBatis3UpdateModel> updateByExample(SimpleTableRecord record)
139139
.set(occupation).equalTo(record.getOccupation());
140140
}
141141

142-
default UpdateDSL<MyBatis3UpdateModel> updateByExampleSelective(SimpleTableRecord record) {
142+
default UpdateDSL<MyBatis3UpdateModelAdapter<Integer>> updateByExampleSelective(SimpleTableRecord record) {
143143
return UpdateDSL.update(this::update, simpleTable)
144144
.set(id).equalToWhenPresent(record.getId())
145145
.set(firstName).equalToWhenPresent(record.getFirstName())

0 commit comments

Comments
 (0)