|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.nec.tdd.tools.dbMapper.DBConnectionImpl
A concrete implementation of DBConnection interface.
It maintains a hashtable of frequently used prepared and callable statements for this database connection.
Field Summary | |
protected java.util.Hashtable |
callStmts
A HashTable of callable statements for this DB connection. Callable statements are indexed by user given name. |
protected java.sql.Connection |
conn
The underlying JDBC connection. |
protected java.util.Hashtable |
prepStmts
A HashTable of prepared statements for this DB connection. Prepared statements are indexed by user given name. |
protected java.sql.Statement |
stmt
A statement associated with this DB connection. Created during object construction and closed when object is destroyed or destroy method is invoked. |
Constructor Summary | |
DBConnectionImpl(java.sql.Connection conn)
Constructs a DBConnectionImpl with the given database connection. |
|
DBConnectionImpl(java.lang.String dbUrl)
Constructs a DBConnectionImpl with the given database url. It is assumed that an appropiate JDBC driver is loaded and registered with DriverManager before constructing any DBConnectionImpl object. |
|
DBConnectionImpl(java.lang.String dbUrl,
java.util.Properties info)
Constructs a DBConnectionImpl with the given database url, and connection arguemnts. It is assumed that an appropiate JDBC driver is loaded and registered with DriverManager before constructing any DBConnectionImpl object. |
|
DBConnectionImpl(java.lang.String dbUrl,
java.lang.String user,
java.lang.String passwd)
Constructs a DBConnectionImpl with the given database url, user and password. It is assumed that an appropiate JDBC driver is loaded and registered with DriverManager before constructing any DBConnectionImpl object. |
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. If an entry with same name exists, isOverWritable parameter determines whether or not to overwrite the cached entry. |
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. If an entry with same name exists, isOverWritable parameter determines whether or not to overwrite the cached entry. |
void |
commit()
Makes all changes made since the previous commit/rollback permanent and releases any database locks currently held by the Connection. |
void |
destroy()
Cleanup for database connection object. |
protected void |
finalize()
Override Object's finalize method to free all the resources acquired by this DBConnection during garbage collection. |
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. Lifecycle of callable statement will be managed by DBConnection. |
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. Lifecycle of prepared statement will be managed by DBConnection. |
java.sql.Statement |
getStatement()
Get statement associated with this DB connection. Lifecycle of statement will be managed by DBConnection. |
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. |
java.lang.String |
toString()
Returns string representation of database connection. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected java.sql.Connection conn
protected java.sql.Statement stmt
protected java.util.Hashtable prepStmts
protected java.util.Hashtable callStmts
Constructor Detail |
public DBConnectionImpl(java.lang.String dbUrl) throws java.sql.SQLException
dbUrl
- a database url of the form jdbc:subprotocol:subnamejava.sql.SQLException
- if a database access error occurs.public DBConnectionImpl(java.lang.String dbUrl, java.lang.String user, java.lang.String passwd) throws java.sql.SQLException
dbUrl
- a database url of the form jdbc:subprotocol:subnameuser
- the database user on whose behalf the connection is being
madepasswd
- the user's passwordjava.sql.SQLException
- if a database access error occurs.public DBConnectionImpl(java.lang.String dbUrl, java.util.Properties info) throws java.sql.SQLException
dbUrl
- a database url of the form jdbc:subprotocol:subnameinfo
- a list of arbitrary string tag/value pairs as connection
arguments; normally at least a "user" and "password"
property should be includedjava.sql.SQLException
- if a database access error occurs.public DBConnectionImpl(java.sql.Connection conn) throws java.sql.SQLException
conn
- a database connection.java.sql.SQLException
- if a database access error occurs.Method Detail |
protected void finalize() throws java.lang.Exception
finalize
in class java.lang.Object
public void destroy()
public java.sql.Statement getStatement()
getStatement
in interface DBConnection
public java.sql.PreparedStatement getPreparedStatement(java.lang.String name)
getPreparedStatement
in interface DBConnection
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
makePreparedStatement
in interface DBConnection
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
addPreparedStatement
in interface DBConnection
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
addPreparedStatement
in interface DBConnection
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)
getCallableStatement
in interface DBConnection
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
makeCallableStatement
in interface DBConnection
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
addCallableStatement
in interface DBConnection
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
addCallableStatement
in interface DBConnection
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
getAutoCommit
in interface DBConnection
java.sql.SQLException
- if a database access error occurs.public void setAutoCommit(boolean isEnabled) throws java.sql.SQLException
setAutoCommit
in interface DBConnection
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
commit
in interface DBConnection
java.sql.SQLException
- if a database access error occurs.public void rollback() throws java.sql.SQLException
rollback
in interface DBConnection
java.sql.SQLException
- if a database access error occurs.public java.sql.DatabaseMetaData getMetaData() throws java.sql.SQLException
getMetaData
in interface DBConnection
java.sql.SQLException
- if a database access error occurs.public boolean isReadOnly() throws java.sql.SQLException
isReadOnly
in interface DBConnection
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.
setReadOnly
in interface DBConnection
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
isClosed
in interface DBConnection
java.sql.SQLException
- if a database access error occurs.public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |