Package org.apache.ofbiz.entity.jdbc
Class JdbcValueHandler<T>
- java.lang.Object
-
- org.apache.ofbiz.entity.jdbc.JdbcValueHandler<T>
-
- Direct Known Subclasses:
JdbcValueHandler.ArrayJdbcValueHandler
,JdbcValueHandler.BigDecimalJdbcValueHandler
,JdbcValueHandler.BlobJdbcValueHandler
,JdbcValueHandler.BooleanJdbcValueHandler
,JdbcValueHandler.ByteArrayJdbcValueHandler
,JdbcValueHandler.ClobJdbcValueHandler
,JdbcValueHandler.DateJdbcValueHandler
,JdbcValueHandler.DoubleJdbcValueHandler
,JdbcValueHandler.FloatJdbcValueHandler
,JdbcValueHandler.IntegerJdbcValueHandler
,JdbcValueHandler.LongJdbcValueHandler
,JdbcValueHandler.ObjectJdbcValueHandler
,JdbcValueHandler.RowIdJdbcValueHandler
,JdbcValueHandler.ShortJdbcValueHandler
,JdbcValueHandler.StringJdbcValueHandler
,JdbcValueHandler.TimeJdbcValueHandler
,JdbcValueHandler.TimestampJdbcValueHandler
public abstract class JdbcValueHandler<T> extends Object
An object that handles getting/setting column values in JDBCPreparedStatement
andResultSet
objects.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
JdbcValueHandler.ArrayJdbcValueHandler
Ajava.sql.Array
JDBC value handler.protected static class
JdbcValueHandler.BigDecimalJdbcValueHandler
Ajava.math.BigDecimal
JDBC value handler.protected static class
JdbcValueHandler.BlobJdbcValueHandler
Ajava.sql.Blob
JDBC value handler.protected static class
JdbcValueHandler.BooleanJdbcValueHandler
Ajava.lang.Boolean
JDBC value handler.protected static class
JdbcValueHandler.ByteArrayJdbcValueHandler
Abyte[]
JDBC value handler.protected static class
JdbcValueHandler.ClobJdbcValueHandler
Ajava.sql.Clob
JDBC value handler.protected static class
JdbcValueHandler.DateJdbcValueHandler
Ajava.sql.Date
JDBC value handler.protected static class
JdbcValueHandler.DoubleJdbcValueHandler
Ajava.lang.Double
JDBC value handler.protected static class
JdbcValueHandler.FloatJdbcValueHandler
Ajava.lang.Float
JDBC value handler.protected static class
JdbcValueHandler.IntegerJdbcValueHandler
Ajava.lang.Integer
JDBC value handler.protected static class
JdbcValueHandler.LongJdbcValueHandler
Ajava.lang.Long
JDBC value handler.protected static class
JdbcValueHandler.ObjectJdbcValueHandler
Ajava.lang.Object
JDBC value handler.protected static class
JdbcValueHandler.RowIdJdbcValueHandler
Ajava.sql.RowId
JDBC value handler.protected static class
JdbcValueHandler.ShortJdbcValueHandler
Ajava.lang.Short
JDBC value handler.protected static class
JdbcValueHandler.StringJdbcValueHandler
Ajava.lang.String
JDBC value handler.protected static class
JdbcValueHandler.TimeJdbcValueHandler
Ajava.sql.Time
JDBC value handler.protected static class
JdbcValueHandler.TimestampJdbcValueHandler
Ajava.sql.Timestamp
JDBC value handler.
-
Constructor Summary
Constructors Modifier Constructor Description protected
JdbcValueHandler(int sqlType)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
castAndSetValue(PreparedStatement ps, int parameterIndex, T obj)
Sets a value in aPreparedStatement
.protected JdbcValueHandler<T>
create(int sqlType)
static JdbcValueHandler<?>
getInstance(String javaType, String sqlType)
Returns theJdbcValueHandler
that corresponds to a field type.abstract Class<T>
getJavaClass()
int
getSqlType()
Returns the SQL type for this handler.abstract T
getValue(ResultSet rs, int columnIndex)
Returns a value from aResultSet
.protected abstract JdbcValueHandler<T>
newInstance(int sqlType)
Returns a new instance of the object - initialized with the specified SQL type.protected static String
parseSqlType(String sqlType)
protected static byte[]
serializeObject(Object obj)
void
setValue(PreparedStatement ps, int parameterIndex, T obj)
Sets a value in aPreparedStatement
.
-
-
-
Field Detail
-
module
public static final String module
-
-
Method Detail
-
getInstance
public static JdbcValueHandler<?> getInstance(String javaType, String sqlType)
Returns theJdbcValueHandler
that corresponds to a field type.- Parameters:
javaType
- The Java type specified in fieldtype*.xmlsqlType
- The SQL type specified in fieldtype*.xml- Returns:
- A
JdbcValueHandler
instance
-
serializeObject
protected static byte[] serializeObject(Object obj) throws SQLException
- Throws:
SQLException
-
castAndSetValue
protected abstract void castAndSetValue(PreparedStatement ps, int parameterIndex, T obj) throws SQLException
Sets a value in aPreparedStatement
. Theobj
argument is converted to the correct data type. Subclasses override this method to castobj
to the correct data type and call the appropriatePreparedStatement.setXxx
method.- Parameters:
ps
-parameterIndex
-obj
-- Throws:
SQLException
-
create
protected JdbcValueHandler<T> create(int sqlType)
-
getSqlType
public int getSqlType()
Returns the SQL type for this handler.- Returns:
- return the SQL type
- See Also:
java.sql.Types
-
getValue
public abstract T getValue(ResultSet rs, int columnIndex) throws SQLException
Returns a value from aResultSet
. The returned object is converted to the Java data type specified in the fieldtype file.- Parameters:
rs
- the ResultSet objectcolumnIndex
- the column index- Returns:
- get value from result set
- Throws:
SQLException
-
newInstance
protected abstract JdbcValueHandler<T> newInstance(int sqlType)
Returns a new instance of the object - initialized with the specified SQL type.- Parameters:
sqlType
- the sql type- Returns:
- returns a new instance
-
setValue
public void setValue(PreparedStatement ps, int parameterIndex, T obj) throws SQLException
Sets a value in aPreparedStatement
. Theobj
argument is converted to the correct data type.- Parameters:
ps
-parameterIndex
-obj
-- Throws:
SQLException
-
-