com.vaadin.flow.data.provider.

Class DataCommunicator<T>

  • Type Parameters:

    T - the bean type

    All Implemented Interfaces:

    Serializable

    Direct Known Subclasses:

    HierarchicalDataCommunicator


    public class DataCommunicator<T>
    extends Object
    implements Serializable

    DataProvider base class. This class is the base for all DataProvider communication implementations. It uses data generators (BiFunctions) to write JsonObjects representing each data object to be sent to the client-side.

    Since:

    1.0

    See Also:

    Serialized Form

    • Constructor Detail

      • DataCommunicator

        public DataCommunicator(DataGenerator<T> dataGenerator,
                                ArrayUpdater arrayUpdater,
                                SerializableConsumer<elemental.json.JsonArray> dataUpdater,
                                StateNode stateNode)

        Creates a new instance.

        Parameters:

        dataGenerator - the data generator function

        arrayUpdater - array updater strategy

        dataUpdater - data updater strategy

        stateNode - the state node used to communicate for

    • Method Detail

      • setRequestedRange

        public void setRequestedRange(int start,
                                      int length)

        Sets the requested range of data to be sent.

        Parameters:

        start - the start of the requested range

        length - the end of the requested range

      • computeRequestedRange

        protected final Range computeRequestedRange(int start,
                                                    int length)

        Computes the requested range, limiting the number of requested items to a given threshold of ten pages.

        Parameters:

        start - the start of the requested range

        length - the end of the requested range

      • enablePushUpdates

        public void enablePushUpdates(Executor executor)

        Control whether DataCommunicator should push data updates to the component asynchronously or not. By default the executor service is not defined and updates are done synchronously. Setting to null will disable the feature.

        Note: This works only with Grid component. If set to true, Push needs to be enabled and set to PushMode.AUTOMATIC in order this to work.

        Parameters:

        executor - The Executor used for async updates.

      • reset

        public void reset()

        Resets all the data.

        It effectively resends all available data.

      • refresh

        public void refresh(T data)

        Informs the DataCommunicator that a data object has been updated.

        Parameters:

        data - updated data object; not null

      • confirmUpdate

        public void confirmUpdate(int updateId)

        Confirm update with the given updateId.

        Parameters:

        updateId - the update identifier

      • getDataProvider

        public DataProvider<T,?> getDataProvider()

        Gets the current data provider from this DataCommunicator.

        Returns:

        the data provider

      • setDataProvider

        public <F> SerializableConsumer<F> setDataProvider(DataProvider<T,F> dataProvider,
                                                           F initialFilter)

        Sets the current data provider for this DataCommunicator.

        The returned consumer can be used to set some other filter value that should be included in queries sent to the data provider. It is only valid until another data provider is set.

        Type Parameters:

        F - the filter type

        Parameters:

        dataProvider - the data provider to set, not null

        initialFilter - the initial filter value to use, or null to not use any initial filter value

        Returns:

        a consumer that accepts a new filter value to use

      • getKeyMapper

        public DataKeyMapper<T> getKeyMapper()

        Gets the DataKeyMapper used by this DataCommunicator. Key mapper can be used to map keys sent to the client-side back to their respective data objects.

        Returns:

        key mapper

      • setKeyMapper

        protected void setKeyMapper(DataKeyMapper<T> keyMapper)

        Sets the DataKeyMapper used in this DataCommunicator. Key mapper can be used to map keys sent to the client-side back to their respective data objects.

        Parameters:

        keyMapper - the keyMapper

      • setInMemorySorting

        public void setInMemorySorting(SerializableComparator<T> comparator)

        Sets the Comparator to use with in-memory sorting.

        Parameters:

        comparator - comparator used to sort data

      • getInMemorySorting

        public SerializableComparator<T> getInMemorySorting()

        Returns the Comparator to use with in-memory sorting.

        Returns:

        comparator used to sort data

      • setBackEndSorting

        public void setBackEndSorting(List<QuerySortOrder> sortOrder)

        Sets the QuerySortOrders to use with backend sorting.

        Parameters:

        sortOrder - list of sort order information to pass to a query

      • getBackEndSorting

        public List<QuerySortOrder> getBackEndSorting()

        Returns the QuerySortOrder to use with backend sorting.

        Returns:

        an unmodifiable list of sort order information to pass to a query

      • getDataProviderSize

        protected int getDataProviderSize()

        Getter method for finding the size of DataProvider. Can be overridden by a subclass that uses a specific type of DataProvider and/or query.

        Returns:

        the size of data provider with current filter

      • getFilter

        protected Object getFilter()

        Get the object used for filtering in this data communicator.

        Returns:

        the filter object of this data communicator

      • fetchFromProvider

        protected Stream<T> fetchFromProvider(int offset,
                                              int limit)

        Fetches a list of items from the DataProvider.

        Parameters:

        offset - the starting index of the range

        limit - the max number of results

        Returns:

        the list of items in given range