com.triactive.jdo.store.mapping
Class ColumnMapping

java.lang.Object
  extended bycom.triactive.jdo.store.mapping.Mapping
      extended bycom.triactive.jdo.store.mapping.ColumnMapping
Direct Known Subclasses:
BigDecimalMapping, BigIntegerMapping, BooleanMapping, ByteArrayMapping, ByteMapping, CharacterMapping, DoubleMapping, FloatMapping, IntegerMapping, LongMapping, OIDMapping, ShortMapping, SqlDateMapping, SqlTimestampMapping, StringMapping

public abstract class ColumnMapping
extends Mapping

A database mapping that maps a Java type to a single column.

A ColumnMapping can set Java objects directly into JDBC PreparedStatement parameters, and get Java objects directly from JDBC ResultSet columns.

Author:
Mike Martin
See Also:
DatabaseAdapter.newColumnMapping(Class)

Field Summary
protected  Column col
          The column we are mapped to, or null for a prototypical mapping.
protected  TypeInfo typeInfo
          The JDBC type info.
 
Fields inherited from class com.triactive.jdo.store.mapping.Mapping
dba, fmd, type
 
Constructor Summary
ColumnMapping(DatabaseAdapter dba, java.lang.Class type)
          Constructs a new column mapping for a given Java type.
ColumnMapping(DatabaseAdapter dba, FieldMetaData fmd)
          Constructs a new column mapping for a given persistent field.
 
Method Summary
 SqlExpression accessAsFieldIn(FcoExpression objExpr)
          Returns an SQL expression representing the persistent field mapped by this mapping within a particular first-class object expression.
 TypeInfo chooseColumnType(Column col)
          Chooses an appropriate SQL type for a column based on the column's options.
 void defineConstraints(BaseTable table, StoreManager.MgmtTransaction mtx)
          Causes the mapping object to define whatever constraints it needs on its backing storage, relative to the specified table. Depending on the type of mapping, this may mean adding any or all of candidate keys, foreign keys, or indexes to the specified table and/or other tables.

This method only applies to base tables. It will always be called after calling Mapping.defineStorage(com.triactive.jdo.store.sql.Table, com.triactive.jdo.store.StoreManager.MgmtTransaction) and is passed the same table argument.

The StoreManager will never call this method more than once..

 void defineStorage(Table table, StoreManager.MgmtTransaction mtx)
          Causes the mapping object to define whatever backing storage it needs, relative to the specified table. Depending on the type of mapping, this may mean adding columns to the table, constructing other related table objects, or both.

Storage in this case means only tables, columns, and primary keys. Other candidate keys, foreign keys, and indexes are added by Mapping.defineConstraints(com.triactive.jdo.store.sql.BaseTable, com.triactive.jdo.store.StoreManager.MgmtTransaction).

The StoreManager will never call this method more than once..

 boolean equals(java.lang.Object obj)
          Tests this object for equality with another object.
 boolean getBoolean(PersistenceManager pm, java.sql.ResultSet rs, int column)
           
 byte getByte(PersistenceManager pm, java.sql.ResultSet rs, int column)
           
 char getChar(PersistenceManager pm, java.sql.ResultSet rs, int column)
           
 Column getColumn()
          Returns the column this object is mapped to, if any.
 double getDouble(PersistenceManager pm, java.sql.ResultSet rs, int column)
           
 float getFloat(PersistenceManager pm, java.sql.ResultSet rs, int column)
           
 int getInt(PersistenceManager pm, java.sql.ResultSet rs, int column)
           
 long getLong(PersistenceManager pm, java.sql.ResultSet rs, int column)
           
 java.lang.Object getObject(PersistenceManager pm, java.sql.ResultSet rs, int column)
           
 short getShort(PersistenceManager pm, java.sql.ResultSet rs, int column)
           
 java.lang.String getSqlInsertionValue()
          Returns the SQL text to be included in INSERT statements when inserting a value into this mapping's column.
 java.lang.String getSqlUpdateValue()
          Returns the SQL text to be included in UPDATE statements when updating a value in this mapping's column.
 java.lang.String getString(PersistenceManager pm, java.sql.ResultSet rs, int column)
           
 TypeInfo getTypeInfo()
          Returns the actual SQL type used by this mapping.
 int hashCode()
          Returns a hash code value for this object.
 void mapTo(Column col)
          Links this mapping to a specific column.
abstract  SqlExpression newSqlExpression(QueryStatement.QueryColumn qsc)
          Returns an SQL expression representing a reference to a column in a query statement.
 void setBoolean(PersistenceManager pm, java.sql.PreparedStatement ps, int param, boolean value)
           
 void setByte(PersistenceManager pm, java.sql.PreparedStatement ps, int param, byte value)
           
 void setChar(PersistenceManager pm, java.sql.PreparedStatement ps, int param, char value)
           
 void setDouble(PersistenceManager pm, java.sql.PreparedStatement ps, int param, double value)
           
 void setFloat(PersistenceManager pm, java.sql.PreparedStatement ps, int param, float value)
           
 void setInt(PersistenceManager pm, java.sql.PreparedStatement ps, int param, int value)
           
 void setLong(PersistenceManager pm, java.sql.PreparedStatement ps, int param, long value)
           
 void setObject(PersistenceManager pm, java.sql.PreparedStatement ps, int param, java.lang.Object value)
           
 void setShort(PersistenceManager pm, java.sql.PreparedStatement ps, int param, short value)
           
 void setString(PersistenceManager pm, java.sql.PreparedStatement ps, int param, java.lang.String value)
           
 
Methods inherited from class com.triactive.jdo.store.mapping.Mapping
getDefaultMappingsByType, getFieldMetaData, getType, newSqlLiteral
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

typeInfo

protected TypeInfo typeInfo
The JDBC type info.


col

protected Column col
The column we are mapped to, or null for a prototypical mapping.

Constructor Detail

ColumnMapping

public ColumnMapping(DatabaseAdapter dba,
                     java.lang.Class type)
Constructs a new column mapping for a given Java type.

Parameters:
dba - the database adapter
type - the Java class that this mapping maps to the database

ColumnMapping

public ColumnMapping(DatabaseAdapter dba,
                     FieldMetaData fmd)
Constructs a new column mapping for a given persistent field.

Parameters:
dba - the database adapter
fmd - the field metadata for the field that this mapping maps to the database
Method Detail

defineStorage

public void defineStorage(Table table,
                          StoreManager.MgmtTransaction mtx)
Causes the mapping object to define whatever backing storage it needs, relative to the specified table. Depending on the type of mapping, this may mean adding columns to the table, constructing other related table objects, or both.

Storage in this case means only tables, columns, and primary keys. Other candidate keys, foreign keys, and indexes are added by Mapping.defineConstraints(com.triactive.jdo.store.sql.BaseTable, com.triactive.jdo.store.StoreManager.MgmtTransaction).

The StoreManager will never call this method more than once..

For this class, the mapping must be for a persistent field or an exception is thrown. A single column is defined in table whose type and options are set according to the field metadata. Once defined, mapTo(com.triactive.jdo.store.sql.Column) is called to link this mapping to the new column.

Specified by:
defineStorage in class Mapping
Parameters:
table - the table relative to which storage should be defined.
mtx - the context in which the mapping is being initialized

defineConstraints

public void defineConstraints(BaseTable table,
                              StoreManager.MgmtTransaction mtx)
Causes the mapping object to define whatever constraints it needs on its backing storage, relative to the specified table. Depending on the type of mapping, this may mean adding any or all of candidate keys, foreign keys, or indexes to the specified table and/or other tables.

This method only applies to base tables. It will always be called after calling Mapping.defineStorage(com.triactive.jdo.store.sql.Table, com.triactive.jdo.store.StoreManager.MgmtTransaction) and is passed the same table argument.

The StoreManager will never call this method more than once..

This method is a no-op for this class.

Specified by:
defineConstraints in class Mapping
Parameters:
table - the table relative to which constraints should be defined.
mtx - the context in which the mapping is being initialized

mapTo

public void mapTo(Column col)
Links this mapping to a specific column. Linkage involves at least two steps:
  1. Calling the column's Column.mapWith(com.triactive.jdo.store.mapping.ColumnMapping) method
  2. Setting this mapping's typeInfo to match the column's

This method can be called at most once for a given mapping. Subclasses may do extra work as a consequence of mapping themselves to a column, but they should always call super.mapTo(col) first.

Throws:
java.lang.IllegalStateException - if this object is already mapped to a column

chooseColumnType

public TypeInfo chooseColumnType(Column col)
Chooses an appropriate SQL type for a column based on the column's options.

Parameters:
col - the column
Returns:
the type info for the chosen SQL type.

getTypeInfo

public final TypeInfo getTypeInfo()
Returns the actual SQL type used by this mapping. If mapped to a specific column it always returns the SQL type of that column.

Returns:
the type info for the actual SQL type used by this mapping.

getColumn

public final Column getColumn()
Returns the column this object is mapped to, if any.

Returns:
the column this object is mapped to, or null if it's not mapped to a specific column.

getSqlInsertionValue

public java.lang.String getSqlInsertionValue()
Returns the SQL text to be included in INSERT statements when inserting a value into this mapping's column. This is usually "?" to indicate a JDBC statement parameter.


getSqlUpdateValue

public java.lang.String getSqlUpdateValue()
Returns the SQL text to be included in UPDATE statements when updating a value in this mapping's column. This is usually "?" to indicate a JDBC statement parameter.


accessAsFieldIn

public SqlExpression accessAsFieldIn(FcoExpression objExpr)
Description copied from class: Mapping
Returns an SQL expression representing the persistent field mapped by this mapping within a particular first-class object expression. Throws an exception if this mapping does not map a specified persistent field.

Specified by:
accessAsFieldIn in class Mapping
Parameters:
objExpr - an expression representing a first-class object

newSqlExpression

public abstract SqlExpression newSqlExpression(QueryStatement.QueryColumn qsc)
Returns an SQL expression representing a reference to a column in a query statement.

Parameters:
qsc - the query column reference

setBoolean

public void setBoolean(PersistenceManager pm,
                       java.sql.PreparedStatement ps,
                       int param,
                       boolean value)

getBoolean

public boolean getBoolean(PersistenceManager pm,
                          java.sql.ResultSet rs,
                          int column)

setChar

public void setChar(PersistenceManager pm,
                    java.sql.PreparedStatement ps,
                    int param,
                    char value)

getChar

public char getChar(PersistenceManager pm,
                    java.sql.ResultSet rs,
                    int column)

setByte

public void setByte(PersistenceManager pm,
                    java.sql.PreparedStatement ps,
                    int param,
                    byte value)

getByte

public byte getByte(PersistenceManager pm,
                    java.sql.ResultSet rs,
                    int column)

setShort

public void setShort(PersistenceManager pm,
                     java.sql.PreparedStatement ps,
                     int param,
                     short value)

getShort

public short getShort(PersistenceManager pm,
                      java.sql.ResultSet rs,
                      int column)

setInt

public void setInt(PersistenceManager pm,
                   java.sql.PreparedStatement ps,
                   int param,
                   int value)

getInt

public int getInt(PersistenceManager pm,
                  java.sql.ResultSet rs,
                  int column)

setLong

public void setLong(PersistenceManager pm,
                    java.sql.PreparedStatement ps,
                    int param,
                    long value)

getLong

public long getLong(PersistenceManager pm,
                    java.sql.ResultSet rs,
                    int column)

setFloat

public void setFloat(PersistenceManager pm,
                     java.sql.PreparedStatement ps,
                     int param,
                     float value)

getFloat

public float getFloat(PersistenceManager pm,
                      java.sql.ResultSet rs,
                      int column)

setDouble

public void setDouble(PersistenceManager pm,
                      java.sql.PreparedStatement ps,
                      int param,
                      double value)

getDouble

public double getDouble(PersistenceManager pm,
                        java.sql.ResultSet rs,
                        int column)

setString

public void setString(PersistenceManager pm,
                      java.sql.PreparedStatement ps,
                      int param,
                      java.lang.String value)

getString

public java.lang.String getString(PersistenceManager pm,
                                  java.sql.ResultSet rs,
                                  int column)

setObject

public void setObject(PersistenceManager pm,
                      java.sql.PreparedStatement ps,
                      int param,
                      java.lang.Object value)

getObject

public java.lang.Object getObject(PersistenceManager pm,
                                  java.sql.ResultSet rs,
                                  int column)

hashCode

public int hashCode()
Returns a hash code value for this object.

Overrides:
hashCode in class Mapping

equals

public boolean equals(java.lang.Object obj)
Tests this object for equality with another object. Two ColumnMapping objects are equal if super.equals() is true and their columns (if any) are equal.

Overrides:
equals in class Mapping
Parameters:
obj - the object to compare with
Returns:
true if the objects are equal, false otherwise.


Copyright © 2001-2007 The TJDO Project All Rights Reserved.