Class PersistableMapping
- java.lang.Object
-
- org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping
-
- org.datanucleus.store.rdbms.mapping.java.MultiMapping
-
- org.datanucleus.store.rdbms.mapping.java.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
Fields Modifier and Type Field Description protected org.datanucleus.metadata.AbstractClassMetaData
cmd
ClassMetaData for the represented class.-
Fields inherited from class org.datanucleus.store.rdbms.mapping.java.MultiMapping
javaTypeMappings, numberOfColumnMappings
-
Fields inherited from class org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping
absFieldNumber, columnMappings, mmd, referenceMapping, roleForMember, storeMgr, table, type
-
-
Constructor Summary
Constructors Constructor Description PersistableMapping()
Create a new empty PersistableMapping.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.datanucleus.metadata.AbstractClassMetaData
getClassMetaData()
Metadata for the class that this represents an object of.Class
getJavaType()
Accessor for the java type being mapped.Object
getObject(org.datanucleus.ExecutionContext ec, ResultSet rs, int[] resultIndexes)
Returns an instance of a persistable class.Object
getValueForColumnMapping(org.datanucleus.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(org.datanucleus.metadata.AbstractMemberMetaData mmd, Table table, org.datanucleus.ClassLoaderResolver clr)
Initialize this JavaTypeMapping with the given DatastoreAdapter for the given metadata.void
initialize(RDBMSStoreManager storeMgr, String type)
Initialise this JavaTypeMapping with the given StoreManager for the given type.void
postInsert(org.datanucleus.state.DNStateManager sm)
Method called after the insert of the object so that additional operations can be performed if necessary.void
postUpdate(org.datanucleus.state.DNStateManager sm)
Method called after the update of the object, so that additional operations can be performed if necessary.void
preDelete(org.datanucleus.state.DNStateManager sm)
Method called before the delete of objects, so that additional operations can be performed if necessary.protected void
prepareColumnMapping(org.datanucleus.ClassLoaderResolver clr)
Method to prepare the PC mapping and add its associated column mappings.void
setObject(org.datanucleus.ExecutionContext ec, PreparedStatement ps, int[] param, Object value)
Method to set an object in the datastore.void
setObject(org.datanucleus.ExecutionContext ec, PreparedStatement ps, int[] param, Object value, org.datanucleus.state.DNStateManager ownerSM, int ownerFieldNumber)
Method to set an object reference (FK) in the datastore.-
Methods inherited from class org.datanucleus.store.rdbms.mapping.java.MultiMapping
addJavaTypeMapping, getColumnMapping, getColumnMappings, getJavaTypeMapping, getNumberOfColumnMappings
-
Methods inherited from class org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping
addColumnMapping, equals, failureMessage, getAbsoluteFieldNumber, getBoolean, getByte, getChar, getColumnMetaDataForMember, getDouble, getFloat, getInt, getJavaTypeForColumnMapping, getLong, getMemberMetaData, getObject, getReferenceMapping, getRoleForMember, getShort, getStoreManager, getString, getTable, getType, hashCode, hasSimpleDatastoreRepresentation, includeInFetchStatement, includeInInsertStatement, includeInUpdateStatement, isNullable, isSerialised, performSetPostProcessing, representableAsStringLiteralInStatement, requiresSetPostProcessing, setAbsFieldNumber, setBoolean, setByte, setChar, setDouble, setFloat, setInt, setLong, setMemberMetaData, setReferenceMapping, setRoleForMember, setShort, setString, setTable
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.datanucleus.store.rdbms.mapping.MappingCallbacks
postFetch
-
-
-
-
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 :- if the field is of type "MyClass" then the mapping will be OIDMapping (or subclass) the javaType will be OID, and the type will be MyClass.
- if the field is of type "int" then the mapping will be IntegerMapping, the javaType will be Integer, and the type will be int.
- Specified by:
getJavaType
in classJavaTypeMapping
- Returns:
- The java type
-
getClassMetaData
public org.datanucleus.metadata.AbstractClassMetaData getClassMetaData()
Metadata for the class that this represents an object of.- Returns:
- ClassMetaData
-
initialize
public void initialize(org.datanucleus.metadata.AbstractMemberMetaData mmd, Table table, org.datanucleus.ClassLoaderResolver clr)
Initialize this JavaTypeMapping with the given DatastoreAdapter for the given metadata.- Overrides:
initialize
in classJavaTypeMapping
- Parameters:
mmd
- MetaData for the field/property to be mapped (if any)table
- The datastore container storing this mapping (if any)clr
- the ClassLoaderResolver
-
initialize
public void initialize(RDBMSStoreManager storeMgr, String type)
Description copied from class:JavaTypeMapping
Initialise this JavaTypeMapping with the given StoreManager for the given type. Used when the mapping is for a parameter in a query. This will not set the "mmd" and "datastoreContainer" parameters. If these are required for usage of the mapping then you should call setFieldInformation(AbstractMemberMetaData, DatastoreContainerObject) below. Subclasses should override this method to perform any datastore initialization operations.- Overrides:
initialize
in classJavaTypeMapping
- Parameters:
storeMgr
- The Datastore Adapter that this Mapping should use.type
- The Class that this mapping maps to the database.
-
prepareColumnMapping
protected void prepareColumnMapping(org.datanucleus.ClassLoaderResolver clr)
Method to prepare the PC mapping and add its associated column mappings.- Parameters:
clr
- The ClassLoaderResolver
-
getValueForColumnMapping
public Object getValueForColumnMapping(org.datanucleus.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:
getValueForColumnMapping
in classJavaTypeMapping
- Parameters:
nucleusCtx
- Contextindex
- The datastore indexvalue
- The overall value for this java type- Returns:
- The value for this datastore index
-
setObject
public void setObject(org.datanucleus.ExecutionContext ec, PreparedStatement ps, int[] param, Object value)
Method to set an object in the datastore.- Overrides:
setObject
in classJavaTypeMapping
- Parameters:
ec
- The ExecutionContextps
- The Prepared Statementparam
- The parameter ids in the statementvalue
- The value to put in the statement at these ids- Throws:
org.datanucleus.exceptions.NotYetFlushedException
- if an object hasn't yet been flushed to the datastore
-
setObject
public void setObject(org.datanucleus.ExecutionContext ec, PreparedStatement ps, int[] param, Object value, org.datanucleus.state.DNStateManager ownerSM, int ownerFieldNumber)
Method to set an object reference (FK) in the datastore.- Overrides:
setObject
in classJavaTypeMapping
- Parameters:
ec
- The ExecutionContextps
- The Prepared Statementvalue
- The value to put in the statement at these idsownerSM
- StateManager for the owner objectownerFieldNumber
- Field number of this PC object in the ownerparam
- The parameter ids in the statement- Throws:
org.datanucleus.exceptions.NotYetFlushedException
- if an object hasn't yet been flushed to the datastore
-
getObject
public Object getObject(org.datanucleus.ExecutionContext ec, ResultSet 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. TODO Pass in the discriminator/version columns also where available- Overrides:
getObject
in classJavaTypeMapping
- Parameters:
ec
- execution contextrs
- The ResultSetresultIndexes
- indexes in the ResultSet to retrieve- Returns:
- The persistable object
-
postInsert
public void postInsert(org.datanucleus.state.DNStateManager sm)
Description copied from interface:MappingCallbacks
Method called after the insert of the object so that additional operations can be performed if necessary.- Specified by:
postInsert
in interfaceMappingCallbacks
- Parameters:
sm
- StateManager of the owner
-
postUpdate
public void postUpdate(org.datanucleus.state.DNStateManager sm)
Description copied from interface:MappingCallbacks
Method called after the update of the object, so that additional operations can be performed if necessary.- Specified by:
postUpdate
in interfaceMappingCallbacks
- Parameters:
sm
- StateManager of the owner
-
preDelete
public void preDelete(org.datanucleus.state.DNStateManager sm)
Description copied from interface:MappingCallbacks
Method called before the delete of objects, so that additional operations can be performed if necessary.- Specified by:
preDelete
in interfaceMappingCallbacks
- Parameters:
sm
- StateManager of the owner
-
-