public class ConnectionWrapper extends Object
Constructor and Description |
---|
ConnectionWrapper()
Constructs a ConnectionWrapper.
|
ConnectionWrapper(Connection conn)
Constructs a ConnectionWrapper.
|
Modifier and Type | Method and Description |
---|---|
void |
clearWarnings()
After this call, getWarnings returns null until a new warning is
reported for this ConnectionWrapper.
|
void |
commit()
Commit makes all changes made since the previous
commit/rollback permanent and releases any database locks
currently held by the ConnectionWrapper.
|
protected CallableStatementWrapper |
constructCallableStatementWrapper(CallableStatement cstmt)
Constructs a CallableStatementWrapper.
|
protected PreparedStatementWrapper |
constructPreparedStatementWrapper(PreparedStatement pstmt)
Constructs a PreparedStatementWrapper.
|
protected StatementWrapper |
constructStatementWrapper(Statement stmt)
Constructs a StatementWrapper.
|
StatementWrapper |
createStatement()
Create a statement.
|
void |
dispose()
Dispose the ConnectionWrapper and any IfsStatement objects.
|
boolean |
execute(PreparedStatement pstmt)
Some prepared statements return multiple results; the execute
method handles these complex statements as well as the simpler
form of statements handled by executeQuery and executeUpdate.
|
boolean |
execute(Statement stmt,
String sql)
Execute a SQL statement that may return multiple results.
|
int[] |
executeBatch(Statement stmt)
Submits a batch of commands to the database for execution and if all
commands execute successfully, returns an array of update counts.
|
ResultSet |
executeQuery(PreparedStatement pstmt)
A prepared SQL query is executed and its ResultSet is returned.
|
ResultSet |
executeQuery(Statement stmt,
String sql)
Execute a SQL statement that returns a single ResultSet.
|
int |
executeUpdate(PreparedStatement pstmt)
Execute a SQL INSERT, UPDATE or DELETE statement.
|
int |
executeUpdate(Statement stmt,
String sql)
Execute a SQL INSERT, UPDATE or DELETE statement.
|
boolean |
getAutoCommit()
Get the current auto-commit state.
|
String |
getCatalog()
Return the ConnectionWrapper's current catalog name.
|
DatabaseMetaData |
getMetaData()
An ConnectionWrapper's database is able to provide information
describing its tables, its supported SQL grammar, its stored
procedures, the capabilities of this connection, etc.
|
int |
getTransactionIsolation()
Get this ConnectionWrapper's current transaction isolation mode.
|
SQLWarning |
getWarnings()
The first warning reported by calls on this ConnectionWrapper is
returned.
|
protected void |
initialize(Connection conn)
Initializes a ConnectionWrapper.
|
boolean |
isClosed()
Tests to see if an ConnectionWrapper is closed.
|
boolean |
isReadOnly()
Tests to see if the connection is in read-only mode.
|
String |
nativeSQL(String sql)
A driver may convert the JDBC sql grammar into its system's
native SQL grammar prior to sending it; nativeSQL returns the
native form of the statement that the driver would have sent.
|
CallableStatementWrapper |
prepareCall(String sql)
Create a callable statement, used for stored procedures.
|
PreparedStatementWrapper |
prepareStatement(String sql)
Create a prepared statement.
|
void |
rollback()
Rollback drops all changes made since the previous
commit/rollback and releases any database locks currently held
by the ConnectionWrapper.
|
void |
setAutoCommit(boolean autoCommit)
If a connection is in auto-commit mode, then all its SQL
statements will be executed and committed as individual
transactions.
|
void |
setCatalog(String catalog)
A sub-space of this ConnectionWrapper's database may be selected by setting a
catalog name.
|
void |
setReadOnly(boolean readOnly)
You can put a connection in read-only mode as a hint to enable
database optimizations.
|
void |
setTransactionIsolation(int level)
You can call this method to try to change the transaction
isolation level using one of the TRANSACTION_* values.
|
public ConnectionWrapper()
public ConnectionWrapper(Connection conn)
conn
- JDBC connectionprotected void initialize(Connection conn)
conn
- JDBC connectionpublic StatementWrapper createStatement() throws SQLException
SQL statements without parameters are normally executed using StatementWrapper objects. If the same SQL statement is executed many times, it is more efficient to use a PreparedStatementWrapper.
SQLException
- if a database-access error occurs.public PreparedStatementWrapper prepareStatement(String sql) throws SQLException
A SQL statement with or without IN parameters can be pre-compiled and stored in an IfsPreparedStatement object. This object can then be used to efficiently execute this statement multiple times.
Note: This method is optimized for handling parametric SQL statements that benefit from precompilation. If the driver supports precompilation, this method will send the statement to the database for precompilation. Some drivers may not support precompilation. In this case, the statement may not be sent to the database until the IfsPreparedStatement is executed. This has no direct affect on users; however, it does affect which method throws certain SQLExceptions.
sql
- a SQL statement that may contain one or more '?' IN
parameter placeholdersSQLException
- if a database-access error occurs.public CallableStatementWrapper prepareCall(String sql) throws SQLException
A SQL stored procedure call statement is handled by creating a IfsCallableStatement for it. The IfsCallableStatement provides methods for setting up its IN and OUT parameters, and methods for executing it.
Note: This method is optimized for handling stored procedure call statements. Some drivers may send the call statement to the database when the prepareCall is done; others may wait until the IfsCallableStatement is executed. This has no direct affect on users; however, it does affect which method throws certain SQLExceptions.
sql
- a SQL statement that may contain one or more '?'
parameter placeholders. Typically this statement is a
JDBC function call escape string.SQLException
- if a database-access error occurs.protected StatementWrapper constructStatementWrapper(Statement stmt)
This can be overridden to construct a subclass of StatementWrapper.
stmt
- the Statement to wrapprotected PreparedStatementWrapper constructPreparedStatementWrapper(PreparedStatement pstmt)
This can be overridden to construct a subclass of PreparedStatementWrapper.
pstmt
- the PreparedStatement to wrapprotected CallableStatementWrapper constructCallableStatementWrapper(CallableStatement cstmt)
This can be overridden to construct a subclass of CallableStatement.
cstmt
- the CallableStatement to wrappublic ResultSet executeQuery(Statement stmt, String sql) throws SQLException
stmt
- the Statementsql
- typically this is a static SQL SELECT statementSQLException
- if a database-access error occurs.public int executeUpdate(Statement stmt, String sql) throws SQLException
stmt
- the Statementsql
- a SQL INSERT, UPDATE or DELETE statement or a SQL
statement that returns nothingSQLException
- if a database-access error occurs.public boolean execute(Statement stmt, String sql) throws SQLException
stmt
- any SQL statementsql
- the SQL stringSQLException
- if a database-access error occurs.public int[] executeBatch(Statement stmt) throws SQLException
stmt
- any SQL statementSQLException
- if a database-access error occurs.public ResultSet executeQuery(PreparedStatement pstmt) throws SQLException
pstmt
- the SQL statementSQLException
- if a database-access error occurs.public int executeUpdate(PreparedStatement pstmt) throws SQLException
pstmt
- the SQL statementSQLException
- if a database-access error occurs.public boolean execute(PreparedStatement pstmt) throws SQLException
pstmt
- the SQL statementSQLException
- if a database-access error occurs.public String nativeSQL(String sql) throws SQLException
sql
- a SQL statement that may contain one or more '?'
parameter placeholdersSQLException
- if a database-access error occurs.public void setAutoCommit(boolean autoCommit) throws SQLException
autoCommit
- true enables auto-commit; false disables
auto-commit.SQLException
- if a database-access error occurs.public boolean getAutoCommit() throws SQLException
SQLException
- if a database-access error occurs.public void commit() throws SQLException
SQLException
- if a database-access error occurs.public void rollback() throws SQLException
SQLException
- if a database-access error occurs.public boolean isClosed() throws SQLException
SQLException
- if a database-access error occurs.public DatabaseMetaData getMetaData() throws SQLException
SQLException
- if a database-access error occurs.public void setReadOnly(boolean readOnly) throws SQLException
Note: setReadOnly cannot be called while in the middle of a transaction.
readOnly
- true enables read-only mode; false disables
read-only mode.SQLException
- if a database-access error occurs.public boolean isReadOnly() throws SQLException
SQLException
- if a database-access error occurs.public void setCatalog(String catalog) throws SQLException
catalog
- tthe catalog nameSQLException
- if a database-access error occurs.public String getCatalog() throws SQLException
SQLException
- if a database-access error occurs.public void setTransactionIsolation(int level) throws SQLException
Note: setTransactionIsolation cannot be called while in the middle of a transaction.
level
- one of the TRANSACTION_* isolation values with the
exception of TRANSACTION_NONE; some databases may not support
other valuesSQLException
- if a database-access error occurs.public int getTransactionIsolation() throws SQLException
SQLException
- if a database-access error occurs.public SQLWarning getWarnings() throws SQLException
Note: Subsequent warnings will be chained to this SQLWarning.
SQLException
- if a database-access error occurs.public void clearWarnings() throws SQLException
SQLException
- if a database-access error occurs.public void dispose() throws SQLException
SQLException
- if the operation failsCopyright © 2023. All rights reserved.