Skip to content

Commit 1db7823

Browse files
committed
JavaDoc for new *ByExample helper interfaces
1 parent 049a8d9 commit 1db7823

File tree

4 files changed

+143
-1
lines changed

4 files changed

+143
-1
lines changed

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,40 @@
2121
import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
2222
import org.mybatis.dynamic.sql.util.Buildable;
2323

24+
/**
25+
* Represents a function that can be used to create a "CountByExample" method in the style
26+
* 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+
*
29+
* <p>For example, you can create mapper interface methods like this:
30+
*
31+
* <pre>
32+
* &#64;SelectProvider(type=SqlProviderAdapter.class, method="select")
33+
* long count(SelectStatementProvider selectStatement);
34+
*
35+
* default long countByExample(MyBatis3CountByExampleHelper helper) {
36+
* return helper.apply(SelectDSL.selectWithMapper(this::count, SqlBuilder.count())
37+
* .from(simpleTable))
38+
* .build()
39+
* .execute();
40+
* }
41+
* </pre>
42+
*
43+
* <p>And then call the simplified default method like this:
44+
*
45+
* <pre>
46+
* long rows = mapper.countByExample(q -&gt;
47+
* q.where(occupation, isNull()));
48+
* </pre>
49+
*
50+
* <p>You can also do a "count all" with the following code:
51+
*
52+
* <pre>
53+
* long rows = mapper.countByExample(q -&gt; q);
54+
* </pre>
55+
*
56+
* @author Jeff Butler
57+
*/
2458
@FunctionalInterface
2559
public interface MyBatis3CountByExampleHelper extends
2660
Function<QueryExpressionDSL<MyBatis3SelectModelAdapter<Long>>, Buildable<MyBatis3SelectModelAdapter<Long>>> {

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,34 @@
2525
* Represents a function that can be used to create a "DeleteByExample" method in the style
2626
* of MyBatis Generator. When using this function, you can create a method that does not require a user to
2727
* call the build().execute() methods - making client code look a bit cleaner.
28+
*
29+
* <p>For example, you can create mapper interface methods like this:
30+
*
31+
* <pre>
32+
* &#64;DeleteProvider(type=SqlProviderAdapter.class, method="delete")
33+
* int delete(DeleteStatementProvider deleteStatement);
34+
*
35+
* default int deleteByExample(MyBatis3DeleteByExampleHelper helper) {
36+
* return helper.apply(DeleteDSL.deleteFromWithMapper(this::delete, simpleTable))
37+
* .build()
38+
* .execute();
39+
* }
40+
* </pre>
41+
*
42+
* <p>And then call the simplified default method like this:
43+
*
44+
* <pre>
45+
* int rows = mapper.deleteByExample(q -&gt;
46+
* q.where(occupation, isNull()));
47+
* </pre>
2848
*
49+
* <p>You can also do a "delete all" with the following code:
50+
*
51+
* <pre>
52+
* int rows = mapper.deleteByExample(q -&gt; q);
53+
* </pre>
54+
*
2955
* @author Jeff Butler
30-
*
3156
*/
3257
@FunctionalInterface
3358
public interface MyBatis3DeleteByExampleHelper extends

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,49 @@
2222
import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
2323
import org.mybatis.dynamic.sql.util.Buildable;
2424

25+
/**
26+
* Represents a function that can be used to create a "SelectByExample" method in the style
27+
* 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.
29+
*
30+
* <p>For example, you can create mapper interface methods like this:
31+
*
32+
* <pre>
33+
* &#64;SelectProvider(type=SqlProviderAdapter.class, method="select")
34+
* &#64;Results(id="SimpleTableResult", value= {
35+
* &#64;Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
36+
* &#64;Result(column="first_name", property="firstName", jdbcType=JdbcType.VARCHAR),
37+
* &#64;Result(column="last_name", property="lastName", jdbcType=JdbcType.VARCHAR),
38+
* &#64;Result(column="birth_date", property="birthDate", jdbcType=JdbcType.DATE),
39+
* &#64;Result(column="employed", property="employed", jdbcType=JdbcType.VARCHAR),
40+
* &#64;Result(column="occupation", property="occupation", jdbcType=JdbcType.VARCHAR)
41+
* })
42+
* List&lt;SimpleTableRecord&gt; selectMany(SelectStatementProvider selectStatement);
43+
*
44+
* default List&lt;SimpleTableRecord&gt; selectByExample(MyBatis3SelectByExampleHelper&lt;SimpleTableRecord&gt; helper) {
45+
* return helper.apply(SelectDSL.selectWithMapper(this::selectMany, simpleTable.allColumns())
46+
* .from(simpleTable))
47+
* .build()
48+
* .execute();
49+
* }
50+
* </pre>
51+
*
52+
* <p>And then call the simplified default method like this:
53+
*
54+
* <pre>
55+
* List&lt;SimpleTableRecord&gt; rows = mapper.selectByExample(q -&gt;
56+
* q.where(id, isEqualTo(1))
57+
* .or(occupation, isNull()));
58+
* </pre>
59+
*
60+
* <p>You can also do a "select all" with the following code:
61+
*
62+
* <pre>
63+
* List&lt;SimpleTableRecord&gt; rows = mapper.selectByExample(q -&gt; q);
64+
* </pre>
65+
*
66+
* @author Jeff Butler
67+
*/
2568
@FunctionalInterface
2669
public interface MyBatis3SelectByExampleHelper<T> extends
2770
Function<QueryExpressionDSL<MyBatis3SelectModelAdapter<List<T>>>,

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,46 @@
2121
import org.mybatis.dynamic.sql.update.UpdateDSL;
2222
import org.mybatis.dynamic.sql.util.Buildable;
2323

24+
/**
25+
* Represents a function that can be used to create an "UpdateByExample" method in the style
26+
* 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+
*
29+
* <p>For example, you can create mapper interface methods like this:
30+
*
31+
* <pre>
32+
* &#64;UpdateProvider(type=SqlProviderAdapter.class, method="update")
33+
* int update(UpdateStatementProvider updateStatement);
34+
*
35+
* default int updateByExampleSelective(SimpleTableRecord record, MyBatis3UpdateByExampleHelper helper) {
36+
* return helper.apply(UpdateDSL.updateWithMapper(this::update, simpleTable)
37+
* .set(id).equalToWhenPresent(record.getId())
38+
* .set(firstName).equalToWhenPresent(record::getFirstName)
39+
* .set(lastName).equalToWhenPresent(record::getLastName)
40+
* .set(birthDate).equalToWhenPresent(record::getBirthDate)
41+
* .set(employed).equalToWhenPresent(record::getEmployed)
42+
* .set(occupation).equalToWhenPresent(record::getOccupation))
43+
* .build()
44+
* .execute();
45+
* }
46+
* </pre>
47+
*
48+
* <p>And then call the simplified default method like this:
49+
*
50+
* <pre>
51+
* int rows = mapper.updateByExampleSelective(record, q -&gt;
52+
* q.where(id, isEqualTo(100))
53+
* .and(firstName, isEqualTo("Joe")));
54+
* </pre>
55+
*
56+
* <p>You can also do an "update all" with the following code:
57+
*
58+
* <pre>
59+
* int rows = mapper.updateByExampleSelective(record, q -&gt; q);
60+
* </pre>
61+
*
62+
* @author Jeff Butler
63+
*/
2464
@FunctionalInterface
2565
public interface MyBatis3UpdateByExampleHelper extends
2666
Function<UpdateDSL<MyBatis3UpdateModelAdapter<Integer>>, Buildable<MyBatis3UpdateModelAdapter<Integer>>> {

0 commit comments

Comments
 (0)