The classic OGSA-DAI data integration scenario deals with the issue of performing a SQL join operation between tables in two different databases. In this page, you will learn how to join a set of XML documents from an XML database with a relational table.
This page will guide you through the following steps:
Below you will find an example solution.
String handle = "http://localhost:8080/wsrf/services/ogsadai/DataService"; String sinkID = "MySQLResource"; String sourceID = "ExistResource"; DataService sinkService = GenericServiceFetcher.getInstance().getDataService(handle, sinkID); DataService sourceService = GenericServiceFetcher.getInstance().getDataService(handle, sourceID);
String tableName = "mytable"; String createTable = "create table if not exists " + tableName + " (id INTEGER, name VARCHAR(64), " + "address VARCHAR(128), phone VARCHAR(20))"; SQLUpdate create = new SQLUpdate( createTable ); sinkService.perform( create );
Session session = sourceService.createSession();
XPathQuery query = new XPathQuery("/entry[@id<500]");
XSLTransform transform = new XSLTransform(); transform.setXMLInput( query.getOutput() );
DeliverFromURL deliver = new DeliverFromURL( url ); transform.setXSLTInput( deliver.getOutput() );
DTOutputStream outputStream = new DTOutputStream(); outputStream.setInput(transform.getOutput());
ActivityRequest sourceRequest = new ActivityRequest(); sourceRequest.add( deliver ); sourceRequest.add( query ); sourceRequest.add( transform ); sourceRequest.add( outputStream );and join the existing session that we created earlier:
sourceRequest.setSessionRequirements(new JoinExistingSession(session));
sourceService.perform( sourceRequest );
DeliverFromDT deliverFromDT = new DeliverFromDT(); deliverFromDT.setDataTransportInput(outputStream.getDataTransport()); deliverFromDT.setDataTransportMode( DataTransportMode.BLOCK ); SQLBulkLoad bulkload = new SQLBulkLoad( deliverFromDT.getOutput(), tableName ); ActivityRequest sinkRequest = new ActivityRequest(); sinkRequest.add( deliverFromDT ); sinkRequest.add( bulkload );
sinkService.perform(sinkRequest);
bulkload.getInsertedRowsCount();
For a complete example, see OGSA-DAI/examples/src/uk/org/ogsadai/examples/clienttoolkit/DataIntegrationExample.java
Back: Asynchronous Delivery | Up: Using the Client Toolkit | |
© International Business Machines Corporation, 2002-2006 | © The University of Edinburgh, 2002-2006 |