org.embl.ebi.escience.baclava.store
Class JDBCBaclavaDataService

java.lang.Object
  extended by org.embl.ebi.escience.baclava.store.JDBCBaclavaDataService
All Implemented Interfaces:
LSIDProvider, BaclavaDataService

public class JDBCBaclavaDataService
extends java.lang.Object
implements BaclavaDataService, LSIDProvider

An implementation of the BaclavaDataService that backs its data with a JDBC based relational database.

Author:
Tom Oinn, Stuart Owen

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.embl.ebi.escience.baclava.LSIDProvider
LSIDProvider.NamespaceEnumeration
 
Field Summary
static java.lang.String TAVERNA_DATASTORE_JDBC_DRIVER
           
static java.lang.String TAVERNA_DATASTORE_JDBC_PASSWORD
           
static java.lang.String TAVERNA_DATASTORE_JDBC_URL
           
static java.lang.String TAVERNA_DATASTORE_JDBC_USER
           
 
Fields inherited from interface org.embl.ebi.escience.baclava.LSIDProvider
DATATHINGCOLLECTION, DATATHINGLEAF, WFDEFINITION, WFINSTANCE
 
Constructor Summary
JDBCBaclavaDataService()
          Create a new JDBC backed BaclavaDataService with properties taken from the current set of system properties.
JDBCBaclavaDataService(java.util.Properties props)
          Create a new JDBC backed BaclavaDataService with the supplied properties.
 
Method Summary
 DataThing fetchDataThing(java.lang.String LSID)
          Fetch a DataThing from the given LSID
 java.lang.String fetchWorkflow(java.lang.String LSID)
           
 java.lang.String getID(LSIDProvider.NamespaceEnumeration namespaceObject)
          Implement LSIDProvider
 java.lang.String getMetadata(java.lang.String LSID)
          Get the metadata associated with this LSID
 java.lang.String getMIMEType(java.lang.String LSID)
          Get the raw mime type for the datathing form of this LSID or null if the node references isn't a leaf or doesn't exist.
 boolean hasData(java.lang.String suppliedLSID)
          Does the given LSID exist in a concrete form?
 boolean hasMetadata(java.lang.String LSID)
          Does the given LSID have associated metadata? Always returns false at present.
 boolean hasWorkflow(java.lang.String LSID)
          public void storeWorkflow(ScuflModel model) { Connection con = null; PreparedStatement pstmt = null; String LSID = model.getDescription().getLSID(); String title = model.getDescription().getTitle(); String author = model.getDescription().getAuthor(); String xml = XScuflView.getXMLText(model); try { boolean exists = hasWorkflow(LSID); con = pool.borrowConnection(); if (exists) { pstmt = con.prepareStatement("UPDATE workflow SET title=?, workflow=?, author=? WHERE lsid=?"); } else { pstmt = con.prepareStatement("INSERT INTO workflow (title,workflow,author,lsid) VALUES (?,?,?,?)"); } pstmt.setString(1, title); pstmt.setString(2, xml); pstmt.setString(3, author); pstmt.setString(4, LSID); pstmt.executeUpdate(); con.commit(); } catch (SQLException e) { log.error("SQLException when storing workflow for LSID=" + LSID, e); } finally { if (con != null) pool.returnConnection(con); if (pstmt != null) { try { pstmt.close(); } catch (SQLException e) { log.error("Error closing prepared statement", e); } } } }
 void reinit()
          Drop and recreate the tables
 void storeDataThing(DataThing theDataThing, boolean silent)
          Store the specified data object
 void storeMetadata(java.lang.String theMetadata)
          Store some metadata
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TAVERNA_DATASTORE_JDBC_DRIVER

public static final java.lang.String TAVERNA_DATASTORE_JDBC_DRIVER
See Also:
Constant Field Values

TAVERNA_DATASTORE_JDBC_PASSWORD

public static final java.lang.String TAVERNA_DATASTORE_JDBC_PASSWORD
See Also:
Constant Field Values

TAVERNA_DATASTORE_JDBC_USER

public static final java.lang.String TAVERNA_DATASTORE_JDBC_USER
See Also:
Constant Field Values

TAVERNA_DATASTORE_JDBC_URL

public static final java.lang.String TAVERNA_DATASTORE_JDBC_URL
See Also:
Constant Field Values
Constructor Detail

JDBCBaclavaDataService

public JDBCBaclavaDataService()
Create a new JDBC backed BaclavaDataService with properties taken from the current set of system properties.


JDBCBaclavaDataService

public JDBCBaclavaDataService(java.util.Properties props)
Create a new JDBC backed BaclavaDataService with the supplied properties.

Method Detail

reinit

public void reinit()
Drop and recreate the tables


getID

public java.lang.String getID(LSIDProvider.NamespaceEnumeration namespaceObject)
Implement LSIDProvider

Specified by:
getID in interface LSIDProvider

storeMetadata

public void storeMetadata(java.lang.String theMetadata)
Store some metadata

Specified by:
storeMetadata in interface BaclavaDataService

storeDataThing

public void storeDataThing(DataThing theDataThing,
                           boolean silent)
                    throws DuplicateLSIDException
Store the specified data object

Specified by:
storeDataThing in interface BaclavaDataService
Parameters:
theDataThing - DataThing object to store
silent - whether to throw exceptions if duplicate LSID values are found. If set to false then the storage operation will fail under this condition, if set to true then the store will always succeed, but duplicate LSID values will not be stored. This is potentially useful when a DataThing is a composition of some previously stored entities and some new ones, effectively setting silent to true allows these new data to be stored and the duplicates safely ignored.
Throws:
DuplicateLSIDException - if an LSID in the DataThing is already held in the store and the silent parameter is set to false

fetchDataThing

public DataThing fetchDataThing(java.lang.String LSID)
                         throws NoSuchLSIDException
Fetch a DataThing from the given LSID

Specified by:
fetchDataThing in interface BaclavaDataService
Parameters:
LSID - a URI referencing an object within a previously stored DataThing contained by the backing store.
Returns:
the DataThing object constructed from the data within the specified LSID.
Throws:
NoSuchLSIDException - if the LSID is not found within the store.

hasData

public boolean hasData(java.lang.String suppliedLSID)
Does the given LSID exist in a concrete form?

Specified by:
hasData in interface BaclavaDataService

getMIMEType

public java.lang.String getMIMEType(java.lang.String LSID)
Get the raw mime type for the datathing form of this LSID or null if the node references isn't a leaf or doesn't exist.


getMetadata

public java.lang.String getMetadata(java.lang.String LSID)
Get the metadata associated with this LSID

Specified by:
getMetadata in interface BaclavaDataService

hasMetadata

public boolean hasMetadata(java.lang.String LSID)
Does the given LSID have associated metadata? Always returns false at present.

Specified by:
hasMetadata in interface BaclavaDataService

hasWorkflow

public boolean hasWorkflow(java.lang.String LSID)
public void storeWorkflow(ScuflModel model) { Connection con = null; PreparedStatement pstmt = null; String LSID = model.getDescription().getLSID(); String title = model.getDescription().getTitle(); String author = model.getDescription().getAuthor(); String xml = XScuflView.getXMLText(model); try { boolean exists = hasWorkflow(LSID); con = pool.borrowConnection(); if (exists) { pstmt = con.prepareStatement("UPDATE workflow SET title=?, workflow=?, author=? WHERE lsid=?"); } else { pstmt = con.prepareStatement("INSERT INTO workflow (title,workflow,author,lsid) VALUES (?,?,?,?)"); } pstmt.setString(1, title); pstmt.setString(2, xml); pstmt.setString(3, author); pstmt.setString(4, LSID); pstmt.executeUpdate(); con.commit(); } catch (SQLException e) { log.error("SQLException when storing workflow for LSID=" + LSID, e); } finally { if (con != null) pool.returnConnection(con); if (pstmt != null) { try { pstmt.close(); } catch (SQLException e) { log.error("Error closing prepared statement", e); } } } }


fetchWorkflow

public java.lang.String fetchWorkflow(java.lang.String LSID)