com.triactive.jdo.store.mapping
Class ObjectReferenceDatastoreIdMapping

java.lang.Object
  extended bycom.triactive.jdo.store.mapping.Mapping
      extended bycom.triactive.jdo.store.mapping.ColumnMapping
          extended bycom.triactive.jdo.store.mapping.OIDMapping
              extended bycom.triactive.jdo.store.mapping.ObjectReferenceDatastoreIdMapping

public class ObjectReferenceDatastoreIdMapping
extends OIDMapping

A column mapping that maps a referrence to a first-class persistent object to a single column via its datastore ID value.

Although the mapping is ostensibly for the entire object, the result of getObject() and setObject() is to transfer only the value of its ID column to/from the PreparedStatement/ResultSet.

Author:
Mike Martin

Field Summary
 
Fields inherited from class com.triactive.jdo.store.mapping.ColumnMapping
col, typeInfo
 
Fields inherited from class com.triactive.jdo.store.mapping.Mapping
dba, fmd, type
 
Constructor Summary
ObjectReferenceDatastoreIdMapping(DatabaseAdapter dba, java.lang.Class type)
          Constructs a new object reference mapping for a given Java type.
ObjectReferenceDatastoreIdMapping(DatabaseAdapter dba, FieldMetaData fmd)
          Constructs a new object reference mapping for a given persistent field.
 
Method Summary
 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.
 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, ColumnMapping.mapTo(com.triactive.jdo.store.sql.Column) is called to link this mapping to the new column..

 java.lang.Object getObject(PersistenceManager pm, java.sql.ResultSet rs, int param)
           
 SqlExpression newSqlExpression(QueryStatement.QueryColumn qsc)
          Returns an SQL expression representing a reference to a column in a query statement.
 SqlExpression newSqlLiteral(QueryStatement qs, java.lang.Object value)
          Returns an SQL expression representing the literal value of a Java object.
 void setObject(PersistenceManager pm, java.sql.PreparedStatement ps, int param, java.lang.Object value)
           
 
Methods inherited from class com.triactive.jdo.store.mapping.OIDMapping
mapTo
 
Methods inherited from class com.triactive.jdo.store.mapping.ColumnMapping
accessAsFieldIn, chooseColumnType, equals, getBoolean, getByte, getChar, getColumn, getDouble, getFloat, getInt, getLong, getShort, getSqlInsertionValue, getSqlUpdateValue, getString, getTypeInfo, hashCode, setBoolean, setByte, setChar, setDouble, setFloat, setInt, setLong, setShort, setString
 
Methods inherited from class com.triactive.jdo.store.mapping.Mapping
getDefaultMappingsByType, getFieldMetaData, getType
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectReferenceDatastoreIdMapping

public ObjectReferenceDatastoreIdMapping(DatabaseAdapter dba,
                                         java.lang.Class type)
Constructs a new object reference mapping for a given Java type.

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

ObjectReferenceDatastoreIdMapping

public ObjectReferenceDatastoreIdMapping(DatabaseAdapter dba,
                                         FieldMetaData fmd)
Constructs a new object reference 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)
Description copied from class: ColumnMapping
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, ColumnMapping.mapTo(com.triactive.jdo.store.sql.Column) is called to link this mapping to the new column.

Overrides:
defineStorage in class ColumnMapping

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.

If the type of this object reference is specifically a persistence- capable class then a foreign key is defined from the reference column to the class table's primary key.

Overrides:
defineConstraints in class ColumnMapping
Parameters:
table - the table relative to which constraints should be defined.

setObject

public void setObject(PersistenceManager pm,
                      java.sql.PreparedStatement ps,
                      int param,
                      java.lang.Object value)
Overrides:
setObject in class OIDMapping

getObject

public java.lang.Object getObject(PersistenceManager pm,
                                  java.sql.ResultSet rs,
                                  int param)
Overrides:
getObject in class OIDMapping

newSqlLiteral

public SqlExpression newSqlLiteral(QueryStatement qs,
                                   java.lang.Object value)
Description copied from class: Mapping
Returns an SQL expression representing the literal value of a Java object. The object must be of a type used with this mapping.

Specified by:
newSqlLiteral in class Mapping
Parameters:
qs - the surrounding query statement for the expression
value - the literal value

newSqlExpression

public SqlExpression newSqlExpression(QueryStatement.QueryColumn qsc)
Description copied from class: ColumnMapping
Returns an SQL expression representing a reference to a column in a query statement.

Specified by:
newSqlExpression in class ColumnMapping
Parameters:
qsc - the query column reference


Copyright 2001-2007 The TJDO Project All Rights Reserved.