Banner
Title: OGSA-DAI Advanced Practical
Subtitle: Search for Mountains
Tutors: Amy Krause, Tom Sugden
Authors: The OGSA-DAI Team

Introduction

In this advanced tutorial, we will prepare to search an area around a given set of coordinates. The locations of mountains on a surface are stored in an OGSA-DAI enabled database. The database contains a set of coordinates and names for mountains. In this practical, you will extend the GT4 client to select a set of starting points from the database.

Top

Extracting Locations from a Data Service

The solutions for the GT4 advanced practical (session 19) is now available on the GT4 notes page. You can use this client as the starting point for the following exercises. You may also use a client you have developed yourself during the practical.

The aim of this exercise is to integrate an OGSA-DAI client which queries the database with the FileStore and sequence generating clients developed in the previous GT4 exercise. First the location coordinates of mountains on a surface are retrieved from a database of which you can find details below. Then, using the sequence generator and cross product services, create a rectangle with regular or random points covering the area around those coordinates and store it in the FileStore service.

The data is available via an OGSA-DAI data service at the following URL:

http://ogsadai:8080/wsrf/services/ogsadai/DataService

The data resource name is MountainData representing a relational database.

The table is called Mountains and has two columns, the x and y coordinates of points on the surface. Each row represents a point which is the tip of a mountain on the surface. The corresponding SQL statement for selecting all rows from the table is as follows:

SELECT x_coord, y_coord FROM Mountains

To make things simpler, you can implement a stand-alone client first which queries the data resource and returns a list of coordinates. Create a method called getCoordinates which returns a List object.

First, you need to create a service object. The GenericServiceFetcher will do this for you. It's the same method as you have used in the introductory practical. You have to provide the data service URL and the resource name. Then you create a new SQLQuery object with the SQL query string as above:

SQLQuery query = new SQLQuery("SELECT x_coord, y_coord FROM Mountains");

The results of this query must now be serialised into CSV or WebRowSet so they can be included in the response to your request. Instantiate a WebRowSet object and connect its input to the output of the above SQLQuery.

WebRowSet webrowset = new WebRowSet(query.getOutput());

Now add both activities to your ActivityRequest and perform the request on the data service! When the perform method returns you can retrieve the results as a java.sql.ResultSet from the WebRowSet object.

ResultSet resultset = webrowset.getResultSet();

The ResultSet interface allows you to scroll through the results by calling ResultSet.next(). This method advances the current row within the result set and returns true if the next row exists. After calling next() you can retrieve values from the row. For example, use ResultSet.getDouble(1) to get the value of the first column in the current row as a double.

When you compile your Java code, make sure that all the GT4 exercise JARs are on the classpath as well as the OGSA-DAI JARs. For example, copy the GT4 exercise JARs into the OGSA-DAI third-party library directory and then run setenv.sh to set up the classpath.

Top

Further Reading

If you have finished the introductory and advanced tutorials and are interested in gaining more experience with OGSA-DAI, a more comprehensive tutorial is available on the OGSA-DAI webpage at Client Toolkit Tutorial.

Top

OGSADAI

Top