ALDSP permits customized updates through the use of the update override feature. The update override logic, which is triggered prior to submitting data, can be used for custom data manipulation, update overrides, logging, debugging, or other custom logic needs.
In this lesson, you will write an update override that computes total orders, based on the quantity and price of each order.
After completing this lesson, you will be able to:
An update override, which you assign to a data service, performs custom logic prior to submitting data. The update override is a Java class that implements the com.bea.sdo.mediator.UpdateOverride class. Using that class's performChange (DataGraph graph) method, a Data Graph instance of the current data service is returned. The Data Graph can then be manipulated in using the update override logic.
For example, you can get the CustomerProfileDocument DataObject through the data graph
(CustomerProfileDocument) graph.getRootObject();
You could also get the Change Logging summary through graph.getChangeSummary()
On return of the Data Graph, the following conditions apply:
An update override enables custom manipulation of data within data service.
import com.bea.ld.dsmediator.update.UpdateOverride;
public class CustomerProfileExit implements UpdateOverride
public boolean performChange(DataGraph graph)
The DataGraph passed in the argument contains the current SDO instance with all changes, including the change summary.
CustomerProfileDocument customerDocument =
(CustomerProfileDocument) graph.getRootObject();
Note: | Use BigDecimals for computations. |
Order[] orders = customerDocument.getCustomerProfile().getCustomerArray(0).getOrders().getOrderArray();
for (int x=0; x<orders.length; x++) {
BigDecimal total = new BigDecimal(0);
OrderLine[] items = orders[x].getOrderLineArray();
for (int y=0; y < items.length; y++) {
total = total.add(items[y].getQuantity().multiply(items[y].getPrice()));
}
orders[x].setTotalOrderAmount(total);
}
System.out.println(">>> CustomerProfile.ds Exit completed");
return true;
}
}
Before you can use the update override, you must associate it with a specific data service.
As with any other data service, you should test the update override to ensure that it works properly.
Note: | It may take a few seconds before the information is returned. |
Update Override Reference Code
package CustomerManagement;
import com.bea.ld.dsmediator.update.UpdateOverride;
import commonj.sdo.DataGraph;
import java.math.BigDecimal;
import org.openuri.temp.dataServices.schemas.customerProfile.CustomerProfileDocument;
import org.openuri.temp.dataServices.schemas.customerProfile.CustomerProfileDocument.CustomerProfile.Customer.Orders.Order;
import org.openuri.temp.dataServices.schemas.customerProfile.CustomerProfileDocument.CustomerProfile.Customer.Orders.Order.OrderLine;
public class CustomerProfileExit implements UpdateOverride
{
public boolean performChange(DataGraph graph)
{
CustomerProfileDocument customerDocument = (CustomerProfileDocument) graph.getRootObject();
Order[] orders = customerDocument.getCustomerProfile().getCustomerArray(0).getOrders().getOrderArray();
for (int x=0; x<orders.length; x++) {
BigDecimal total = new BigDecimal(0);
OrderLine[] items = orders[x].getOrderLineArray();
for (int y=0; y < items.length; y++) {
total = total.add(items[y].getQuantity().multiply(items[y].getPrice()));
}
orders[x].setTotalOrderAmount(total);
}
return true;
}
}
In this lesson, you learned how to: