org.jpox.store.mapped.mapping
Class PersistenceCapableMapping

java.lang.Object
  extended by org.jpox.store.mapped.mapping.JavaTypeMapping
      extended by org.jpox.store.mapped.mapping.SingleFieldMapping
          extended by org.jpox.store.mapped.mapping.OIDMapping
              extended by org.jpox.store.mapped.mapping.PersistenceCapableMapping
All Implemented Interfaces:
MappingCallbacks, SimpleDatastoreRepresentation
Direct Known Subclasses:
ObjectIdClassMapping

public class PersistenceCapableMapping
extends OIDMapping
implements MappingCallbacks

Maps a java field to a PersistenceCapable class. For PersistenceCapable classes using datastore identity most of the necessary behaviour is coded in the OIDMapping super class. TODO Split this from OIDMapping since a PCMapping may represent an application identity object instead of a datastore identity object

Version:
$Revision: 1.154 $

Field Summary
protected  JavaTypeMapping[] javaTypeMappings
          Mappings for all fields necessary to represent the id of the PC object.
 
Fields inherited from class org.jpox.store.mapped.mapping.JavaTypeMapping
datastoreContainer, datastoreMappings, dba, fmd, LOCALISER, MAPPING_ARRAY_ELEMENT, MAPPING_COLLECTION_ELEMENT, MAPPING_FIELD, MAPPING_MAP_KEY, MAPPING_MAP_VALUE, referenceMapping, roleForField, type
 
Constructor Summary
PersistenceCapableMapping()
          Create a new empty PersistenceCapableMapping.
 
Method Summary
 void addJavaTypeMapping(JavaTypeMapping mapping)
          Add a new JavaTypeMapping
 DatastoreMapping getDataStoreMapping(int index)
          Accessor for a datastore mapping.
 JavaTypeMapping[] getJavaTypeMapping()
          Accessor for the Java type mappings
 int getNumberOfDatastoreFields()
          Accessor for the number of datastore fields.
 java.lang.Object getObject(ObjectManager om, java.lang.Object rs, int[] param)
          Returns a instance of a PersistenceCapable class.
 void initialize(DatastoreAdapter dba, AbstractMemberMetaData fmd, DatastoreContainerObject container, ClassLoaderResolver clr)
          Initialize this JavaTypeMapping with the given DatastoreAdapter for the given FieldMetaData.
 ScalarExpression newLiteral(QueryExpression qs, java.lang.Object value)
          Creates a literal from an value.
 ScalarExpression newScalarExpression(QueryExpression qs, LogicSetExpression te)
          Creates a expression from a field name/table.
 void postFetch(StateManager sm)
          Method executed just after a fetch of the owning object, allowing any necessary action to this field and the object stored in it.
 void postInsert(StateManager sm)
          Method executed just after the insert of the owning object, allowing any necessary action to this field and the object stored in it.
 void postUpdate(StateManager sm)
          Method executed just afer any update of the owning object, allowing any necessary action to this field and the object stored in it.
 void preDelete(StateManager sm)
          Method executed just before the owning object is deleted, allowing tidying up of any relation information.
protected  void prepareDatastoreMapping()
          Method to prepare the PC mapping and add its associated datastore mappings.
protected  void prepareDatastoreMapping(ClassLoaderResolver clr)
          Method to prepare the PC mapping and add its associated datastore mappings.
 void setObject(ObjectManager om, java.lang.Object ps, int[] param, java.lang.Object value)
          Method to set an object in the datastore.
 void setObject(ObjectManager om, java.lang.Object ps, int[] param, java.lang.Object value, StateManager ownerSM, int ownerFieldNumber)
          Method to set an object reference (FK) in the datastore.
 
Methods inherited from class org.jpox.store.mapped.mapping.OIDMapping
getJavaType, getSampleValue
 
Methods inherited from class org.jpox.store.mapped.mapping.SingleFieldMapping
equals, getBoolean, getByte, getChar, getDefaultLength, getDouble, getFloat, getInt, getJavaTypeForDatastoreMapping, getLong, getShort, getString, getValidValues, setBoolean, setByte, setChar, setDouble, setFloat, setInt, setLong, setShort, setString
 
Methods inherited from class org.jpox.store.mapped.mapping.JavaTypeMapping
addDataStoreMapping, failureMessage, getDatastoreContainer, getDataStoreMappings, getFieldMetaData, getObject, getReferenceMapping, getRoleForField, getType, includeInFetchStatement, includeInInsertStatement, includeInUpdateStatement, initialize, isNullable, isSerialised, setDefault, setFieldInformation, setReferenceMapping, setRoleForField
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

javaTypeMappings

protected JavaTypeMapping[] javaTypeMappings
Mappings for all fields necessary to represent the id of the PC object.

Constructor Detail

PersistenceCapableMapping

public PersistenceCapableMapping()
Create a new empty PersistenceCapableMapping. The caller must call one of the initialize methods to initialize the instance with the DatastoreAdapter and its type.

Method Detail

initialize

public void initialize(DatastoreAdapter dba,
                       AbstractMemberMetaData fmd,
                       DatastoreContainerObject container,
                       ClassLoaderResolver clr)
Initialize this JavaTypeMapping with the given DatastoreAdapter for the given FieldMetaData.

Overrides:
initialize in class SingleFieldMapping
Parameters:
dba - The Datastore Adapter that this Mapping should use.
fmd - FieldMetaData for the field to be mapped (if any)
container - The datastore container storing this mapping (if any)
clr - the ClassLoaderResolver

addJavaTypeMapping

public void addJavaTypeMapping(JavaTypeMapping mapping)
Add a new JavaTypeMapping

Parameters:
mapping - the JavaTypeMapping

prepareDatastoreMapping

protected void prepareDatastoreMapping()
Method to prepare the PC mapping and add its associated datastore mappings.

Overrides:
prepareDatastoreMapping in class SingleFieldMapping

prepareDatastoreMapping

protected void prepareDatastoreMapping(ClassLoaderResolver clr)
Method to prepare the PC mapping and add its associated datastore mappings.

Parameters:
clr - The ClassLoaderResolver

getJavaTypeMapping

public JavaTypeMapping[] getJavaTypeMapping()
Accessor for the Java type mappings

Returns:
The Java type mappings

getNumberOfDatastoreFields

public int getNumberOfDatastoreFields()
Accessor for the number of datastore fields. Zero datastore fields implies that the mapping uses a FK in the associated class to reference back.

Overrides:
getNumberOfDatastoreFields in class JavaTypeMapping
Returns:
Number of datastore fields for this PC mapping.

getDataStoreMapping

public DatastoreMapping getDataStoreMapping(int index)
Accessor for a datastore mapping. This method works through the java type mappings, and for each mapping through its datastore mappings incrementing the index with each datastore mapping.

Overrides:
getDataStoreMapping in class JavaTypeMapping
Parameters:
index - The position of the mapping.
Returns:
The datastore mapping.

setObject

public void setObject(ObjectManager om,
                      java.lang.Object ps,
                      int[] param,
                      java.lang.Object value)
Method to set an object in the datastore.

Overrides:
setObject in class OIDMapping
Parameters:
om - The ObjectManager
ps - The Prepared Statement
param - The parameter ids in the statement
value - The value to put in the statement at these ids
Throws:
NotYetFlushedException

setObject

public void setObject(ObjectManager om,
                      java.lang.Object ps,
                      int[] param,
                      java.lang.Object value,
                      StateManager ownerSM,
                      int ownerFieldNumber)
Method to set an object reference (FK) in the datastore.

Overrides:
setObject in class JavaTypeMapping
Parameters:
om - The Object Manager
ps - The Prepared Statement
param - The parameter ids in the statement
value - The value to put in the statement at these ids
ownerSM - StateManager for the owner object
ownerFieldNumber - Field number of this PC object in the owner
Throws:
NotYetFlushedException

getObject

public java.lang.Object getObject(ObjectManager om,
                                  java.lang.Object rs,
                                  int[] param)
Returns a instance of a PersistenceCapable class. Processes a FK field and converts the id stored firstly into an OID/AID and then into the object that the FK id relates to.

Overrides:
getObject in class OIDMapping
Parameters:
om - The Object Manager
rs - The ResultSet
param - Array of parameter ids in the ResultSet to retrieve
Returns:
The Persistence Capable object

newLiteral

public ScalarExpression newLiteral(QueryExpression qs,
                                   java.lang.Object value)
Description copied from class: JavaTypeMapping
Creates a literal from an value. A string literal is enclosed in single quotes. for example: "literal". A string literal that includes a single quote is represented by two single quotes. for example: "literal''s". An exact numeric literal is a numeric value without a decimal point, such as 57, -957, +62. An approximate numeric literal is a numeric value in scientific notation, such as 7E3, -57.9E2, or a numeric value with a decimal, such as 7., -95.7, +6.2.

Overrides:
newLiteral in class OIDMapping
Parameters:
qs - The Query statement
value - The object
Returns:
A Scalar Expression

newScalarExpression

public ScalarExpression newScalarExpression(QueryExpression qs,
                                            LogicSetExpression te)
Description copied from class: JavaTypeMapping
Creates a expression from a field name/table. e.g. tablename.fieldname; tablealias.fieldalias

Overrides:
newScalarExpression in class OIDMapping
Parameters:
qs - The Query statement
te - the alias for the table
Returns:
A Scalar Expression

postFetch

public void postFetch(StateManager sm)
Method executed just after a fetch of the owning object, allowing any necessary action to this field and the object stored in it.

Specified by:
postFetch in interface MappingCallbacks
Parameters:
sm - StateManager for the owner.

postInsert

public void postInsert(StateManager sm)
Method executed just after the insert of the owning object, allowing any necessary action to this field and the object stored in it.

Specified by:
postInsert in interface MappingCallbacks
Parameters:
sm - StateManager for the owner

postUpdate

public void postUpdate(StateManager sm)
Method executed just afer any update of the owning object, allowing any necessary action to this field and the object stored in it.

Specified by:
postUpdate in interface MappingCallbacks
Parameters:
sm - StateManager for the owner

preDelete

public void preDelete(StateManager sm)
Method executed just before the owning object is deleted, allowing tidying up of any relation information.

Specified by:
preDelete in interface MappingCallbacks
Parameters:
sm - StateManager for the owner


Copyright © -2008 . All Rights Reserved.