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(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> criterion,
org.ujorm.Key<? super U,?> defaultSort)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
addHidden(org.ujorm.Key<? super U,?> column)
Add the hidden column for a fetch loading from database
|
void |
clearCache()
Do nothing
|
protected Query<U> |
createQuery(org.ujorm.criterion.Criterion<U> criterion)
Create default Query
|
void |
detach()
Commit and close transaction
|
protected void |
fetchDatabaseColumns(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 Session |
getOrmSession()
Returns ORM Session
|
boolean |
isFetchDatabaseColumns()
Fetch database columns for better SQL performance
where the feature is enabled by default
|
protected boolean |
isSortingEnabled(org.ujorm.Key<U,?> column)
The sorting is enabled for a persistent Ujorm Key by default
|
Iterator<U> |
iterator(long first,
long count)
Build a JDBC ResultSet always.
|
protected Iterator<U> |
iterator(long first,
long count,
org.ujorm.criterion.Criterion<U> crn)
Build a JDBC ResultSet always.
|
static <T extends OrmUjo> |
of(org.ujorm.criterion.Criterion<T> criterion)
Factory for the class
|
static <T extends OrmUjo> |
of(org.ujorm.criterion.Criterion<T> criterion,
org.ujorm.Key<? super T,?> defaultSort)
Factory for the class
|
static <T extends OrmUjo> |
of(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T>> criterion)
Factory for the class
|
static <T extends OrmUjo> |
of(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T>> criterion,
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(@Nonnull org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> criterion, @Nonnull org.ujorm.Key<? super U,?> defaultSort)
criterion - Model of a condition to a database querydefaultSort - Default sorting can be assigned optionallypublic void addHidden(@Nonnull org.ujorm.Key<? super U,?> column)
@Nonnull public Iterator<U> iterator(long first, long count)
@Nonnull protected Iterator<U> iterator(long first, long count, @Nonnull org.ujorm.criterion.Criterion<U> crn)
public long size()
public void detach()
detach in interface org.apache.wicket.model.IDetachabledetach in class AbstractDataProvider<U extends OrmUjo>@Nonnull protected Query<U> createQuery(@Nonnull org.ujorm.criterion.Criterion<U> criterion)
protected boolean isSortingEnabled(@Nonnull org.ujorm.Key<U,?> column) throws IllegalArgumentException
isSortingEnabled in class AbstractDataProvider<U extends OrmUjo>IllegalArgumentExceptionAbstractDataProvider.isDefaultColumnSorting()protected void fetchDatabaseColumns(@Nonnull 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(@Nonnull org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T>> criterion, @Nonnull org.ujorm.Key<? super T,?> defaultSort)
public static <T extends OrmUjo> OrmDataProvider<T> of(@Nonnull org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T>> criterion)
public static <T extends OrmUjo> OrmDataProvider<T> of(@Nonnull org.ujorm.criterion.Criterion<T> criterion, @Nonnull org.ujorm.Key<? super T,?> defaultSort)
public static <T extends OrmUjo> OrmDataProvider<T> of(@Nonnull org.ujorm.criterion.Criterion<T> criterion)
Copyright © 2019. All rights reserved.