|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
A DBConnection object is a connection object with additional features of maintaining cache of frequently used (prepared, callable) statements for the connection.
DBConnection also restricts access to underlying java.sql.Connection methods (i.e. close, prepare Call etc). This is done to give full control of DBConnection object lifecycle to the connection manager which created this DBConnection.
Recommendation: Cached prepared and callable statements for this database
connections can be indexed/keyed as following :
[User class name as defined in mapping file] + "_" + [Corresponding table name from mapping file] + "_" + [operation_type i.e. create, delete, find]
Method Summary | |
void |
addCallableStatement(java.lang.String name,
java.lang.String sql)
Prepare and add a callable statement to this DB connection. |
void |
addCallableStatement(java.lang.String name,
java.lang.String sql,
boolean isOverWritable)
Prepare and add a callable statement to this DB connection. |
void |
addPreparedStatement(java.lang.String name,
java.lang.String sql)
Prepare and add a prepared statement to this DB connection. |
void |
addPreparedStatement(java.lang.String name,
java.lang.String sql,
boolean isOverWritable)
Prepare and add a prepared statement to this DB connection. |
void |
commit()
Makes all changes made since the previous commit/rollback permanent and releases any database locks currently held by the Connection. |
boolean |
getAutoCommit()
Get the current auto-commit state. |
java.sql.CallableStatement |
getCallableStatement(java.lang.String name)
Get a cached callable statement associated with this DB connection. |
java.sql.DatabaseMetaData |
getMetaData()
Gets the metadata regarding this connection's database. |
java.sql.PreparedStatement |
getPreparedStatement(java.lang.String name)
Get a cached prepared statement associated with this DB connection. |
java.sql.Statement |
getStatement()
Get statement associated with this DB connection. |
boolean |
isClosed()
Tests to see if a Connection is closed. |
boolean |
isReadOnly()
Tests to see if the connection is in read-only mode. |
java.sql.CallableStatement |
makeCallableStatement(java.lang.String sql)
Make/create a callable statement for this DB connection. |
java.sql.PreparedStatement |
makePreparedStatement(java.lang.String sql)
Make/create a prepared statement for this DB connection. |
void |
rollback()
Drops all changes made since the previous commit/rollback and releases any database locks currently held by this Connection. |
void |
setAutoCommit(boolean isEnabled)
Sets this connection's auto-commit state. |
void |
setReadOnly(boolean isReadOnly)
Puts this connection in read-only mode as a hint to enable database optimizations. |
Method Detail |
public java.sql.Statement getStatement()
public java.sql.PreparedStatement getPreparedStatement(java.lang.String name)
name
- key whose associated cached prepared statement is to be
returned (provided during addPreparedStatement).public java.sql.PreparedStatement makePreparedStatement(java.lang.String sql) throws java.sql.SQLException
sql
- a SQL statement that may contain one or more '?' IN
parameter placeholdersjava.sql.SQLException
- if a database access error occurs.public void addPreparedStatement(java.lang.String name, java.lang.String sql, boolean isOverWritable) throws java.sql.SQLException
name
- key with which the prepared statement is to be associatedsql
- a SQL statement that may contain one or more '?' IN
parameter placeholdersisOverWritable
- specifies whether or not to overwrite
cached entry.java.sql.SQLException
- if a database access error occurs.addPreparedStatement(String,String)
public void addPreparedStatement(java.lang.String name, java.lang.String sql) throws java.sql.SQLException
name
- key with which the prepared statement is to be associatedsql
- a SQL statement that may contain one or more '?' IN
parameter placeholdersjava.sql.SQLException
- if a database access error occurs.addPreparedStatement(String,String,boolean)
public java.sql.CallableStatement getCallableStatement(java.lang.String name)
name
- key whose associated cached callable statement is to be
returned (provided during addCallableStatement).public java.sql.CallableStatement makeCallableStatement(java.lang.String sql) throws java.sql.SQLException
sql
- a SQL statement that may contain one or more '?' parameter
placeholders. Typically this statement is a JDBC function
call escape string.java.sql.SQLException
- if a database access error occurs.public void addCallableStatement(java.lang.String name, java.lang.String sql, boolean isOverWritable) throws java.sql.SQLException
name
- key with which the callable statement is to be associatedsql
- a SQL statement that may contain one or more '?' parameter
placeholders. Typically this statement is a JDBC function
call escape string.isOverWritable
- specifies whether or not to overwrite
cached entry.java.sql.SQLException
- if a database access error occurs.addCallableStatement(String,String)
public void addCallableStatement(java.lang.String name, java.lang.String sql) throws java.sql.SQLException
name
- key with which the callable statement is to be associatedsql
- a SQL statement that may contain one or more '?' parameter
placeholders. Typically this statement is a JDBC function
call escape string.java.sql.SQLException
- if a database access error occurs.addCallableStatement(String,String,boolean)
public boolean getAutoCommit() throws java.sql.SQLException
java.sql.SQLException
- if a database access error occurs.public void setAutoCommit(boolean isEnabled) throws java.sql.SQLException
isEnabled
- true enables auto-commit; false disables auto-commit.java.sql.SQLException
- if a database access error occurs.public void commit() throws java.sql.SQLException
java.sql.SQLException
- if a database access error occurs.public void rollback() throws java.sql.SQLException
java.sql.SQLException
- if a database access error occurs.public java.sql.DatabaseMetaData getMetaData() throws java.sql.SQLException
java.sql.SQLException
- if a database access error occurs.public boolean isReadOnly() throws java.sql.SQLException
java.sql.SQLException
- if a database access error occurs.public void setReadOnly(boolean isReadOnly) throws java.sql.SQLException
Note: This method cannot be called while in the middle of a transaction. Calling routines are responsible to to check the connection type before using it.
isReadOnly
- true enables read-only mode; false disables
read-only mode.java.sql.SQLException
- if a database access error occurs.public boolean isClosed() throws java.sql.SQLException
java.sql.SQLException
- if a database access error occurs.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |