Skip to content

Commit 61fd0cd

Browse files
authored
Merge pull request #128 from jeffgbutler/master
Improved Utilities for use by MyBatis Generator
2 parents 88eaaff + 1e6b73e commit 61fd0cd

14 files changed

+378
-563
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,16 @@
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.MyBatis3SelectListHelper;
25-
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3SelectOneHelper;
24+
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3SelectCompleter;
2625

2726
/**
2827
* This interface describes operations allowed for a select statement after the from and join clauses. This is
29-
* primarily to support the {@link MyBatis3SelectListHelper} and {@link MyBatis3SelectOneHelper} classes.
28+
* primarily to support {@link MyBatis3SelectCompleter}.
3029
*
3130
* @author Jeff Butler
3231
*
3332
* @param <R> the model type created by these operations
3433
*
35-
* @see MyBatis3SelectListHelper
36-
* @see MyBatis3SelectOneHelper
37-
*
3834
*/
3935
public interface CompletableQuery<R> extends Buildable<R> {
4036
QueryExpressionDSL<R>.QueryExpressionWhereBuilder where();

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: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +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;
23+
import org.mybatis.dynamic.sql.delete.DeleteModel;
2124
import org.mybatis.dynamic.sql.util.Buildable;
2225

2326
/**
2427
* Represents a function that can be used to create a general delete method in the style
2528
* of MyBatis Generator. When using this function, you can create a method that does not require a user to
26-
* 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)}
2733
*
2834
* <p>For example, you can create mapper interface methods like this:
2935
*
3036
* <pre>
3137
* &#64;DeleteProvider(type=SqlProviderAdapter.class, method="delete")
3238
* int delete(DeleteStatementProvider deleteStatement);
3339
*
34-
* default int delete(MyBatis3DeleteHelper helper) {
35-
* return helper.apply(DeleteDSL.deleteFromWithMapper(this::delete, simpleTable))
36-
* .build()
37-
* .execute();
40+
* default int delete(MyBatis3DeleteCompleter completer) {
41+
* return MyBatis3Utils.deleteFrom(this::delete, person, completer);
3842
* }
3943
* </pre>
4044
*
4145
* <p>And then call the simplified default method like this:
4246
*
4347
* <pre>
44-
* int rows = mapper.delete(q -&gt;
45-
* q.where(occupation, isNull()));
48+
* int rows = mapper.delete(c -&gt;
49+
* c.where(occupation, isNull()));
4650
* </pre>
4751
*
4852
* <p>You can implement a "delete all" with the following code:
@@ -54,21 +58,21 @@
5458
* <p>Or
5559
*
5660
* <pre>
57-
* long rows = mapper.delete(MyBatis3DeleteHelper.allRows());
61+
* long rows = mapper.delete(MyBatis3DeleteCompleter.allRows());
5862
* </pre>
5963
6064
* @author Jeff Butler
6165
*/
6266
@FunctionalInterface
63-
public interface MyBatis3DeleteHelper extends
64-
Function<DeleteDSL<MyBatis3DeleteModelToIntAdapter>, Buildable<MyBatis3DeleteModelToIntAdapter>> {
67+
public interface MyBatis3DeleteCompleter extends
68+
Function<DeleteDSL<DeleteModel>, Buildable<DeleteModel>> {
6569

6670
/**
6771
* Returns a helper that can be used to delete every row in a table.
6872
*
6973
* @return the helper that will delete every row in a table
7074
*/
71-
static MyBatis3DeleteHelper allRows() {
75+
static MyBatis3DeleteCompleter allRows() {
7276
return h -> h;
7377
}
7478
}

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

Lines changed: 0 additions & 59 deletions
This file was deleted.

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

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,41 @@
1717

1818
import java.util.function.Function;
1919

20-
import org.mybatis.dynamic.sql.select.MyBatis3SelectModelAdapter;
21-
import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
20+
import org.mybatis.dynamic.sql.SortSpecification;
21+
import org.mybatis.dynamic.sql.select.CompletableQuery;
22+
import org.mybatis.dynamic.sql.select.SelectModel;
2223
import org.mybatis.dynamic.sql.util.Buildable;
2324

2425
/**
2526
* Represents a function that can be used to create a general count method in the style
2627
* 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.
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}
2832
*
2933
* <p>For example, you can create mapper interface methods like this:
3034
*
3135
* <pre>
3236
* &#64;SelectProvider(type=SqlProviderAdapter.class, method="select")
3337
* long count(SelectStatementProvider selectStatement);
3438
*
35-
* default long count(MyBatis3CountHelper helper) {
36-
* return helper.apply(SelectDSL.selectWithMapper(this::count, SqlBuilder.count())
37-
* .from(simpleTable))
38-
* .build()
39-
* .execute();
39+
* default long count(MyBatis3SelectCompleter completer) {
40+
return MyBatis3Utils.count(this::count, person, completer);
4041
* }
4142
* </pre>
4243
*
4344
* <p>And then call the simplified default method like this:
4445
*
4546
* <pre>
46-
* long rows = mapper.count(q -&gt;
47-
* q.where(occupation, isNull()));
47+
* long rows = mapper.count(c -&gt;
48+
* c.where(occupation, isNull()));
4849
* </pre>
4950
*
5051
* <p>You can implement a "count all" with the following code:
5152
*
5253
* <pre>
53-
* long rows = mapper.count(q -&gt; q);
54+
* long rows = mapper.count(c -&gt; c);
5455
* </pre>
5556
*
5657
* <p>Or
@@ -62,15 +63,19 @@
6263
* @author Jeff Butler
6364
*/
6465
@FunctionalInterface
65-
public interface MyBatis3CountHelper extends
66-
Function<QueryExpressionDSL<MyBatis3SelectModelAdapter<Long>>, Buildable<MyBatis3SelectModelAdapter<Long>>> {
66+
public interface MyBatis3SelectCompleter extends
67+
Function<CompletableQuery<SelectModel>, Buildable<SelectModel>> {
6768

6869
/**
6970
* Returns a helper that can be used to count every row in a table.
7071
*
7172
* @return the helper that will count every row in a table
7273
*/
73-
static MyBatis3CountHelper allRows() {
74+
static MyBatis3SelectCompleter allRows() {
7475
return h -> h;
7576
}
77+
78+
static MyBatis3SelectCompleter allRowsOrderedBy(SortSpecification...columns) {
79+
return h -> h.orderBy(columns);
80+
}
7681
}

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

Lines changed: 0 additions & 102 deletions
This file was deleted.

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

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)