Exporting and Importing Relationships
AwareIM can export and import not only simple attributes of business objects but also reference attributes that represent relationships between business objects. When values of reference attributes are exported AwareIM writes out the following information:
- For single references the name and the value of the ID attribute of the referred instance is exported. The name and ID are separated by the “#” symbol.
- Values of all “multiple” references of the object are written into a separate file called the relationships file. Each record in the file includes the ID of the reference owner (see ID attribute), the name of the referred instance, the ID of the referred instance and the name of the reference attribute.
Importing relationships is arguably most useful when importing data from other systems as described in scenario 3 of the Export and Import section. Relationships of a business object are represented in the import file by values of one or several attributes in each record. The first record in the import file contains names of the imported attributes; the names of reference attributes must include the name of the reference attribute and the name of some attribute in the referred object – for example, Account.Owner.FirstName. When AwareIM imports a record containing relationships it reads attribute values representing a relationship and uses these values to find the instance of the referred object in the database. Values of reference attributes must point to only one instance of the referred object (in other words, these attributes must uniquely identify the instance) – for example, values of attributes Account.Owner.FirstName and Account.Owner.LastName uniquely identify the owner of the account. If AwareIM finds the single instance of the referred object in the database it associates this instance with the imported instance through the specified reference attribute (Account.Owner in the above example). If AwareIM finds more than one instance of the referred object it does not import the relationship and adds an error record into the import log.
It is possible that referred instances have not been imported into the system yet, so AwareIM does not find any instance of the referred object from the values of the reference attribute. In this case AwareIM creates a relationship file where it writes the ID of the reference owner and the values of the reference attributes. Later on, when referred instances have been imported into the system, this relationship file can be re-imported to recreate the relationships.
For example, let us assume that we are importing accounts of the account owners. The Customer object is referenced by the Account.Owner attribute and an instance of the owner is identified by the Account.Owner.FirstName and Account.Owner.LastName attributes. Let us assume that we are importing a single record representing a new instance of the Account object. The record has the following values:
| Account.Date | Account.Balance | Account.Owner.FirstName | Account.Owner.LastName |
|---|---|---|---|
| 22/06/2004 | 1000 | John | Smith |
When AwareIM imports this record it creates a new instance of the Account object with the value of the Date attribute equal to 22/06/04 and the value of the Balance attribute equal to 1000. Account.Owner.FirstName and Account.Owner.LastName represent a relationship of the account, so AwareIM tries to find the instance of the Customer object with the value of the FirstName attribute equal to “John” and the value of the LastName attribute equal to “Smith”. If it finds such an instance it creates a relationship between the new instance of the Account object and the found instance of the Customer object. If AwareIM does not find the instance of the Customer object with these values it writes the following record into the relationship file (here we assume that the value of the ID attribute of the new Account object automatically assigned by AwareIM is 1734):
| Account.ID | Account.Owner.FirstName | Account.Owner.LastName |
|---|---|---|
| 1734 | John | Smith |
Once the instance of the Customer object representing John Smith has been imported into the system we can import the above relationship file created when importing accounts. This time AwareIM will find the instance of the Customer object representing John Smith and create a relationship between the account with ID 1734 and this instance.