public class UjoDataProvider<T extends OrmUjo> extends org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider<T,Object>
This class called UjoDataProvider is an database
Wicket DataProvider. For a customization you can use a your own IColumn implementations
or you can owerwrite selected 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 owerwrite 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);
UjoDataProvider<Hotel> dataProvider = UjoDataProvider.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));
| Modifier and Type | Field and Description |
|---|---|
protected org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T>> |
criterion
Data criterion model
|
static String |
DEFAULT_DATATABLE_ID
Default Datatable ID have got value
"datatable". |
protected KeyRing<T> |
model
Domain model
|
protected Long |
size
Data size
|
| Constructor and Description |
|---|
UjoDataProvider(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T>> criterion)
Constructor
|
UjoDataProvider(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T>> criterion,
Key<T,?> defaultSort)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn<T,?> column)
Add table column
|
<V> boolean |
add(Key<T,V> column)
Add table column according to column type
|
<V> boolean |
add(Key<T,V> column,
CssAppender cssClass)
Add table column according to column type including CSS class
|
<S> org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<T,S> |
createDataTable(int rowsPerPage)
Create AJAX-based DataTable with a
DEFAULT_DATATABLE_ID |
<S> org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<T,S> |
createDataTable(String id,
int rowsPerPage)
Create AJAX-based DataTable
|
protected Query<T> |
createQuery(org.ujorm.criterion.Criterion<T> criterion)
Create default Query
|
void |
detach()
Commit and close transaction
|
protected void |
fetchDatabaseColumns(Query<T> query)
The method reduces a lazy database requests from relational table columns.
|
List<org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn<T,?>> |
getColumns()
Transient table columns
|
KeyRing<T> |
getModel()
Get a bean Model
|
protected Session |
getOrmSession()
Returns orm Session
|
Key<T,?> |
getSortKey()
Vrací klíč pro řazení
|
boolean |
isDefaultColumnSorting()
Default column sorting for the method
#addColumn(org.ujorm.Key)
where the feature is enabled by default |
boolean |
isFetchDatabaseColumns()
Fetch database columns for better SQL performance
where the feature is enabled by default
|
protected boolean |
isSortingEnabled(Key<T,?> column)
The sorting is enabled for a persistent Ujorm Key by default
|
Iterator<T> |
iterator(long first,
long count)
Build a JDBC ResultSet allways.
|
org.apache.wicket.model.IModel<T> |
model(T object)
Create a model
|
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,
Key<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,
Key<T,?> defaultSort)
Factory for the class
|
void |
setCssClass(Key<T,?> key,
String cssClass)
Assign a CSS class to a KeyColumn, if exists
|
void |
setDefaultColumnSorting(boolean defaultColumnSorting)
Default column sorting for the method
#addColumn(org.ujorm.Key)
where the feature is enabled by default |
void |
setFetchDatabaseColumns(boolean fetchDatabaseColumns)
Fetch database columns for better SQL performance
where the feature is enabled by default
|
void |
setSort(Key<T,?> property)
Sets the current sort state and assign the BaseClass
|
long |
size()
Method calculate the size using special SQL requst.
|
protected void |
sortDatabaseQuery(Query<T> query)
Add sorting to a database Query,
an empty method causes a natural sorting from database
|
public static final String DEFAULT_DATATABLE_ID
"datatable".protected Long size
protected org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T extends OrmUjo>> criterion
public UjoDataProvider(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T>> criterion)
criterion - Condition to a database querypublic UjoDataProvider(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T>> criterion, Key<T,?> defaultSort)
criterion - Model of a condition to a database querydefaultSort - Default sorting can be assigned optionallypublic final void setSort(Key<T,?> property)
property - sort propertyorder - sort orderpublic Iterator<T> iterator(long first, long count)
public long size()
protected Session getOrmSession()
public void detach()
protected Query<T> createQuery(org.ujorm.criterion.Criterion<T> criterion)
public boolean add(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn<T,?> column)
public <V> boolean add(Key<T,V> column, CssAppender cssClass)
protected boolean isSortingEnabled(Key<T,?> column) throws IllegalArgumentException
IllegalArgumentExceptionisDefaultColumnSorting()public <S> org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<T,S> createDataTable(int rowsPerPage)
DEFAULT_DATATABLE_IDpublic <S> org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<T,S> createDataTable(String id, int rowsPerPage)
protected void fetchDatabaseColumns(Query<T> query)
isFetchDatabaseColumns()protected void sortDatabaseQuery(Query<T> query)
public final boolean isDefaultColumnSorting()
#addColumn(org.ujorm.Key)
where the feature is enabled by defaultpublic void setDefaultColumnSorting(boolean defaultColumnSorting)
#addColumn(org.ujorm.Key)
where the feature is enabled by defaultdefaultColumnSorting - the defaultColumnSorting to setpublic final boolean isFetchDatabaseColumns()
public void setFetchDatabaseColumns(boolean fetchDatabaseColumns)
fetchDatabaseColumns - the fetchDatabaseColumns to setpublic List<org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn<T,?>> getColumns()
public static <T extends OrmUjo> UjoDataProvider<T> of(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T>> criterion, Key<T,?> defaultSort)
public static <T extends OrmUjo> UjoDataProvider<T> of(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T>> criterion)
public static <T extends OrmUjo> UjoDataProvider<T> of(org.ujorm.criterion.Criterion<T> criterion, Key<T,?> defaultSort)
public static <T extends OrmUjo> UjoDataProvider<T> of(org.ujorm.criterion.Criterion<T> criterion)
Copyright © 2013. All Rights Reserved.