com.vaadin.data.provider.
Class DataCommunicator<T>
- java.lang.Object
-
- com.vaadin.server.AbstractClientConnector
-
- com.vaadin.server.AbstractExtension
-
- com.vaadin.data.provider.DataCommunicator<T>
-
Type Parameters:
T
- the bean typeAll Implemented Interfaces:
MethodEventSource
,ClientConnector
,Extension
,Connector
,Serializable
Direct Known Subclasses:
public class DataCommunicator<T> extends AbstractExtension
DataProvider base class. This class is the base for all DataProvider communication implementations. It uses
DataGenerator
s to writeJsonObject
s representing each data object to be sent to the client-side.Since:
8.0
See Also:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
DataCommunicator.ActiveDataHandler
A class for handling currently active data and dropping data that is no longer needed.
protected class
DataCommunicator.SimpleDataRequestRpc
Simple implementation of collection data provider communication.
-
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
reset
Boolean for pending hard reset.
-
Constructor Summary
Constructors Constructor Description DataCommunicator()
-
Method Summary
All Methods Modifier and Type Method Description void
addDataGenerator(DataGenerator<T> generator)
Adds a data generator to this data communicator.
void
attach()
Notifies the connector that it is connected to a VaadinSession (and therefore also to a UI).
void
beforeClientResponse(boolean initial)
Initially and in the case of a reset all data should be pushed to the client.
protected DataKeyMapper<T>
createKeyMapper(ValueProvider<T,Object> identifierGetter)
Creates a
DataKeyMapper
to use with this DataCommunicator.protected DataRequestRpc
createRpc()
Creates a
DataRequestRpc
used with thisDataCommunicator
.void
detach()
Notifies the connector that it is detached from its VaadinSession.
protected void
dropAllData()
Drops all data associated with this data communicator.
List<T>
fetchItemsWithRange(int offset, int limit)
Fetches a list of items from the DataProvider.
protected DataCommunicator.ActiveDataHandler
getActiveDataHandler()
Returns the active data handler.
List<QuerySortOrder>
getBackEndSorting()
Returns the
QuerySortOrder
to use with backend sorting.protected DataCommunicatorClientRpc
getClientRpc()
Get the client rpc interface for this data communicator.
protected elemental.json.JsonObject
getDataObject(T data)
Creates the JsonObject for given data object.
DataProvider<T,?>
getDataProvider()
Gets the current data provider from this DataCommunicator.
int
getDataProviderSize()
Getter method for finding the size of DataProvider.
protected Object
getFilter()
Get the object used for filtering in this data communicator.
Comparator<T>
getInMemorySorting()
Returns the
Comparator
to use with in-memory sorting.DataKeyMapper<T>
getKeyMapper()
Gets the
DataKeyMapper
used by thisDataCommunicator
.protected int
getMaximumAllowedRows()
Get the maximum allowed rows to be fetched in one query.
int
getMinPushSize()
Get minimum size of data which will be sent to the client when data source is set.
protected Range
getPushRows()
Get the current range of rows to push in the next response.
protected DataCommunicatorState
getState()
Returns the shared state for this connector.
protected DataCommunicatorState
getState(boolean markAsDirty)
Returns the shared state for this connector.
protected Set<T>
getUpdatedData()
Returns the currently set updated data.
protected void
onDropRows(elemental.json.JsonArray keys)
Triggered when rows have been dropped from the client side cache.
protected void
onRequestRows(int firstRowIndex, int numberOfRows, int firstCachedRowIndex, int cacheSize)
Request the given rows to be available on the client side.
protected void
pushData(int firstIndex, List<T> data)
Sends given collection of data objects to the client-side.
void
refresh(T data)
Informs the DataProvider that a data object has been updated.
void
removeDataGenerator(DataGenerator<T> generator)
Removes a data generator from this data communicator.
void
reset()
Method for internal reset from a change in the component, requiring a full data update.
protected void
sendDataToClient(boolean initial)
Send the needed data and updates to the client side.
void
setBackEndSorting(List<QuerySortOrder> sortOrder)
Sets the
QuerySortOrder
s to use with backend sorting.void
setBackEndSorting(List<QuerySortOrder> sortOrder, boolean immediateReset)
Sets the
QuerySortOrder
s to use with backend sorting.protected void
setDataProvider(DataProvider<T,?> dataProvider)
Sets a new
DataProvider
and refreshes all the internal structures.<F> SerializableConsumer<F>
setDataProvider(DataProvider<T,F> dataProvider, F initialFilter)
Sets the current data provider for this DataCommunicator.
protected <F> void
setFilter(F filter)
Sets the filter for this DataCommunicator.
void
setInMemorySorting(Comparator<T> comparator)
Sets the
Comparator
to use with in-memory sorting.void
setInMemorySorting(Comparator<T> comparator, boolean immediateReset)
Sets the
Comparator
to use with in-memory sorting.void
setMaximumAllowedRows(int maximumAllowedRows)
Set the maximum allowed rows to be fetched in one query.
void
setMinPushSize(int size)
Set minimum size of data which will be sent to the client when data source is set.
protected void
setPushRows(Range pushRows)
Set the range of rows to push for next response.
-
Methods inherited from class com.vaadin.server.AbstractExtension
extend, getParent, getSupportedParentType, remove, setParent
-
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isConnectorEnabled, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, getUI, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
-
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
-
-
-
-
Method Detail
-
attach
public void attach()
Description copied from interface:
ClientConnector
Notifies the connector that it is connected to a VaadinSession (and therefore also to a UI).
The caller of this method is
Component.setParent(HasComponents)
if the parent is itself already attached to the session. If not, the parent will call theClientConnector.attach()
for all its children when it is attached to the session. This method is always called before the connector's data is sent to the client-side for the first time.The attachment logic is implemented in
AbstractClientConnector
.Specified by:
attach
in interfaceClientConnector
Overrides:
attach
in classAbstractClientConnector
-
detach
public void detach()
Description copied from class:
AbstractClientConnector
Notifies the connector that it is detached from its VaadinSession.
The caller of this method is
Component.setParent(HasComponents)
if the parent is in the session. When the parent is detached from the session it is its responsibility to callClientConnector.detach()
for each of its children.The
AbstractClientConnector.getSession()
andAbstractClientConnector.getUI()
methods might returnnull
after this method is called.Specified by:
detach
in interfaceClientConnector
Overrides:
detach
in classAbstractClientConnector
-
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 rownumberOfRows
- the number of requested rowsfirstCachedRowIndex
- the index of the first cached rowcacheSize
- the number of cached rowsSince:
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 droppedSince:
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 interfaceClientConnector
Overrides:
beforeClientResponse
in classAbstractClientConnector
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 notSince:
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 rangelimit
- the max number of resultsReturns:
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 thisDataCommunicator
. 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 datadata
- 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 objectReturns:
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; notnull
-
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 dataimmediateReset
-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
QuerySortOrder
s to use with backend sorting.Parameters:
sortOrder
- list of sort order information to pass to a queryimmediateReset
-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
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
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 generalhashCode()
andequals()
contract, seeObject.hashCode()
for details.Returns:
key mapper
Since:
8.1
-
createRpc
protected DataRequestRpc createRpc()
Creates a
DataRequestRpc
used with thisDataCommunicator
.This method is called from the constructor.
Returns:
data request rpc implementation
-
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
-
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 typeParameters:
filter
- the filterSince:
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:
-
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(boolean markAsDirty)
Description copied from class:
AbstractClientConnector
Returns the shared state for this connector.
Overrides:
getState
in classAbstractClientConnector
Parameters:
markAsDirty
- true if the connector should automatically be marked dirty, false otherwiseReturns:
The shared state for this connector. Never null.
See Also:
-
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 classAbstractClientConnector
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
-
-