org.opensolaris.opengrok.jdbc
Class ConnectionResource

java.lang.Object
  extended by org.opensolaris.opengrok.jdbc.ConnectionResource

public class ConnectionResource
extends java.lang.Object

Class that manages the resources associated with a database connection. This includes a cache of PreparedStatements.


Method Summary
 void commit()
          Commit the transaction.
 java.sql.Statement createStatement()
          Create a new Statement object.
 java.sql.DatabaseMetaData getMetaData()
          Get a meta-data object for the underlying connection.
 java.sql.PreparedStatement getStatement(StatementCreator creator)
          Get a PreparedStatement as defined by the specified StatementCreator.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql)
          Prepare a statement.
 void rollback()
          Abort the transaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

commit

public void commit()
            throws java.sql.SQLException
Commit the transaction.

Throws:
java.sql.SQLException - if a database error occurs

rollback

public void rollback()
              throws java.sql.SQLException
Abort the transaction.

Throws:
java.sql.SQLException - if a database error occurs

getStatement

public java.sql.PreparedStatement getStatement(StatementCreator creator)
                                        throws java.sql.SQLException
Get a PreparedStatement as defined by the specified StatementCreator. If it is the first time the statement creator is used on this ConnectionResource, the creator's StatementCreator.create(Connection) method is called to create a new PreparedStatement. This statement is cached, so that on subsequent calls with the same statement creator, the same PreparedStatement will be returned.

Parameters:
creator - object that specifies how to create the statement if necessary
Returns:
a PreparedStatement object
Throws:
java.sql.SQLException - if a database error occurs

createStatement

public java.sql.Statement createStatement()
                                   throws java.sql.SQLException
Create a new Statement object.

Returns:
a Statement object
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql)
                                            throws java.sql.SQLException
Prepare a statement. This method should only be used to prepare statements that are used infrequently. If a statement is likely to be used frequently, a StatementCreator object should be created for it, and the method getStatement(StatementCreator) should be used instead.

Parameters:
sql - the SQL text to compile
Returns:
a prepared statement
Throws:
java.sql.SQLException - if a database error occurs

getMetaData

public java.sql.DatabaseMetaData getMetaData()
                                      throws java.sql.SQLException
Get a meta-data object for the underlying connection.

Returns:
a DatabaseMetaData object
Throws:
java.sql.SQLException - if a database error occurs