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
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
FieldsModifier and TypeFieldDescriptionstatic final int
Single column containing the "identity" of an object.protected int
Strategy for how the reference(s) are mapped.static final int
Each implementation has its own column(s) as a FK to the related table.static final int
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 -
Method Summary
Modifier and TypeMethodDescription(package private) void
createPerImplementationColumnsForReferenceField
(boolean pk, boolean nullable, boolean serialised, boolean embedded, org.datanucleus.metadata.FieldRole fieldRole, org.datanucleus.metadata.ColumnMetaData[] columnMetaData, org.datanucleus.ClassLoaderResolver clr) Create columns for reference (Interface/Object) fields on a per-implementation basis.Accessor for the java type being mapped.getJavaTypeForColumnMapping
(int index) Accessor for the java type represented by a particular datastore mapping.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
Accessor for the mapping strategy.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.private String
getReferenceFieldType
(org.datanucleus.metadata.FieldRole fieldRole) Convenience method to extract the type of the reference field.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 Details
-
PER_IMPLEMENTATION_MAPPING
public static final int PER_IMPLEMENTATION_MAPPINGEach implementation has its own column(s) as a FK to the related table.- See Also:
-
ID_MAPPING
public static final int ID_MAPPINGSingle column containing the "identity" of an object.- See Also:
-
XCALIA_MAPPING
public static final int XCALIA_MAPPINGSingle column containing the Xcalia form of the "identity" of an object.- See Also:
-
mappingStrategy
protected int mappingStrategyStrategy for how the reference(s) are mapped.
-
-
Constructor Details
-
ReferenceMapping
public ReferenceMapping()
-
-
Method Details
-
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
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
-
getReferenceFieldType
Convenience method to extract the type of the reference field.- Parameters:
fieldRole
- Role of this field- Returns:
- The field type name
-
createPerImplementationColumnsForReferenceField
void createPerImplementationColumnsForReferenceField(boolean pk, boolean nullable, boolean serialised, boolean embedded, org.datanucleus.metadata.FieldRole fieldRole, org.datanucleus.metadata.ColumnMetaData[] columnMetaData, org.datanucleus.ClassLoaderResolver clr) Create columns for reference (Interface/Object) fields on a per-implementation basis. This call ColumnCreator.createColumnsForField for each implementation class of the reference. -
getJavaTypeForColumnMapping
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
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 databasepos
- The position(s) of the PreparedStatement to populatevalue
- the value stored in this fieldownerSM
- the owner StateManagerownerFieldNumber
- the owner absolute field number
-
getObject
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
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
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
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
-