skip to main content
OpenEdge Development: AppBuilder
Data-Access Objects : SmartBusinessObject
 
SmartBusinessObject
The SBO allows you to neatly package and fully synchronize—including the ability to update in a single, server-side transaction—up to twenty SDOs. Figure 27 illustrates the place of an SBO in a Web-enabled application.
Figure 27: SBO in a Web environment
Each static SDO produces and manages a single data stream. The nature and composition of that data stream is dependent on the query that you define within the object. Although you can cause a single SDO to produce a data stream of great complexity by the skillful use of JOINs, the result is often messy and difficult to use for business purposes.
One way to reduce complexity is to create a number of SDOs, each with a more simple query, and then synchronize them at the application level. For example, you might create five SDOs that respectively supply:
1. Customer records
2. Order records for a particular Customer
3. OrderLine records from a particular Order
4. Item records related to a particular OrderLine
5. Inventory records related to a particular OrderLine
Figure 28 illustrates these relationships.
Figure 28: Data relationship among five tables
Synchronizing their read operations is not difficult. You can use DATA SmartLinks for that purpose regardless of whether you use an SBO.
The difficult task is synchronizing updates. In general, there is no simple way to update multiple, standalone SDOs in a single transaction, if the objects run in a distributed environment. Such objects operate independently of one another on an AppServer.
The new SBO solves this problem by providing a single context for all the SDOs you embed in it. Because the code you write in the SBO can operate on all the RowObject temp-tables belonging to its subordinate SDOs, the SBO allows you to perform updates in a single server-side transaction. With the SBO, you can create and manage integrated data streams that are as complex and powerful as your customers’ business needs demand.
The SBO presents a single point of contact for external modules such as Smart data-display objects. Internally, it uses its CONTAINER links to connect those external objects with the SDOs it contains—communicating navigation instructions from a SmartPanel, for example, or sending data out to a SmartDataViewer for visualization. This all happens automatically; you need do nothing to make it work. The SDOs synchronize themselves using DATA links that you create.
Creating and placing a SmartBusinessObject
The SBO is a special-purpose organizer object and a member of the class SmartContainer. As is true of other organizer objects, the SBO is supplied as a nearly finished template. There is no wizard involved; you need only create a copy, populate it, and add SmartLinks.
Caution: The SBO only supports static SDOs. If it cannot find the client-side (_cl) files at run time, it will not be able to use the dynamic SDO and will report an error when it fails to start up successfully.
To create an SBO master:
1. Click the SmartBusinessObject in the Object Palette. The Choose dialog box appears.
2. Click New. AppBuilder creates the appropriate workspace, which looks like a frameless SmartWindow. Because an SBO has no frame element, you will see no layout grid even if you have grid visibility turned on:
3. Populate the object and configure it. See the “Populating and configuring a SmartBusinessObject” section for more detailed information. Save the object using a distinctive filename. Note that SBO names conventionally begin with sbo.
4. Click the SmartContainer tool icon in the Object Palette. When the Selection dialog box opens, select the SBO master you just defined.
5. Move your mouse cursor over your application workspace and click to place the new object instance.
6. If you have already placed other SmartObjects such as a SmartDataBrowser, an Advisor might now appear and offer to create SmartLinks between those objects and the new SBO. Examine the offers and accept those that meet your needs.
7. If the Advisor does not offer to create all the links you desire, choose ToolsProcedure Settings and open the SmartLinks Editor to add links by hand. For information about the SmartLinks Editor, see the “SmartLinks editor” section.
8. Save your work.
Populating and configuring a SmartBusinessObject
You must complete the following major tasks when configuring your SBO master:
1. Determine what data this object will supply and decide how you will divide the total effort.
In general, consider using one SDO per table. You can populate your SBO with a maximum of twenty SDOs.
2. Create and place the SDOs, add DATA links to represent the logical dependencies among them, and identify the foreign-field (relational) mappings.
For detailed information about creating and placing SDOs, see the “Synchronizing SmartDataObjects using DATA links” section.
3. Determine whether the users of your application are more likely to prefer efficiency or completeness when browsing the data stream and set the property CascadeOnBrowse accordingly. This is a somewhat subtle issue.
4. Determine your validation needs and create the appropriate routines to perform those tests.
The SBO makes it easier to perform comprehensive validation tests. Besides the tests local to each SDO, you can write validation routines that run in the SBO itself. The SBO can see the Update tables belonging to each of its contained SDOs and you can take advantage of that fact to create whole-stream validation.
Within the SDOs themselves, their update tables all have the same RowObjUpd identifier. Since they have separate namespaces internally, this is not a problem. But at the level of the SBO, each such update table needs a unique name. The ObjectName property serves that purpose.
So if your SBO contains two SDOs to which you have given the ObjectNames CustSDO and OrderSDO, you can write code referring to fields in their respective RowObjUpd tables as CustSDO.SomeFieldName and OrderSDO.SomeFieldName and everything will work as you intend.
For additional information about creating validation routines, see OpenEdge Development: ADM and SmartObjects.
Synchronizing SmartDataObjects using DATA links
To get the benefits the SBO can provide, you must identify the business hierarchy between the contained SDOs. You do this using SmartLinks of type DATA. The DATA-SOURCE is always the object that initiates a change and the DATA-TARGET is the object that must respond by staying in sync.
In the situation shown in Figure 28, you would create DATA links from the Customer object to the Order object, from Order to OrderLine, and from OrderLine to both Item and Inventory.
Figure 29 shows the hierarchy imposed by the DATA links.
Figure 29: Resynchronization hierarchy defined by DATA SmartLinks
Before deciding how to organize your DATA links, determine your business focus. If you are interested in both Customer and Order records, which are more central? Are you interested in orders only in connection with a particular customer? Or is your focus the order itself, with customer information being secondary? In the first case, you would create your DATA link from the Customer object to the Order object. In the second case, the link would go in the opposite direction. How you organize the dependencies is a function of your business goals.
Note: The SBO itself can be the target of a DATA link from some SDO outside itself. The effect when resynchronization takes place is exactly as though both objects were combined—the resynchronization process propagates through both objects.
To create a synchronizing relationship between two SDOs within the SBO:
1. Create and place the first (controlling) object.
2. Create the second (controlled) object, being sure to include at least one field shared with the first object. For example, the CustNum field is common to both the Customer table and the Order table. That field (the foreign field) relates those two tables. Note that the field need not have the same name in both tables, although it often does.
3. Place the second object. An Advisor dialog box appears and offers to create a DATA link from the first object. Accept the offer, as shown:
4. Another Advisor dialog box appears asking you if you wish to identify the foreign-field (relational) mapping. Unless you have a reason to defer this operation, accept this offer as shown:
5. The Multi-Field Mapping dialog box appears showing the lists of available fields. Select the field common to both tables, for example CustNum, as shown:
6. Click Map. Your selections disappear from the Source and Target lists and reappear as an associated pair in the Mapped Fields field, as shown:
7. Create additional associations, if you so desire and there are suitable field pairs. When you have finished, click OK to close the dialog box. Synchronization between these two SDOs is now established.
8. Repeat from Step 2 for each additional SDO you place, creating a synchronizing DATA link only from the immediately preceding object.
Note: The Advisor is not aware of your goal, so it will offer to create a link from any existing object. It is easy to become confused and select the wrong object. If you make such a mistake, use the SmartLinks Editor to correct it.
9. When you have linked all the SDOs appropriately, save your work.
If you were to create the relationships shown in Figure 29, they would appear in the SmartLinks Editor looking similar to the following:
Configuring a SmartBusinessObject instance
Configuration options are found on the SmartBusinessObject menu.
To configure the properties once you have populated and created the synchronizing relationships in your SBO:
1. Right-click on the instance and choose Properties. The Property Sheet dialog box appears:
2. Change the object identifier to more accurately reflect the role of this SBO in your application.
3. If you wish to use the object as a placeholder, check the Parameterize as Variable box. See the “Creating a SmartObject placeholder” section for further information about placeholders and resolving them at run time.
4. Click OK to close the dialog box. Right-click on the instance and choose Properties. The following dialog box appears:
5. Select the Partition this object will be assigned to when running on an AppServer.
If there are no partitions listed, you can define as many as you need. Close the dialog box and use the AppServer Service Parameter Maintenance Tool, available from the PRO*Tools toolbar. The Partition tags that you define in this way are immediately made available to AppBuilder and will appear in this list when you reopen this dialog box.
6. Use the MoveUp/MoveDown buttons to arrange the list of SDO names to agree with the synchronization hierarchy you have defined. The first object (Customer, in the example shown in Figure 29) must be at the top of the list. The order of objects at the same level (in Figure 29, Item and Inventory are at the same level) is not significant.
7. Click OK and save your work.