org.edg.info
Class RemoteDatabase

java.lang.Object
  extended byorg.edg.info.RemoteDatabase

public class RemoteDatabase
extends java.lang.Object

Encapsulates a remote database. Currently maintains a single connection to the database, but could be expanded to use a connection pool. TODO: remove isConnectionValid() and use getState after each execute to work out if the connection is dead.


Constructor Summary
RemoteDatabase(java.lang.String location, java.lang.String user, java.lang.String password, java.lang.String driver)
          Creates a new RemoteDatabase object.
 
Method Summary
 void checkConnection(java.sql.SQLException e)
          Checks the SQL state following an exception to determine if the connection needs to be reestablished.
 void close()
          Closes all connections to this remote database.
static void closeStatement(java.sql.Statement statement)
          Closes the given statement if it is not null.
 java.sql.Connection getConnection()
          Returns a connection to this remote database, creating one if necessary.
 java.sql.Statement getStatement()
          Returns a Statement object to send SQL to this database.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RemoteDatabase

public RemoteDatabase(java.lang.String location,
                      java.lang.String user,
                      java.lang.String password,
                      java.lang.String driver)
Creates a new RemoteDatabase object.

Parameters:
location - The URL of the database.
user - The user name to access the database.
password - The password to access the database.
driver - The class name of the database driver.
Method Detail

getConnection

public java.sql.Connection getConnection()
                                  throws org.glite.rgma.system.RGMAInternalException
Returns a connection to this remote database, creating one if necessary.

Returns:
A Connection object to this remote database.
Throws:
org.glite.rgma.system.RGMAException
org.glite.rgma.system.RGMAInternalException

toString

public java.lang.String toString()

close

public void close()
Closes all connections to this remote database.


getStatement

public java.sql.Statement getStatement()
                                throws java.sql.SQLException,
                                       org.glite.rgma.system.RGMAInternalException
Returns a Statement object to send SQL to this database.

Returns:
A Statement object.
Throws:
java.sql.SQLException
org.glite.rgma.system.RGMAException
org.glite.rgma.system.RGMAInternalException

checkConnection

public void checkConnection(java.sql.SQLException e)
                     throws org.glite.rgma.system.RGMAException,
                            java.sql.SQLException
Checks the SQL state following an exception to determine if the connection needs to be reestablished.

Parameters:
e - The SQLException.
Throws:
org.glite.rgma.system.RGMAException - If the attempt to recreate the connection fails.
java.sql.SQLException

closeStatement

public static void closeStatement(java.sql.Statement statement)
Closes the given statement if it is not null.

Parameters:
statement - Statement to close.