The mapping API provides methods to handle operations on relationship tables for some basic relationships such as lookup and identity relationships.For other relationships, you can create custom relationships by programming the adding and deleting of participants yourself.
How you program the transformation code for a relationship attribute depends on several factors that vary with each execution of the map. You typically structure the code as a series of cases handling each of the possible situations that might occur. The following factors are those you most typically need to consider:
The Relationship and IdentityRelationship classes contain methods for creating relationship instances and adding, deleting, and updating participant instances. The Participant class provides "set" and "get" methods for specifying and retrieving various properties of participant instances.
The following sections provide information on how to manage a custom relationship:
To create a new relationship instance, use the create() or addMyChildren() methods. Both methods create a relationship instance with one new participant instance.
The most common example of creating a new relationship instance is when the verb is Create and the calling context is EVENT_DELIVERY (or ACCESS_REQUEST). In this case, an application generates a "create" event for which a collaboration has subscribed, and the map transforms an application-specific business object to a generic business object. To create a new relationship instance, you must supply the relationship definition name, the participant definition name for the participant you are adding, and the data associated with the participant.
The following code creates a new instance of a relationship called CustIden after a customer is added in the Clarify application. The participant definition representing Clarify is called ClarCust:
instanceId = Relationship.create ("CustIden","ClarCust",appBusObj);
The return value, instanceId, is the instance ID of the new relationship instance.
To create a new participant instance for a relationship, use the addParticipant() method. You typically create a new participant instance when:
The following code adds a new participant instance to a relationship called CustIden. It assumes a verb of Create and a calling context of SERVICE_CALL_RESPONSE. The relID variable contains the ID of the relationship instance to receive the new participant instance.
instanceId = Relationship.addParticipant("CustIden","SAPCust", relID, appBusObj);
To delete a participant instance from a relationship instance, use one of the methods of the Relationship class listed in Table 112.
Relationship method | Description |
---|---|
deleteParticipant() | Deletes all participant instances that match the relationship definition name, participant definition name, and participant data that you specify. |
deleteParticipantByInstance() | Deletes one participant from a specific relationship instance that you specify. |
deactivateParticipant() | Identical to deleteParticipant() except that it leaves a record of the participant in the relationship tables. |
deactivateParticipantByInstance() | Identical to deleteParticipantByInstance() except that it leaves a record of the participant in the relationship tables. |
You typically delete participant instances when the source business object has a verb of Delete and the calling context is either EVENT_DELIVERY (or ACCESS_REQUEST) or SERVICE_CALL_RESPONSE.
Example: The following code assumes a calling context of SERVICE_CALL_RESPONSE and a verb of Delete. It deletes a participant instance representing a Clarify customer from the CustIden relationship.
Relationship.deleteParticipant ("CustIden","ClarCust",appBusObj);