Relationships

User-defined relationships are defined as UserDefinedRelationship objects.

Any object that extends from BaseObject has a method called getUserDefinedRelationships() that returns a List which can have UserDefinedRelationship objects added to it, or removed from it. To make this process easier a number of methods are defined on the BSRSDOHelper that will allow retrieving and setting these relationships easier.

A relationship needs to be added to an instance before it can be retrieved or reset. For example to add a relationship named relatedObjects with a single target object to an instance of a Document, implement the following steps:

	WSDLDocument stockQuote ?.  
	XMLDocument policy

BSRSDOHelper.INSTANCE.addRelationship(stockQuote,"relatedObjects","development");

There are other methods that allow you to add a List rather than a single target object.

Use the following method to retrieve the list of target objects that are associated with a relationship.

List targetObjects = BSRSDOHelper.INSTANCE.getTargetObjects(stockQuote,"relatedObjects");

To add new target objects to the list, you can implement the following steps:

targetObjects.add(newTargetObject);

However, because of the behavior of SDO, which will be explained in the DataGraph section, you must invoke another method on the BSRSDOHelper. There are four methods available. The methods that have a parameter called clearList can be used to add the value passed onto the existing list. The methods that do not have the boolean value will automatically clear the list.

public void setTargetObject(BaseObject instance, String name, BaseObject value, 
 boolean clearList);

public void setTargetObject(BaseObject instance, String name, BaseObject value);

public void setTargetObjects(BaseObject instance, String name, List value, 
 boolean clearList)

public void setTargetObjects(BaseObject instance, String name, List value)

To find out the names of the relationships that exist on the instance, use the following method.

	List propertyNames = BSRSDOHelper.INSTANCE.getRelationshipNames(instance);

To retrieve modelled values on the instances, either use the static methods defined on the object, or cast the object to a DataObject and use the getList() methods.

Note: For user defined relationships, the maximum name length supported is 961 bytes for DB2®, Oracle, and 391 bytes for Microsoft SQL Server. This name length restriction applies to the user defined relationships name only, not to the value.