Using OGSA-DAI from Groovy (basic)
This tutorial demonstrates how to use the GRIA client API to interact with a GRIA OGSA-DAI Service. The executeUpdate and executeSelect helper methods are used. They take SQL strings as input and return the response document. If data needs to be extracted from the response document then it may be better to use the more advanced techniques shown in the advanced tutorial.
The tutorial code assumes that you already have a single administrative subscription to an SQL database as it creates, updates and queries a table.
import uk.ac.soton.itinnovation.grid.types.ConversationID
import uk.ac.soton.itinnovation.grid.comms.ogsadai.OgsaDaiSubscription
import uk.ac.soton.itinnovation.grid.types.MatchRule
// create proxy to service
ogsadaiService = serviceFactory.createServiceProxy("https://YOUR.SERVICE:PORT/gria-ogsadai-service/services/OgsaDaiServiceI2?wsdl")
// print all resources we can access and (arbitrarily) choose the last subscription
resources = ogsadaiService.getResources()
resources.each {
println(ConversationID.getLabel(it) + ": " + ConversationID.getURLReferenceFromEPR(it))
println(ConversationID.getResourceType(it))
if (ConversationID.getResourceType(it) == "http://www.it-innovation.soton.ac.uk/grid/resource/ogsadai-db-subscription") {
subEPR = it
}
}
println("Choosing this subscription: " + ConversationID.getURLReferenceFromEPR(subEPR))
// create a proxy to the data resource subscription
subscription = proxyFactory.createProxy(subEPR, OgsaDaiSubscription)
// create a MatchRule matching the current user:
myMatchRule = new MatchRule(idp.getIdentity().getMatchPattern(), "owner", false)
createSQL = "CREATE TABLE test (testcol int)"
insertSQL = "INSERT INTO test (testcol) VALUES (42)"
selectSQL = "SELECT * FROM test"
// executeUpdate and executeSelect are convenience methods:
println subscription.executeUpdate(myMatchRule, createSQL)
println subscription.executeUpdate(myMatchRule, insertSQL)
println subscription.executeSelect(myMatchRule, selectSQL)
