com.vaadin.data.provider.
Class AbstractBackEndDataProvider<T,F>
- java.lang.Object
-
- com.vaadin.data.provider.AbstractDataProvider<T,F>
-
- com.vaadin.data.provider.AbstractBackEndDataProvider<T,F>
-
Type Parameters:
T
- data provider data typeF
- data provider filter typeAll Implemented Interfaces:
BackEndDataProvider<T,F>
,DataProvider<T,F>
,Serializable
Direct Known Subclasses:
public abstract class AbstractBackEndDataProvider<T,F> extends AbstractDataProvider<T,F> implements BackEndDataProvider<T,F>
Abstract base class for implementing back end data providers.
Since:
8.0
See Also:
-
-
Constructor Summary
Constructors Constructor Description AbstractBackEndDataProvider()
-
Method Summary
All Methods Modifier and Type Method Description Stream<T>
fetch(Query<T,F> query)
Fetches data from this DataProvider using given
query
.protected abstract Stream<T>
fetchFromBackEnd(Query<T,F> query)
Fetches data from the back end using the given query.
void
setSortOrders(List<QuerySortOrder> sortOrders)
Sets a list of sort orders to use as the default sorting for this data provider.
int
size(Query<T,F> query)
Gets the amount of data in this DataProvider.
protected abstract int
sizeInBackEnd(Query<T,F> query)
Counts the number of items available in the back end.
-
Methods inherited from class com.vaadin.data.provider.AbstractDataProvider
addDataProviderListener, addListener, fireEvent, refreshAll, refreshItem
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.data.provider.BackEndDataProvider
isInMemory, setSortOrder, setSortOrders
-
Methods inherited from interface com.vaadin.data.provider.DataProvider
addDataProviderListener, getId, refreshAll, refreshItem, withConfigurableFilter, withConfigurableFilter, withConvertedFilter
-
-
-
-
Method Detail
-
fetch
public Stream<T> fetch(Query<T,F> query)
Description copied from interface:
DataProvider
Fetches data from this DataProvider using given
query
.Depending on the use case this operation might open I/O channels.
Consumers of the returned stream are responsible for closing it when all the stream operations are done to ensure that any resources feeding the stream are properly released. Failure to close an I/O stream might lead to resource leaks.
It is strongly recommended to use a try-with-resources block to automatically close an I/O stream after its terminal operation has been executed. Below is an example of how to properly use and close the stream:
NOTE: This mainly concerns data providers wheretry (Stream<T> stream = fetch(query)) { stream.forEach(System.out::println); // Example terminal operation }
DataProvider.isInMemory()
returnsfalse
. While it is technically possible to configure or extend an in-memory data provider in a way that compromises the in-memory nature, doing so is conceptually frowned upon. In applications that choose to do so regardless, the use of this pattern is strongly recommended even ifDataProvider.isInMemory()
returnstrue
.The try-with-resources pattern is safe to use with this method even if you are unsure whether or not it returns an I/O stream, but it's unnecessary to apply the pattern to all stream handling everywhere. For most streams the only consumed resource is memory, and Java's built-in cleanup is sufficient to free it.
With large data sets where memory consumption might become a problem it is recommended to use lazy data providers instead of in-memory ones. See e.g.
DataProvider.fromCallbacks(FetchCallback, CountCallback)
orBackEndDataProvider
for more info.Specified by:
fetch
in interfaceDataProvider<T,F>
Parameters:
query
- given query to request dataReturns:
the result of the query request: a stream of data objects, not
null
-
size
public int size(Query<T,F> query)
Description copied from interface:
DataProvider
Gets the amount of data in this DataProvider.
Specified by:
size
in interfaceDataProvider<T,F>
Parameters:
query
- query with sorting and filteringReturns:
the size of the data provider
-
fetchFromBackEnd
protected abstract Stream<T> fetchFromBackEnd(Query<T,F> query)
Fetches data from the back end using the given query.
Parameters:
query
- the query that defines sorting, filtering and paging for fetching the dataReturns:
a stream of items matching the query
-
sizeInBackEnd
protected abstract int sizeInBackEnd(Query<T,F> query)
Counts the number of items available in the back end.
Parameters:
query
- the query that defines filtering to be used for counting the number of itemsReturns:
the number of available items
-
setSortOrders
public void setSortOrders(List<QuerySortOrder> sortOrders)
Description copied from interface:
BackEndDataProvider
Sets a list of sort orders to use as the default sorting for this data provider. This overrides the sorting set by any other method that manipulates the default sorting of this data provider.
The default sorting is used if the query defines no sorting. The default sorting is also used to determine the ordering of items that are considered equal by the sorting defined in the query.
Specified by:
setSortOrders
in interfaceBackEndDataProvider<T,F>
Parameters:
sortOrders
- a list of sort orders to set, notnull
See Also:
-
-