Class DataFetchObserver

java.lang.Object
com.vaadin.flow.data.provider.DataFetchObserver
All Implemented Interfaces:
Serializable

public final class DataFetchObserver extends Object implements Serializable
Runs a data provider query and reports it on the service event bus.

For internal use by data communicators. Each method wraps the query it is given, so the started/failed/ended sequence is defined in one place rather than repeated at every call site. The ended event is fired in reverse registration order, so listeners nest around the started one.

The caller supplies the UI rather than this class looking one up, because VaadinService.getCurrent() is unavailable on the thread that matters: DataCommunicator.enablePushUpdates(java.util.concurrent.Executor) runs fetches on the supplied executor without propagating CurrentInstance. When the component is not attached to a live UI the query simply runs unreported.

Since:
25.3
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    count(com.vaadin.flow.component.UI ui, com.vaadin.flow.component.Component component, boolean filtered, IntSupplier query)
    Runs a count query, reporting it on the service event bus.
    static int
    fetch(com.vaadin.flow.component.UI ui, com.vaadin.flow.component.Component component, com.vaadin.flow.internal.Range range, boolean filtered, IntSupplier query)
    Runs a fetch query, reporting it on the service event bus.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • count

      public static int count(com.vaadin.flow.component.UI ui, com.vaadin.flow.component.Component component, boolean filtered, IntSupplier query)
      Runs a count query, reporting it on the service event bus.
      Parameters:
      ui - the UI the counting component belongs to, or null if it is not attached
      component - the component whose data is being counted, or null if it could not be resolved
      filtered - whether the query carries a filter
      query - the count query to run
      Returns:
      whatever the query returned
    • fetch

      public static int fetch(com.vaadin.flow.component.UI ui, com.vaadin.flow.component.Component component, com.vaadin.flow.internal.Range range, boolean filtered, IntSupplier query)
      Runs a fetch query, reporting it on the service event bus.

      The query must consume the items it loads and return how many there were, so that the reported duration covers the backend round-trip even for a data provider that returns a lazily evaluated Stream.

      Parameters:
      ui - the UI the fetching component belongs to, or null if it is not attached
      component - the component whose data is being fetched, or null if it could not be resolved
      range - the range of items requested
      filtered - whether the query carries a filter
      query - the fetch query to run, returning the number of items loaded
      Returns:
      whatever the query returned