Data Integration

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. You'll need to use threads in order to start both requests at once (or you could write two programs and pass the parameters manually). Make sure that the request which waits for the data is started first.

  1. Create a sink GDS which connects to a MySQL database and a source GDS which connects to a Xindice database.
    sinkGDS = factoryMySQL.createGridDataService();
    sourceGDS = factoryXindice.createGridDataService();
    
  2. Create a new table in the sink database.
    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 );
    sinkGDS.perform( create );
    
  3. Construct another request for the sink with two activities: inputStream (using an InputStream object) and sqlBulkLoadRowSet (using an SQLBulkLoad object). The inputStream will wait for input data from the source GDS and then pass on the data to the sqlBulkLoadRowSet activity.
    InputStreamActivity inputStream = new InputStreamActivity();
    SQLBulkLoad bulkload = new SQLBulkLoad( inputStream.getOutput(), tableName );
    sinkRequest = new ActivityRequest();
    sinkRequest.addActivity( inputStream );
    sinkRequest.addActivity( bulkload );
    
  4. Store the URL of the sink GDS and the inputStream - you will need them later in the source request.
    String sinkGDSHandle       = sinkGDS.getHandle();
    String sinkInputStreamName = inputStream.getName();
    
  5. Now start the sink request in a separate thread before you start the source request. Prepare the thread's run method:
    public void run() {
       try {
          sinkResponse = sinkGDS.perform(sinkRequest);
       } catch ...
    }
    
    And start the new thread:
    Thread sinkThread = new Thread(this, "Sink");
    sinkThread.start();
    
  6. Prepare an XPath query for the source XML database - via xPathStatement (using an XPathQuery object). Since Xindice is quite slow, we will use only the first 1000 entries in the littleblackbook collection.
    XPathQuery query = new XPathQuery("/entry[@id<1000]");
    
  7. Connect the output of the XPathQuery activity object to an XSLTransform activity object in order to transform the resource set format into WebRowSet format (via execution of the xslTransform activity).
    XSLTransform transform = new XSLTransform();
    transform.setXMLInput( query.getOutput() );
    
  8. You can use the XSLT document here to translate the resource set into the WebRowSet format. Deliver the XSLT document from the URL above and connect the input of the transform activity to the delivery's output.
    DeliverFromURL deliver = new DeliverFromURL( url );
    transform.setXSLTInput( deliver.getOutput() );
    
  9. Connect the output of the XSLTransform activity object to the DeliverToGDT activity object's input and set the target of the delivery to the sink GDS, using the URL and inputStream name you stored above.
    DeliverToGDT deliverToGDT = new DeliverToGDT();
    deliverToGDT.setInput( transform.getOutput() );
    deliverToGDT.setGDTGSH( sinkGDSHandle );
    deliverToGDT.setGDTActivityName( sinkInputStreamName );
    deliverToGDT.setGDTMode( GDTMode.BLOCK );
    
  10. Then add all activities to the source request.
    ActivityRequest sourceRequest = new ActivityRequest();
    sourceRequest.addActivity( deliver );
    sourceRequest.addActivity( query );
    sourceRequest.addActivity( transform );
    sourceRequest.addActivity( deliverToGDT );
    
  11. Since you have already started the request at the sink GDS in a separate thread it is ready to receive data. You can now start the source request to kick off processing.
    sourceGDS.perform( sourceRequest );
    

See OGSA-DAI/examples/tutorials/clienttoolkit/DataIntegrationExample.java for the complete code.