diff --git a/docs/15_0_0/components/datatable.md b/docs/15_0_0/components/datatable.md index be79cb7b1a..fda72164f8 100644 --- a/docs/15_0_0/components/datatable.md +++ b/docs/15_0_0/components/datatable.md @@ -976,7 +976,7 @@ public class CarBean { PrimeFaces provides a OOTB implementation for JPA users, which supports basic features. ```java -JPALazyDataModel lazyDataModel = JPALazyDataModel.builder()) +JPALazyDataModel lazyDataModel = JPALazyDataModel. builder() .entityClass(MyEntity.class) .entityManager(() -> entityManager) .build(); @@ -987,7 +987,7 @@ It's very likely that this is the mapped JPA `@Id`, so we try to auto-lookup per Otherwise you can also define it: ```java -JPALazyDataModel lazyDataModel = JPALazyDataModel.builder()) +JPALazyDataModel lazyDataModel = JPALazyDataModel. builder() ... .rowKeyField(MyEntity_.id) // JPA MetaModel .rowKeyField("id") // or as String @@ -997,7 +997,7 @@ JPALazyDataModel lazyDataModel = JPALazyDataModel.builder()) or provide a existing JSF `Converter`: ```java -JPALazyDataModel lazyDataModel = JPALazyDataModel.builder()) +JPALazyDataModel lazyDataModel = JPALazyDataModel. builder() ... .rowKeyConverter(myConverter) ... @@ -1007,7 +1007,7 @@ JPALazyDataModel lazyDataModel = JPALazyDataModel.builder()) Per default the filters are case sensitive but you can also disable it: ```java -JPALazyDataModel lazyDataModel = JPALazyDataModel.builder()) +JPALazyDataModel lazyDataModel = JPALazyDataModel. builder() ... .caseSensitive(false) ... @@ -1019,7 +1019,7 @@ while `?` and `_` mean replace a single character. For example `Smith*` would f the word `Smith`. For single character replacement like `Te?t` would match words `Tent` and `Test`. ```java -JPALazyDataModel lazyDataModel = JPALazyDataModel.builder()) +JPALazyDataModel lazyDataModel = JPALazyDataModel. builder() ... .wildcardSupport(true) ... @@ -1029,13 +1029,35 @@ JPALazyDataModel lazyDataModel = JPALazyDataModel.builder()) You can add global filters or manipulate generated predicates (from the DataTable columns) via: ```java -JPALazyDataModel lazyDataModel = JPALazyDataModel.builder()) +JPALazyDataModel lazyDataModel = JPALazyDataModel. builder() ... .filterEnricher((filterBy, cb, cq, root, predicates) -> { predicates.add(cb.isNull(root.get("id"))); }) ... ``` + +#### `Iterator` and performance considerations +`JPALazyDataModel`, being an extension of `DataModel`, is iterable over the JPA values. This is accomplished lazily by paging through, and therefore querying, the data as needed (calls to `hasNext()` and `next()` from `Iterator` in turn call `load(first, pageSize, sortBy, filterBy)`). + +If you know you are going to retrieve all pages of data this can be inefficient, especially for large datasets. Loading the data, as the following, can result in far fewer individual queries to pull the full dataset. +```java +JPALazyDataModel lazyDataModel = JPALazyDataModel. builder() + ... + +// Load all sorted and filtered data in one query (plus one for count) +DataTable binding = ... +Map sortMeta = binding.getSortByAsMap(); +Map filterMeta = binding.getFilterByAsMap(); +List result = lazyDataModel.load(0, lazyDataModel.count(filterMeta), sortMeta, filterMeta); + +// OR, to load all +Map sortMeta = Collections.emptyMap(); +Map filterMeta = Collections.emptyMap(); +List result = lazyDataModel.load(0, lazyDataModel.count(filterMeta), sortMeta, filterMeta); +``` + + ### FlowLogix JPALazyDataModel (PrimeFaces Community) `JPALazyDataModel` implementation that's fully integrated with Jakarta EE and `@Inject`able.