Class OneToOneMapping

    • Field Detail

      • sourceToTargetKeyFields

        protected Map<DatabaseField,​DatabaseField> sourceToTargetKeyFields
        Maps the source foreign/primary key fields to the target primary/foreign key fields.
      • targetToSourceKeyFields

        protected Map<DatabaseField,​DatabaseField> targetToSourceKeyFields
        Maps the target primary/foreign key fields to the source foreign/primary key fields.
      • shouldVerifyDelete

        protected boolean shouldVerifyDelete
        These are used for non-unit of work modification to check if the value of the 1-1 was changed and a deletion is required.
      • privateOwnedCriteria

        protected transient Expression privateOwnedCriteria
      • mechanism

        protected RelationTableMechanism mechanism
        Mechanism holds relationTable and all fields and queries associated with it.
      • isOneToOneRelationship

        protected boolean isOneToOneRelationship
        Define if this mapping is really for a OneToOne relationship. This is a backward compatibility issue, in that before the ManyToOneMapping was created OneToOneMapping was used for both.
      • isOneToOnePrimaryKeyRelationship

        protected boolean isOneToOnePrimaryKeyRelationship
        Defines if this mapping was built using primary key join columns.
      • insertableFields

        protected HashSet<DatabaseField> insertableFields
        Keep track of which fields are insertable and updatable.
      • sourceExpressionsToPostInitialize

        protected transient List<Expression> sourceExpressionsToPostInitialize
        Keep a reference to the source and target expressions to post initialize when building a selection criteria early.
      • targetExpressionsToPostInitialize

        protected transient List<Expression> targetExpressionsToPostInitialize
    • Constructor Detail

      • OneToOneMapping

        public OneToOneMapping()
        PUBLIC: Default constructor.
    • Method Detail

      • addAdditionalFieldsToQuery

        public void addAdditionalFieldsToQuery​(ReadQuery selectionQuery,
                                               Expression baseExpression)
        INTERNAL: Used when initializing queries for mappings that use a Map. Called when the selection query is being initialized to add the fields for the map key to the query.
        Specified by:
        addAdditionalFieldsToQuery in interface MapKeyMapping
      • addFieldsForMapKey

        public void addFieldsForMapKey​(AbstractRecord joinRow)
        INTERNAL: Used when initializing queries for mappings that use a Map Called when the insert query is being initialized to ensure the fields for the map key are in the insert query
        Specified by:
        addFieldsForMapKey in interface MapKeyMapping
      • addForeignKeyField

        public void addForeignKeyField​(DatabaseField sourceForeignKeyField,
                                       DatabaseField targetPrimaryKeyField)
        PUBLIC: Define the foreign key relationship in the 1-1 mapping. This method is used for composite foreign key relationships, that is the source object's table has multiple foreign key fields to the target object's primary key fields. Both the source foreign key field and the target foreign key field must be specified. When a foreign key is specified TopLink will automatically populate the value for that field from the target object when the object is written to the database. If the foreign key is also mapped through a direct-to-field then the direct-to-field must be set read-only.
        Overrides:
        addForeignKeyField in class ForeignReferenceMapping
      • addForeignKeyFieldName

        public void addForeignKeyFieldName​(String sourceForeignKeyFieldName,
                                           String targetPrimaryKeyFieldName)
        PUBLIC: Define the foreign key relationship in the 1-1 mapping. This method is used for composite foreign key relationships, that is the source object's table has multiple foreign key fields to the target object's primary key fields. Both the source foreign key field name and the target foreign key field name must be specified. When a foreign key is specified TopLink will automatically populate the value for that field from the target object when the object is written to the database. If the foreign key is also mapped through a direct-to-field then the direct-to-field must be set read-only.
      • addTargetForeignKeyField

        public void addTargetForeignKeyField​(DatabaseField targetForeignKeyField,
                                             DatabaseField sourcePrimaryKeyField)
        PUBLIC: Define the target foreign key relationship in the 1-1 mapping. This method is used for composite target foreign key relationships, that is the target object's table has multiple foreign key fields to the source object's primary key fields. Both the target foreign key field and the source primary key field must be specified. The distinction between a foreign key and target foreign key is that the 1-1 mapping will not populate the target foreign key value when written (because it is in the target table). Normally 1-1's are through foreign keys but in bi-directional 1-1's the back reference will be a target foreign key. In obscure composite legacy data models a 1-1 may consist of a foreign key part and a target foreign key part, in this case both method will be called with the correct parts.
        Overrides:
        addTargetForeignKeyField in class ForeignReferenceMapping
      • addTargetForeignKeyFieldName

        public void addTargetForeignKeyFieldName​(String targetForeignKeyFieldName,
                                                 String sourcePrimaryKeyFieldName)
        PUBLIC: Define the target foreign key relationship in the 1-1 mapping. This method is used for composite target foreign key relationships, that is the target object's table has multiple foreign key fields to the source object's primary key fields. Both the target foreign key field name and the source primary key field name must be specified. The distinction between a foreign key and target foreign key is that the 1-1 mapping will not populate the target foreign key value when written (because it is in the target table). Normally 1-1's are through foreign keys but in bi-directional 1-1's the back reference will be a target foreign key. In obscure composite legacy data models a 1-1 may consist of a foreign key part and a target foreign key part, in this case both method will be called with the correct parts.
      • addKeyToDeletedObjectsList

        public void addKeyToDeletedObjectsList​(Object object,
                                               Map deletedObjects)
        INTERNAL: For mappings used as MapKeys in MappedKeyContainerPolicy. Add the target of this mapping to the deleted objects list if necessary This method is used for removal of private owned relationships.
        Specified by:
        addKeyToDeletedObjectsList in interface MapKeyMapping
      • collectQueryParameters

        public void collectQueryParameters​(Set<DatabaseField> cacheFields)
        Description copied from class: ObjectReferenceMapping
        INTERNAL: This method is used to store the FK fields that can be cached that correspond to noncacheable mappings the FK field values will be used to re-issue the query when cloning the shared cache entity
        Overrides:
        collectQueryParameters in class ObjectReferenceMapping
      • createMapComponentsFromSerializableKeyInfo

        public List<Object> createMapComponentsFromSerializableKeyInfo​(Object[] keyInfo,
                                                                       AbstractSession session)
        INTERNAL: Create an instance of the Key object from the key information extracted from the map. This may return the value directly in case of a simple key or will be used as the FK to load a related entity.
        Specified by:
        createMapComponentsFromSerializableKeyInfo in interface MapKeyMapping
      • deleteMapKey

        public void deleteMapKey​(Object objectDeleted,
                                 AbstractSession session)
        INTERNAL: For mappings used as MapKeys in MappedKeyContainerPolicy, Delete the passed object if necessary. This method is used for removal of private owned relationships
        Specified by:
        deleteMapKey in interface MapKeyMapping
        Parameters:
        objectDeleted -
        session -
      • extendPessimisticLockScopeInSourceQuery

        public void extendPessimisticLockScopeInSourceQuery​(ObjectLevelReadQuery sourceQuery)
        INTERNAL: Called only if both shouldExtendPessimisticLockScope and shouldExtendPessimisticLockScopeInSourceQuery are true. Adds fields to be locked to the where clause of the source query. Note that the sourceQuery must be ObjectLevelReadQuery so that it has ExpressionBuilder. This method must be implemented in subclasses that allow setting shouldExtendPessimisticLockScopeInSourceQuery to true.
        Overrides:
        extendPessimisticLockScopeInSourceQuery in class ForeignReferenceMapping
      • extractKeyFromReferenceObject

        protected Object extractKeyFromReferenceObject​(Object object,
                                                       AbstractSession session)
        INTERNAL: Extract the key value from the reference object.
      • getForeignKeyFieldNames

        public Vector getForeignKeyFieldNames()
        PUBLIC: Return the foreign key field names associated with the mapping. These are only the source fields that are writable.
      • getForeignKeysToPrimaryKeys

        protected Map getForeignKeysToPrimaryKeys()
        Return the appropriate map that maps the "foreign keys" to the "primary keys".
      • getIdentityFieldsForMapKey

        public List<DatabaseField> getIdentityFieldsForMapKey()
        INTERNAL: Return the fields that make up the identity of the mapped object. For mappings with a primary key, it will be the set of fields in the primary key. For mappings without a primary key it will likely be all the fields
        Specified by:
        getIdentityFieldsForMapKey in interface MapKeyMapping
        Returns:
      • getOrderedForeignKeyFields

        public Vector getOrderedForeignKeyFields()
        INTERNAL: Return a vector of the foreign key fields in the same order as the corresponding primary key fields are in their descriptor.
      • getPrimaryKeyDescriptor

        protected ClassDescriptor getPrimaryKeyDescriptor()
        Return the descriptor for whichever side of the relation has the "primary key".
      • getPrivateOwnedCriteria

        public Expression getPrivateOwnedCriteria()
        INTERNAL: The private owned criteria is only used outside of the unit of work to compare the previous value of the reference.
      • getSourceToTargetKeyFieldAssociations

        public Vector getSourceToTargetKeyFieldAssociations()
        INTERNAL: Return a collection of the source to target field value associations.
      • getSourceToTargetKeyFields

        public Map<DatabaseField,​DatabaseField> getSourceToTargetKeyFields()
        INTERNAL: Returns the source keys to target keys fields association.
      • getTargetToSourceKeyFields

        public Map<DatabaseField,​DatabaseField> getTargetToSourceKeyFields()
        INTERNAL: Returns the target keys to source keys fields association.
      • getMapKeyTargetType

        public Class getMapKeyTargetType()
        INTERNAL: Return the class this key mapping maps or the descriptor for it
        Specified by:
        getMapKeyTargetType in interface MapKeyMapping
        Returns:
      • initializeForeignKeys

        protected void initializeForeignKeys​(AbstractSession session)
        INTERNAL: The foreign keys primary keys are stored as database fields in the map.
      • initializeForeignKeysWithDefaults

        protected void initializeForeignKeysWithDefaults​(AbstractSession session)
        INTERNAL: The foreign keys primary keys are stored as database fields in the map.
      • initializePrivateOwnedCriteria

        protected void initializePrivateOwnedCriteria()
        INTERNAL: Selection criteria is created with source foreign keys and target keys.
      • buildSelectionCriteria

        public Expression buildSelectionCriteria()
        This method would allow customers to get the potential selection criteria for a mapping prior to initialization. This would allow them to more easily create an amendment method that would amend the SQL for the join.
      • buildSelectionCriteria

        public Expression buildSelectionCriteria​(boolean useParameter,
                                                 boolean usePreviousSelectionCriteria)
        INTERNAL: Build the selection criteria for this mapping. Allows several variations. Either a parameter can be used for the join or simply the database field The existing selection criteria can be built upon or a whole new criteria can be built.
      • rehashFieldDependancies

        public void rehashFieldDependancies​(AbstractSession session)
        INTERNAL: Rehash any map based on fields. This is used to clone descriptors for aggregates, which hammer field names, it is probably better not to hammer the field name and this should be refactored.
        Overrides:
        rehashFieldDependancies in class DatabaseMapping
      • requiresDataModificationEventsForMapKey

        public boolean requiresDataModificationEventsForMapKey()
        INTERNAL: Return whether this mapping requires extra queries to update the rows if it is used as a key in a map. This will typically be true if there are any parts to this mapping that are not read-only.
        Specified by:
        requiresDataModificationEventsForMapKey in interface MapKeyMapping
      • isOneToOneRelationship

        public boolean isOneToOneRelationship()
        Return if this mapping is really for a OneToOne relationship. This is a backward compatibility issue, in that before the ManyToOneMapping was created OneToOneMapping was used for both. false means it may be a OneToOne or a ManyToOne (unknown).
      • isOneToOnePrimaryKeyRelationship

        public boolean isOneToOnePrimaryKeyRelationship()
        Return if this mapping is mapped using primary key join columns.
      • setIsOneToOneRelationship

        public void setIsOneToOneRelationship​(boolean isOneToOneRelationship)
        Define if this mapping is really for a OneToOne relationship. This is a backward compatibility issue, in that before the ManyToOneMapping was created OneToOneMapping was used for both.
      • setIsOneToOnePrimaryKeyRelationship

        public void setIsOneToOnePrimaryKeyRelationship​(boolean isOneToOnePrimaryKeyRelationship)
        Set if this mapping is defined using primary key join columns.
      • setForeignKeyFieldName

        public void setForeignKeyFieldName​(String sourceForeignKeyFieldName)
        PUBLIC: Define the foreign key relationship in the 1-1 mapping. This method is used for singleton foreign key relationships only, that is the source object's table has a foreign key field to the target object's primary key field. Only the source foreign key field name is specified. When a foreign key is specified TopLink will automatically populate the value for that field from the target object when the object is written to the database. If the foreign key is also mapped through a direct-to-field then the direct-to-field must be set read-only.
      • setForeignKeyFieldNames

        public void setForeignKeyFieldNames​(Vector fieldNames)
        PUBLIC: Return the foreign key field names associated with the mapping. These are only the source fields that are writable.
      • setPrivateOwnedCriteria

        protected void setPrivateOwnedCriteria​(Expression expression)
        INTERNAL: Private owned criteria is used to verify the deletion of the target. It joins from the source table on the foreign key to the target table, with a parameterization of the primary key of the source object.
      • setShouldVerifyDelete

        public void setShouldVerifyDelete​(boolean shouldVerifyDelete)
        PUBLIC: Verify delete is used during delete and update on private 1:1's outside of a unit of work only. It checks for the previous value of the target object through joining the source and target tables. By default it is always done, but may be disabled for performance on distributed database reasons. In the unit of work the previous value is obtained from the backup-clone so it is never used.
      • setSourceToTargetKeyFieldAssociations

        public void setSourceToTargetKeyFieldAssociations​(Vector sourceToTargetKeyFieldAssociations)
        INTERNAL: Set a collection of the source to target field associations.
      • setSourceToTargetKeyFields

        public void setSourceToTargetKeyFields​(Map<DatabaseField,​DatabaseField> sourceToTargetKeyFields)
        INTERNAL: Set the source keys to target keys fields association.
      • setTargetForeignKeyFieldName

        public void setTargetForeignKeyFieldName​(String targetForeignKeyFieldName)
        PUBLIC: Define the target foreign key relationship in the 1-1 mapping. This method is used for singleton target foreign key relationships only, that is the target object's table has a foreign key field to the source object's primary key field. The target foreign key field name is specified. The distinction between a foreign key and target foreign key is that the 1-1 mapping will not populate the target foreign key value when written (because it is in the target table). Normally 1-1's are through foreign keys but in bi-directional 1-1's the back reference will be a target foreign key.
      • setTargetToSourceKeyFields

        public void setTargetToSourceKeyFields​(Map<DatabaseField,​DatabaseField> targetToSourceKeyFields)
        INTERNAL: Set the target keys to source keys fields association.
      • shouldVerifyDelete

        public boolean shouldVerifyDelete()
        PUBLIC: Verify delete is used during delete and update outside of a unit of work only. It checks for the previous value of the target object through joining the source and target tables.
      • shouldWriteField

        protected boolean shouldWriteField​(DatabaseField field,
                                           DatabaseMapping.WriteType writeType)
        INTERNAL: By default returns true. Will also return true if: 1 - WriteType is INSERT and the field is insertable. 2 - WriteType is UPDATE and the field is updatable.
      • isCascadedLockingSupported

        public boolean isCascadedLockingSupported()
        INTERNAL Return true if this mapping supports cascaded version optimistic locking.
        Overrides:
        isCascadedLockingSupported in class DatabaseMapping
      • iterateOnMapKey

        public void iterateOnMapKey​(DescriptorIterator iterator,
                                    Object element)
        INTERNAL: Called when iterating through descriptors to handle iteration on this mapping when it is used as a MapKey
        Specified by:
        iterateOnMapKey in interface MapKeyMapping
      • updateInsertableAndUpdatableFields

        protected void updateInsertableAndUpdatableFields​(DatabaseField field)
        INTERNAL: Add the field to the updatable and/or insertable list. Remove any previous field under the same name, otherwise shouldn't matter if we leave an old name (before translation) in the list as it should 'never' be used anyway.
      • writeFromObjectIntoRowInternal

        protected void writeFromObjectIntoRowInternal​(Object object,
                                                      AbstractRecord databaseRow,
                                                      AbstractSession session,
                                                      OneToOneMapping.ShallowMode mode,
                                                      DatabaseMapping.WriteType writeType)
        INTERNAL: Get a value from the object and set that in the respective field of the row. The fields and the values added to the row depend on ShallowMode mode: null - all fields with their values from object; Insert - nullable fields added with value null, non nullable fields added with their values from object; UpdateAfterInsert - nullable fields added with with their non-null values from object, non nullable fields (and nullable with null values) are ignored; UpdateBeforeDelete - the same fields as for UpdateAfterShallowInsert - but all values are nulls.
      • hasRelationTable

        public boolean hasRelationTable()
        PUBLIC: Indicates whether the mapping has RelationTable.
      • getRelationTableMechanism

        public RelationTableMechanism getRelationTableMechanism()
        PUBLIC: Returns RelationTableMechanism that may be owned by the mapping, that allows to configure the mapping to use relation table (just like ManyToManyMapping). By default its null, should be created and set into the mapping before use.
      • setRelationTable

        public void setRelationTable​(DatabaseTable relationTable)
        PUBLIC: Set the relational table. This is the join table that store both the source and target primary keys.
      • setRelationTableMechanism

        public void setRelationTableMechanism​(RelationTableMechanism mechanism)
        PUBLIC: Set RelationTableMechanism into the mapping, that allows to configure the mapping to use relation table (just like ManyToManyMapping).
      • getRelationTable

        public DatabaseTable getRelationTable()
        PUBLIC: Return RelationTable.
      • postInsert

        public void postInsert​(WriteObjectQuery query)
                        throws DatabaseException
        INTERNAL: Insert into relation table. This follows following steps.

        - Extract primary key and its value from the source object.

        - Extract target key and its value from the target object.

        - Construct a insert statement with above fields and values for relation table.

        - execute the statement.

        Overrides:
        postInsert in class ObjectReferenceMapping
        Throws:
        DatabaseException