Package org.mybatis.dynamic.sql.select
Interface CountDSLCompleter
- All Superinterfaces:
Function<CountDSL<SelectModel>,
Buildable<SelectModel>>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface
public interface CountDSLCompleter
extends Function<CountDSL<SelectModel>,Buildable<SelectModel>>
Represents a function that can be used to create a general count method. When using this function,
you can create a method that does not require a user to call the build() and render() methods - making
client code look a bit cleaner.
This function is intended to by used in conjunction with a utility method like
MyBatis3Utils.countFrom(ToLongFunction, CountDSL, CountDSLCompleter)
For example, you can create mapper interface methods like this:
@SelectProvider(type=SqlProviderAdapter.class, method="select") long count(SelectStatementProvider selectStatement); default long count(CountDSLCompleter completer) { return MyBatis3Utils.count(this::count, person, completer); }
And then call the simplified default method like this:
long rows = mapper.count(c -> c.where(occupation, isNull()));
You can implement a "count all" with the following code:
long rows = mapper.count(c -> c);
Or
long rows = mapper.count(CountDSLCompleter.allRows());
- Author:
- Jeff Butler
-
Method Summary
Modifier and TypeMethodDescriptionstatic CountDSLCompleter
allRows()
Returns a completer that can be used to count every row in a table.
-
Method Details
-
allRows
Returns a completer that can be used to count every row in a table.- Returns:
- the completer that will count every row in a table
-