org.radrails.db.core
Class DatabaseHelper

java.lang.Object
  extended byorg.radrails.db.core.DatabaseHelper

public class DatabaseHelper
extends java.lang.Object

Provides a helper class around the IDatabaseConnection class.

Version:
0.2.1
Author:
mkent

Method Summary
 java.sql.Connection connect(java.io.File project, java.lang.String environment)
          Establishes a database connection based on the parameters.
 java.lang.String[] getAdapters()
          Gets a list of the available adapters.
 DatabaseConnection getConnectionForName(java.lang.String adapterName)
          Gets the database connection based on the adapter name.
static DatabaseHelper getInstance()
          Gets an instance of this class.
 boolean testConnection(java.io.File project, java.lang.String environment)
          Tests is a database connection can be established based on the project and environment type.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static DatabaseHelper getInstance()
Gets an instance of this class.

Returns:
A DatabaseHelper object.

getAdapters

public java.lang.String[] getAdapters()
Gets a list of the available adapters.

Returns:
A String array of the adapter names.

testConnection

public boolean testConnection(java.io.File project,
                              java.lang.String environment)
Tests is a database connection can be established based on the project and environment type.

Parameters:
project - The project to test a connection on.
environment - The environment from the database.yml file to use. Use the IDatabaseConstants for the available environment strings.
Returns:
true if a database connection could be established, false otherwise.

connect

public java.sql.Connection connect(java.io.File project,
                                   java.lang.String environment)
                            throws java.sql.SQLException,
                                   java.lang.InstantiationException,
                                   java.lang.IllegalAccessException,
                                   java.io.FileNotFoundException,
                                   java.io.IOException
Establishes a database connection based on the parameters.

Parameters:
project - The location to the project.
environment - The environment to test (Use IDatabaseConstants).
Returns:
A java.sql.Connection object with a connection to the corresponding environment database.
Throws:
java.sql.SQLException - If an error occured while connecting to the database.
java.lang.InstantiationException - If the adaptor for the specified database could not be created.
java.lang.IllegalAccessException - If the user specified does not have access to the database.
java.io.FileNotFoundException - If the project's database.yml file could not be found.
java.io.IOException - If an I/O error occurs while connecting.

getConnectionForName

public DatabaseConnection getConnectionForName(java.lang.String adapterName)
Gets the database connection based on the adapter name.

Parameters:
adapterName - The name of the adapter. Use the IDatabaseConstants class for the available adapters.
Returns:
The IDatabaseConnection object for the specified adapter, or null if no IDatabaseConnection is defined for the specified adapter name.