Package com.oorian.data
Class CallbackDataProvider<T>
java.lang.Object
com.oorian.data.AbstractDataProvider<T>
com.oorian.data.CallbackDataProvider<T>
- Type Parameters:
T- the data item type
- All Implemented Interfaces:
DataProvider<T>
A data provider that delegates fetching and counting to user-provided callbacks.
Use this for database-backed lazy loading where the callbacks translate
Query parameters into SQL queries, REST API calls, or other data access.
DataProvider<User> provider = new CallbackDataProvider<>(
query -> {
List<User> users = userDao.findAll(
query.getOffset(), query.getLimit(),
query.getSorts(), query.getFilters());
int total = userDao.count(query.getFilters());
return DataResult.of(users, total);
},
query -> userDao.count(query.getFilters())
);
- Since:
- 2.1
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCallback for counting matching items.static interfaceCallback for fetching a page of data. -
Constructor Summary
ConstructorsConstructorDescriptionCallbackDataProvider(CallbackDataProvider.FetchCallback<T> fetchCallback, CallbackDataProvider.CountCallback countCallback) Creates a callback data provider. -
Method Summary
Methods inherited from class com.oorian.data.AbstractDataProvider
addDataChangeListener, refresh, removeDataChangeListener
-
Constructor Details
-
CallbackDataProvider
public CallbackDataProvider(CallbackDataProvider.FetchCallback<T> fetchCallback, CallbackDataProvider.CountCallback countCallback) Creates a callback data provider.- Parameters:
fetchCallback- the callback for fetching data pagescountCallback- the callback for counting matching items
-
-
Method Details
-
fetch
Description copied from interface:DataProviderFetches a page of data matching the query parameters.- Parameters:
query- the query with offset, limit, sorts, and filters- Returns:
- the result containing items and total count
-
size
Description copied from interface:DataProviderReturns the total number of items matching the query's filters.- Parameters:
query- the query (only filters are relevant; offset/limit are ignored)- Returns:
- the total count of matching items
-