Business Objects and Data Sources > Data Sources > Defining Business Object Relationships

Business object relationships, such as links or containment, are defined in the data source using the following methods:

How to Define Parent-Child Relationships between Business Objects

The following example illustrates the use of the methods setParent and setChildren in a default data source.

IlpObject parent = new IltNetworkElement("NE1");
IlpObject child = new IltNetworkElement("NE1_1");
dataSource.setParent(child, parent);
dataSource.addObject(child);
dataSource.addObject(parent);

or

IlpObject parent = new IltNetworkElement("NE1");
IlpObject child1 = new IltNetworkElement("NE1_1");
IlpObject child2 = new IltNetworkElement("NE1_2");
IlpObject child3 = new IltNetworkElement("NE1_3");
List children = new ArrayList();
children.add(child1);
children.add(child2);
children.add(child3);
dataSource.setChildren(parent, children);
dataSource.addObjects(children);
dataSource.addObject(parent);
How to Define a Link between Business Objects

The following example illustrates the use of the method setLink in a default data source.

IlpObject fromEnd = new IltNetworkElement("NE1");
IlpObject toEnd = new IltNetworkElement("NE2");
IlpObject link = new IltLink("NE1<->NE2");
 
dataSource.setLink (link, fromEnd, toEnd);
List objects = new ArrayList();
objects.add(fromEnd);
objects.add(toEnd);
dataSource.addObjects(objects);
dataSource.addObject(link);

Whenever possible, first add all end-point objects to the data source, then add the corresponding link objects. This avoids internal checks and temporary object storage to properly create and arrange the object hierarchy.

To improve the data source and component performance, it is also recommended to avoid changing relationships after the objects have been added to the data source. For example:

Less Efficient:

dataSource.addObject(object);
dataSource.setParent(object, parent);

More Efficient:

dataSource.setParent(object, parent);
dataSource.addObject(object);
How to Define an Intergraph Link

JViews TGO is able to display links connecting objects in different hierarchies. These links are known as intergraph links. To have an intergraph link properly displayed, you need to take care of how the link object is created in the data source, specially at which hierarchy level the link object is added.

To illustrate an intergraph link use case, let's imagine the following object hierarchy:

images/ObjectHierarchyExample3.gif

Figure 3.3 Object Hierarchy

Suppose you wanted to create a link connecting Leaf A and Leaf B. You would have to add it to the data source in the following way:

ArrayList objects = new ArrayList();
IltNetworkElement net = new IltNetworkElement("Network");
net.setName("Network");
 
IltNetworkElement branchA = new IltNetworkElement("BranchA");
branchA.setName("A");
IltNetworkElement branchB = new IltNetworkElement("BranchB");
branchB.setName("B");
 
objects.add(net);
objects.add(branchA);
objects.add(branchB);
 
dataSource.setParent(branchA, net);
dataSource.setParent(branchB, net);
 
IltNetworkElement leafA = new IltNetworkElement("LeafA");
leafA.setType(IltNetworkElement.Type.NMW);
leafA.setPosition(new IlpPoint(100,100));
leafA.setName("Leaf A");
IltNetworkElement leafB = new IltNetworkElement("LeafB");
leafB.setType(IltNetworkElement.Type.NMW);
leafB.setPosition(new IlpPoint(250,250));
leafB.setName("Leaf B");
 
dataSource.setParent(leafA, branchA);
dataSource.setParent(leafB, branchB);
objects.add(leafA);
objects.add(leafB);
 
// Creating the intergraph link
IltLink link = new IltLink("LeafA-LeafB");
link.setName("LeafA-LeafB");
dataSource.setLink(link, leafA, leafB);
// Setting the link hierarchy level
dataSource.setParent(link, net);
objects.add(link);
dataSource.addObjects(objects);

The intergraph link should be placed at the highest hierarchy level common to both end points. This is illustrated in the example above where the link is set as a child of the "network" business object.

How to Retrieve Business Object Structural Information

The current implementation of IltDefaultDataSource handles structural information, such as child-parent relationships described earlier, pertaining to IlpObject instances independently of the objects themselves. This implementation makes it possible for you to load objects on demand. See How to Implement Load-on-Demand in a Data Source for more information.

The strucutral information is defined in JViews TGO through the following interfaces:

The default data source implementation provides the following methods to retrieve each one of these interfaces:

Besides, you can use the following convenience methods to retrieve the structural information. But note that these methods return the structural information based on the fact that the queried business objects are all present in the data source. (If this is not the case, you should retrieve the structural information using the above listed interfaces.)