We can automatically figure out whether rows need to be updated or inserted from the XML message, but for delete we need an additional hint. This hint is the bc4j-action attribute. In the following simple example we read the XML message from a local String variable, then pass it to ViewObject.readXML. Notice the bc4j-action='remove' attribute on the <EmployeesRow> to indicate that we want that row to be deleted. At a minimum, the element representing the primary key attribute of the row -- in this case <Empno> -- must be present in the message to know which row to act on. In general, the XML message can have any number of elements which can represent inserts, updates, and deletes (with the appropriate bc4j-action='remove' marker), even at multiple levels of nesting. Here's the sample code.
package test; import java.io.StringReader; import oracle.jbo.ApplicationModule; import oracle.jbo.ViewObject; import oracle.jbo.client.Configuration; import oracle.xml.parser.v2.DOMParser; import org.w3c.dom.Element; public class TestClient { private static final String XML = "<Employees>"+ " <EmployeesRow bc4j-action='remove'>"+ " <Empno>7839</Empno>"+ " </EmployeesRow>"+ "</Employees>"; public static void main(String[] args) throws Throwable { String amDef = "test.TestService"; String config = "TestServiceLocal"; ApplicationModule am = Configuration.createRootApplicationModule(amDef,config); ViewObject vo = am.findViewObject("EmpView"); /* * Parse the XML string into an XMLDocument */ DOMParser d = new DOMParser(); d.parse(new StringReader(XML)); Element e = d.getDocument().getDocumentElement(); /* * Have the VO read the XML message and act on it */ vo.readXML(e,-1); am.getTransaction().commit(); Configuration.releaseRootApplicationModule(am,true); } }
9:29:24 AM
|
|