Holger's Java API

## com.antelmann.sql
Class WrappedObjectRowMapper<T extends DBEntry>

    java.lang.Object
      com.antelmann.sql.WrappedObjectRowMapper<T>

All Implemented Interfaces:
  TransactionRequired, MappingInfo, ObjectRowMapper<T>, Wrapped<ObjectRowMapper<T>>

Direct Known Subclasses:
  AddressableMapper

    public class WrappedObjectRowMapper<T extends DBEntry>

extends Object
implements ObjectRowMapper<T>, Wrapped<ObjectRowMapper<T>>

eases the task of wrapping a given mapper and overriding only certain aspects of its behavior. All `ObjectRowMapper`-implementing methods are delegated to the embedded mapper. Often, a `WrappedDBClassStoreMapping` does a better job.

Since:
  21.11.2008, 12:53:57
Author:
  Holger Antelmann
See Also:
  `WrappedDBClassStoreMapping`

Field Summary
`protected ObjectRowMapper<T>` `mapper`

Constructor Summary
`WrappedObjectRowMapper(ObjectRowMapper<T> mapper)`

Method Summary
`Stub<T>` `extractStub(ResultSet rs, Class<T> typeClass)`
`Object` `generateNewID()`
`String[]` `getColumnNames()` returns all the columns that are retrieved by the mapper when querying the database); the column names for the ID column and display column are included in the returned array.
`String[]` `getColumnsForTopic(Object topic)` allows to determine whether there are any columns that are applicable for the given topic
`int` `getColumnSize(String column)` allows to determine the size of the given column name.
`Connection` `getConnection()`
`String` `getDisplayColumn()` for use in stubs (in case a single column is used as a display value)
`String` `getDisplayNameForColumn(String column)` returns a name suitable for display in a GUI if different from the column name used in the database
`String` `getIDColumn()` specifies the column where the ID of the entry is mapped to
`String` `getMappingForTopic(Object topic)` allows to determine whether a specific given topic maps to a distinct table, query or column name.
`String[]` `getRestrictMappedColumns()` allows to limit the columns retrieved from a ResultSet when loading the data from a table query.
`ResultSet` `getResultSet(Filter<? super T> filter)` constructs the ResultSet used for fetching entries that corresponds closest to the filter; note that the filter may be null, in which case the select statement should return all rows.
`int` `getSQLTypeforColumn(String column)` allows to determine the SQL-type for a given column name
`ResultSet` `getStubResultSet(Filter<? super Stub<?>> filter)` creates and returns the ResultSet used for fetching stubs that corresponds closest to the filter for extracting Stub entries.
`String` `getTableName()` provides the name of the table that stores the data for the store
`String` `getTableQuery()` if querying involves something different than just selecting all columns of the table, this method returns the string used to replace the table name in a query.
`void` `handleAfterStore(T entry, boolean isInsert)` called by the store after a given entry is either inserted or updated, so that additional updates (other than providing the RowItem for storage) can take place.
`T` `instantiate(RowItem row)` instantiates the DBEntry based on the properties in the given row.
`RowItem` `mapToRow(T object)` generates a RowItem containing all relevant properties, so that it can be used to store the object into the database
`ObjectRowMapper<T>` `unwrap()` returns the embedded mapper that was given to the constructor
`void` `verifyBeforeDelete(Object id)` called by the store before a given entry is deleted, so that additional checks can easily be incorporated.
`void` `verifyBeforeStore(T entry, boolean isInsert)` called by the store before a given entry is either inserted or updated, so that additional checks can easily be incorporated.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### mapper

    protected final ObjectRowMapper<T extends DBEntry> mapper

Constructor Detail

### WrappedObjectRowMapper

    public WrappedObjectRowMapper(ObjectRowMapper<T> mapper)

Method Detail

### unwrap

    public ObjectRowMapper<T> unwrap()

  returns the embedded mapper that was given to the constructor

  Specified by:
    `unwrap` in interface `Wrapped<ObjectRowMapper<T extends DBEntry>>`

### extractStub

    public Stub<T> extractStub(ResultSet rs,
                               Class<T> typeClass)
                                        throws SQLException

  Specified by:
    `extractStub` in interface `ObjectRowMapper<T extends DBEntry>`
  Throws:
    `SQLException`

### generateNewID

    public Object generateNewID()
                         throws DatabaseException,
                                UnsupportedOperationException

  Specified by:
    `generateNewID` in interface `ObjectRowMapper<T extends DBEntry>`
  Throws:
    `DatabaseException`
    `UnsupportedOperationException`
  See Also:
    `DBClassStore.generateNewID()`, `SQLNumberGenerator`, `TransactionalNumberGenerator`

### getConnection

    public Connection getConnection()

  Specified by:
    `getConnection` in interface `ObjectRowMapper<T extends DBEntry>`

### getDisplayColumn

    public String getDisplayColumn()

  Description copied from interface: `MappingInfo`
  for use in stubs (in case a single column is used as a display value)

  Specified by:
    `getDisplayColumn` in interface `MappingInfo`

### getIDColumn

    public String getIDColumn()

  Description copied from interface: `MappingInfo`
  specifies the column where the ID of the entry is mapped to

  Specified by:
    `getIDColumn` in interface `MappingInfo`

### getResultSet

    public ResultSet getResultSet(Filter<? super T> filter)
                           throws SQLException

  Description copied from interface: `ObjectRowMapper`
  constructs the ResultSet used for fetching entries that corresponds closest to the filter; note that the filter may be null, in which case the select statement should return all rows. The returned ResultSet should allow at least for all objects accepted by the filter; it may include more, which would then be filtered out by the filter itself.

  Specified by:
    `getResultSet` in interface `ObjectRowMapper<T extends DBEntry>`
  Throws:
    `SQLException`

### getStubResultSet

    public ResultSet getStubResultSet(Filter<? super Stub<?>> filter)
                               throws SQLException

  Description copied from interface: `ObjectRowMapper`
  creates and returns the ResultSet used for fetching stubs that corresponds closest to the filter for extracting Stub entries. The filter may be null.

  Specified by:
    `getStubResultSet` in interface `ObjectRowMapper<T extends DBEntry>`
  Throws:
    `SQLException`

### getTableName

    public String getTableName()

  Description copied from interface: `MappingInfo`
  provides the name of the table that stores the data for the store

  Specified by:
    `getTableName` in interface `MappingInfo`
  See Also:
    `MappingInfo.getTableQuery()`

### getTableQuery

    public String getTableQuery()

  Description copied from interface: `MappingInfo`
  if querying involves something different than just selecting all columns of the table, this method returns the string used to replace the table name in a query. The return value - if non-null - is used to create ResultSet objects, so that other columns than those merely present in the original table can be retrieved (e.g. through a join). If this value is null, the value from `MappingInfo.getTableName()` is used in all cases. If non-null, this variable would have a value like '(select a.field1, b.* from a, b where a.id=b.id) as t1'.

  Specified by:
    `getTableQuery` in interface `MappingInfo`
  See Also:
    `MappingInfo.getTableName()`

### instantiate

    public T instantiate(RowItem row)
                                  throws Exception

  Description copied from interface: `ObjectRowMapper`
  instantiates the DBEntry based on the properties in the given row. The given row contains all the columns of the queried ResultSet unless the columns to be retrieved are restricted by `ObjectRowMapper.getRestrictMappedColumns()`.

  Specified by:
    `instantiate` in interface `ObjectRowMapper<T extends DBEntry>`
  Throws:
    `Exception`

### mapToRow

    public RowItem mapToRow(T object)
                     throws WrongDataException

  Description copied from interface: `ObjectRowMapper`
  generates a RowItem containing all relevant properties, so that it can be used to store the object into the database

  Specified by:
    `mapToRow` in interface `ObjectRowMapper<T extends DBEntry>`
  Throws:
    `WrongDataException`

### verifyBeforeDelete

    public void verifyBeforeDelete(Object id)
                            throws DatabaseException,
                                   SQLException

  Description copied from interface: `ObjectRowMapper`
  called by the store before a given entry is deleted, so that additional checks can easily be incorporated. This method would be called only from within an open transaction. Note that this method NOT called if `DBClassStore.deleteEntries(Filter)` is called and `JDBCRowStore.isFastDelete()` returns is true!

  Specified by:
    `verifyBeforeDelete` in interface `ObjectRowMapper<T extends DBEntry>`
  Throws:
    `WrongDataException` - if the deletion is not allowed for semantical reasons
    `DatabaseException`
    `SQLException`

### verifyBeforeStore

    public void verifyBeforeStore(T entry,
                                  boolean isInsert)
                           throws DatabaseException,
                                  SQLException

  Description copied from interface: `ObjectRowMapper`
  called by the store before a given entry is either inserted or updated, so that additional checks can easily be incorporated. This method would be called only from within an open transaction.

  Specified by:
    `verifyBeforeStore` in interface `ObjectRowMapper<T extends DBEntry>`
    `isInsert` - if true, the entry is about to be inserted; if false, it is an update
  Throws:
    `DatabaseException`
    `SQLException`

### handleAfterStore

    public void handleAfterStore(T entry,
                                 boolean isInsert)
                          throws DatabaseException,
                                 SQLException

  Description copied from interface: `ObjectRowMapper`
  called by the store after a given entry is either inserted or updated, so that additional updates (other than providing the RowItem for storage) can take place.

  Specified by:
    `handleAfterStore` in interface `ObjectRowMapper<T extends DBEntry>`
    `isInsert` - if true, the entry is about to be inserted; if false, it is an update
  Throws:
    `DatabaseException`
    `SQLException`

### getMappingForTopic

    public String getMappingForTopic(Object topic)

  Description copied from interface: `MappingInfo`
  allows to determine whether a specific given topic maps to a distinct table, query or column name.

  Specified by:
    `getMappingForTopic` in interface `MappingInfo`
  Returns:
    either a table name, a column name, a query string or null - depending on the given topic

### getColumnsForTopic

    public String[] getColumnsForTopic(Object topic)

  Description copied from interface: `MappingInfo`
  allows to determine whether there are any columns that are applicable for the given topic

  Specified by:
    `getColumnsForTopic` in interface `MappingInfo`
  Returns:
    an array of column names that apply to the given topic; the array may be empty but never null

### getColumnNames

    public String[] getColumnNames()

  Description copied from interface: `MappingInfo`
  returns all the columns that are retrieved by the mapper when querying the database); the column names for the ID column and display column are included in the returned array. Note that the return value refers to the columns in the table query; only if the query is null, the return value refers to the columns in the table itself.

  Specified by:
    `getColumnNames` in interface `MappingInfo`
  Returns:
    all columns that are retrieved by the mapper or null if this doesn't apply for this instance.
  See Also:
    `MappingInfo.getTableName()`, `MappingInfo.getTableQuery()`, `MappingInfo.getIDColumn()`, `MappingInfo.getDisplayColumn()`

### getDisplayNameForColumn

    public String getDisplayNameForColumn(String column)

  Description copied from interface: `MappingInfo`
  returns a name suitable for display in a GUI if different from the column name used in the database

  Specified by:
    `getDisplayNameForColumn` in interface `MappingInfo`
  Returns:
    a suitable display value for the given column or the given column itself if no better display name exists

### getSQLTypeforColumn

    public int getSQLTypeforColumn(String column)
                            throws IllegalArgumentException

  Description copied from interface: `MappingInfo`
  allows to determine the SQL-type for a given column name

  Specified by:
    `getSQLTypeforColumn` in interface `MappingInfo`
  Returns:
    the SQL-type for the given column
  Throws:
    `IllegalArgumentException` - if the given column is not known
  See Also:
    `Types`

### getColumnSize

    public int getColumnSize(String column)
                      throws IllegalArgumentException

  Description copied from interface: `MappingInfo`
  allows to determine the size of the given column name. For a text column, this is the maximum number of characters; for a number column, this specifies the precision.

  Specified by:
    `getColumnSize` in interface `MappingInfo`
  Throws:
    `IllegalArgumentException` - if the given column is not known

### getRestrictMappedColumns

    public String[] getRestrictMappedColumns()

  Description copied from interface: `ObjectRowMapper`
  allows to limit the columns retrieved from a ResultSet when loading the data from a table query. If the return value is null, all columns are retrieved without restriction. If the return value is an empty array, only the ID column is retrieved. If the return value is a non-empty array, only those columns are retrieved from the query that are contained in this array. The id column is always retrieved.

  Specified by:
    `getRestrictMappedColumns` in interface `ObjectRowMapper<T extends DBEntry>`
  Returns:
    an array of column names that limit which columns are retrieved from a `ResultSet` when extracting the data into a `RowItem`; null may be returned.
  See Also:
    `ObjectRowMapper.instantiate(RowItem)`

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads