This ValueListAdapter returns a ValueList of wrapped records from ResultSet.
Using wrappers is recommended in cases, when your hibernate hql is too complex, and you cannot controll all composite joins. Then you would appreciate jdbc with the conjuction of wrappers that allow you to call third party managers, that return you wanted object. Wrappers helps you to replace the orignal ResultSet with wrapped record and still support paging. Sorting could be problematic due to replacement of records. But it is possible, depends on you!
Name | Required | Default | Description |
---|---|---|---|
adapterType | N | 0 |
A bitwise OR of the following:
|
dataSource | Y | N/A | An instance of javax.sql.DataSource. |
sql | Y | N/A | The sql query. |
defaultNumberPerPage | N | Integer.MAX_VALUE | The number if items per page. This can be overridden by a value in the ValueListInfo. |
defaultSortColumn | N | N/A | The column to sort the results by. This can be overridden by a value in the ValueListInfo. |
defaultSortDirection | N | N/A | The direction (asc or desc) to sort the results by. This can be overridden by a value in the ValueListInfo. |
validator | N | null |
|
wrapper | Y | N/A | Replace orignal record with wrapped record. |
wrapResultSet | N | false | Determine object to be wrapped - resultSet or column from result set. |
To use DefaultWrapperAdapter
you have to
net.mlw.vlh.adapter.util.ObjectWrapper
interface.
public class PlayersWrapper implements ObjectWrapper { private PlayerManager playerManager; public Object getWrappedRecord(Object objectToBeWrapped) { Long id = (Long) objectToBeWrapped; return playerManager.getPlayer(id); } /** * @see net.mlw.vlh.adapter.util.ObjectWrapper#setValueListInfo(net.mlw.vlh.ValueListInfo) */ public void setValueListInfo(ValueListInfo info) { // This method is called by adapter! // In this example is it not used, you can use it as additional way how // to pass some additional parameters to method isAcceptable. } }
<bean id="valueListHandler" singleton="true" class="net.mlw.vlh.DefaultValueListHandlerImpl"> <property name="config.adapters"> <map> ... <entry key="nbaPlayersWrapper"> <bean class="net.mlw.vlh.adapter.jdbc.objectWrapper.DefaultWrapperAdapter"> <property name="dataSource"><ref bean="myDataSource"/></property> <property name="defaultNumberPerPage"><value>20</value></property> <property name="defaultSortColumn"><value>playerId</value></property> <property name="defaultSortDirection"><value>asc</value></property> <property name="sql"> <value> SELECT p.PLAYER_ID as playerId FROM player p /~sortColumn: ORDER BY [sortColumn] [sortDirection]~/ </value> </property> <!-- this validator is optional see war example where is it used <property name="validator"><ref bean="playersIdValidator"/></property> --> <property name="wrapper"><ref bean="playersIdWrapper"/></property> <property name="wrapResultSet"><value>false</value></property> </bean> </entry> ... </map> </property> </bean> <bean id="playersIdWrapper" class="my.package.PlayersWrapper"/>
As you can see, we used the first variant of usage of
DefautlWrapperAdapter. Another is to wrap instead of the
given column, whole ResultSet. You can enable this with
the property wrapResultSet
by setting it to true.
For more details see war example version (0-1-7Beta11 or higher).