One of the features introduced with Data Services Platform (ALDSP) is the ability to write data back to the underlying data sources. This write service is built on top of the Service Data Object (SDO) specification, and provides the ability to update, insert, and delete results returned by a data service. It also provides the ability to submit all changes to the SDO (inserts, deletes, and updates) to the underlying data sources for persisting.
After completing this lesson, you will be able to:
When you update, add, or delete from data service objects, all changes are logged in the SDO's change summary.
Although the steps in the next three exercises are different, the underlying principle is the same: When you update, add, or delete from data service objects, all changes are logged in the SDO's change summary. When the change is submitted, items indicated in the Change Summary log are applied in a transactionally-safe manner, and then persisted to the underlying data source. Changes to relational data sources are automatically applied, while changes to other data services, such as Web services and portals, are applied using a ALDSP update framework.
Customer customer = doc[0].getCustomerProfile().getCustomerArray(0);
customer.setLastName("Smith");
customer.setFirstName("Joe");
System.out.println("Customer Name: " + customer.getLastName() +
", " + customer.getFirstName());
Note: | The Array of function has been deprecated. Ensure that you modify doc.getCustomerProfile().getCustomerArray(0) to doc[0].getCustomerProfile().getCustomerArray(0): |
Note: | At this point, the changes only exist as entries in the SDO Change Summary Log, not in the data source. You must complete the remaining steps in this exercise to ensure that the underlying data source is updated. |
ds.submit(doc);
System.out.println("Change Submitted");
getCustomerProfile(CustomerID)
function.
You can use the Mediator API to add new information to the underlying data source, thereby reducing the need to know a variety of data source APIs.
// Get the order
Order myorder = customer.getOrders().getOrderArray(0);
// Create a new order item
OrderLine newitem = myorder.addNewOrderLine();
You do not need to setOrderID(); the SDO update will automatically set the foreign key to match its parent because the item will be added as a child of ORDER_3_0.
To set the values, insert the following code above the //Show Order Data section of the Java file:
// Fill the values of the new order item
newitem.setLineId("8");
newitem.setProductId("APPA_GL_3");
newitem.setProduct("Shirt");
newitem.setQuantity(new BigDecimal(10));
newitem.setPrice(new BigDecimal(10));
newitem.setStatus("OPEN");
You do this by inserting the following code before the //Show Order Data section of the java file:
// Submit new order item
ds.submit(doc, "ld:DataServices/CustomerManagement/CustomerProfile.ds");
System.out.println("Change Submitted");
You can use the Mediator API to delete information to the underlying data source, thereby reducing the need to know a variety of data source APIs.
// Get the order item
OrderLine myItem = customer.getOrders().getOrderArray(0).getOrderLineArray(4);
Note: | The getOrderLineArray() is based on the item's placement in the array. In this case, 8 is the fifth item, making the variable 4. You should use the variable that is correct for your situation. |
// Delete the order item
myItem.delete();
// Submit delete order item
" ds.submit(doc);
System.out.println("Change Submitted");
In this lesson, you learned how to: