org.stanwood.media.database
Interface IDatabase

All Known Implementing Classes:
AbstractGenericDatabase, HSQLDatabase, MysqlDatabase

public interface IDatabase

This interface should be implemented by database manager classes that want to provide a connection to the database.


Method Summary
 void closeConnection(java.sql.Connection connection)
          This is used to close a connection.
 void closeDatabaseResources(java.sql.Connection connection, java.sql.PreparedStatement stmt, java.sql.ResultSet rs)
          This is used to make sure that all DB resources are closed.
 void commitTransactionConnection(java.sql.Connection connection)
          This is used to commit a connection to the database
 java.sql.Connection createConnection()
          This is used to get a connection to the database
 java.sql.Connection createTransactionConnection()
          This is used to get a connection to the database
 boolean dropTable(java.sql.Connection connection, java.lang.String tableName)
          This is called to delete a table from the database.
 boolean dropTable(java.lang.String tableName)
          This is called to delete a table from the database It creates it's own connection too the DB
 void executeSQL(java.sql.Connection connection, java.lang.String sql)
          This is used to execute a simple SQL statement on the database.
 void executeSQL(java.lang.String sql)
          This is used to execute a simple SQL statement on the database.
 long executeUpdate(java.sql.Connection connection, java.lang.String sql, java.lang.Object[] params)
          This is used to execute a update state that takes params.
 long executeUpdate(java.lang.String sql, java.lang.Object[] params)
          This is used to execute a update state that takes params.
 java.sql.PreparedStatement getStatement(java.sql.Connection connection, java.lang.String sql)
          This is used to create a PreparedStatement from the give SQL.
 java.sql.PreparedStatement getStatement(java.sql.Connection connection, java.lang.String sql, java.lang.Object[] params)
          This is used to create a PreparedStatement from the given SQL.
 void init()
          This is used to setup the database manager class, it should be called after creating a database manager class.
 long insertIntoTable(java.sql.Connection connection, java.lang.String tableName, java.util.List<Field> fields)
          This is used to insert table row into a table.
 long insertIntoTable(java.lang.String tableName, java.util.List<Field> fields)
          This is used to insert table row into a table.
 void rollbackTransactionConnection(java.sql.Connection connection)
          This is used to rollback all statements pushed through this connection since the last commit or save from the database
 

Method Detail

init

void init()
          throws UnableToConnectToDatabaseException
This is used to setup the database manager class, it should be called after creating a database manager class.

Throws:
UnableToConnectToDatabaseException - Thrown if unable to connect to the database

createConnection

java.sql.Connection createConnection()
                                     throws java.sql.SQLException
This is used to get a connection to the database

Returns:
The connection to the database
Throws:
java.sql.SQLException - Thrown if there is a problem getting the connection to the database

createTransactionConnection

java.sql.Connection createTransactionConnection()
                                                throws java.sql.SQLException
This is used to get a connection to the database

Returns:
The connection to the database, which is not auto-committing
Throws:
java.sql.SQLException - Thrown if there is a problem getting the connection to the database

commitTransactionConnection

void commitTransactionConnection(java.sql.Connection connection)
                                 throws java.sql.SQLException
This is used to commit a connection to the database

Parameters:
connection - This connection is committed
Throws:
java.sql.SQLException - Thrown if there is a problem getting the connection to the database

rollbackTransactionConnection

void rollbackTransactionConnection(java.sql.Connection connection)
This is used to rollback all statements pushed through this connection since the last commit or save from the database

Parameters:
connection - This connection is rolled back

executeSQL

void executeSQL(java.lang.String sql)
                throws java.sql.SQLException
This is used to execute a simple SQL statement on the database.

Parameters:
sql - The SQL to execute on the database
Throws:
java.sql.SQLException - Thrown if their is a problem talking to the database

executeSQL

void executeSQL(java.sql.Connection connection,
                java.lang.String sql)
                throws java.sql.SQLException
This is used to execute a simple SQL statement on the database.

Parameters:
connection - a connection to be re-used, useful for running a series of updates as a transaction
sql - the SQL to execute on the database
Throws:
java.sql.SQLException - Thrown if their is a problem talking to the database

executeUpdate

long executeUpdate(java.lang.String sql,
                   java.lang.Object[] params)
                   throws java.sql.SQLException
This is used to execute a update state that takes params. The SQL should contain ? were the params should be inserted.

Parameters:
sql - The SQL to execute on the database
params - The params to insert into the SQL statement.
Returns:
If a key was generated, then it is pass here, otherwise -1
Throws:
java.sql.SQLException - Thrown if their is a problem talking to the database

insertIntoTable

long insertIntoTable(java.sql.Connection connection,
                     java.lang.String tableName,
                     java.util.List<Field> fields)
                     throws java.sql.SQLException
This is used to insert table row into a table. The table row is made up from fields.

Parameters:
connection - a connection to be re-used, useful for running a series
tableName - The name of the table
fields - The fields of the table that are to be inserted.
Returns:
If a key was generated, then it is pass here, otherwise -1
Throws:
java.sql.SQLException - Thrown if their is a problem talking to the database

insertIntoTable

long insertIntoTable(java.lang.String tableName,
                     java.util.List<Field> fields)
                     throws java.sql.SQLException
This is used to insert table row into a table. The table row is made up from fields.

Parameters:
tableName - The name of the table
fields - The fields of the table that are to be inserted.
Returns:
If a key was generated, then it is pass here, otherwise -1
Throws:
java.sql.SQLException - Thrown if their is a problem talking to the database

executeUpdate

long executeUpdate(java.sql.Connection connection,
                   java.lang.String sql,
                   java.lang.Object[] params)
                   throws java.sql.SQLException
This is used to execute a update state that takes params. The SQL should contain ? were the params should be inserted.

Parameters:
connection - A connection to the database
sql - The SQL to execute on the database
params - The params to insert into the SQL statement.
Returns:
If a key was generated, then it is pass here, otherwise -1
Throws:
java.sql.SQLException - Thrown if their is a problem talking to the database

dropTable

boolean dropTable(java.lang.String tableName)
This is called to delete a table from the database It creates it's own connection too the DB

Parameters:
tableName - The table to delete
Returns:
True if it was successful, otherwise false;

dropTable

boolean dropTable(java.sql.Connection connection,
                  java.lang.String tableName)
This is called to delete a table from the database. It uses the connection passed in.

Parameters:
tableName - The table to delete
connection - The database connection
Returns:
True if it was successful, otherwise false;

getStatement

java.sql.PreparedStatement getStatement(java.sql.Connection connection,
                                        java.lang.String sql)
                                        throws java.sql.SQLException
This is used to create a PreparedStatement from the give SQL. This is useful as different implementations of the interface can translate the SQL so that it is under stood by the database. The SQL should be in the format of MySQL SQL.

Parameters:
connection - A connection to the database
sql - The statements sql
Returns:
A Prepared Statement
Throws:
java.sql.SQLException - Thrown if their is a problem creating the statement
See Also:
PreparedStatement

getStatement

java.sql.PreparedStatement getStatement(java.sql.Connection connection,
                                        java.lang.String sql,
                                        java.lang.Object[] params)
                                        throws java.sql.SQLException
This is used to create a PreparedStatement from the given SQL. The SQL should contain ? were the params should be inserted.

Parameters:
connection - a connection to the database
sql - the statements sql
params - the params to place into the statement
Returns:
a Prepared Statement
Throws:
java.sql.SQLException - thrown if their is a problem creating the statement
See Also:
PreparedStatement

closeDatabaseResources

void closeDatabaseResources(java.sql.Connection connection,
                            java.sql.PreparedStatement stmt,
                            java.sql.ResultSet rs)
This is used to make sure that all DB resources are closed. If any of the parameters are null, then they an attempt to close them is not made.

Parameters:
connection - The connection to close
stmt - The statement to close
rs - The result set to close

closeConnection

void closeConnection(java.sql.Connection connection)
                     throws java.sql.SQLException
This is used to close a connection. This is done in the database interface so that connection closure can be logged from a central location and open connection count can be kept

Parameters:
connection - The connection to close
Throws:
java.sql.SQLException - Thrown if their is a problem talking to the database