T
- the bean typepublic class DataCommunicator<T> extends Object implements Serializable
BiFunction
s)
to write JsonObject
s representing each data object to be sent to the
client-side.Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_PAGE_INCREASE_COUNT |
Constructor and Description |
---|
DataCommunicator(DataGenerator<T> dataGenerator,
ArrayUpdater arrayUpdater,
SerializableConsumer<elemental.json.JsonArray> dataUpdater,
StateNode stateNode)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
Query |
buildQuery(int offset,
int limit)
Generate a data query with component sorting and filtering.
|
void |
confirmUpdate(int updateId)
Confirm update with the given
updateId . |
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 determining the item count of the data.
|
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. |
T |
getItem(int index)
Gets the item at the given index from the data available to the
component.
|
int |
getItemCount()
This is the latest DataProvider item count informed to the client or
fetched from the DataProvider if client data has not been sent.
|
int |
getItemCountEstimate()
Gets the item count estimate used.
|
int |
getItemCountEstimateIncrease()
Gets the item count estimate increase used.
|
DataKeyMapper<T> |
getKeyMapper()
Gets the
DataKeyMapper used by this DataCommunicator . |
int |
getPageSize()
Returns the page size set to fetch items.
|
protected void |
handleDataRefreshEvent(DataChangeEvent.DataRefreshEvent<T> event) |
boolean |
isDefinedSize()
Returns whether defined or undefined size is used.
|
boolean |
isItemActive(T item)
Returns whether the given item is part of the active items.
|
boolean |
isPagingEnabled()
Returns whether paged queries are enabled or not.
|
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. |
void |
setCountCallback(CallbackDataProvider.CountCallback<T,?> countCallback)
Sets the size callback to be used and switches the component to exact row
count.
|
<F> SerializableConsumer<F> |
setDataProvider(DataProvider<T,F> dataProvider,
F initialFilter)
Sets the current data provider for this DataCommunicator.
|
void |
setDefinedSize(boolean definedSize)
Changes between defined and undefined size and clears any previously set
count callback.
|
void |
setInMemorySorting(SerializableComparator<T> comparator)
Sets the
Comparator to use with in-memory sorting. |
void |
setItemCountEstimate(int itemCountEstimate)
Sets the item count estimate to use and switches component to undefined
size.
|
void |
setItemCountEstimateIncrease(int itemCountEstimateIncrease)
Sets the item count estimate increase to use and switches the component
to undefined size if not yet used.
|
protected void |
setKeyMapper(DataKeyMapper<T> keyMapper)
Sets the
DataKeyMapper used in this DataCommunicator . |
void |
setPageSize(int pageSize)
Sets the page size that is used to fetch items.
|
void |
setPagingEnabled(boolean pagingEnabled)
Sets whether paged queries or offset/limit queries will be used.
|
void |
setRequestedRange(int start,
int length)
Sets the requested range of data to be sent.
|
public static final int DEFAULT_PAGE_INCREASE_COUNT
public DataCommunicator(DataGenerator<T> dataGenerator, ArrayUpdater arrayUpdater, SerializableConsumer<elemental.json.JsonArray> dataUpdater, StateNode stateNode)
dataGenerator
- the data generator functionarrayUpdater
- array updater strategydataUpdater
- data updater strategystateNode
- the state node used to communicate forpublic void setRequestedRange(int start, int length)
start
- the start of the requested rangelength
- the end of the requested rangepublic void reset()
It effectively resends all available data.
public void refresh(T data)
data
- updated data object; not null
public void confirmUpdate(int updateId)
updateId
.updateId
- the update identifierpublic DataProvider<T,?> getDataProvider()
public <F> SerializableConsumer<F> setDataProvider(DataProvider<T,F> dataProvider, F initialFilter)
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.
This method also sets the data communicator to defined size - meaning that the given data provider is queried for size and previous size estimates are discarded.
F
- the filter typedataProvider
- the data provider to set, not null
initialFilter
- the initial filter value to use, or null
to not
use any initial filter valuepublic int getItemCount()
public boolean isItemActive(T item)
item
- the item to check, not null
true
if item is active, false
if notpublic T getItem(int index)
Call to the backend is triggered if the item for a requested index is not present in the cached active items.
index
- the index of the item to getIndexOutOfBoundsException
- requested index is outside of the filtered and sorted data
setpublic Query buildQuery(int offset, int limit)
offset
- first index to fetchlimit
- fetched item countQuery
for component statepublic void setPageSize(int pageSize)
pageSize
- the page size to setpublic int getPageSize()
public void setCountCallback(CallbackDataProvider.CountCallback<T,?> countCallback)
countCallback
- the size callback to usepublic void setItemCountEstimate(int itemCountEstimate)
NOTE: setting item count estimate that is less than two pages
(set with setPageSize(int)
) can cause extra requests initially
or after a reset.
itemCountEstimate
- the item count estimate to be usedpublic int getItemCountEstimate()
public void setItemCountEstimateIncrease(int itemCountEstimateIncrease)
setPageSize(int)
or it may cause bad performance.itemCountEstimateIncrease
- the item count estimate step to usepublic int getItemCountEstimateIncrease()
public void setDefinedSize(boolean definedSize)
true
will use the
DataProvider.size(Query)
for getting the size. Calling with
false
will use whatever has been set with
setItemCountEstimate(int)
and increase the count when needed
with setItemCountEstimateIncrease(int)
.definedSize
- true
for defined size, false
for undefined
sizepublic boolean isDefinedSize()
true
for defined size, false
for undefined sizepublic DataKeyMapper<T> getKeyMapper()
DataKeyMapper
used by this DataCommunicator
. Key
mapper can be used to map keys sent to the client-side back to their
respective data objects.protected void setKeyMapper(DataKeyMapper<T> keyMapper)
DataKeyMapper
used in this DataCommunicator
. Key
mapper can be used to map keys sent to the client-side back to their
respective data objects.keyMapper
- the keyMapperpublic void setInMemorySorting(SerializableComparator<T> comparator)
Comparator
to use with in-memory sorting.comparator
- comparator used to sort datapublic SerializableComparator<T> getInMemorySorting()
Comparator
to use with in-memory sorting.public void setBackEndSorting(List<QuerySortOrder> sortOrder)
QuerySortOrder
s to use with backend sorting.sortOrder
- list of sort order information to pass to a querypublic List<QuerySortOrder> getBackEndSorting()
QuerySortOrder
to use with backend sorting.public boolean isPagingEnabled()
When the paged queries are supported, the Query.getPage()
and
Query.getPageSize()
can be used to fetch items from the paged
repositories. Otherwise, one should use Query.getOffset()
and
Query.getLimit()
. Paged queries are enabled by default.
true
for paged queries, false
for offset/limit
queriessetPagingEnabled(boolean)
public void setPagingEnabled(boolean pagingEnabled)
pagingEnabled
- true
for paged queries, false
for offset/limit
queriesprotected int getDataProviderSize()
protected Object getFilter()
protected Stream<T> fetchFromProvider(int offset, int limit)
NOTE: the limit
parameter shows how many items the
client wants to fetch, but the actual number of results may be greater,
and vary from 0 to pages * pageSize
.
offset
- the starting index of the rangelimit
- the desired number of resultsprotected void handleDataRefreshEvent(DataChangeEvent.DataRefreshEvent<T> event)
Copyright © 2020. All rights reserved.