org.intermine.sql
Class Database

java.lang.Object
  extended by org.intermine.sql.Database
All Implemented Interfaces:
Shutdownable

public class Database
extends java.lang.Object
implements Shutdownable

Class that represents a physical SQL database


Field Summary
protected  javax.sql.DataSource datasource
           
protected  java.lang.String driver
           
protected  int parallel
          The number of worker threads to use for background SQL statements
protected  java.lang.String platform
           
protected  java.util.Properties settings
           
 
Constructor Summary
protected Database()
          No argument constructor for testing purposes
protected Database(java.util.Properties props)
          Constructs a Database object from a set of properties
 
Method Summary
protected  void configure(java.util.Properties props)
          Configures a datasource from a Properties object
 void executeSqlInParallel(java.lang.String sql)
          Executes an SQL statement on the database in a separate thread.
 void finalize()
          
 java.lang.String getColumnTypeString(java.lang.Class<?> c)
          Return the SQL type used to store objects of the given Class.
 java.sql.Connection getConnection()
          Gets a Connection to this Database
 javax.sql.DataSource getDataSource()
          Gets the DataSource object for this Database
 java.lang.String getDriver()
          Gets the driver this Database
 java.lang.String getName()
          Gets the database name only, not the full URL.
 java.lang.String getPassword()
          Gets the password for this Database
 java.lang.String getPlatform()
          Gets the platform of this Database
 java.lang.String getURL()
          Gets the URL from this database
 java.lang.String getUser()
          Gets the username for this Database
 void shutdown()
          Logs stuff
 java.lang.String toString()
          
 void waitForCurrentJobs()
          Blocks until all the current pending jobs are finished.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

datasource

protected javax.sql.DataSource datasource

platform

protected java.lang.String platform

driver

protected java.lang.String driver

parallel

protected int parallel
The number of worker threads to use for background SQL statements


settings

protected java.util.Properties settings
Constructor Detail

Database

protected Database()
No argument constructor for testing purposes


Database

protected Database(java.util.Properties props)
            throws java.lang.ClassNotFoundException
Constructs a Database object from a set of properties

Parameters:
props - the properties by which this Database is configured
Throws:
java.lang.ClassNotFoundException - if there is a class in props that cannot be found
Method Detail

getDataSource

public javax.sql.DataSource getDataSource()
Gets the DataSource object for this Database

Returns:
the datasource for this Database

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Gets a Connection to this Database

Returns:
a Connection to this Database
Throws:
java.sql.SQLException - if there is a problem in the underlying database

shutdown

public void shutdown()
Logs stuff

Specified by:
shutdown in interface Shutdownable

finalize

public void finalize()
              throws java.lang.Throwable

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

getPlatform

public java.lang.String getPlatform()
Gets the platform of this Database

Returns:
the datasource for this Database

getDriver

public java.lang.String getDriver()
Gets the driver this Database

Returns:
the driver for this Database

getUser

public java.lang.String getUser()
Gets the username for this Database

Returns:
the username for this Database

getPassword

public java.lang.String getPassword()
Gets the password for this Database

Returns:
the password for this Database

getURL

public java.lang.String getURL()
Gets the URL from this database

Returns:
the URL for this database

getName

public java.lang.String getName()
Gets the database name only, not the full URL.

Returns:
the database name

configure

protected void configure(java.util.Properties props)
                  throws java.lang.ClassNotFoundException
Configures a datasource from a Properties object

Parameters:
props - the properties for configuring the Database
Throws:
java.lang.ClassNotFoundException - if the class given in the properties file cannot be found
java.lang.IllegalArgumentException - if the configuration properties are empty
java.lang.NullPointerException - if props is null

getColumnTypeString

public java.lang.String getColumnTypeString(java.lang.Class<?> c)
Return the SQL type used to store objects of the given Class. eg. return "double precision" for Double.class

Parameters:
c - the Class representing the java type
Returns:
the SQL type

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

executeSqlInParallel

public void executeSqlInParallel(java.lang.String sql)
                          throws java.sql.SQLException
Executes an SQL statement on the database in a separate thread. A certain number of worker threads controlled by the "parallel" property will operate simultaneously.

Parameters:
sql - an SQL string.
Throws:
java.sql.SQLException - if an error has been reported by a previous operation - however, this does not cancel the current operation.

waitForCurrentJobs

public void waitForCurrentJobs()
                        throws java.sql.SQLException
Blocks until all the current pending jobs are finished. This will not block new jobs from arriving, and those new jobs do not need to be finished for this method to return.

Throws:
java.sql.SQLException - if an error has been reported by a previous operation