avignon.handlers.database
Class DatabaseConnection

java.lang.Object
  extended byavignon.handlers.database.DatabaseConnection

public class DatabaseConnection
extends java.lang.Object

Encapsulates a connection to a database. The database driver used is defined by the DatabaseDriver property in the Avignon properties file. The JDBC url to use is defined by the DatabaseURL property.


Constructor Summary
protected DatabaseConnection()
          Constructs a database connection with no commandQueue.
  DatabaseConnection(java.lang.String driver, java.lang.String url, java.lang.String user, java.lang.String password)
           
 
Method Summary
 void addCommand(DatabaseCommand command)
          Queues a command to be executed.
 void copyTable(java.lang.String originalName, java.lang.String destinationName)
          Executes a SQL statement that will make a copy of a table.
 boolean equals(java.lang.Object value)
           
 void executeCommand(DatabaseCommand command)
          Adds the given command to the queue and executes all commandQueue in the queue.
 void executeCommands()
          Calls the execute method of each command currently in the queue.
protected  java.util.List getCommandQueue()
           
 java.sql.Connection getConnection()
          Returns a new java.sql.Connection to the database defined by the Avignon properties.
static DatabaseConnection newConnection()
           
protected  void setCommandQueue(java.util.List commandQueue)
           
static void shunt(java.util.List queue, java.sql.SQLException error)
           
 boolean tableExists(java.lang.String name)
          Determines if the table with the given name exists or not.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseConnection

protected DatabaseConnection()
Constructs a database connection with no commandQueue.


DatabaseConnection

public DatabaseConnection(java.lang.String driver,
                          java.lang.String url,
                          java.lang.String user,
                          java.lang.String password)
Method Detail

newConnection

public static DatabaseConnection newConnection()

shunt

public static void shunt(java.util.List queue,
                         java.sql.SQLException error)

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Returns a new java.sql.Connection to the database defined by the Avignon properties.

Returns:
Throws:
java.sql.SQLException

tableExists

public boolean tableExists(java.lang.String name)
Determines if the table with the given name exists or not. This method requires that the TableExistsQuery property exist in the Avignon properties. This property should contain a SQL statement that returns one or more rows if the table exists and no rows if it does it. The query should have one parameter that will be set with the name of the table.

Parameters:
name -
Returns:

copyTable

public void copyTable(java.lang.String originalName,
                      java.lang.String destinationName)
Executes a SQL statement that will make a copy of a table. The statement is defined by the TableCopySQL property in the Avignon properties file. This statement should have two parameters; the first is the name of the table that will be copied, the second is the name of the new table that should be created.

Parameters:
originalName -
destinationName -

addCommand

public void addCommand(DatabaseCommand command)
Queues a command to be executed.

Parameters:
command -

executeCommand

public void executeCommand(DatabaseCommand command)
                    throws java.sql.SQLException
Adds the given command to the queue and executes all commandQueue in the queue.

Parameters:
command -
Throws:
java.sql.SQLException

executeCommands

public void executeCommands()
                     throws java.sql.SQLException
Calls the execute method of each command currently in the queue.

Throws:
java.sql.SQLException

getCommandQueue

protected java.util.List getCommandQueue()

setCommandQueue

protected void setCommandQueue(java.util.List commandQueue)

equals

public boolean equals(java.lang.Object value)

SourceForge.net Logo