com.vaadin.flow.data.provider.
Class DataCommunicator<T>
- java.lang.Object
-
- com.vaadin.flow.data.provider.DataCommunicator<T>
-
Type Parameters:
T
- the bean typeAll Implemented Interfaces:
Direct Known Subclasses:
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 (
BiFunction
s) to writeJsonObject
s representing each data object to be sent to the client-side.Since:
1.0
See Also:
-
-
Constructor Summary
Constructors Constructor and Description DataCommunicator(DataGenerator<T> dataGenerator, ArrayUpdater arrayUpdater, SerializableConsumer<elemental.json.JsonArray> dataUpdater, StateNode stateNode)
Creates a new instance.
-
Method Summary
All Methods Modifier and Type Method and Description protected Range
computeRequestedRange(int start, int length)
Computes the requested range, limiting the number of requested items to a given threshold of ten pages.
void
confirmUpdate(int updateId)
Confirm update with the given
updateId
.void
enablePushUpdates(Executor executor)
Control whether DataCommunicator should push data updates to the component asynchronously or not.
protected Stream<T>
fetchFromProvider(int offset, int limit)
Fetches a list of items from the DataProvider.
List<QuerySortOrder>
getBackEndSorting()
Returns the
QuerySortOrder
to use with backend sorting.DataProvider<T,?>
getDataProvider()
Gets the current data provider from this DataCommunicator.
protected int
getDataProviderSize()
Getter method for finding the size of DataProvider.
protected Object
getFilter()
Get the object used for filtering in this data communicator.
SerializableComparator<T>
getInMemorySorting()
Returns the
Comparator
to use with in-memory sorting.DataKeyMapper<T>
getKeyMapper()
Gets the
DataKeyMapper
used by thisDataCommunicator
.protected Set<String>
getPassivatedKeys(Set<String> oldActive)
protected void
handleDataRefreshEvent(DataChangeEvent.DataRefreshEvent<T> event)
void
refresh(T data)
Informs the DataCommunicator that a data object has been updated.
void
reset()
Resets all the data.
void
setBackEndSorting(List<QuerySortOrder> sortOrder)
Sets the
QuerySortOrder
s to use with backend sorting.<F> SerializableConsumer<F>
setDataProvider(DataProvider<T,F> dataProvider, F initialFilter)
Sets the current data provider for this DataCommunicator.
void
setInMemorySorting(SerializableComparator<T> comparator)
Sets the
Comparator
to use with in-memory sorting.protected void
setKeyMapper(DataKeyMapper<T> keyMapper)
Sets the
DataKeyMapper
used in thisDataCommunicator
.void
setRequestedRange(int start, int length)
Sets the requested range of data to be sent.
-
-
-
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 functionarrayUpdater
- array updater strategydataUpdater
- data updater strategystateNode
- 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 rangelength
- 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 rangelength
- 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; notnull
-
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 typeParameters:
dataProvider
- the data provider to set, notnull
initialFilter
- the initial filter value to use, ornull
to not use any initial filter valueReturns:
a consumer that accepts a new filter value to use
-
getKeyMapper
public DataKeyMapper<T> getKeyMapper()
Gets the
DataKeyMapper
used by thisDataCommunicator
. 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 thisDataCommunicator
. 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
QuerySortOrder
s 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 rangelimit
- the max number of resultsReturns:
the list of items in given range
-
handleDataRefreshEvent
protected void handleDataRefreshEvent(DataChangeEvent.DataRefreshEvent<T> event)
-
-