Home

 

Updating the SDO data graph

An SDO data graph can be modified and the modifications reflected in the source XML file that was loaded. In this example we update the interest rate of one account, add an account, and finally delete an existing account...

Example 10-9 Updating an SDO data graph

// updating the SDO data graph
account1.setString("interest", "10");
DataObject account3 = accountsTypeImpl.createDataObject("account");
account3.setString("accountID", "333333");
account3.set("accountType", AccountTypeType.LOAN_LITERAL);
account3.setString("balance", "999999");
account3.setString("interest", "2.5");
DataObject newCustomerInfo = account3.createDataObject("customerInfo");
newCustomerInfo.setString("firstName", "Mike");
newCustomerInfo.setString("lastName", "Smith");
newCustomerInfo.setString("phoneNumber", "(201) 654-8754");
account2.delete();
System.out.println("\n--- Printing updated XML document ---");
ItsoResourceUtil.getInstance().save(documentRoot, System.out);

The complete code listing of SDOSample.java can be found in the c:\7672code\xml folder.

Select Run Æ Run History Æ SDOSample.

You can see that the interest rate for the first account (accountID = '123456') has been updated, the second account (accountID = '123457') has been removed, and a new account (accountId = '333333') has been added.

Note that the accounts.xml file is not updated because we only saved to the Console.

ibm.com/redbooks