Class JpaGridDataSource<E>

  extended by org.apache.tapestry5.jpa.JpaGridDataSource<E>
All Implemented Interfaces:

public class JpaGridDataSource<E>
extends Object
implements GridDataSource

A simple implementation of GridDataSource based on a EntityManager and a known entity class. This implementation does support multiple sort constraints.

This class is not thread-safe; it maintains internal state.

Typically, an instance of this object is created fresh as needed (that is, it is not stored between requests).


Constructor Summary
JpaGridDataSource(EntityManager entityManager, Class<E> entityType)
Method Summary
protected  void applyAdditionalConstraints(CriteriaQuery<?> criteria, Root<E> root, CriteriaBuilder builder)
 int getAvailableRows()
          Returns the number of rows available in the data source.
 Class<E> getRowType()
          Returns the type of value in the rows, or null if not known.
 Object getRowValue(int index)
          Returns the row value at the provided index.
 void prepare(int startIndex, int endIndex, List<SortConstraint> sortConstraints)
          Invoked to allow the source to prepare to present values.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public JpaGridDataSource(EntityManager entityManager,
                         Class<E> entityType)
Method Detail


public int getAvailableRows()
Returns the number of rows available in the data source.

Specified by:
getAvailableRows in interface GridDataSource


public void prepare(int startIndex,
                    int endIndex,
                    List<SortConstraint> sortConstraints)
Invoked to allow the source to prepare to present values. This gives the source a chance to pre-fetch data (when appropriate) and informs the source of the desired sort order. Sorting comes first, then extraction by range.

Specified by:
prepare in interface GridDataSource
startIndex - the starting index to be retrieved
endIndex - the ending index to be retrieved
sortConstraints - identify how data is to be sorted


protected void applyAdditionalConstraints(CriteriaQuery<?> criteria,
                                          Root<E> root,
                                          CriteriaBuilder builder)


public Object getRowValue(int index)
Returns the row value at the provided index. This method will be invoked in sequential order. In rare instances, GridDataSource.getAvailableRows() may return a different number of rows than are actually available (i.e., the database was changed between calls to GridDataSource.getAvailableRows() and the call to GridDataSource.prepare(int, int, java.util.List)). In that case, this method should return null for any out-of-range indexes.

Specified by:
getRowValue in interface GridDataSource


public Class<E> getRowType()
Returns the type of value in the rows, or null if not known. This value is used to create a default BeanModel when no such model is explicitly provided.

Specified by:
getRowType in interface GridDataSource
the row type, or null

Copyright © 2003-2012 The Apache Software Foundation.