Holger's
Java API

com.antelmann.sql
Class GenericPropertyEntryMapper<T extends PropertyEntry>

java.lang.Object
  extended by com.antelmann.sql.BaseRowMapper<T>
      extended by com.antelmann.sql.GenericPropertyEntryMapper<T>
All Implemented Interfaces:
TransactionRequired, MappingInfo, ObjectRowMapper<T>, Converter<RowItem,T>

public class GenericPropertyEntryMapper<T extends PropertyEntry>
extends BaseRowMapper<T>

provides an easy way to map a table to a PropertyEntry class; this implementation makes several (common) assumptions about the mapping. All properties are mapped to column values. Unless a PropertyEntryFactory is supplied, the PropertyEntry class must have a constructor that uses an Object for the ID and then a Map for the properties, like PropertyEntryImpl.PropertyEntryImpl(Object, Map). If no IDFactory is given, the ID column is assumed to store Integer objects, which is relevant for the generation of new IDs.

Since:
17. August 2007, 15:00
Author:
Holger Antelmann
See Also:
GenericPropertyEntryStore

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.antelmann.util.Converter
Converter.Adapter<T1,T2>
 
Field Summary
 
Fields inherited from class com.antelmann.sql.BaseRowMapper
db, helper
 
Constructor Summary
GenericPropertyEntryMapper(Database<Connection> db, String table, String idColumn, Class<T> type)
          uses reflection to utilize the constructor that takes the ID and then the properties as a map
GenericPropertyEntryMapper(Database<Connection> db, String table, String idColumn, IDFactory idFactory, Class<T> type)
           
GenericPropertyEntryMapper(Database<Connection> db, String table, String idColumn, PropertyEntryFactory<T> factory, Class<T> type)
          uses the factory to generate instances; either factory or type must not be null
GenericPropertyEntryMapper(Database<Connection> db, String table, String idColumn, String displayColumn, Class<T> type)
          uses reflection to utilize the constructor that takes the ID and then the properties as a map
GenericPropertyEntryMapper(Database<Connection> db, String table, String idColumn, String displayColumn, PropertyEntryFactory<T> factory, Class<T> type)
          uses the factory to generate instances; either factory or type must not be null
GenericPropertyEntryMapper(Database<Connection> db, String table, String idColumn, String displayColumn, PropertyEntryFactory<T> factory, Class<T> type, IDFactory idFactory)
          uses the factory to generate instances; either factory or type must not be null
GenericPropertyEntryMapper(DBClassStore<?> refStore, Class<T> type)
           
GenericPropertyEntryMapper(DBClassStore<?> refStore, PropertyEntryFactory<T> factory, Class<T> type, IDFactory idFactory)
           
 
Method Summary
 Object generateNewID()
          simply returns getNextIntID(), unless an IDFactory was provided
protected  Map<String,Object> generateRowProperties(T entry)
          simply returns entry.getProperties() and 'translates' it if BaseRowMapper.isTranslate() is set
 String getDisplayProperty()
          if the returned String is non-null and T is an EntryHeader, the appropriate value will be set accordingly.
 T instantiate(RowItem row)
          instantiates the DBEntry based on the properties in the given row.
 void setDisplayProperty(String displayProperty)
          allows to specify the display property for EntryHeader instances.
 void setTableQuery(String tableQuery)
          allows to set a query for mapping the data instead of just using the table name.
 void setTableQuery(String tableQuery, String newIdColumn)
          in addition to setting a table query, this also allows to change the id column (often required to ensure the uniqueness of the id column in a query that may contain the column multiple times).
 
Methods inherited from class com.antelmann.sql.BaseRowMapper
addColumnsForTopic, applyFromMapping, checkExistence, convert, convertBack, convertTopicFilter, emptyStringsToNull, extractReference, extractStub, extractStub, getAll, getColumnDisplayMapping, getColumnNames, getColumnsForTopic, getColumnSize, getConnection, getConnectionHelper, getDisplayColumn, getDisplayNameForColumn, getEntryClass, getEntryClassMapper, getIDColumn, getIDFactory, getMappedValue, getMappingForTopic, getNextIntID, getNextIntIDFactory, getNextIntIDFactory, getPreStoreFilter, getReadOnlyColumns, getRestrictMappedColumns, getResultSet, getSQLTypeforColumn, getStubColumns, getStubQuery, getStubResultSet, getSupportedTopicColumns, getTableColumnNames, getTableName, getTableQuery, getTableQueryForComboFilter, getTransactionCounter, getUniqueRandomString, handleAfterStore, initMapping, isMappedTopic, isTranslate, javaToSql, javaToSql, lockTable, mapReference, mapReference, mapToRow, removeColumnTopic, setColumnsForTopic, setDisplayColumn, setEntryClass, setEntryClassMapper, setIDFactory, setMappedValue, setNextIntIdAsFactory, setPreStoreFilter, setReadOnlyColumns, setRestrictedMappedColumns, setStubQuery, setTopic, setTranslate, sqlToJava, toSQLMap, verifyBeforeDelete, verifyBeforeStore
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericPropertyEntryMapper

public GenericPropertyEntryMapper(Database<Connection> db,
                                  String table,
                                  String idColumn,
                                  Class<T> type)
                           throws DatabaseException
uses reflection to utilize the constructor that takes the ID and then the properties as a map

Throws:
DatabaseException

GenericPropertyEntryMapper

public GenericPropertyEntryMapper(Database<Connection> db,
                                  String table,
                                  String idColumn,
                                  String displayColumn,
                                  Class<T> type)
                           throws DatabaseException
uses reflection to utilize the constructor that takes the ID and then the properties as a map

Throws:
DatabaseException

GenericPropertyEntryMapper

public GenericPropertyEntryMapper(Database<Connection> db,
                                  String table,
                                  String idColumn,
                                  PropertyEntryFactory<T> factory,
                                  Class<T> type)
                           throws DatabaseException
uses the factory to generate instances; either factory or type must not be null

Throws:
DatabaseException

GenericPropertyEntryMapper

public GenericPropertyEntryMapper(Database<Connection> db,
                                  String table,
                                  String idColumn,
                                  IDFactory idFactory,
                                  Class<T> type)
                           throws DatabaseException
Throws:
DatabaseException

GenericPropertyEntryMapper

public GenericPropertyEntryMapper(Database<Connection> db,
                                  String table,
                                  String idColumn,
                                  String displayColumn,
                                  PropertyEntryFactory<T> factory,
                                  Class<T> type)
                           throws DatabaseException
uses the factory to generate instances; either factory or type must not be null

Throws:
DatabaseException

GenericPropertyEntryMapper

public GenericPropertyEntryMapper(Database<Connection> db,
                                  String table,
                                  String idColumn,
                                  String displayColumn,
                                  PropertyEntryFactory<T> factory,
                                  Class<T> type,
                                  IDFactory idFactory)
                           throws DatabaseException
uses the factory to generate instances; either factory or type must not be null

Throws:
DatabaseException

GenericPropertyEntryMapper

public GenericPropertyEntryMapper(DBClassStore<?> refStore,
                                  Class<T> type)
                           throws DatabaseException
Throws:
DatabaseException

GenericPropertyEntryMapper

public GenericPropertyEntryMapper(DBClassStore<?> refStore,
                                  PropertyEntryFactory<T> factory,
                                  Class<T> type,
                                  IDFactory idFactory)
                           throws DatabaseException
Throws:
DatabaseException
Method Detail

getDisplayProperty

public String getDisplayProperty()
if the returned String is non-null and T is an EntryHeader, the appropriate value will be set accordingly. This value is ignored if T (the entry class) is not an EntryHeader.

See Also:
setDisplayProperty(String), EntryHeader.setDisplayProperty(String)

setDisplayProperty

public void setDisplayProperty(String displayProperty)
                        throws IllegalStateException
allows to specify the display property for EntryHeader instances.

Throws:
IllegalStateException - if T is not an EntryHeader class.
See Also:
getDisplayProperty()

generateRowProperties

protected Map<String,Object> generateRowProperties(T entry)
                                            throws WrongDataException
simply returns entry.getProperties() and 'translates' it if BaseRowMapper.isTranslate() is set

Specified by:
generateRowProperties in class BaseRowMapper<T extends PropertyEntry>
Throws:
WrongDataException
See Also:
BaseRowMapper.setTranslate(boolean), BaseRowMapper.toSQLMap(Map)

generateNewID

public Object generateNewID()
                     throws DatabaseException,
                            UnsupportedOperationException
simply returns getNextIntID(), unless an IDFactory was provided

Specified by:
generateNewID in interface ObjectRowMapper<T extends PropertyEntry>
Overrides:
generateNewID in class BaseRowMapper<T extends PropertyEntry>
Throws:
DatabaseException
UnsupportedOperationException
See Also:
DBClassStore.generateNewID(), SQLNumberGenerator, TransactionalNumberGenerator

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().

Throws:
Exception

setTableQuery

public void setTableQuery(String tableQuery)
                   throws DatabaseException
Description copied from class: BaseRowMapper
allows to set a query for mapping the data instead of just using the table name. This method calls BaseRowMapper.initMapping() after setting the data. Since a query of the form '(select ...) as t1' may not be query optimized in certain databases, this implementation also supports a plain select statement to act as a query.

Overrides:
setTableQuery in class BaseRowMapper<T extends PropertyEntry>
Throws:
DatabaseException

setTableQuery

public void setTableQuery(String tableQuery,
                          String newIdColumn)
                   throws DatabaseException
Description copied from class: BaseRowMapper
in addition to setting a table query, this also allows to change the id column (often required to ensure the uniqueness of the id column in a query that may contain the column multiple times).

Overrides:
setTableQuery in class BaseRowMapper<T extends PropertyEntry>
Throws:
DatabaseException
See Also:
BaseRowMapper.setTableQuery(String)


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