Class AbstractColumnMapping
- java.lang.Object
-
- org.datanucleus.store.rdbms.mapping.column.AbstractColumnMapping
-
- All Implemented Interfaces:
ColumnMapping
- Direct Known Subclasses:
AbstractLargeBinaryColumnMapping
,ArrayColumnMapping
,BigIntColumnMapping
,BinaryStreamColumnMapping
,BooleanColumnMapping
,CharColumnMapping
,DateColumnMapping
,DecimalColumnMapping
,DoubleColumnMapping
,IntegerColumnMapping
,LongVarcharColumnMapping
,NumericColumnMapping
,OracleBlobColumnMapping
,OtherColumnMapping
,RealColumnMapping
,SmallIntColumnMapping
,TimeColumnMapping
,TimestampColumnMapping
,TinyIntColumnMapping
public abstract class AbstractColumnMapping extends Object implements ColumnMapping
Implementation of the mapping of a column.
-
-
Field Summary
Fields Modifier and Type Field Description protected Column
column
The Column being persisted to.protected JavaTypeMapping
mapping
Mapping of the Java type.protected RDBMSStoreManager
storeMgr
Store Manager to use for mapping.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractColumnMapping(RDBMSStoreManager storeMgr, JavaTypeMapping mapping)
Create a new Mapping with the given DatabaseAdapter for the given type.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
protected String
failureMessage(String method)
Utility to output any error message.protected String
failureMessage(String method, int position, Exception e)
Utility to output any error message.protected String
failureMessage(String method, Object value, Exception e)
Utility to output any error message.boolean
getBoolean(ResultSet resultSet, int exprIndex)
Obtains a value fromresultSet
at position specified byexprIndex
.byte
getByte(ResultSet resultSet, int exprIndex)
Obtains a value fromresultSet
at position specified byexprIndex
.char
getChar(ResultSet resultSet, int exprIndex)
Obtains a value fromresultSet
at position specified byexprIndex
.Column
getColumn()
Accessor for the columnprotected DatastoreAdapter
getDatastoreAdapter()
Convenience to access the datastore adapter.double
getDouble(ResultSet resultSet, int exprIndex)
Obtains a value fromresultSet
at position specified byexprIndex
.float
getFloat(ResultSet resultSet, int exprIndex)
Obtains a value fromresultSet
at position specified byexprIndex
.String
getInsertionInputParameter()
Accessor for the string to put in any retrieval datastore statement for this field.int
getInt(ResultSet resultSet, int exprIndex)
Obtains a value fromresultSet
at position specified byexprIndex
.JavaTypeMapping
getJavaTypeMapping()
Accessor for the java type mappingabstract int
getJDBCType()
Method to return the java.sql.Types type that this relates to.long
getLong(ResultSet resultSet, int exprIndex)
Obtains a value fromresultSet
at position specified byexprIndex
.Object
getObject(ResultSet resultSet, int exprIndex)
Obtains a value fromresultSet
at position specified byexprIndex
.short
getShort(ResultSet resultSet, int exprIndex)
Obtains a value fromresultSet
at position specified byexprIndex
.String
getString(ResultSet resultSet, int exprIndex)
Obtains a value fromresultSet
at position specified byexprIndex
.SQLTypeInfo
getTypeInfo()
Accessor for the (SQL) type info for this datastore type.String
getUpdateInputParameter()
Accessor for the string to put in any update datastore statements for this field.int
hashCode()
boolean
includeInFetchStatement()
Whether this mapping is included in the fetch statement.protected void
initTypeInfo()
Sets the TypeInfo for the columns of the Mapping.boolean
insertValuesOnInsert()
Accessor for whether this mapping requires values inserting on an INSERT.boolean
isBitBased()
Accessor for whether the mapping is bit-based.boolean
isBooleanBased()
Accessor for whether the mapping is boolean-based.boolean
isDecimalBased()
Accessor for whether the mapping is decimal-based.boolean
isIntegerBased()
Accessor for whether the mapping is integer-based.boolean
isNullable()
Accessor for whether the mapping is nullable.boolean
isStringBased()
Accessor for whether the mapping is string-based.void
setBoolean(PreparedStatement ps, int exprIndex, boolean value)
Sets avalue
intops
at position specified byparamIndex
.void
setByte(PreparedStatement ps, int exprIndex, byte value)
Sets avalue
intops
at position specified byparamIndex
.void
setChar(PreparedStatement ps, int exprIndex, char value)
Sets avalue
intops
at position specified byparamIndex
.void
setDouble(PreparedStatement ps, int exprIndex, double value)
Sets avalue
intops
at position specified byparamIndex
.void
setFloat(PreparedStatement ps, int exprIndex, float value)
Sets avalue
intops
at position specified byparamIndex
.void
setInt(PreparedStatement ps, int exprIndex, int value)
Sets avalue
intops
at position specified byparamIndex
.void
setLong(PreparedStatement ps, int exprIndex, long value)
Sets avalue
intops
at position specified byparamIndex
.void
setObject(PreparedStatement ps, int exprIndex, Object value)
Sets avalue
intops
at position specified byparamIndex
.void
setShort(PreparedStatement ps, int exprIndex, short value)
Sets avalue
intops
at position specified byparamIndex
.void
setString(PreparedStatement ps, int exprIndex, String value)
Sets avalue
intops
at position specified byparamIndex
.protected boolean
useDefaultWhenNull()
-
-
-
Field Detail
-
mapping
protected final JavaTypeMapping mapping
Mapping of the Java type.
-
storeMgr
protected final RDBMSStoreManager storeMgr
Store Manager to use for mapping.
-
column
protected Column column
The Column being persisted to.
-
-
Constructor Detail
-
AbstractColumnMapping
protected AbstractColumnMapping(RDBMSStoreManager storeMgr, JavaTypeMapping mapping)
Create a new Mapping with the given DatabaseAdapter for the given type.- Parameters:
storeMgr
- The Store Manager that this Mapping should use.mapping
- Mapping for the underlying java type. This can be null on an "unmapped column".
-
-
Method Detail
-
getJavaTypeMapping
public JavaTypeMapping getJavaTypeMapping()
Accessor for the java type mapping- Specified by:
getJavaTypeMapping
in interfaceColumnMapping
- Returns:
- The java type mapping used
-
getDatastoreAdapter
protected DatastoreAdapter getDatastoreAdapter()
Convenience to access the datastore adapter.- Returns:
- The adapter in use
-
initTypeInfo
protected void initTypeInfo()
Sets the TypeInfo for the columns of the Mapping. Mappings using two or more columns using different TypeInfo(s) should overwrite this method to appropriate set the TypeInfo (SQL type) for all the columns
-
getJDBCType
public abstract int getJDBCType()
Method to return the java.sql.Types type that this relates to.- Returns:
- The JDBC "type"
-
getTypeInfo
public SQLTypeInfo getTypeInfo()
Accessor for the (SQL) type info for this datastore type. Finds the SQLTypeInfo using the JDBC Type for this mapping. Override if you want a different method.- Returns:
- The type info
-
isNullable
public boolean isNullable()
Accessor for whether the mapping is nullable.- Specified by:
isNullable
in interfaceColumnMapping
- Returns:
- Whether it is nullable
-
includeInFetchStatement
public boolean includeInFetchStatement()
Whether this mapping is included in the fetch statement.- Returns:
- Whether to include in fetch statement
-
insertValuesOnInsert
public boolean insertValuesOnInsert()
Accessor for whether this mapping requires values inserting on an INSERT.- Specified by:
insertValuesOnInsert
in interfaceColumnMapping
- Returns:
- Whether values are to be inserted into this mapping on an INSERT
-
getInsertionInputParameter
public String getInsertionInputParameter()
Accessor for the string to put in any retrieval datastore statement for this field. In RDBMS, this is typically a ? to be used in JDBC statements.- Specified by:
getInsertionInputParameter
in interfaceColumnMapping
- Returns:
- The input parameter
-
getUpdateInputParameter
public String getUpdateInputParameter()
Accessor for the string to put in any update datastore statements for this field. In RDBMS, this is typically a ? to be used in JDBC statements.- Specified by:
getUpdateInputParameter
in interfaceColumnMapping
- Returns:
- The input parameter.
-
getColumn
public Column getColumn()
Accessor for the column- Specified by:
getColumn
in interfaceColumnMapping
- Returns:
- The column
-
useDefaultWhenNull
protected boolean useDefaultWhenNull()
-
failureMessage
protected String failureMessage(String method, int position, Exception e)
Utility to output any error message.- Parameters:
method
- The method that failed.position
- The position of the columne
- The exception- Returns:
- The localised failure message
-
failureMessage
protected String failureMessage(String method, Object value, Exception e)
Utility to output any error message.- Parameters:
method
- The method that failed.value
- Value at the positione
- The exception- Returns:
- The localised failure message
-
setBoolean
public void setBoolean(PreparedStatement ps, int exprIndex, boolean value)
Description copied from interface:ColumnMapping
Sets avalue
intops
at position specified byparamIndex
.- Specified by:
setBoolean
in interfaceColumnMapping
- Parameters:
ps
- PreparedStatementexprIndex
- the position of the value in the statementvalue
- the value
-
getBoolean
public boolean getBoolean(ResultSet resultSet, int exprIndex)
Description copied from interface:ColumnMapping
Obtains a value fromresultSet
at position specified byexprIndex
.- Specified by:
getBoolean
in interfaceColumnMapping
- Parameters:
resultSet
- ResultSetexprIndex
- the position of the value in the result- Returns:
- the value
-
setChar
public void setChar(PreparedStatement ps, int exprIndex, char value)
Description copied from interface:ColumnMapping
Sets avalue
intops
at position specified byparamIndex
.- Specified by:
setChar
in interfaceColumnMapping
- Parameters:
ps
- PreparedStatementexprIndex
- the position of the value in the statementvalue
- the value
-
getChar
public char getChar(ResultSet resultSet, int exprIndex)
Description copied from interface:ColumnMapping
Obtains a value fromresultSet
at position specified byexprIndex
.- Specified by:
getChar
in interfaceColumnMapping
- Parameters:
resultSet
- ResultSetexprIndex
- the position of the value in the result- Returns:
- the value
-
setByte
public void setByte(PreparedStatement ps, int exprIndex, byte value)
Description copied from interface:ColumnMapping
Sets avalue
intops
at position specified byparamIndex
.- Specified by:
setByte
in interfaceColumnMapping
- Parameters:
ps
- PreparedStatementexprIndex
- the position of the value in the statementvalue
- the value
-
getByte
public byte getByte(ResultSet resultSet, int exprIndex)
Description copied from interface:ColumnMapping
Obtains a value fromresultSet
at position specified byexprIndex
.- Specified by:
getByte
in interfaceColumnMapping
- Parameters:
resultSet
- ResultSetexprIndex
- the position of the value in the result- Returns:
- the value
-
setShort
public void setShort(PreparedStatement ps, int exprIndex, short value)
Description copied from interface:ColumnMapping
Sets avalue
intops
at position specified byparamIndex
.- Specified by:
setShort
in interfaceColumnMapping
- Parameters:
ps
- PreparedStatementexprIndex
- the position of the value in the statementvalue
- the value
-
getShort
public short getShort(ResultSet resultSet, int exprIndex)
Description copied from interface:ColumnMapping
Obtains a value fromresultSet
at position specified byexprIndex
.- Specified by:
getShort
in interfaceColumnMapping
- Parameters:
resultSet
- ResultSetexprIndex
- the position of the value in the result- Returns:
- the value
-
setInt
public void setInt(PreparedStatement ps, int exprIndex, int value)
Description copied from interface:ColumnMapping
Sets avalue
intops
at position specified byparamIndex
.- Specified by:
setInt
in interfaceColumnMapping
- Parameters:
ps
- PreparedStatementexprIndex
- the position of the value in the statementvalue
- the value
-
getInt
public int getInt(ResultSet resultSet, int exprIndex)
Description copied from interface:ColumnMapping
Obtains a value fromresultSet
at position specified byexprIndex
.- Specified by:
getInt
in interfaceColumnMapping
- Parameters:
resultSet
- ResultSetexprIndex
- the position of the value in the result- Returns:
- the value
-
setLong
public void setLong(PreparedStatement ps, int exprIndex, long value)
Description copied from interface:ColumnMapping
Sets avalue
intops
at position specified byparamIndex
.- Specified by:
setLong
in interfaceColumnMapping
- Parameters:
ps
- PreparedStatementexprIndex
- the position of the value in the statementvalue
- the value
-
getLong
public long getLong(ResultSet resultSet, int exprIndex)
Description copied from interface:ColumnMapping
Obtains a value fromresultSet
at position specified byexprIndex
.- Specified by:
getLong
in interfaceColumnMapping
- Parameters:
resultSet
- ResultSetexprIndex
- the position of the value in the result- Returns:
- the value
-
setFloat
public void setFloat(PreparedStatement ps, int exprIndex, float value)
Description copied from interface:ColumnMapping
Sets avalue
intops
at position specified byparamIndex
.- Specified by:
setFloat
in interfaceColumnMapping
- Parameters:
ps
- PreparedStatementexprIndex
- the position of the value in the statementvalue
- the value
-
getFloat
public float getFloat(ResultSet resultSet, int exprIndex)
Description copied from interface:ColumnMapping
Obtains a value fromresultSet
at position specified byexprIndex
.- Specified by:
getFloat
in interfaceColumnMapping
- Parameters:
resultSet
- ResultSetexprIndex
- the position of the value in the result- Returns:
- the value
-
setDouble
public void setDouble(PreparedStatement ps, int exprIndex, double value)
Description copied from interface:ColumnMapping
Sets avalue
intops
at position specified byparamIndex
.- Specified by:
setDouble
in interfaceColumnMapping
- Parameters:
ps
- PreparedStatementexprIndex
- the position of the value in the statementvalue
- the value
-
getDouble
public double getDouble(ResultSet resultSet, int exprIndex)
Description copied from interface:ColumnMapping
Obtains a value fromresultSet
at position specified byexprIndex
.- Specified by:
getDouble
in interfaceColumnMapping
- Parameters:
resultSet
- ResultSetexprIndex
- the position of the value in the result- Returns:
- the value
-
setString
public void setString(PreparedStatement ps, int exprIndex, String value)
Description copied from interface:ColumnMapping
Sets avalue
intops
at position specified byparamIndex
.- Specified by:
setString
in interfaceColumnMapping
- Parameters:
ps
- PreparedStatementexprIndex
- the position of the value in the statementvalue
- the value
-
getString
public String getString(ResultSet resultSet, int exprIndex)
Description copied from interface:ColumnMapping
Obtains a value fromresultSet
at position specified byexprIndex
.- Specified by:
getString
in interfaceColumnMapping
- Parameters:
resultSet
- ResultSetexprIndex
- the position of the value in the result- Returns:
- the value
-
setObject
public void setObject(PreparedStatement ps, int exprIndex, Object value)
Description copied from interface:ColumnMapping
Sets avalue
intops
at position specified byparamIndex
.- Specified by:
setObject
in interfaceColumnMapping
- Parameters:
ps
- PreparedStatementexprIndex
- the position of the value in the statementvalue
- the value
-
getObject
public Object getObject(ResultSet resultSet, int exprIndex)
Description copied from interface:ColumnMapping
Obtains a value fromresultSet
at position specified byexprIndex
.- Specified by:
getObject
in interfaceColumnMapping
- Parameters:
resultSet
- ResultSetexprIndex
- the position of the value in the result- Returns:
- the value
-
isDecimalBased
public boolean isDecimalBased()
Accessor for whether the mapping is decimal-based.- Specified by:
isDecimalBased
in interfaceColumnMapping
- Returns:
- Whether the mapping is decimal based
-
isIntegerBased
public boolean isIntegerBased()
Accessor for whether the mapping is integer-based.- Specified by:
isIntegerBased
in interfaceColumnMapping
- Returns:
- Whether the mapping is integer based
-
isStringBased
public boolean isStringBased()
Accessor for whether the mapping is string-based.- Specified by:
isStringBased
in interfaceColumnMapping
- Returns:
- Whether the mapping is string based
-
isBitBased
public boolean isBitBased()
Accessor for whether the mapping is bit-based.- Specified by:
isBitBased
in interfaceColumnMapping
- Returns:
- Whether the mapping is bit based
-
isBooleanBased
public boolean isBooleanBased()
Accessor for whether the mapping is boolean-based.- Specified by:
isBooleanBased
in interfaceColumnMapping
- Returns:
- Whether the mapping is boolean based
-
-