Package com.im.commons.db.columnhandling
Interface DBValueHandler<T>
-
- Type Parameters:
T
- type of handled value
public interface DBValueHandler<T>
Interface that handles reading/writing values from/to a database. Values are potentially complex objects whose values are persisted in multiple database columns of different types.- Author:
- Tim Dudgeon
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description T
assembleValue(java.lang.Object[] v)
Assemble the value from the values stored in the DB columns.void
bindVariable(java.sql.PreparedStatement stmt, T value, int[] indexes)
Bind the variable to thePreparedStatement
.org.springframework.jdbc.core.RowMapper<T>
createRowMapper()
Creates aRowMapper
instance capable of reading and assembling the value from aResultSet
.java.lang.Object[]
dissasembleValue(T v)
Split the value up into its components suitable for storing in each column.java.lang.Class<T>
getAssembledValueClass()
int[]
getColumnJdbcTypes()
The JDBC type(s) as defined inTypes
.java.lang.String[]
getColumnNames()
The names of the column(s) used to store these values.DBDatabaseInfo.ColumnSQLType[]
getColumnTypes()
The SQL type of the column(s).java.lang.Class[]
getDisassembledValuesClasses()
-
-
-
Method Detail
-
getColumnNames
java.lang.String[] getColumnNames()
The names of the column(s) used to store these values. Note that the array can be empty.- Returns:
- The column names
-
getColumnJdbcTypes
int[] getColumnJdbcTypes()
The JDBC type(s) as defined inTypes
. Note that the array can be empty.- Returns:
- the column types
-
getColumnTypes
DBDatabaseInfo.ColumnSQLType[] getColumnTypes()
The SQL type of the column(s). Note that the array can be empty.- Returns:
- The SQL type of the column(s)
-
createRowMapper
org.springframework.jdbc.core.RowMapper<T> createRowMapper()
Creates aRowMapper
instance capable of reading and assembling the value from aResultSet
. TheRowMapper
will useColumnHandler
for each of the columns grouped under this handler to read this column's value. It will then callassembleValue(Object[])
to combine those column values into the final result.- Returns:
- A row mapper for reading the assembled value from a
ResultSet
.
-
bindVariable
void bindVariable(java.sql.PreparedStatement stmt, T value, int[] indexes) throws java.sql.SQLException
Bind the variable to thePreparedStatement
. Only for simple column types that do not need special treatment, such as LobHandler TODO - this method may be replaced with something more generic in the future- Parameters:
stmt
- The PreparedStatementvalue
- The value to bind. Will be disassembled into the corresponding values for each column.indexes
- The positional indexes of parameter holders for each column, starting from 1- Throws:
java.sql.SQLException
- If the operation fails.
-
assembleValue
T assembleValue(java.lang.Object[] v)
Assemble the value from the values stored in the DB columns. For single column values this will be the value itself, but for multi-column values the value for each column must be assembled into the appropriate object.- Parameters:
v
- The column values to assemble- Returns:
- The assembled values
-
dissasembleValue
java.lang.Object[] dissasembleValue(T v)
Split the value up into its components suitable for storing in each column. For single column values this will be the value itself, but for multi-column values the value must be split up into its composite parts for each column.- Parameters:
v
- The value to disassemble- Returns:
- The disassembled parts
-
getAssembledValueClass
java.lang.Class<T> getAssembledValueClass()
- Returns:
- The class of the assembled values
-
getDisassembledValuesClasses
java.lang.Class[] getDisassembledValuesClasses()
- Returns:
- The classes of the disassembled values suitable for storing in each column
-
-