org.datanucleus.store.mapped.mapping
Class PersistableMapping

java.lang.Object
  extended by org.datanucleus.store.mapped.mapping.JavaTypeMapping
      extended by org.datanucleus.store.mapped.mapping.SingleFieldMapping
          extended by org.datanucleus.store.mapped.mapping.OIDMapping
              extended by org.datanucleus.store.mapped.mapping.PersistableMapping
All Implemented Interfaces:
MappingCallbacks
Direct Known Subclasses:
PersistableIdMapping

public class PersistableMapping
extends OIDMapping
implements MappingCallbacks

Maps a java field to a persistable class. For persistable classes using datastore-id most of the behaviour is coded in the OIDMapping superclass. TODO Split this from OIDMapping since PCMapping may represent app-id instead of datastore-id TODO Move column creation for join table collection/map/array of PC to this class


Field Summary
protected  AbstractClassMetaData cmd
          ClassMetaData for the represented class.
protected  JavaTypeMapping[] javaTypeMappings
          Mappings for all fields necessary to represent the id of the PC object.
 
Fields inherited from class org.datanucleus.store.mapped.mapping.JavaTypeMapping
datastoreContainer, datastoreMappings, LOCALISER, mmd, referenceMapping, roleForMember, storeMgr, type
 
Constructor Summary
PersistableMapping()
          Create a new empty PersistenceCapableMapping.
 
Method Summary
 void addJavaTypeMapping(JavaTypeMapping mapping)
          Add a new JavaTypeMapping
 DatastoreMapping getDatastoreMapping(int index)
          Accessor for a datastore mapping.
 DatastoreMapping[] getDatastoreMappings()
          Accessor for the datastore mappings for this java type.
 JavaTypeMapping[] getJavaTypeMapping()
          Accessor for the Java type mappings
 int getNumberOfDatastoreMappings()
          Accessor for the number of datastore fields.
 java.lang.Object getObject(ExecutionContext ec, java.lang.Object rs, int[] param)
          Returns a instance of a PersistenceCapable class.
 java.lang.Object getValueForDatastoreMapping(OMFContext omfCtx, int index, java.lang.Object value)
          Method to return the value to be stored in the specified datastore index given the overall value for this java type.
 void initialize(AbstractMemberMetaData mmd, DatastoreContainerObject container, ClassLoaderResolver clr)
          Initialize this JavaTypeMapping with the given DatastoreAdapter for the given metadata.
 void insertPostProcessing(ObjectProvider op)
          Hook so that we can handle any post-processing on the insert of a particular field.
 ScalarExpression newLiteral(QueryExpression qs, java.lang.Object value)
          Creates a literal from an value for use in TJDO-style JDOQL.
 ScalarExpression newScalarExpression(QueryExpression qs, LogicSetExpression te)
          Creates a expression from a field name/table.
 void postFetch(ObjectProvider 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(ObjectProvider 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(ObjectProvider 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(ObjectProvider 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(ExecutionContext ec, java.lang.Object ps, int[] param, java.lang.Object value)
          Method to set an object in the datastore.
 void setObject(ExecutionContext ec, java.lang.Object ps, int[] param, java.lang.Object value, ObjectProvider ownerSM, int ownerFieldNumber)
          Method to set an object reference (FK) in the datastore.
 
Methods inherited from class org.datanucleus.store.mapped.mapping.OIDMapping
getJavaType, getSampleValue
 
Methods inherited from class org.datanucleus.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.datanucleus.store.mapped.mapping.JavaTypeMapping
addDatastoreMapping, failureMessage, getColumnMetaDataForMember, getDatastoreContainer, getMemberMetaData, getObject, getReferenceMapping, getRoleForMember, getType, hashCode, hasSimpleDatastoreRepresentation, includeInFetchStatement, includeInInsertStatement, includeInUpdateStatement, initialize, isNullable, isSerialised, setDatastoreContainer, setDefault, setMemberMetaData, setReferenceMapping, setRoleForMember
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, 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.


cmd

protected AbstractClassMetaData cmd
ClassMetaData for the represented class. Create a new one on each getObject invoke is expensive

Constructor Detail

PersistableMapping

public PersistableMapping()
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(AbstractMemberMetaData mmd,
                       DatastoreContainerObject container,
                       ClassLoaderResolver clr)
Initialize this JavaTypeMapping with the given DatastoreAdapter for the given metadata.

Overrides:
initialize in class SingleFieldMapping
Parameters:
mmd - MetaData for the field/property 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

getNumberOfDatastoreMappings

public int getNumberOfDatastoreMappings()
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:
getNumberOfDatastoreMappings 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.

getDatastoreMappings

public DatastoreMapping[] getDatastoreMappings()
Accessor for the datastore mappings for this java type. Overrides the method in JavaTypeMapping so we can add on datastore mappings of any sub mappings here.

Overrides:
getDatastoreMappings in class JavaTypeMapping
Returns:
The datastore mapping(s)

getValueForDatastoreMapping

public java.lang.Object getValueForDatastoreMapping(OMFContext omfCtx,
                                                    int index,
                                                    java.lang.Object value)
Method to return the value to be stored in the specified datastore index given the overall value for this java type.

Overrides:
getValueForDatastoreMapping in class JavaTypeMapping
Parameters:
omfCtx - OMF Context
index - The datastore index
value - The overall value for this java type
Returns:
The value for this datastore index

setObject

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

Overrides:
setObject in class OIDMapping
Parameters:
ec - 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(ExecutionContext ec,
                      java.lang.Object ps,
                      int[] param,
                      java.lang.Object value,
                      ObjectProvider ownerSM,
                      int ownerFieldNumber)
Method to set an object reference (FK) in the datastore.

Overrides:
setObject in class JavaTypeMapping
Parameters:
ec - 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(ExecutionContext ec,
                                  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:
ec - execution context
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 for use in TJDO-style JDOQL. This implementation just throws a NucleusException.

Overrides:
newLiteral in class OIDMapping
Parameters:
qs - The Query statement
value - The object
Returns:
A Scalar Expression TODO Remove this when we drop legacy query mechanism

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 For use in TJDO-style JDOQL. This implementation just throws a NucleusException.

Overrides:
newScalarExpression in class OIDMapping
Parameters:
qs - The Query statement
te - the alias for the table
Returns:
A Scalar Expression TODO Remove this when we drop legacy query mechanism

postFetch

public void postFetch(ObjectProvider 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.

insertPostProcessing

public void insertPostProcessing(ObjectProvider op)
Description copied from interface: MappingCallbacks
Hook so that we can handle any post-processing on the insert of a particular field. For example with Oracle we need to insert "EMPTY_CLOB" and then immediately after do a SELECT of it and update the contents of the CLOB/BLOB.

Specified by:
insertPostProcessing in interface MappingCallbacks
Parameters:
op - ObjectProvider

postInsert

public void postInsert(ObjectProvider 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(ObjectProvider 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(ObjectProvider 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 © 2010. All Rights Reserved.