Skip to content

Commit 5b3be4b

Browse files
committed
Add some utility interfaces to support new style *ByExample methods
1 parent 31b911b commit 5b3be4b

File tree

8 files changed

+720
-4
lines changed

8 files changed

+720
-4
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
import org.mybatis.dynamic.sql.SqlTable;
2424
import org.mybatis.dynamic.sql.VisitableCondition;
2525
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
26+
import org.mybatis.dynamic.sql.util.Buildable;
2627
import org.mybatis.dynamic.sql.where.AbstractWhereDSL;
2728

28-
public class DeleteDSL<R> {
29+
public class DeleteDSL<R> implements Buildable<R> {
2930

3031
private Function<DeleteModel, R> adapterFunction;
3132
private SqlTable table;
@@ -54,6 +55,7 @@ public <T> DeleteWhereBuilder where(BindableColumn<T> column, VisitableCondition
5455
*
5556
* @return the model class
5657
*/
58+
@Override
5759
public R build() {
5860
DeleteModel deleteModel = DeleteModel.withTable(table).build();
5961
return adapterFunction.apply(deleteModel);
@@ -72,7 +74,7 @@ public static <T> DeleteDSL<MyBatis3DeleteModelAdapter<T>> deleteFromWithMapper(
7274
return deleteFrom(deleteModel -> MyBatis3DeleteModelAdapter.of(deleteModel, mapperMethod), table);
7375
}
7476

75-
public class DeleteWhereBuilder extends AbstractWhereDSL<DeleteWhereBuilder> {
77+
public class DeleteWhereBuilder extends AbstractWhereDSL<DeleteWhereBuilder> implements Buildable<R> {
7678

7779
private <T> DeleteWhereBuilder() {
7880
super();
@@ -87,6 +89,7 @@ private <T> DeleteWhereBuilder(BindableColumn<T> column, VisitableCondition<T> c
8789
super(column, condition, subCriteria);
8890
}
8991

92+
@Override
9093
public R build() {
9194
DeleteModel deleteModel = DeleteModel.withTable(table)
9295
.withWhereModel(buildWhereModel())
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright 2016-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.mybatis.dynamic.sql.delete;
17+
18+
import java.util.function.Function;
19+
20+
import org.mybatis.dynamic.sql.util.Buildable;
21+
22+
/**
23+
* Represents a function that can be used to create a "DeleteByExample" method in the style
24+
* of MyBatis Generator. When using this function, you can create a method that does not require a user to
25+
* call the build().execute() methods - making client code look a bit cleaner.
26+
*
27+
* @author Jeff Butler
28+
*
29+
*/
30+
@FunctionalInterface
31+
public interface MyBatis3DeleteByExampleSupport extends
32+
Function<DeleteDSL<MyBatis3DeleteModelAdapter<Integer>>, Buildable<MyBatis3DeleteModelAdapter<Integer>>> {
33+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright 2016-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.mybatis.dynamic.sql.select;
17+
18+
import java.util.function.Function;
19+
20+
import org.mybatis.dynamic.sql.util.Buildable;
21+
22+
@FunctionalInterface
23+
public interface MyBatis3CountByExampleSupport extends
24+
Function<QueryExpressionDSL<MyBatis3SelectModelAdapter<Long>>, Buildable<MyBatis3SelectModelAdapter<Long>>> {
25+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright 2016-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.mybatis.dynamic.sql.select;
17+
18+
import java.util.List;
19+
import java.util.function.Function;
20+
21+
import org.mybatis.dynamic.sql.util.Buildable;
22+
23+
@FunctionalInterface
24+
public interface MyBatis3SelectByExampleSupport<T> extends
25+
Function<QueryExpressionDSL<MyBatis3SelectModelAdapter<List<T>>>,
26+
Buildable<MyBatis3SelectModelAdapter<List<T>>>> {
27+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright 2016-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.mybatis.dynamic.sql.update;
17+
18+
import java.util.function.Function;
19+
20+
import org.mybatis.dynamic.sql.util.Buildable;
21+
22+
@FunctionalInterface
23+
public interface MyBatis3UpdateByExampleSupport extends
24+
Function<UpdateDSL<MyBatis3UpdateModelAdapter<Integer>>, Buildable<MyBatis3UpdateModelAdapter<Integer>>> {
25+
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import org.mybatis.dynamic.sql.util.ValueMapping;
4040
import org.mybatis.dynamic.sql.where.AbstractWhereDSL;
4141

42-
public class UpdateDSL<R> {
42+
public class UpdateDSL<R> implements Buildable<R> {
4343

4444
private Function<UpdateModel, R> adapterFunction;
4545
private List<UpdateMapping> columnMappings = new ArrayList<>();
@@ -73,6 +73,7 @@ public <T> UpdateWhereBuilder where(BindableColumn<T> column, VisitableCondition
7373
*
7474
* @return the update model
7575
*/
76+
@Override
7677
public R build() {
7778
UpdateModel updateModel = UpdateModel.withTable(table)
7879
.withColumnMappings(columnMappings)
@@ -147,7 +148,7 @@ public UpdateDSL<R> equalToWhenPresent(Supplier<T> valueSupplier) {
147148
}
148149
}
149150

150-
public class UpdateWhereBuilder extends AbstractWhereDSL<UpdateWhereBuilder> {
151+
public class UpdateWhereBuilder extends AbstractWhereDSL<UpdateWhereBuilder> implements Buildable<R> {
151152

152153
public <T> UpdateWhereBuilder() {
153154
super();
@@ -162,6 +163,7 @@ public <T> UpdateWhereBuilder(BindableColumn<T> column, VisitableCondition<T> co
162163
super(column, condition, subCriteria);
163164
}
164165

166+
@Override
165167
public R build() {
166168
UpdateModel updateModel = UpdateModel.withTable(table)
167169
.withColumnMappings(columnMappings)

0 commit comments

Comments
 (0)