Skip to content

Commit d1e02d9

Browse files
authored
Merge pull request #130 from jeffgbutler/master
Refactoring/Code Polishing
2 parents c855aea + 9c418a9 commit d1e02d9

18 files changed

+114
-103
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2017 the original author or authors.
2+
* Copyright 2016-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -66,4 +66,15 @@ default String renderWithTableAndColumnAlias(TableAliasCalculator tableAliasCalc
6666
return alias().map(a -> nameAndTableAlias + " as " + a) //$NON-NLS-1$
6767
.orElse(nameAndTableAlias);
6868
}
69+
70+
/**
71+
* Utility method to make it easier to build column lists for methods that require an
72+
* array rather than the varargs method.
73+
*
74+
* @param columns list of BasicColumn
75+
* @return an array of BasicColumn
76+
*/
77+
static BasicColumn[] columnList(BasicColumn...columns) {
78+
return columns;
79+
}
6980
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.mybatis.dynamic.sql.VisitableCondition;
2626
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
2727
import org.mybatis.dynamic.sql.util.Buildable;
28-
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3DeleteCompleter;
2928
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;
3029
import org.mybatis.dynamic.sql.where.AbstractWhereDSL;
3130

@@ -81,7 +80,7 @@ public static DeleteDSL<DeleteModel> deleteFrom(SqlTable table) {
8180
/**
8281
* Delete record(s) by executing a MyBatis3 mapper method.
8382
*
84-
* @deprecated in favor of {@link MyBatis3Utils#deleteFrom(ToIntFunction, SqlTable, MyBatis3DeleteCompleter)}.
83+
* @deprecated in favor of {@link MyBatis3Utils#deleteFrom(ToIntFunction, SqlTable, DeleteDSLCompleter)}.
8584
* This method will be removed without direct replacement in a future version
8685
* @param <T> return value from a delete method - typically Integer
8786
* @param mapperMethod MyBatis3 mapper method that performs the delete

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,30 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.mybatis.dynamic.sql.util.mybatis3;
16+
package org.mybatis.dynamic.sql.delete;
1717

1818
import java.util.function.Function;
1919
import java.util.function.ToIntFunction;
2020

2121
import org.mybatis.dynamic.sql.SqlTable;
22-
import org.mybatis.dynamic.sql.delete.DeleteDSL;
23-
import org.mybatis.dynamic.sql.delete.DeleteModel;
2422
import org.mybatis.dynamic.sql.util.Buildable;
23+
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;
2524

2625
/**
2726
* Represents a function that can be used to create a general delete method in the style
2827
* of MyBatis Generator. When using this function, you can create a method that does not require a user to
2928
* call the build() and render() methods - making client code look a bit cleaner.
3029
*
31-
* <p>This function is intended to be used in conjunction with the utility function
32-
* {@link MyBatis3Utils#deleteFrom(ToIntFunction, SqlTable, MyBatis3DeleteCompleter)}
30+
* <p>This function is intended to be used in conjunction with a utility method like
31+
* {@link MyBatis3Utils#deleteFrom(ToIntFunction, SqlTable, DeleteDSLCompleter)}
3332
*
3433
* <p>For example, you can create mapper interface methods like this:
3534
*
3635
* <pre>
3736
* &#64;DeleteProvider(type=SqlProviderAdapter.class, method="delete")
3837
* int delete(DeleteStatementProvider deleteStatement);
3938
*
40-
* default int delete(MyBatis3DeleteCompleter completer) {
39+
* default int delete(DeleteDSLCompleter completer) {
4140
* return MyBatis3Utils.deleteFrom(this::delete, person, completer);
4241
* }
4342
* </pre>
@@ -52,27 +51,27 @@
5251
* <p>You can implement a "delete all" with the following code:
5352
*
5453
* <pre>
55-
* int rows = mapper.delete(q -&gt; q);
54+
* int rows = mapper.delete(c -&gt; c);
5655
* </pre>
5756
*
5857
* <p>Or
5958
*
6059
* <pre>
61-
* long rows = mapper.delete(MyBatis3DeleteCompleter.allRows());
60+
* long rows = mapper.delete(DeleteDSLCompleter.allRows());
6261
* </pre>
6362
6463
* @author Jeff Butler
6564
*/
6665
@FunctionalInterface
67-
public interface MyBatis3DeleteCompleter extends
66+
public interface DeleteDSLCompleter extends
6867
Function<DeleteDSL<DeleteModel>, Buildable<DeleteModel>> {
6968

7069
/**
71-
* Returns a helper that can be used to delete every row in a table.
70+
* Returns a completer that can be used to delete every row in a table.
7271
*
73-
* @return the helper that will delete every row in a table
72+
* @return the completer that will delete every row in a table
7473
*/
75-
static MyBatis3DeleteCompleter allRows() {
76-
return h -> h;
74+
static DeleteDSLCompleter allRows() {
75+
return c -> c;
7776
}
7877
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020

2121
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
2222
import org.mybatis.dynamic.sql.render.RenderingStrategy;
23-
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3DeleteCompleter;
2423

2524
/**
2625
* This adapter will render the underlying delete model for MyBatis3, and then call a MyBatis mapper method.
2726
*
28-
* @deprecated in favor of {@link MyBatis3DeleteCompleter}. This class will be removed without replacement in a
27+
* @deprecated in favor of {@link DeleteDSLCompleter}. This class will be removed without replacement in a
2928
* future version
3029
*
3130
* @author Jeff Butler

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
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.MyBatis3SelectCompleter;
2524

2625
/**
2726
* This interface describes operations allowed for a select statement after the from and join clauses. This is
28-
* primarily to support {@link MyBatis3SelectCompleter}.
27+
* primarily to support {@link SelectDSLCompleter}.
2928
*
3029
* @author Jeff Butler
3130
*

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020

2121
import org.mybatis.dynamic.sql.render.RenderingStrategy;
2222
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
23-
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3SelectCompleter;
2423

2524
/**
2625
* This adapter will render the underlying select model for MyBatis3, and then call a MyBatis mapper method.
2726
*
28-
* @deprecated in favor is {@link MyBatis3SelectCompleter}. This class will be removed without direct replacement
27+
* @deprecated in favor is {@link SelectDSLCompleter}. This class will be removed without direct replacement
2928
* in a future version
3029
*
3130
* @author Jeff Butler

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

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,29 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.mybatis.dynamic.sql.util.mybatis3;
16+
package org.mybatis.dynamic.sql.select;
1717

1818
import java.util.function.Function;
1919

2020
import org.mybatis.dynamic.sql.SortSpecification;
21-
import org.mybatis.dynamic.sql.select.CompletableQuery;
22-
import org.mybatis.dynamic.sql.select.SelectModel;
2321
import org.mybatis.dynamic.sql.util.Buildable;
22+
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;
2423

2524
/**
2625
* Represents a function that can be used to create a general count method in the style
2726
* of MyBatis Generator. When using this function, you can create a method that does not require a user to
2827
* call the build() and render() methods - making client code look a bit cleaner.
2928
*
30-
* <p>This function is intended to by used in conjunction with several utility methods in
31-
* {@link MyBatis3Utils}
29+
* <p>This function is intended to by used in conjunction with utility methods like the select and count
30+
* methods in {@link MyBatis3Utils}
3231
*
3332
* <p>For example, you can create mapper interface methods like this:
3433
*
3534
* <pre>
3635
* &#64;SelectProvider(type=SqlProviderAdapter.class, method="select")
3736
* long count(SelectStatementProvider selectStatement);
3837
*
39-
* default long count(MyBatis3SelectCompleter completer) {
38+
* default long count(SelectDSLCompleter completer) {
4039
return MyBatis3Utils.count(this::count, person, completer);
4140
* }
4241
* </pre>
@@ -57,25 +56,31 @@
5756
* <p>Or
5857
*
5958
* <pre>
60-
* long rows = mapper.count(MyBatis3CountHelper.allRows());
59+
* long rows = mapper.count(SelectDSLCompleter.allRows());
6160
* </pre>
6261
*
6362
* @author Jeff Butler
6463
*/
6564
@FunctionalInterface
66-
public interface MyBatis3SelectCompleter extends
65+
public interface SelectDSLCompleter extends
6766
Function<CompletableQuery<SelectModel>, Buildable<SelectModel>> {
6867

6968
/**
70-
* Returns a helper that can be used to count every row in a table.
69+
* Returns a completer that can be used to select every row in a table.
7170
*
72-
* @return the helper that will count every row in a table
71+
* @return the completer that will select every row in a table
7372
*/
74-
static MyBatis3SelectCompleter allRows() {
75-
return h -> h;
73+
static SelectDSLCompleter allRows() {
74+
return c -> c;
7675
}
7776

78-
static MyBatis3SelectCompleter allRowsOrderedBy(SortSpecification...columns) {
79-
return h -> h.orderBy(columns);
77+
/**
78+
* Returns a completer that can be used to select every row in a table with specified order.
79+
*
80+
* @param columns list of sort specifications for an order by clause
81+
* @return the completer that will select every row in a table with specified order
82+
*/
83+
static SelectDSLCompleter allRowsOrderedBy(SortSpecification...columns) {
84+
return c -> c.orderBy(columns);
8085
}
8186
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020

2121
import org.mybatis.dynamic.sql.render.RenderingStrategy;
2222
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
23-
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3UpdateCompleter;
2423

2524
/**
2625
* This adapter will render the underlying update model for MyBatis3, and then call a MyBatis mapper method.
2726
*
28-
* @deprecated in favor of {@link MyBatis3UpdateCompleter}. This class will be removed without direct
27+
* @deprecated in favor of {@link UpdateDSLCompleter}. This class will be removed without direct
2928
* replacement in a future version.
3029
* @author Jeff Butler
3130
*

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.mybatis.dynamic.sql.util.StringConstantMapping;
3939
import org.mybatis.dynamic.sql.util.UpdateMapping;
4040
import org.mybatis.dynamic.sql.util.ValueMapping;
41-
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3UpdateCompleter;
4241
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;
4342
import org.mybatis.dynamic.sql.where.AbstractWhereDSL;
4443

@@ -100,7 +99,7 @@ public static UpdateDSL<UpdateModel> update(SqlTable table) {
10099
/**
101100
* Executes an update using a MyBatis3 mapper method.
102101
*
103-
* @deprecated in favor of {@link MyBatis3Utils#update(ToIntFunction, SqlTable, MyBatis3UpdateCompleter)}. This
102+
* @deprecated in favor of {@link MyBatis3Utils#update(ToIntFunction, SqlTable, UpdateDSLCompleter)}. This
104103
* method will be removed without direct replacement in a future version.
105104
* @param <T> return value from an update method - typically Integer
106105
* @param mapperMethod MyBatis3 mapper method that performs the update

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,30 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.mybatis.dynamic.sql.util.mybatis3;
16+
package org.mybatis.dynamic.sql.update;
1717

1818
import java.util.function.Function;
1919
import java.util.function.ToIntFunction;
2020

2121
import org.mybatis.dynamic.sql.SqlTable;
22-
import org.mybatis.dynamic.sql.update.UpdateDSL;
23-
import org.mybatis.dynamic.sql.update.UpdateModel;
2422
import org.mybatis.dynamic.sql.util.Buildable;
23+
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;
2524

2625
/**
2726
* Represents a function that can be used to create a general update method in the style
2827
* of MyBatis Generator. When using this function, you can create a method that does not require a user to
2928
* call the build() and render() methods - making client code look a bit cleaner.
3029
*
31-
* <p>This function is intended to be used in conjunction with the utility function
32-
* {@link MyBatis3Utils#update(ToIntFunction, SqlTable, MyBatis3UpdateCompleter)}
30+
* <p>This function is intended to be used in conjunction in the utility method like
31+
* {@link MyBatis3Utils#update(ToIntFunction, SqlTable, UpdateDSLCompleter)}
3332
*
3433
* <p>For example, you can create mapper interface methods like this:
3534
*
3635
* <pre>
3736
* &#64;UpdateProvider(type=SqlProviderAdapter.class, method="update")
3837
* int update(UpdateStatementProvider updateStatement);
3938
*
40-
* default int update(MyBatis3UpdateCompleter completer) {
39+
* default int update(UpdateDSLCompleter completer) {
4140
return MyBatis3Utils.update(this::update, person, completer);
4241
* }
4342
* </pre>
@@ -88,6 +87,6 @@
8887
* @author Jeff Butler
8988
*/
9089
@FunctionalInterface
91-
public interface MyBatis3UpdateCompleter extends
90+
public interface UpdateDSLCompleter extends
9291
Function<UpdateDSL<UpdateModel>, Buildable<UpdateModel>> {
9392
}

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.mybatis.dynamic.sql.SqlBuilder;
2727
import org.mybatis.dynamic.sql.SqlTable;
2828
import org.mybatis.dynamic.sql.delete.DeleteDSL;
29+
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
2930
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
3031
import org.mybatis.dynamic.sql.insert.InsertDSL;
3132
import org.mybatis.dynamic.sql.insert.MultiRowInsertDSL;
@@ -35,9 +36,11 @@
3536
import org.mybatis.dynamic.sql.select.CompletableQuery;
3637
import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
3738
import org.mybatis.dynamic.sql.select.SelectDSL;
39+
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
3840
import org.mybatis.dynamic.sql.select.SelectModel;
3941
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
4042
import org.mybatis.dynamic.sql.update.UpdateDSL;
43+
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
4144
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
4245

4346
/**
@@ -50,17 +53,17 @@ public class MyBatis3Utils {
5053
private MyBatis3Utils() {}
5154

5255
public static long count(ToLongFunction<SelectStatementProvider> mapper,
53-
SqlTable table, MyBatis3SelectCompleter completer) {
56+
SqlTable table, SelectDSLCompleter completer) {
5457
return count(mapper, SelectDSL.select(SqlBuilder.count()).from(table), completer);
5558
}
5659

5760
public static long count(ToLongFunction<SelectStatementProvider> mapper,
58-
QueryExpressionDSL<SelectModel> start, MyBatis3SelectCompleter completer) {
61+
QueryExpressionDSL<SelectModel> start, SelectDSLCompleter completer) {
5962
return mapper.applyAsLong(completer.apply(start).build().render(RenderingStrategies.MYBATIS3));
6063
}
6164

6265
public static int deleteFrom(ToIntFunction<DeleteStatementProvider> mapper,
63-
SqlTable table, MyBatis3DeleteCompleter completer) {
66+
SqlTable table, DeleteDSLCompleter completer) {
6467
return mapper.applyAsInt(
6568
completer.apply(DeleteDSL.deleteFrom(table))
6669
.build()
@@ -80,38 +83,38 @@ public static <R> int insertMultiple(ToIntFunction<MultiRowInsertStatementProvid
8083
}
8184

8285
public static <R> List<R> selectDistinct(Function<SelectStatementProvider, List<R>> mapper,
83-
BasicColumn[] selectList, SqlTable table, MyBatis3SelectCompleter completer) {
86+
BasicColumn[] selectList, SqlTable table, SelectDSLCompleter completer) {
8487
return selectDistinct(mapper, SelectDSL.selectDistinct(selectList).from(table), completer);
8588
}
8689

8790
public static <R> List<R> selectDistinct(Function<SelectStatementProvider, List<R>> mapper,
88-
CompletableQuery<SelectModel> start, MyBatis3SelectCompleter completer) {
91+
CompletableQuery<SelectModel> start, SelectDSLCompleter completer) {
8992
return mapper.apply(completer.apply(start).build().render(RenderingStrategies.MYBATIS3));
9093
}
9194

9295
public static <R> List<R> selectList(Function<SelectStatementProvider, List<R>> mapper,
93-
BasicColumn[] selectList, SqlTable table, MyBatis3SelectCompleter completer) {
96+
BasicColumn[] selectList, SqlTable table, SelectDSLCompleter completer) {
9497
return selectList(mapper, SelectDSL.select(selectList).from(table), completer);
9598
}
9699

97100
public static <R> List<R> selectList(Function<SelectStatementProvider, List<R>> mapper,
98-
CompletableQuery<SelectModel> start, MyBatis3SelectCompleter completer) {
101+
CompletableQuery<SelectModel> start, SelectDSLCompleter completer) {
99102
return mapper.apply(completer.apply(start).build().render(RenderingStrategies.MYBATIS3));
100103
}
101104

102105
public static <R> R selectOne(Function<SelectStatementProvider, R> mapper,
103-
BasicColumn[] selectList, SqlTable table, MyBatis3SelectCompleter completer) {
106+
BasicColumn[] selectList, SqlTable table, SelectDSLCompleter completer) {
104107
return selectOne(mapper, SelectDSL.select(selectList).from(table), completer);
105108
}
106109

107110
public static <R> R selectOne(Function<SelectStatementProvider, R> mapper,
108111
CompletableQuery<SelectModel> start,
109-
MyBatis3SelectCompleter completer) {
112+
SelectDSLCompleter completer) {
110113
return mapper.apply(completer.apply(start).build().render(RenderingStrategies.MYBATIS3));
111114
}
112115

113116
public static int update(ToIntFunction<UpdateStatementProvider> mapper,
114-
SqlTable table, MyBatis3UpdateCompleter completer) {
117+
SqlTable table, UpdateDSLCompleter completer) {
115118
return mapper.applyAsInt(
116119
completer.apply(UpdateDSL.update(table))
117120
.build()

0 commit comments

Comments
 (0)