gov.usda.gdpc.database
Class AbstractJDBCConnection

java.lang.Object
  extended bygov.usda.gdpc.AbstractDBConnection
      extended bygov.usda.gdpc.database.AbstractJDBCConnection
All Implemented Interfaces:
DBConnection
Direct Known Subclasses:
PanzeaDBConnection

public abstract class AbstractJDBCConnection
extends AbstractDBConnection
implements DBConnection

This class provides a skeletal implementation of the DBConnection interface which should be used as a connection to a database via JDBC.

To implement a jdbc database connection, the programmer needs to extend this class and provide implementations for the following methods defined in the DBConnection interface:



Author:
terryc

Field Summary
protected  java.sql.Connection myConnection
          The handle to the connection
protected  java.lang.String myDriver
          The jdbc driver
protected  char[] myPassword
          The user's password
protected  java.lang.String myUID
          The database user on whose behalf the connection is being made
protected  java.lang.String myURL
          The database url of the form jdbc:subprotocol:subname
 
Fields inherited from class gov.usda.gdpc.AbstractDBConnection
myDataSource, myDescription
 
Constructor Summary
AbstractJDBCConnection(java.lang.String dataSource, java.lang.String description, java.lang.String driver, java.lang.String url, java.lang.String uid, char[] passwd)
          AbstractJDBCConnection Constructor.
AbstractJDBCConnection(java.lang.String dataSource, java.lang.String description, java.lang.String driver, java.lang.String url, java.lang.String uid, java.lang.String passwd)
          AbstractJDBCConnection Constructor.
 
Method Summary
 void close()
          Close the database connection.
 boolean equals(java.lang.Object obj)
          This determines if two database connections are equal.
protected  java.sql.ResultSet executeQuery(java.lang.String statement)
          This executes the specified select statement.
protected  java.sql.ResultSet executeQueryNoScroll(java.lang.String statement)
           
 java.lang.String getDriver()
          Returns the jdbc driver.
static java.lang.String getInString(int[] list)
          This returns a string generated from the specified list intended to be used in a SQL statement.
static java.lang.String getInString(java.lang.Object[] list)
          This returns a string generated from the specified list intended to be used in a SQL statement.
static java.lang.String getInStringWithQuotes(java.lang.Object[] list)
          This returns a string generated from the specified list intended to be used in a SQL statement.
static java.lang.String[] getMultiInStringWithQuotes(java.lang.Object[] list, int max)
          This returns an array of strings generated from the specified list intended to be used in a SQL statement.
 java.lang.String getUID()
          Returns the database user on whose behalf the connection is being made.
 java.lang.String getURL()
          Returns the database url of the form jdbc:subprotocol:subname.
protected  boolean isClosed()
          This returns whether database connection is closed.
protected  void makeConnection()
          Make connection to database.
 
Methods inherited from class gov.usda.gdpc.AbstractDBConnection
getDataSource, getDescription, getDistinctProperties, getEnvironmentExperimentGroup, getGenotypeExperimentGroup, getGenotypeGenericTable, getGenotypeGroup, getLocalityGroup, getLocusGroup, getPhenotypeGroup, getPhenotypeOntologyGroup, getTaxonGroup, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gov.usda.gdpc.DBConnection
getDataSource, getDescription, getDistinctProperties, getEnvironmentExperimentGroup, getGenotypeExperimentGroup, getGenotypeGenericTable, getGenotypeGroup, getLocalityGroup, getLocusGroup, getPhenotypeGroup, getPhenotypeOntologyGroup, getTaxonGroup
 

Field Detail

myConnection

protected java.sql.Connection myConnection
The handle to the connection


myDriver

protected java.lang.String myDriver
The jdbc driver


myURL

protected java.lang.String myURL
The database url of the form jdbc:subprotocol:subname


myUID

protected java.lang.String myUID
The database user on whose behalf the connection is being made


myPassword

protected char[] myPassword
The user's password

Constructor Detail

AbstractJDBCConnection

public AbstractJDBCConnection(java.lang.String dataSource,
                              java.lang.String description,
                              java.lang.String driver,
                              java.lang.String url,
                              java.lang.String uid,
                              java.lang.String passwd)
AbstractJDBCConnection Constructor.

Parameters:
dataSource - the data source of this connection
description - description of the connection
driver - the jdbc driver
url - a database url of the form jdbc:subprotocol:subname
uid - the database user on whose behalf the connection is being made
passwd - the user's password

AbstractJDBCConnection

public AbstractJDBCConnection(java.lang.String dataSource,
                              java.lang.String description,
                              java.lang.String driver,
                              java.lang.String url,
                              java.lang.String uid,
                              char[] passwd)
AbstractJDBCConnection Constructor.

Parameters:
dataSource - the data source of this connection
description - description of the connection
driver - the jdbc driver
url - a database url of the form jdbc:subprotocol:subname
uid - the database user on whose behalf the connection is being made
passwd - the user's password
Method Detail

makeConnection

protected void makeConnection()
Make connection to database.


isClosed

protected boolean isClosed()
This returns whether database connection is closed.

Returns:
false if database connection open, true otherwise.

close

public void close()
Close the database connection.

Specified by:
close in interface DBConnection
Overrides:
close in class AbstractDBConnection

getInStringWithQuotes

public static java.lang.String getInStringWithQuotes(java.lang.Object[] list)
This returns a string generated from the specified list intended to be used in a SQL statement. Returns string with the following format: ('first', 'second', 'third')

Parameters:
list - the list to include
Returns:
the SQL formatted list

getMultiInStringWithQuotes

public static java.lang.String[] getMultiInStringWithQuotes(java.lang.Object[] list,
                                                            int max)
This returns an array of strings generated from the specified list intended to be used in a SQL statement. Returns strings with the following format: ('first', 'second', 'third')

Parameters:
list - the list to include
max - the maximum number in each generated list
Returns:
the SQL formatted list(s)

getInString

public static java.lang.String getInString(java.lang.Object[] list)
This returns a string generated from the specified list intended to be used in a SQL statement. Returns string with the following format: (first, second, third)

Parameters:
list - the list to include
Returns:
the SQL formatted list

getInString

public static java.lang.String getInString(int[] list)
This returns a string generated from the specified list intended to be used in a SQL statement. Returns string with the following format: (first, second, third)

Parameters:
list - the list to include
Returns:
the SQL formatted list

executeQuery

protected java.sql.ResultSet executeQuery(java.lang.String statement)
                                   throws java.sql.SQLException
This executes the specified select statement. It is synchronized to only execute one database query at a time.

Parameters:
statement - select statement to execute.
Returns:
results of query
Throws:
java.sql.SQLException

executeQueryNoScroll

protected java.sql.ResultSet executeQueryNoScroll(java.lang.String statement)
                                           throws java.sql.SQLException
Throws:
java.sql.SQLException

getDriver

public final java.lang.String getDriver()
Returns the jdbc driver.

Returns:
driver

getURL

public final java.lang.String getURL()
Returns the database url of the form jdbc:subprotocol:subname.

Returns:
url

getUID

public final java.lang.String getUID()
Returns the database user on whose behalf the connection is being made.

Returns:
userid

equals

public boolean equals(java.lang.Object obj)
This determines if two database connections are equal.

Parameters:
obj - object to test
Returns:
true if equal