Skip to content

Commit 9169596

Browse files
committed
Better Names
1 parent d4c1086 commit 9169596

File tree

8 files changed

+146
-140
lines changed

8 files changed

+146
-140
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
import org.mybatis.dynamic.sql.SqlCriterion;
2222
import org.mybatis.dynamic.sql.VisitableCondition;
2323
import org.mybatis.dynamic.sql.util.Buildable;
24-
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3SelectHelper;
24+
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3SelectCompleter;
2525

2626
/**
2727
* This interface describes operations allowed for a select statement after the from and join clauses. This is
28-
* primarily to support the {@link MyBatis3SelectHelper} class.
28+
* primarily to support {@link MyBatis3SelectCompleter}.
2929
*
3030
* @author Jeff Butler
3131
*

src/main/java/org/mybatis/dynamic/sql/util/mybatis3/MyBatis3DeleteHelper.java renamed to src/main/java/org/mybatis/dynamic/sql/util/mybatis3/MyBatis3DeleteCompleter.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,37 @@
1616
package org.mybatis.dynamic.sql.util.mybatis3;
1717

1818
import java.util.function.Function;
19+
import java.util.function.ToIntFunction;
1920

21+
import org.mybatis.dynamic.sql.SqlTable;
2022
import org.mybatis.dynamic.sql.delete.DeleteDSL;
2123
import org.mybatis.dynamic.sql.delete.DeleteModel;
2224
import org.mybatis.dynamic.sql.util.Buildable;
2325

2426
/**
2527
* Represents a function that can be used to create a general delete method in the style
2628
* of MyBatis Generator. When using this function, you can create a method that does not require a user to
27-
* call the build().execute() methods - making client code look a bit cleaner.
29+
* call the build() and render() methods - making client code look a bit cleaner.
30+
*
31+
* <p>This function is intended to be used in conjunction with the utility function
32+
* {@link MyBatis3Utils#deleteFrom(ToIntFunction, SqlTable, MyBatis3DeleteCompleter)}
2833
*
2934
* <p>For example, you can create mapper interface methods like this:
3035
*
3136
* <pre>
3237
* &#64;DeleteProvider(type=SqlProviderAdapter.class, method="delete")
3338
* int delete(DeleteStatementProvider deleteStatement);
3439
*
35-
* default int delete(MyBatis3DeleteHelper helper) {
36-
* return helper.apply(DeleteDSL.deleteFromWithMapper(this::delete, simpleTable))
37-
* .build()
38-
* .execute();
40+
* default int delete(MyBatis3DeleteCompleter completer) {
41+
* return MyBatis3Utils.deleteFrom(this::delete, person, completer);
3942
* }
4043
* </pre>
4144
*
4245
* <p>And then call the simplified default method like this:
4346
*
4447
* <pre>
45-
* int rows = mapper.delete(q -&gt;
46-
* q.where(occupation, isNull()));
48+
* int rows = mapper.delete(c -&gt;
49+
* c.where(occupation, isNull()));
4750
* </pre>
4851
*
4952
* <p>You can implement a "delete all" with the following code:
@@ -55,21 +58,21 @@
5558
* <p>Or
5659
*
5760
* <pre>
58-
* long rows = mapper.delete(MyBatis3DeleteHelper.allRows());
61+
* long rows = mapper.delete(MyBatis3DeleteCompleter.allRows());
5962
* </pre>
6063
6164
* @author Jeff Butler
6265
*/
6366
@FunctionalInterface
64-
public interface MyBatis3DeleteHelper extends
67+
public interface MyBatis3DeleteCompleter extends
6568
Function<DeleteDSL<DeleteModel>, Buildable<DeleteModel>> {
6669

6770
/**
6871
* Returns a helper that can be used to delete every row in a table.
6972
*
7073
* @return the helper that will delete every row in a table
7174
*/
72-
static MyBatis3DeleteHelper allRows() {
75+
static MyBatis3DeleteCompleter allRows() {
7376
return h -> h;
7477
}
7578
}

src/main/java/org/mybatis/dynamic/sql/util/mybatis3/MyBatis3SelectHelper.java renamed to src/main/java/org/mybatis/dynamic/sql/util/mybatis3/MyBatis3SelectCompleter.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,33 @@
2525
/**
2626
* Represents a function that can be used to create a general count method in the style
2727
* of MyBatis Generator. When using this function, you can create a method that does not require a user to
28-
* call the build().execute() methods - making client code look a bit cleaner.
28+
* call the build() and render() methods - making client code look a bit cleaner.
29+
*
30+
* <p>This function is intended to by used in conjunction with several utility methods in
31+
* {@link MyBatis3Utils}
2932
*
3033
* <p>For example, you can create mapper interface methods like this:
3134
*
3235
* <pre>
3336
* &#64;SelectProvider(type=SqlProviderAdapter.class, method="select")
3437
* long count(SelectStatementProvider selectStatement);
3538
*
36-
* default long count(MyBatis3CountHelper helper) {
37-
* return helper.apply(SelectDSL.selectWithMapper(this::count, SqlBuilder.count())
38-
* .from(simpleTable))
39-
* .build()
40-
* .execute();
39+
* default long count(MyBatis3SelectCompleter completer) {
40+
return MyBatis3Utils.count(this::count, person, completer);
4141
* }
4242
* </pre>
4343
*
4444
* <p>And then call the simplified default method like this:
4545
*
4646
* <pre>
47-
* long rows = mapper.count(q -&gt;
48-
* q.where(occupation, isNull()));
47+
* long rows = mapper.count(c -&gt;
48+
* c.where(occupation, isNull()));
4949
* </pre>
5050
*
5151
* <p>You can implement a "count all" with the following code:
5252
*
5353
* <pre>
54-
* long rows = mapper.count(q -&gt; q);
54+
* long rows = mapper.count(c -&gt; c);
5555
* </pre>
5656
*
5757
* <p>Or
@@ -63,19 +63,19 @@
6363
* @author Jeff Butler
6464
*/
6565
@FunctionalInterface
66-
public interface MyBatis3SelectHelper extends
66+
public interface MyBatis3SelectCompleter extends
6767
Function<CompletableQuery<SelectModel>, Buildable<SelectModel>> {
6868

6969
/**
7070
* Returns a helper that can be used to count every row in a table.
7171
*
7272
* @return the helper that will count every row in a table
7373
*/
74-
static MyBatis3SelectHelper allRows() {
74+
static MyBatis3SelectCompleter allRows() {
7575
return h -> h;
7676
}
7777

78-
static MyBatis3SelectHelper allRowsOrderedBy(SortSpecification...columns) {
78+
static MyBatis3SelectCompleter allRowsOrderedBy(SortSpecification...columns) {
7979
return h -> h.orderBy(columns);
8080
}
8181
}

src/main/java/org/mybatis/dynamic/sql/util/mybatis3/MyBatis3UpdateHelper.java renamed to src/main/java/org/mybatis/dynamic/sql/util/mybatis3/MyBatis3UpdateCompleter.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,52 +16,55 @@
1616
package org.mybatis.dynamic.sql.util.mybatis3;
1717

1818
import java.util.function.Function;
19+
import java.util.function.ToIntFunction;
1920

21+
import org.mybatis.dynamic.sql.SqlTable;
2022
import org.mybatis.dynamic.sql.update.UpdateDSL;
2123
import org.mybatis.dynamic.sql.update.UpdateModel;
2224
import org.mybatis.dynamic.sql.util.Buildable;
2325

2426
/**
2527
* Represents a function that can be used to create a general update method in the style
2628
* of MyBatis Generator. When using this function, you can create a method that does not require a user to
27-
* call the build().execute() methods - making client code look a bit cleaner.
29+
* call the build() and render() methods - making client code look a bit cleaner.
30+
*
31+
* <p>This function is intended to be used in conjunction with the utility function
32+
* {@link MyBatis3Utils#update(ToIntFunction, SqlTable, MyBatis3UpdateCompleter)}
2833
*
2934
* <p>For example, you can create mapper interface methods like this:
3035
*
3136
* <pre>
3237
* &#64;UpdateProvider(type=SqlProviderAdapter.class, method="update")
3338
* int update(UpdateStatementProvider updateStatement);
3439
*
35-
* default int update(MyBatis3UpdateHelper helper) {
36-
* return helper.apply(UpdateDSL.updateWithMapper(this::update, simpleTable))
37-
* .build()
38-
* .execute();
40+
* default int update(MyBatis3UpdateCompleter completer) {
41+
return MyBatis3Utils.update(this::update, person, completer);
3942
* }
4043
* </pre>
4144
*
4245
* <p>And then call the simplified default method like this:
4346
*
4447
* <pre>
45-
* int rows = mapper.update(q -&gt;
46-
* q.set(firstName).equalTo("Fred")
48+
* int rows = mapper.update(c -&gt;
49+
* c.set(firstName).equalTo("Fred")
4750
* .where(id, isEqualTo(100))
4851
* );
4952
* </pre>
5053
*
5154
* <p>You can implement an "update all" simply by omitting a where clause:
5255
*
5356
* <pre>
54-
* int rows = mapper.update(q -&gt;
55-
* q.set(firstName).equalTo("Fred")
57+
* int rows = mapper.update(c -&gt;
58+
* c.set(firstName).equalTo("Fred")
5659
* );
5760
* </pre>
5861
*
5962
* <p>You could also implement a helper method that would set fields based on values of a record. For example,
6063
* the following method would set all fields of a record based on whether or not the values are null:
6164
*
6265
* <pre>
63-
* static UpdateDSL&lt;MyBatis3UpdateModelAdapter&lt;Integer&gt;&gt; setSelective(SimpleTableRecord record,
64-
* UpdateDSL&lt;MyBatis3UpdateModelAdapter&lt;Integer&gt;&gt; dsl) {
66+
* static UpdateDSL&lt;UpdateModel&gt; setSelective(PersonRecord record,
67+
* UpdateDSL&lt;UpdateModel&gt; dsl) {
6568
* return dsl.set(id).equalToWhenPresent(record::getId)
6669
* .set(firstName).equalToWhenPresent(record::getFirstName)
6770
* .set(lastName).equalToWhenPresent(record::getLastName)
@@ -74,8 +77,8 @@
7477
* <p>The helper method could be used like this:
7578
*
7679
* <pre>
77-
* rows = mapper.update(dsl -&gt;
78-
* SimpleTableAnnotatedMapperNewStyle.setSelective(record, dsl)
80+
* rows = mapper.update(c -&gt;
81+
* PersonMapper.setSelective(record, c)
7982
* .where(id, isLessThan(100)));
8083
* </pre>
8184
*
@@ -85,6 +88,6 @@
8588
* @author Jeff Butler
8689
*/
8790
@FunctionalInterface
88-
public interface MyBatis3UpdateHelper extends
91+
public interface MyBatis3UpdateCompleter extends
8992
Function<UpdateDSL<UpdateModel>, Buildable<UpdateModel>> {
9093
}

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,70 +51,70 @@ public class MyBatis3Utils {
5151
private MyBatis3Utils() {}
5252

5353
public static long count(ToLongFunction<SelectStatementProvider> mapper,
54-
SqlTable table, MyBatis3SelectHelper helper) {
55-
return count(mapper, SelectDSL.select(SqlBuilder.count()).from(table), helper);
54+
SqlTable table, MyBatis3SelectCompleter completer) {
55+
return count(mapper, SelectDSL.select(SqlBuilder.count()).from(table), completer);
5656
}
5757

5858
public static long count(ToLongFunction<SelectStatementProvider> mapper,
59-
QueryExpressionDSL<SelectModel> start, MyBatis3SelectHelper helper) {
60-
return mapper.applyAsLong(helper.apply(start).build().render(RenderingStrategy.MYBATIS3));
59+
QueryExpressionDSL<SelectModel> start, MyBatis3SelectCompleter completer) {
60+
return mapper.applyAsLong(completer.apply(start).build().render(RenderingStrategy.MYBATIS3));
6161
}
6262

6363
public static int deleteFrom(ToIntFunction<DeleteStatementProvider> mapper,
64-
SqlTable table, MyBatis3DeleteHelper helper) {
64+
SqlTable table, MyBatis3DeleteCompleter completer) {
6565
return mapper.applyAsInt(
66-
helper.apply(DeleteDSL.deleteFrom(table))
66+
completer.apply(DeleteDSL.deleteFrom(table))
6767
.build()
6868
.render(RenderingStrategy.MYBATIS3));
6969
}
7070

7171
public static <R> int insert(ToIntFunction<InsertStatementProvider<R>> mapper, R record,
72-
SqlTable table, UnaryOperator<InsertDSL<R>> helper) {
73-
return mapper.applyAsInt(helper.apply(
72+
SqlTable table, UnaryOperator<InsertDSL<R>> completer) {
73+
return mapper.applyAsInt(completer.apply(
7474
InsertDSL.insert(record).into(table)).build().render(RenderingStrategy.MYBATIS3));
7575
}
7676

7777
public static <R> int insertMultiple(ToIntFunction<MultiRowInsertStatementProvider<R>> mapper,
78-
Collection<R> records, SqlTable table, UnaryOperator<MultiRowInsertDSL<R>> helper) {
79-
return mapper.applyAsInt(helper.apply(
78+
Collection<R> records, SqlTable table, UnaryOperator<MultiRowInsertDSL<R>> completer) {
79+
return mapper.applyAsInt(completer.apply(
8080
MultiRowInsertDSL.insert(records).into(table)).build().render(RenderingStrategy.MYBATIS3));
8181
}
8282

8383
public static <R> List<R> selectDistinct(Function<SelectStatementProvider, List<R>> mapper,
84-
BasicColumn[] selectList, SqlTable table, MyBatis3SelectHelper helper) {
85-
return selectDistinct(mapper, SelectDSL.selectDistinct(selectList).from(table), helper);
84+
BasicColumn[] selectList, SqlTable table, MyBatis3SelectCompleter completer) {
85+
return selectDistinct(mapper, SelectDSL.selectDistinct(selectList).from(table), completer);
8686
}
8787

8888
public static <R> List<R> selectDistinct(Function<SelectStatementProvider, List<R>> mapper,
89-
CompletableQuery<SelectModel> start, MyBatis3SelectHelper helper) {
90-
return mapper.apply(helper.apply(start).build().render(RenderingStrategy.MYBATIS3));
89+
CompletableQuery<SelectModel> start, MyBatis3SelectCompleter completer) {
90+
return mapper.apply(completer.apply(start).build().render(RenderingStrategy.MYBATIS3));
9191
}
9292

9393
public static <R> List<R> selectList(Function<SelectStatementProvider, List<R>> mapper,
94-
BasicColumn[] selectList, SqlTable table, MyBatis3SelectHelper helper) {
95-
return selectList(mapper, SelectDSL.select(selectList).from(table), helper);
94+
BasicColumn[] selectList, SqlTable table, MyBatis3SelectCompleter completer) {
95+
return selectList(mapper, SelectDSL.select(selectList).from(table), completer);
9696
}
9797

9898
public static <R> List<R> selectList(Function<SelectStatementProvider, List<R>> mapper,
99-
CompletableQuery<SelectModel> start, MyBatis3SelectHelper helper) {
100-
return mapper.apply(helper.apply(start).build().render(RenderingStrategy.MYBATIS3));
99+
CompletableQuery<SelectModel> start, MyBatis3SelectCompleter completer) {
100+
return mapper.apply(completer.apply(start).build().render(RenderingStrategy.MYBATIS3));
101101
}
102102

103103
public static <R> Optional<R> selectOne(Function<SelectStatementProvider, Optional<R>> mapper,
104-
BasicColumn[] selectList, SqlTable table, MyBatis3SelectHelper helper) {
105-
return selectOne(mapper, SelectDSL.select(selectList).from(table), helper);
104+
BasicColumn[] selectList, SqlTable table, MyBatis3SelectCompleter completer) {
105+
return selectOne(mapper, SelectDSL.select(selectList).from(table), completer);
106106
}
107107

108108
public static <R> Optional<R> selectOne(Function<SelectStatementProvider, Optional<R>> mapper,
109109
CompletableQuery<SelectModel> start,
110-
MyBatis3SelectHelper helper) {
111-
return mapper.apply(helper.apply(start).build().render(RenderingStrategy.MYBATIS3));
110+
MyBatis3SelectCompleter completer) {
111+
return mapper.apply(completer.apply(start).build().render(RenderingStrategy.MYBATIS3));
112112
}
113113

114114
public static int update(ToIntFunction<UpdateStatementProvider> mapper,
115-
SqlTable table, MyBatis3UpdateHelper helper) {
115+
SqlTable table, MyBatis3UpdateCompleter completer) {
116116
return mapper.applyAsInt(
117-
helper.apply(UpdateDSL.update(table))
117+
completer.apply(UpdateDSL.update(table))
118118
.build()
119119
.render(RenderingStrategy.MYBATIS3));
120120
}

0 commit comments

Comments
 (0)