public class OrmDataProvider<U extends OrmUjo> extends AbstractDataProvider<U>
This class called OrmDataProvider is an ORM based
Wicket DataProvider. For a customization you can use a your own IColumn implementations
or you can overwrite highlighting methods of this provider.
The implementation generates two database requests per a one rendering,
the first one get size and the second one get paged data. You can overwrite the two data methods:
iterator() and the size()
for more optimization.
The current class uses a WicketApplication implementation, which must
implement the interface OrmHandlerProvider for an ORM support. See the example:
Criterion<Hotel> allActiveHotels = Hotel.ACTIVE.whereEq(true);
OrmDataProvider<Hotel> dataProvider = OrmDataProvider.of(allActiveHotels);
dataProvider.addColumn(Hotel.NAME);
dataProvider.addColumn(Hotel.CITY.add(City.NAME)); // An example of relations
dataProvider.addColumn(Hotel.STREET);
dataProvider.addColumn(Hotel.PRICE);
dataProvider.addColumn(KeyColumn.of(Hotel.CURRENCY, SORTING_OFF));
dataProvider.addColumn(Hotel.STARS);
dataProvider.addColumn(Hotel.PHONE);
dataProvider.setSort(Hotel.NAME);
panel.add(dataProvider.createDataTable("datatable", 10));
DEFAULT_CSS_ACTION, DEFAULT_CSS_SELECTED, DEFAULT_DATATABLE_ID, filter, highlighting, size| Constructor and Description |
|---|
OrmDataProvider(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> criterion)
Constructor
|
OrmDataProvider(@NotNull org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> criterion,
@NotNull org.ujorm.Key<? super U,?> defaultSort)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
addHidden(@NotNull org.ujorm.Key<? super U,?> column)
Add the hidden column for a fetch loading from database
|
void |
clearCache()
Do nothing
|
protected @NotNull Query<U> |
createQuery(@NotNull org.ujorm.criterion.Criterion<U> criterion)
Create default Query
|
void |
detach()
Commit and close transaction
|
protected void |
fetchDatabaseColumns(@NotNull Query<U> query)
The method reduces a lazy database requests from relational table columns.
|
List<org.ujorm.core.KeyRing<U>> |
getHiddenColumns()
Hidden column table list
|
protected @NotNull Session |
getOrmSession()
Returns ORM Session
|
boolean |
isFetchDatabaseColumns()
Fetch database columns for better SQL performance
where the feature is enabled by default
|
protected boolean |
isSortingEnabled(@NotNull org.ujorm.Key<U,?> column)
The sorting is enabled for a persistent Ujorm Key by default
|
@NotNull Iterator<U> |
iterator(long first,
long count)
Build a JDBC ResultSet always.
|
protected @NotNull Iterator<U> |
iterator(long first,
long count,
@NotNull org.ujorm.criterion.Criterion<U> crn)
Build a JDBC ResultSet always.
|
static <T extends OrmUjo> |
of(@NotNull org.ujorm.criterion.Criterion<T> criterion)
Factory for the class
|
static <T extends OrmUjo> |
of(@NotNull org.ujorm.criterion.Criterion<T> criterion,
@NotNull org.ujorm.Key<? super T,?> defaultSort)
Factory for the class
|
static <T extends OrmUjo> |
of(@NotNull org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T>> criterion)
Factory for the class
|
static <T extends OrmUjo> |
of(@NotNull org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T>> criterion,
@NotNull org.ujorm.Key<? super T,?> defaultSort)
Factory for the class
|
void |
setFetchDatabaseColumns(boolean fetchDatabaseColumns)
Fetch database columns for better SQL performance
where the feature is enabled by default
|
long |
size()
Method calculate the size using special SQL request.
|
protected void |
sortDatabaseQuery(Query<U> query)
Add sorting to a database Query,
an empty method causes a natural sorting from database
|
add, add, add, add, add, add, add, add, createBottomToolbars, createDataTable, createDataTable, createDataTable, createDataTable, createKeyColumn, createTopToolbars, deleteRow, getColumns, getCssSelected, getDomainClass, getExportableColumns, getFirstTableRow, getHighlighting, getSortKey, getSortKeys, insertRow, isDefaultColumnSorting, model, setCssClass, setDefaultColumnSorting, setHighlighting, setHighlighting, setSelected, setSelected, setSort, updateRowpublic OrmDataProvider(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> criterion)
criterion - Condition to a database querypublic OrmDataProvider(@NotNull
@NotNull org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> criterion,
@NotNull
@NotNull org.ujorm.Key<? super U,?> defaultSort)
criterion - Model of a condition to a database querydefaultSort - Default sorting can be assigned optionallypublic void addHidden(@NotNull
@NotNull org.ujorm.Key<? super U,?> column)
@NotNull public @NotNull Iterator<U> iterator(long first, long count)
@NotNull protected @NotNull Iterator<U> iterator(long first, long count, @NotNull @NotNull org.ujorm.criterion.Criterion<U> crn)
public long size()
@NotNull protected @NotNull Session getOrmSession()
public void detach()
detach in interface org.apache.wicket.model.IDetachabledetach in class AbstractDataProvider<U extends OrmUjo>@NotNull protected @NotNull Query<U> createQuery(@NotNull @NotNull org.ujorm.criterion.Criterion<U> criterion)
protected boolean isSortingEnabled(@NotNull
@NotNull org.ujorm.Key<U,?> column)
throws IllegalArgumentException
isSortingEnabled in class AbstractDataProvider<U extends OrmUjo>IllegalArgumentExceptionAbstractDataProvider.isDefaultColumnSorting()protected void fetchDatabaseColumns(@NotNull
@NotNull Query<U> query)
isFetchDatabaseColumns()protected void sortDatabaseQuery(Query<U> query)
public final boolean isFetchDatabaseColumns()
public void setFetchDatabaseColumns(boolean fetchDatabaseColumns)
fetchDatabaseColumns - the fetchDatabaseColumns to setpublic void clearCache()
public static <T extends OrmUjo> OrmDataProvider<T> of(@NotNull @NotNull org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T>> criterion, @NotNull @NotNull org.ujorm.Key<? super T,?> defaultSort)
public static <T extends OrmUjo> OrmDataProvider<T> of(@NotNull @NotNull org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T>> criterion)
public static <T extends OrmUjo> OrmDataProvider<T> of(@NotNull @NotNull org.ujorm.criterion.Criterion<T> criterion, @NotNull @NotNull org.ujorm.Key<? super T,?> defaultSort)
public static <T extends OrmUjo> OrmDataProvider<T> of(@NotNull @NotNull org.ujorm.criterion.Criterion<T> criterion)
Copyright © 2024. All rights reserved.