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 ColumncolumnThe Column being persisted to.protected JavaTypeMappingmappingMapping of the Java type.protected RDBMSStoreManagerstoreMgrStore Manager to use for mapping.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractColumnMapping(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 booleanequals(Object obj)protected StringfailureMessage(String method)Utility to output any error message.protected StringfailureMessage(String method, int position, Exception e)Utility to output any error message.protected StringfailureMessage(String method, Object value, Exception e)Utility to output any error message.booleangetBoolean(ResultSet resultSet, int exprIndex)Obtains a value fromresultSetat position specified byexprIndex.bytegetByte(ResultSet resultSet, int exprIndex)Obtains a value fromresultSetat position specified byexprIndex.chargetChar(ResultSet resultSet, int exprIndex)Obtains a value fromresultSetat position specified byexprIndex.ColumngetColumn()Accessor for the columnprotected DatastoreAdaptergetDatastoreAdapter()Convenience to access the datastore adapter.doublegetDouble(ResultSet resultSet, int exprIndex)Obtains a value fromresultSetat position specified byexprIndex.floatgetFloat(ResultSet resultSet, int exprIndex)Obtains a value fromresultSetat position specified byexprIndex.StringgetInsertionInputParameter()Accessor for the string to put in any retrieval datastore statement for this field.intgetInt(ResultSet resultSet, int exprIndex)Obtains a value fromresultSetat position specified byexprIndex.JavaTypeMappinggetJavaTypeMapping()Accessor for the java type mappingabstract intgetJDBCType()Method to return the java.sql.Types type that this relates to.longgetLong(ResultSet resultSet, int exprIndex)Obtains a value fromresultSetat position specified byexprIndex.ObjectgetObject(ResultSet resultSet, int exprIndex)Obtains a value fromresultSetat position specified byexprIndex.shortgetShort(ResultSet resultSet, int exprIndex)Obtains a value fromresultSetat position specified byexprIndex.StringgetString(ResultSet resultSet, int exprIndex)Obtains a value fromresultSetat position specified byexprIndex.SQLTypeInfogetTypeInfo()Accessor for the (SQL) type info for this datastore type.StringgetUpdateInputParameter()Accessor for the string to put in any update datastore statements for this field.inthashCode()booleanincludeInFetchStatement()Whether this mapping is included in the fetch statement.protected voidinitTypeInfo()Sets the TypeInfo for the columns of the Mapping.booleaninsertValuesOnInsert()Accessor for whether this mapping requires values inserting on an INSERT.booleanisBitBased()Accessor for whether the mapping is bit-based.booleanisBooleanBased()Accessor for whether the mapping is boolean-based.booleanisDecimalBased()Accessor for whether the mapping is decimal-based.booleanisIntegerBased()Accessor for whether the mapping is integer-based.booleanisNullable()Accessor for whether the mapping is nullable.booleanisStringBased()Accessor for whether the mapping is string-based.voidsetBoolean(PreparedStatement ps, int exprIndex, boolean value)Sets avalueintopsat position specified byparamIndex.voidsetByte(PreparedStatement ps, int exprIndex, byte value)Sets avalueintopsat position specified byparamIndex.voidsetChar(PreparedStatement ps, int exprIndex, char value)Sets avalueintopsat position specified byparamIndex.voidsetDouble(PreparedStatement ps, int exprIndex, double value)Sets avalueintopsat position specified byparamIndex.voidsetFloat(PreparedStatement ps, int exprIndex, float value)Sets avalueintopsat position specified byparamIndex.voidsetInt(PreparedStatement ps, int exprIndex, int value)Sets avalueintopsat position specified byparamIndex.voidsetLong(PreparedStatement ps, int exprIndex, long value)Sets avalueintopsat position specified byparamIndex.voidsetObject(PreparedStatement ps, int exprIndex, Object value)Sets avalueintopsat position specified byparamIndex.voidsetShort(PreparedStatement ps, int exprIndex, short value)Sets avalueintopsat position specified byparamIndex.voidsetString(PreparedStatement ps, int exprIndex, String value)Sets avalueintopsat position specified byparamIndex.protected booleanuseDefaultWhenNull()
-
-
-
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:
getJavaTypeMappingin 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:
isNullablein 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:
insertValuesOnInsertin 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:
getInsertionInputParameterin 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:
getUpdateInputParameterin interfaceColumnMapping- Returns:
- The input parameter.
-
getColumn
public Column getColumn()
Accessor for the column- Specified by:
getColumnin 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:ColumnMappingSets avalueintopsat position specified byparamIndex.- Specified by:
setBooleanin 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:ColumnMappingObtains a value fromresultSetat position specified byexprIndex.- Specified by:
getBooleanin 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:ColumnMappingSets avalueintopsat position specified byparamIndex.- Specified by:
setCharin 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:ColumnMappingObtains a value fromresultSetat position specified byexprIndex.- Specified by:
getCharin 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:ColumnMappingSets avalueintopsat position specified byparamIndex.- Specified by:
setBytein 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:ColumnMappingObtains a value fromresultSetat position specified byexprIndex.- Specified by:
getBytein 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:ColumnMappingSets avalueintopsat position specified byparamIndex.- Specified by:
setShortin 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:ColumnMappingObtains a value fromresultSetat position specified byexprIndex.- Specified by:
getShortin 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:ColumnMappingSets avalueintopsat position specified byparamIndex.- Specified by:
setIntin 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:ColumnMappingObtains a value fromresultSetat position specified byexprIndex.- Specified by:
getIntin 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:ColumnMappingSets avalueintopsat position specified byparamIndex.- Specified by:
setLongin 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:ColumnMappingObtains a value fromresultSetat position specified byexprIndex.- Specified by:
getLongin 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:ColumnMappingSets avalueintopsat position specified byparamIndex.- Specified by:
setFloatin 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:ColumnMappingObtains a value fromresultSetat position specified byexprIndex.- Specified by:
getFloatin 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:ColumnMappingSets avalueintopsat position specified byparamIndex.- Specified by:
setDoublein 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:ColumnMappingObtains a value fromresultSetat position specified byexprIndex.- Specified by:
getDoublein 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:ColumnMappingSets avalueintopsat position specified byparamIndex.- Specified by:
setStringin 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:ColumnMappingObtains a value fromresultSetat position specified byexprIndex.- Specified by:
getStringin 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:ColumnMappingSets avalueintopsat position specified byparamIndex.- Specified by:
setObjectin 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:ColumnMappingObtains a value fromresultSetat position specified byexprIndex.- Specified by:
getObjectin 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:
isDecimalBasedin interfaceColumnMapping- Returns:
- Whether the mapping is decimal based
-
isIntegerBased
public boolean isIntegerBased()
Accessor for whether the mapping is integer-based.- Specified by:
isIntegerBasedin interfaceColumnMapping- Returns:
- Whether the mapping is integer based
-
isStringBased
public boolean isStringBased()
Accessor for whether the mapping is string-based.- Specified by:
isStringBasedin interfaceColumnMapping- Returns:
- Whether the mapping is string based
-
isBitBased
public boolean isBitBased()
Accessor for whether the mapping is bit-based.- Specified by:
isBitBasedin interfaceColumnMapping- Returns:
- Whether the mapping is bit based
-
isBooleanBased
public boolean isBooleanBased()
Accessor for whether the mapping is boolean-based.- Specified by:
isBooleanBasedin interfaceColumnMapping- Returns:
- Whether the mapping is boolean based
-
-