org.ujorm.wicket.component.grid
Class OrmDataProvider<U extends OrmUjo>

java.lang.Object
  extended by org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider<U,Object>
      extended by org.ujorm.wicket.component.grid.AbstractDataProvider<U>
          extended by org.ujorm.wicket.component.grid.OrmDataProvider<U>
All Implemented Interfaces:
Serializable, org.apache.wicket.extensions.markup.html.repeater.data.sort.ISortStateLocator<Object>, org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider<U,Object>, org.apache.wicket.markup.repeater.data.IDataProvider<U>, org.apache.wicket.model.IDetachable, org.apache.wicket.util.io.IClusterable
Direct Known Subclasses:
UjoDataProvider

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:

See the simple sample:

 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));
 
 

Author:
Pavel Ponec
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.ujorm.wicket.component.grid.AbstractDataProvider
DEFAULT_CSS_ACTION, DEFAULT_CSS_SELECTED, DEFAULT_DATATABLE_ID, filter, highlighting, size
 
Constructor Summary
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, Key<? super U,?> defaultSort)
          Constructor
 
Method Summary
 void addHidden(Key<? super U,?> column)
          Add the hidden column for a fetch loading from database
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<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(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.
static
<T extends OrmUjo>
OrmDataProvider<T>
of(org.ujorm.criterion.Criterion<T> criterion)
          Factory for the class
static
<T extends OrmUjo>
OrmDataProvider<T>
of(org.ujorm.criterion.Criterion<T> criterion, Key<? super T,?> defaultSort)
          Factory for the class
static
<T extends OrmUjo>
OrmDataProvider<T>
of(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T>> criterion)
          Factory for the class
static
<T extends OrmUjo>
OrmDataProvider<T>
of(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T>> criterion, 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 requst.
protected  void sortDatabaseQuery(Query<U> query)
          Add sorting to a database Query, an empty method causes a natural sorting from database
 
Methods inherited from class org.ujorm.wicket.component.grid.AbstractDataProvider
add, add, add, add, add, add, createBottomToolbars, createDataTable, createDataTable, createDataTable, createDataTable, createTopToolbars, deleteRow, getColumns, getCssSelected, getDomainClass, getFirstTableRow, getHighlighting, getSortKey, insertRow, isDefaultColumnSorting, model, setCssClass, setDefaultColumnSorting, setHighlighting, setHighlighting, setSelected, setSelected, setSort, updateRow
 
Methods inherited from class org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider
getSort, getSortState, setSort, setSort
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OrmDataProvider

public OrmDataProvider(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> criterion)
Constructor

Parameters:
criterion - Condition to a database query

OrmDataProvider

public OrmDataProvider(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> criterion,
                       Key<? super U,?> defaultSort)
Constructor

Parameters:
criterion - Model of a condition to a database query
defaultSort - Default sorting can be assigned optionally
Method Detail

addHidden

public void addHidden(Key<? super U,?> column)
Add the hidden column for a fetch loading from database


iterator

public Iterator<U> iterator(long first,
                            long count)
Build a JDBC ResultSet always. Overwrite the method for an optimization.

Specified by:
iterator in interface org.apache.wicket.markup.repeater.data.IDataProvider<U extends OrmUjo>
Specified by:
iterator in class AbstractDataProvider<U extends OrmUjo>

size

public long size()
Method calculate the size using special SQL requst. Overwrite the method for an optimization.
Original documentation: Method calculate the size using special SQL request. Overwrite the method for an optimization.
Original documentation:

Specified by:
size in interface org.apache.wicket.markup.repeater.data.IDataProvider<U extends OrmUjo>
Specified by:
size in class AbstractDataProvider<U extends OrmUjo>

getOrmSession

protected Session getOrmSession()
Returns ORM Session


detach

public void detach()
Commit and close transaction

Specified by:
detach in interface org.apache.wicket.model.IDetachable
Specified by:
detach in class AbstractDataProvider<U extends OrmUjo>

createQuery

protected Query<U> createQuery(org.ujorm.criterion.Criterion<U> criterion)
Create default Query


isSortingEnabled

protected boolean isSortingEnabled(Key<U,?> column)
                            throws IllegalArgumentException
The sorting is enabled for a persistent Ujorm Key by default

Overrides:
isSortingEnabled in class AbstractDataProvider<U extends OrmUjo>
Throws:
IllegalArgumentException
See Also:
AbstractDataProvider.isDefaultColumnSorting()

fetchDatabaseColumns

protected void fetchDatabaseColumns(Query<U> query)
The method reduces a lazy database requests from relational table columns. The current implementation assigns all direct keys/columns from domain entity and all required keys/columns from the IColumn object.
Note: You can overwrite the method for a different behaviour.
Note: If the implementation will be empty, so all related attributes will be lazy loaded, so it can be a performance problem in some cases.

See Also:
isFetchDatabaseColumns()

getHiddenColumns

public List<KeyRing<U>> getHiddenColumns()
Hidden column table list


sortDatabaseQuery

protected void sortDatabaseQuery(Query<U> query)
Add sorting to a database Query, an empty method causes a natural sorting from database


isFetchDatabaseColumns

public final boolean isFetchDatabaseColumns()
Fetch database columns for better SQL performance where the feature is enabled by default

Returns:
the fetchDatabaseColumns

setFetchDatabaseColumns

public void setFetchDatabaseColumns(boolean fetchDatabaseColumns)
Fetch database columns for better SQL performance where the feature is enabled by default

Parameters:
fetchDatabaseColumns - the fetchDatabaseColumns to set

of

public static <T extends OrmUjo> OrmDataProvider<T> of(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T>> criterion,
                                                       Key<? super T,?> defaultSort)
Factory for the class


of

public static <T extends OrmUjo> OrmDataProvider<T> of(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T>> criterion)
Factory for the class


of

public static <T extends OrmUjo> OrmDataProvider<T> of(org.ujorm.criterion.Criterion<T> criterion,
                                                       Key<? super T,?> defaultSort)
Factory for the class


of

public static <T extends OrmUjo> OrmDataProvider<T> of(org.ujorm.criterion.Criterion<T> criterion)
Factory for the class



Copyright © 2015. All Rights Reserved.