com.vaadin.data.provider.

Class DataCommunicator<T>

    • Field Detail

      • reset

        protected boolean reset

        Boolean for pending hard reset.

    • Constructor Detail

      • DataCommunicator

        public DataCommunicator()
    • Method Detail

      • setPushRows

        protected void setPushRows​(Range pushRows)

        Set the range of rows to push for next response.

        Parameters:

        pushRows -

        Since:

        8.0.6

      • getPushRows

        protected Range getPushRows()

        Get the current range of rows to push in the next response.

        Returns:

        the range of rows to push

        Since:

        8.0.6

      • getFilter

        protected Object getFilter()

        Get the object used for filtering in this data communicator.

        Returns:

        the filter object of this data communicator

        Since:

        8.0.6

      • getClientRpc

        protected DataCommunicatorClientRpc getClientRpc()

        Get the client rpc interface for this data communicator.

        Returns:

        the client rpc interface for this data communicator

        Since:

        8.0.6

      • onRequestRows

        protected void onRequestRows​(int firstRowIndex,
                                     int numberOfRows,
                                     int firstCachedRowIndex,
                                     int cacheSize)

        Request the given rows to be available on the client side.

        Parameters:

        firstRowIndex - the index of the first requested row

        numberOfRows - the number of requested rows

        firstCachedRowIndex - the index of the first cached row

        cacheSize - the number of cached rows

        Since:

        8.0.6

      • getMaximumAllowedRows

        protected int getMaximumAllowedRows()

        Get the maximum allowed rows to be fetched in one query.

        Returns:

        Maximum allowed rows for one query.

        Since:

        8.14.1

      • setMaximumAllowedRows

        public void setMaximumAllowedRows​(int maximumAllowedRows)

        Set the maximum allowed rows to be fetched in one query.

        Parameters:

        maximumAllowedRows - Maximum allowed rows for one query.

        Since:

        8.15

      • onDropRows

        protected void onDropRows​(elemental.json.JsonArray keys)

        Triggered when rows have been dropped from the client side cache.

        Parameters:

        keys - the keys of the rows that have been dropped

        Since:

        8.0.6

      • beforeClientResponse

        public void beforeClientResponse​(boolean initial)

        Initially and in the case of a reset all data should be pushed to the client.

        Specified by:

        beforeClientResponse in interface ClientConnector

        Overrides:

        beforeClientResponse in class AbstractClientConnector

        Parameters:

        initial - true if the client-side connector will be created and initialized after this method has been invoked. false if there is already an initialized client-side connector.

      • sendDataToClient

        protected void sendDataToClient​(boolean initial)

        Send the needed data and updates to the client side.

        Parameters:

        initial - true if initial data load, false if not

        Since:

        8.0.6

      • fetchItemsWithRange

        public List<T> fetchItemsWithRange​(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

        Since:

        8.1

      • addDataGenerator

        public void addDataGenerator​(DataGenerator<T> generator)

        Adds a data generator to this data communicator. Data generators can be used to insert custom data to the rows sent to the client. If the data generator is already added, does nothing.

        Parameters:

        generator - the data generator to add, not null

      • removeDataGenerator

        public void removeDataGenerator​(DataGenerator<T> generator)

        Removes a data generator from this data communicator. If there is no such data generator, does nothing.

        Parameters:

        generator - the data generator to remove, not null

      • 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

      • pushData

        protected void pushData​(int firstIndex,
                                List<T> data)

        Sends given collection of data objects to the client-side.

        Parameters:

        firstIndex - first index of pushed data

        data - data objects to send as an iterable

      • getDataObject

        protected elemental.json.JsonObject getDataObject​(T data)

        Creates the JsonObject for given data object. This method calls all data generators for it.

        Parameters:

        data - data object to be made into a json object

        Returns:

        json object representing the data object

      • getActiveDataHandler

        protected DataCommunicator.ActiveDataHandler getActiveDataHandler()

        Returns the active data handler.

        Returns:

        the active data handler

        Since:

        8.0.6

      • dropAllData

        protected void dropAllData()

        Drops all data associated with this data communicator.

      • reset

        public void reset()

        Method for internal reset from a change in the component, requiring a full data update.

      • refresh

        public void refresh​(T data)

        Informs the DataProvider that a data object has been updated.

        Parameters:

        data - updated data object; not null

      • getUpdatedData

        protected Set<T> getUpdatedData()

        Returns the currently set updated data.

        Returns:

        the set of data that should be updated on the next response

        Since:

        8.0.6

      • setInMemorySorting

        public void setInMemorySorting​(Comparator<T> comparator,
                                       boolean immediateReset)

        Sets the Comparator to use with in-memory sorting.

        Parameters:

        comparator - comparator used to sort data

        immediateReset - true if an internal reset should be performed immediately after updating the comparator (unless full reset is already pending), false if you are going to trigger reset separately later

      • setInMemorySorting

        public void setInMemorySorting​(Comparator<T> comparator)

        Sets the Comparator to use with in-memory sorting.

        Parameters:

        comparator - comparator used to sort data

      • getInMemorySorting

        public Comparator<T> getInMemorySorting()

        Returns the Comparator to use with in-memory sorting.

        Returns:

        comparator used to sort data

        Since:

        8.0.6

      • setBackEndSorting

        public void setBackEndSorting​(List<QuerySortOrder> sortOrder,
                                      boolean immediateReset)

        Sets the QuerySortOrders to use with backend sorting.

        Parameters:

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

        immediateReset - true if an internal reset should be performed immediately after updating the comparator (unless full reset is already pending), false if you are going to trigger reset separately later

      • 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

        Since:

        8.0.6

      • createKeyMapper

        protected DataKeyMapper<T> createKeyMapper​(ValueProvider<T,​Object> identifierGetter)

        Creates a DataKeyMapper to use with this DataCommunicator.

        This method is called from the constructor.

        Parameters:

        identifierGetter - has to return a unique key for every bean, and the returned key has to follow general hashCode() and equals() contract, see Object.hashCode() for details.

        Returns:

        key mapper

        Since:

        8.1

      • 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

      • setFilter

        protected <F> void setFilter​(F filter)

        Sets the filter for this DataCommunicator. This method is used by user through the consumer method from setDataProvider(com.vaadin.data.provider.DataProvider<T, F>, F) and should not be called elsewhere.

        Type Parameters:

        F - the filter type

        Parameters:

        filter - the filter

        Since:

        8.1

      • setMinPushSize

        public void setMinPushSize​(int size)

        Set minimum size of data which will be sent to the client when data source is set.

        Server doesn't send all data from data source to the client. It sends some initial chunk of data (whose size is determined as minimum between size parameter of this method and data size). Client decides whether it is able to show more data and request server to send more data (next chunk).

        When component is disabled then client cannot communicate to the server side (by design, because of security reasons). It means that client will get only initial chunk of data whose size is set here.

        Parameters:

        size - the size of initial data to send to the client

      • getMinPushSize

        public int getMinPushSize()

        Get minimum size of data which will be sent to the client when data source is set.

        Returns:

        current minimum push size of initial data chunk which is sent to the client when data source is set

        See Also:

        setMinPushSize(int)

      • getDataProviderSize

        public 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

      • getState

        protected DataCommunicatorState getState()

        Description copied from class: AbstractClientConnector

        Returns the shared state for this connector. The shared state object is shared between the server connector and the client connector. Changes are only communicated from the server to the client and not in the other direction.

        As a side effect, marks the connector dirty so any changes done to the state will be sent to the client. Use getState(false) to avoid marking the connector as dirty.

        Overrides:

        getState in class AbstractClientConnector

        Returns:

        The shared state for this connector. Never null.

      • setDataProvider

        protected void setDataProvider​(DataProvider<T,​?> dataProvider)

        Sets a new DataProvider and refreshes all the internal structures.

        Parameters:

        dataProvider -

        Since:

        8.1