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.MultiMapping
          extended by org.datanucleus.store.mapped.mapping.PersistableMapping
All Implemented Interfaces:
MappingCallbacks
Direct Known Subclasses:
PersistableIdMapping

public class PersistableMapping
extends MultiMapping
implements MappingCallbacks

Maps a field storing a persistable object. 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.
 
Fields inherited from class org.datanucleus.store.mapped.mapping.MultiMapping
javaTypeMappings, numberOfDatastoreMappings
 
Fields inherited from class org.datanucleus.store.mapped.mapping.JavaTypeMapping
absFieldNumber, datastoreContainer, datastoreMappings, LOCALISER, mmd, referenceMapping, roleForMember, storeMgr, type
 
Constructor Summary
PersistableMapping()
          Create a new empty PersistableMapping.
 
Method Summary
 Class getJavaType()
          Accessor for the java type being mapped.
 Object getObject(ExecutionContext ec, Object rs, int[] resultIndexes)
          Returns an instance of a persistable class.
 Object getValueForDatastoreMapping(NucleusContext nucleusCtx, int index, 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.
 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(ClassLoaderResolver clr)
          Method to prepare the PC mapping and add its associated datastore mappings.
 void setObject(ExecutionContext ec, Object ps, int[] param, Object value)
          Method to set an object in the datastore.
 void setObject(ExecutionContext ec, Object ps, int[] param, 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.MultiMapping
addJavaTypeMapping, getDatastoreMapping, getDatastoreMappings, getJavaTypeMapping, getNumberOfDatastoreMappings
 
Methods inherited from class org.datanucleus.store.mapped.mapping.JavaTypeMapping
addDatastoreMapping, equals, failureMessage, getAbsoluteFieldNumber, getBoolean, getByte, getChar, getColumnMetaDataForMember, getDatastoreContainer, getDouble, getFloat, getInt, getJavaTypeForDatastoreMapping, getLong, getMemberMetaData, getObject, getReferenceMapping, getRoleForMember, getShort, getStoreManager, getString, getType, hashCode, hasSimpleDatastoreRepresentation, includeInFetchStatement, includeInInsertStatement, includeInUpdateStatement, initialize, isNullable, isSerialised, representableAsStringLiteralInStatement, setAbsFieldNumber, setBoolean, setByte, setChar, setDatastoreContainer, setDouble, setFloat, setInt, setLong, setMemberMetaData, setReferenceMapping, setRoleForMember, setShort, setString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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 PersistableMapping. The caller must call one of the initialize methods to initialize the instance with the DatastoreAdapter and its type.

Method Detail

getJavaType

public Class getJavaType()
Description copied from class: JavaTypeMapping
Accessor for the java type being mapped. This is the java type that the mapping represents. Some examples : The "java type" is the java-type name used in the plugin.xml mapping file

Specified by:
getJavaType in class JavaTypeMapping
Returns:
The java type

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 JavaTypeMapping
Parameters:
mmd - MetaData for the field/property to be mapped (if any)
container - The datastore container storing this mapping (if any)
clr - the ClassLoaderResolver

prepareDatastoreMapping

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

Parameters:
clr - The ClassLoaderResolver

getValueForDatastoreMapping

public Object getValueForDatastoreMapping(NucleusContext nucleusCtx,
                                          int index,
                                          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:
nucleusCtx - 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,
                      Object ps,
                      int[] param,
                      Object value)
Method to set an object in the datastore.

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

Overrides:
setObject in class JavaTypeMapping
Parameters:
ec - The ExecutionContext
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 Object getObject(ExecutionContext ec,
                        Object rs,
                        int[] resultIndexes)
Returns an instance of a persistable class. Processes the FK field and generates the id of the object from the result values, and hence the object itself.

Overrides:
getObject in class JavaTypeMapping
Parameters:
ec - execution context
rs - The ResultSet
resultIndexes - indexes in the ResultSet to retrieve
Returns:
The persistable object

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 © 2012. All Rights Reserved.