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>

public class CallbackDataProvider<T> extends AbstractDataProvider<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:
  • Constructor Details

  • Method Details

    • fetch

      public DataResult<T> fetch(Query query)
      Description copied from interface: DataProvider
      Fetches 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

      public int size(Query query)
      Description copied from interface: DataProvider
      Returns 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