Class ReferenceMapping
- java.lang.Object
-
- org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping
-
- org.datanucleus.store.rdbms.mapping.java.MultiMapping
-
- org.datanucleus.store.rdbms.mapping.java.MultiPersistableMapping
-
- org.datanucleus.store.rdbms.mapping.java.ReferenceMapping
-
- All Implemented Interfaces:
MappingCallbacks
- Direct Known Subclasses:
InterfaceMapping
,ObjectMapping
,ReferenceIdMapping
public abstract class ReferenceMapping extends MultiPersistableMapping implements MappingCallbacks
Mapping for a "reference" type. This can be used for things like interfaces, or Object which are simply a reference to some specific (persistable) class. This can be persisted in several ways (see "mappingStrategy") :-- List of possible "implementations" of the reference type where column(s) are created for each possible implementation of the reference as a FK to the implementation table. This has the advantage that it retains referential integrity since direct FKs are used.
- What Kodo/Xcalia used was a single column storing the identity toString() form.
-
-
Field Summary
Fields Modifier and Type Field Description static int
ID_MAPPING
Single column containing the "identity" of an object.protected int
mappingStrategy
Strategy for how the reference(s) are mapped.static int
PER_IMPLEMENTATION_MAPPING
Each implementation has its own column(s) as a FK to the related table.static int
XCALIA_MAPPING
Single column containing the Xcalia form of the "identity" of an object.-
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 ReferenceMapping()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Class
getJavaType()
Accessor for the java type being mapped.String
getJavaTypeForColumnMapping(int index)
Accessor for the java type represented by a particular datastore mapping.JavaTypeMapping
getJavaTypeMappingForType(Class type)
Method to return the submapping for the specified (implementation) type.int
getMappingNumberForValue(org.datanucleus.ExecutionContext ec, Object value)
Convenience accessor for the number of the java type mapping where the passed value would be stored.int
getMappingStrategy()
Accessor for the mapping strategy.Object
getObject(org.datanucleus.ExecutionContext ec, ResultSet rs, int[] pos)
Method to retrieve an object of this type from the ResultSet.protected Object
getObjectForReferenceString(org.datanucleus.ExecutionContext ec, String refString)
Method to convert a "reference string" into the associated object.protected String
getReferenceStringForObject(org.datanucleus.ExecutionContext ec, Object value)
Method to convert an object to be stored into a "reference string" to store.void
initialize(org.datanucleus.metadata.AbstractMemberMetaData mmd, Table table, org.datanucleus.ClassLoaderResolver clr)
Initialize this JavaTypeMapping for the specified field/property.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)
Convenience method to create the necessary columns to represent this reference in the datastore.void
setObject(org.datanucleus.ExecutionContext ec, PreparedStatement ps, int[] pos, Object value, org.datanucleus.state.DNStateManager ownerSM, int ownerFieldNumber)
Sets the specified positions in the PreparedStatement associated with this field, and value.-
Methods inherited from class org.datanucleus.store.rdbms.mapping.java.MultiPersistableMapping
setObject
-
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, getLong, getMemberMetaData, getObject, getReferenceMapping, getRoleForMember, getShort, getStoreManager, getString, getTable, getType, getValueForColumnMapping, hashCode, hasSimpleDatastoreRepresentation, includeInFetchStatement, includeInInsertStatement, includeInUpdateStatement, initialize, 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, postInsert, postUpdate
-
-
-
-
Field Detail
-
PER_IMPLEMENTATION_MAPPING
public static final int PER_IMPLEMENTATION_MAPPING
Each implementation has its own column(s) as a FK to the related table.- See Also:
- Constant Field Values
-
ID_MAPPING
public static final int ID_MAPPING
Single column containing the "identity" of an object.- See Also:
- Constant Field Values
-
XCALIA_MAPPING
public static final int XCALIA_MAPPING
Single column containing the Xcalia form of the "identity" of an object.- See Also:
- Constant Field Values
-
mappingStrategy
protected int mappingStrategy
Strategy for how the reference(s) are mapped.
-
-
Method Detail
-
initialize
public void initialize(org.datanucleus.metadata.AbstractMemberMetaData mmd, Table table, org.datanucleus.ClassLoaderResolver clr)
Initialize this JavaTypeMapping for the specified field/property.- Overrides:
initialize
in classJavaTypeMapping
- Parameters:
mmd
- AbstractMemberMetaData for the field to be mapped (if any)table
- The datastore container storing this mapping (if any)clr
- the ClassLoaderResolver
-
getMappingStrategy
public int getMappingStrategy()
Accessor for the mapping strategy. There are various supported strategies for reference fields with the default being one mapping per implementation, but also allowing a single (String) mapping for all implementations.- Returns:
- The mapping strategy
-
getJavaTypeMappingForType
public JavaTypeMapping getJavaTypeMappingForType(Class type)
Method to return the submapping for the specified (implementation) type. If PER_IMPLEMENTATION_MAPPING is specified then tries to find the appropriate submapping for this implementation type. Otherwise just returns this mapping.- Parameters:
type
- The implementation type we want the submapping for- Returns:
- The javaTypeMapping for this implementation
-
prepareColumnMapping
protected void prepareColumnMapping(org.datanucleus.ClassLoaderResolver clr)
Convenience method to create the necessary columns to represent this reference in the datastore. With "per-implementation" mapping strategy will create columns for each of the possible implementations. With "identity"/"xcalia" will create a single column to store a reference to the implementation value.- Parameters:
clr
- The ClassLoaderResolver
-
getJavaTypeForColumnMapping
public String getJavaTypeForColumnMapping(int index)
Accessor for the java type represented by a particular datastore mapping. This implementation relays to the superclass implementation except in the case of "identity" mapping strategy, in which case it returns "java.lang.String".- Overrides:
getJavaTypeForColumnMapping
in classJavaTypeMapping
- Parameters:
index
- requested column index.- Returns:
- the name of java-type for the requested column.
-
getMappingNumberForValue
public int getMappingNumberForValue(org.datanucleus.ExecutionContext ec, Object value)
Convenience accessor for the number of the java type mapping where the passed value would be stored. If no suitable mapping is found will return -1. If is a persistent interface then will return -2 meaning persist against *any* mapping- Overrides:
getMappingNumberForValue
in classMultiPersistableMapping
- Parameters:
ec
- ExecutionContextvalue
- The value- Returns:
- The index of javaTypeMappings to use (if any), or -1 (none), or -2 (any)
-
setObject
public void setObject(org.datanucleus.ExecutionContext ec, PreparedStatement ps, int[] pos, Object value, org.datanucleus.state.DNStateManager ownerSM, int ownerFieldNumber)
Sets the specified positions in the PreparedStatement associated with this field, and value.- Overrides:
setObject
in classMultiPersistableMapping
- Parameters:
ec
- the ExecutionContextps
- a datastore object that executes statements in the databasevalue
- the value stored in this fieldownerSM
- the owner StateManagerownerFieldNumber
- the owner absolute field numberpos
- The position(s) of the PreparedStatement to populate
-
getObject
public Object getObject(org.datanucleus.ExecutionContext ec, ResultSet rs, int[] pos)
Method to retrieve an object of this type from the ResultSet.- Overrides:
getObject
in classMultiPersistableMapping
- Parameters:
ec
- ExecutionContextrs
- The ResultSetpos
- The parameter positions- Returns:
- The object
-
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
-
getReferenceStringForObject
protected String getReferenceStringForObject(org.datanucleus.ExecutionContext ec, Object value)
Method to convert an object to be stored into a "reference string" to store. Reference string is of the form :- ID_MAPPING : "{classname}:{id}"
- XCALIA_MAPPING (datastore-id) : "{definer}:{id-key}" where definer is discriminator/classname
- XCALIA_MAPPING (app-id) : "{definer}:{id}" where definer is discriminator/classname
- Parameters:
ec
- ExecutionContextvalue
- The object- Returns:
- The reference string
-
getObjectForReferenceString
protected Object getObjectForReferenceString(org.datanucleus.ExecutionContext ec, String refString)
Method to convert a "reference string" into the associated object. Reference string is of the form :- ID_MAPPING : "{classname}:{id}"
- XCALIA_MAPPING (datastore-id) : "{definer}:{id-key}" where definer is discriminator/classname
- XCALIA_MAPPING (app-id) : "{definer}:{id}" where definer is discriminator/classname
- Parameters:
ec
- execution contextrefString
- The reference string- Returns:
- The referenced object
-
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
-
-