Spring Data JDBC Extensions

org.springframework.data.jdbc.support.oracle
Class BeanPropertyStructMapper<T>

java.lang.Object
  extended by org.springframework.data.jdbc.support.oracle.BeanPropertyStructMapper<T>
All Implemented Interfaces:
StructMapper<T>

public class BeanPropertyStructMapper<T>
extends Object
implements StructMapper<T>

Mapping implementation that converts struct attributes into a new instance of the specified mapped target class. The mapped target class must be a top-level class and it must have a default or no-arg constructor.

Attribute values are mapped based on matching the column name as obtained from result set metadata to public setters for the corresponding properties. The names are matched either directly or by transforming a name separating the parts with underscores to the same name using "camel" case.

Mapping is provided for fields in the target class for many common types, e.g.: String, boolean, Boolean, byte, Byte, short, Short, int, Integer, long, Long, float, Float, double, Double, BigDecimal, java.util.Date, etc.

Since:
1.0
Author:
Thomas Risberg, Juergen Hoeller

Field Summary
protected  org.apache.commons.logging.Log logger
          Logger available to subclasses
protected  Class<T> mappedClass
          The class we are mapping to
 
Constructor Summary
BeanPropertyStructMapper()
          Create a new BeanPropertyRowMapper.
BeanPropertyStructMapper(Class<T> mappedClass)
          Create a new BeanPropertyRowMapper.
 
Method Summary
 T fromStruct(oracle.sql.STRUCT struct)
          Extract the values for all attributes in the struct.
 Class<T> getMappedClass()
          Get the class that we are mapping to.
 Map<String,PropertyDescriptor> getMappedFields()
          Get the fields that we are mapping to.
protected  void initBeanWrapper(BeanWrapper bw)
          Initialize the given BeanWrapper to be used for row mapping.
protected  void initialize(Class<T> mappedClass)
          Initialize the mapping metadata for the given class.
static
<T> BeanPropertyStructMapper<T>
newInstance(Class<T> mappedClass)
          Static factory method to create a new BeanPropertyStructMapper (with the mapped class specified only once).
 void setMappedClass(Class<T> mappedClass)
          Set the class that each row should be mapped to.
 oracle.sql.STRUCT toStruct(T source, Connection conn, String typeName)
          Create a struct of the defined type and populate it with values from the passed in source object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
Logger available to subclasses


mappedClass

protected Class<T> mappedClass
The class we are mapping to

Constructor Detail

BeanPropertyStructMapper

public BeanPropertyStructMapper()
Create a new BeanPropertyRowMapper.

See Also:
setMappedClass(java.lang.Class)

BeanPropertyStructMapper

public BeanPropertyStructMapper(Class<T> mappedClass)
Create a new BeanPropertyRowMapper.

Parameters:
mappedClass - the class that each row should be mapped to.
Method Detail

setMappedClass

public void setMappedClass(Class<T> mappedClass)
Set the class that each row should be mapped to.


initialize

protected void initialize(Class<T> mappedClass)
Initialize the mapping metadata for the given class.

Parameters:
mappedClass - the mapped class.

getMappedClass

public final Class<T> getMappedClass()
Get the class that we are mapping to.


getMappedFields

public final Map<String,PropertyDescriptor> getMappedFields()
Get the fields that we are mapping to.


toStruct

public oracle.sql.STRUCT toStruct(T source,
                                  Connection conn,
                                  String typeName)
                           throws SQLException
Description copied from interface: StructMapper
Create a struct of the defined type and populate it with values from the passed in source object.

Specified by:
toStruct in interface StructMapper<T>
Parameters:
source - instance containing the values to map
conn - database connection to be used to create the STRUCT
typeName - name of the STRUCT type
Returns:
the new STRUCT
Throws:
SQLException

fromStruct

public T fromStruct(oracle.sql.STRUCT struct)
             throws SQLException
Extract the values for all attributes in the struct.

Utilizes public setters and result set metadata.

Specified by:
fromStruct in interface StructMapper<T>
Parameters:
struct - the STRUCT containing attribute values to be used
Returns:
new instance of the target class populated with attribute values
Throws:
SQLException
See Also:
ResultSetMetaData

initBeanWrapper

protected void initBeanWrapper(BeanWrapper bw)
Initialize the given BeanWrapper to be used for row mapping. To be called for each row.

The default implementation is empty. Can be overridden in subclasses.

Parameters:
bw - the BeanWrapper to initialize

newInstance

public static <T> BeanPropertyStructMapper<T> newInstance(Class<T> mappedClass)
Static factory method to create a new BeanPropertyStructMapper (with the mapped class specified only once).

Parameters:
mappedClass - the class that each row should be mapped to

Spring Data JDBC Extensions