Package com.sun.gjc.spi.base
Class ConnectionHolder
- java.lang.Object
-
- com.sun.gjc.spi.base.ConnectionHolder
-
- All Implemented Interfaces:
AutoCloseable
,Connection
,Wrapper
- Direct Known Subclasses:
ConnectionHolder40
public abstract class ConnectionHolder extends Object implements Connection
Holds the java.sql.Connection object, which is to be passed to the application program.- Version:
- 1.0, 02/07/23
- Author:
- Binod P.G
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ConnectionHolder.ConnectionType
-
Field Summary
Fields Modifier and Type Field Description protected boolean
active
protected Connection
con
protected boolean
isClosed
protected ManagedConnectionImpl
mc
protected static StringManager
sm
The active flag is false when the connection handle is created.protected int
statementTimeout
protected boolean
statementTimeoutEnabled
protected boolean
valid
protected boolean
wrappedAlready
-
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
-
-
Constructor Summary
Constructors Constructor Description ConnectionHolder(Connection con, ManagedConnectionImpl mc, jakarta.resource.spi.ConnectionRequestInfo cxRequestInfo)
Constructs a Connection holder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
associateConnection(Connection con, ManagedConnectionImpl mc)
Replace the actualjava.sql.Connection
object with the one supplied.protected void
checkValidity()
Checks the validity of this objectvoid
clearWarnings()
Clears all warnings reported for the underlying connection object.void
close()
Closes the logical connection.void
commit()
Commit the changes in the underlying Connection.Statement
createStatement()
Creates a statement from the underlying ConnectionStatement
createStatement(int resultSetType, int resultSetConcurrency)
Creates a statement from the underlying Connection.Statement
createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
Creates a statement from the underlying Connection.void
dissociateConnection()
Dis-associate ManagedConnection and actual-connection from this user connection.boolean
getAutoCommit()
Retrieves the current auto-commit mode for the underlyingConnection
.String
getCatalog()
Retrieves the underlyingConnection
object's catalog name.Connection
getConnection()
Returns the actual connection in this holder object.ConnectionHolder.ConnectionType
getConnectionType()
int
getHoldability()
Retrieves the current holdability ofResultSet
objects created using this connection object.ManagedConnectionImpl
getManagedConnection()
Returns theManagedConnection
instance responsible for this connection.DatabaseMetaData
getMetaData()
Retrieves theDatabaseMetaData
object from the underlyingConnection
object.protected MethodExecutor
getMethodExecutor()
int
getTransactionIsolation()
Retrieves thisConnection
object's current transaction isolation level.Map<String,Class<?>>
getTypeMap()
Retrieves theMap
object associated withConnection
Object.SQLWarning
getWarnings()
Retrieves the the first warning reported by calls on the underlyingConnection
object.void
invalidate()
Invalidates this object.boolean
isClosed()
Retrieves whether underlyingConnection
object is closed.boolean
isReadOnly()
Retrieves whether thisConnection
object is read-only.boolean
isWrapped()
Returns whether it is wrapped already or not.protected void
jdbcPreInvoke()
String
nativeSQL(String sql)
Converts the given SQL statement into the system's native SQL grammer.protected void
performLazyAssociation()
protected void
performLazyEnlistment()
CallableStatement
prepareCall(String sql)
Creates aCallableStatement
object for calling database stored procedures.CallableStatement
prepareCall(String sql, int resultSetType, int resultSetConcurrency)
Creates aCallableStatement
object for calling database stored procedures.CallableStatement
prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
Creates aCallableStatement
object for calling database stored procedures.PreparedStatement
prepareStatement(String sql)
Creates aPreparedStatement
object for sending paramterized SQL statements to databasePreparedStatement
prepareStatement(String sql, int autoGeneratedKeys)
Creates aPreparedStatement
object for sending paramterized SQL statements to databasePreparedStatement
prepareStatement(String sql, int[] columnIndexes)
Creates aPreparedStatement
object for sending paramterized SQL statements to databasePreparedStatement
prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
Creates aPreparedStatement
object for sending paramterized SQL statements to databasePreparedStatement
prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
Creates aPreparedStatement
object for sending paramterized SQL statements to databasePreparedStatement
prepareStatement(String sql, String[] columnNames)
Creates aPreparedStatement
object for sending paramterized SQL statements to databasevoid
releaseSavepoint(Savepoint savepoint)
Removes the givenSavepoint
object from the current transaction.void
rollback()
Rolls back the changes made in the current transaction.void
rollback(Savepoint savepoint)
Rolls back the changes made after the savepoint.void
setActive(boolean actv)
Sets the active flag to truevoid
setAutoCommit(boolean autoCommit)
Sets the auto-commmit mode of theConnection
object.void
setCatalog(String catalog)
Sets the catalog name to theConnection
objectvoid
setClosed(boolean flag)
Set the isClosed flag based on whether the underlyingConnection
object is closed.void
setConnectionType(ConnectionHolder.ConnectionType type)
void
setHoldability(int holdability)
Sets the holdability ofResultSet
objects created using thisConnection
object.void
setLazyAssociatableConnectionManager(jakarta.resource.spi.LazyAssociatableConnectionManager cm)
void
setLazyEnlistableConnectionManager(jakarta.resource.spi.LazyEnlistableConnectionManager cm)
void
setReadOnly(boolean readOnly)
Puts the connection in read-only mode as a hint to the driver to perform database optimizations.Savepoint
setSavepoint()
Creates and unnamed savepoint and returns an object corresponding to that.Savepoint
setSavepoint(String name)
Creates a savepoint with the name and returns an object corresponding to that.void
setTransactionIsolation(int level)
Creates the transaction isolation level.void
setTypeMap(Map<String,Class<?>> map)
Installs the givenMap
object as the tyoe map for thisConnection
object.void
wrapped(boolean wrapFlag)
Sets the flag to indicate that, the connection is wrapped already or not.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.sql.Connection
abort, beginRequest, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStruct, endRequest, getClientInfo, getClientInfo, getNetworkTimeout, getSchema, isValid, setClientInfo, setClientInfo, setNetworkTimeout, setSchema, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid
-
Methods inherited from interface java.sql.Wrapper
isWrapperFor, unwrap
-
-
-
-
Field Detail
-
con
protected Connection con
-
mc
protected ManagedConnectionImpl mc
-
wrappedAlready
protected boolean wrappedAlready
-
isClosed
protected boolean isClosed
-
valid
protected boolean valid
-
active
protected boolean active
-
statementTimeout
protected int statementTimeout
-
statementTimeoutEnabled
protected boolean statementTimeoutEnabled
-
sm
protected static final StringManager sm
The active flag is false when the connection handle is created. When a method is invoked on this object, it asks the ManagedConnection if it can be the active connection handle out of the multiple connection handles. If the ManagedConnection reports that this connection handle can be active by setting this flag to true via the setActive function, the above method invocation succeeds; otherwise an exception is thrown.
-
-
Constructor Detail
-
ConnectionHolder
public ConnectionHolder(Connection con, ManagedConnectionImpl mc, jakarta.resource.spi.ConnectionRequestInfo cxRequestInfo)
Constructs a Connection holder.- Parameters:
con
-java.sql.Connection
object.
-
-
Method Detail
-
getConnection
public Connection getConnection() throws SQLException
Returns the actual connection in this holder object.- Returns:
- Connection object.
- Throws:
SQLException
-
wrapped
public void wrapped(boolean wrapFlag)
Sets the flag to indicate that, the connection is wrapped already or not.- Parameters:
wrapFlag
-
-
isWrapped
public boolean isWrapped()
Returns whether it is wrapped already or not.- Returns:
- wrapped flag.
-
getManagedConnection
public ManagedConnectionImpl getManagedConnection()
Returns theManagedConnection
instance responsible for this connection.- Returns:
ManagedConnection
instance.
-
associateConnection
public void associateConnection(Connection con, ManagedConnectionImpl mc)
Replace the actualjava.sql.Connection
object with the one supplied. Also replaceManagedConnection
link.- Parameters:
con
-Connection
object.mc
-ManagedConnection
object.
-
dissociateConnection
public void dissociateConnection()
Dis-associate ManagedConnection and actual-connection from this user connection. Used when lazy-connection-association is ON.
-
clearWarnings
public void clearWarnings() throws SQLException
Clears all warnings reported for the underlying connection object.- Specified by:
clearWarnings
in interfaceConnection
- Throws:
SQLException
- In case of a database error.
-
close
public void close() throws SQLException
Closes the logical connection.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceConnection
- Throws:
SQLException
- In case of a database error.
-
invalidate
public void invalidate()
Invalidates this object.
-
commit
public void commit() throws SQLException
Commit the changes in the underlying Connection.- Specified by:
commit
in interfaceConnection
- Throws:
SQLException
- In case of a database error.
-
createStatement
public Statement createStatement() throws SQLException
Creates a statement from the underlying Connection- Specified by:
createStatement
in interfaceConnection
- Returns:
Statement
object.- Throws:
SQLException
- In case of a database error.
-
createStatement
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException
Creates a statement from the underlying Connection.- Specified by:
createStatement
in interfaceConnection
- Parameters:
resultSetType
- Type of the ResultSetresultSetConcurrency
- ResultSet Concurrency.- Returns:
Statement
object.- Throws:
SQLException
- In case of a database error.
-
createStatement
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
Creates a statement from the underlying Connection.- Specified by:
createStatement
in interfaceConnection
- Parameters:
resultSetType
- Type of the ResultSetresultSetConcurrency
- ResultSet Concurrency.resultSetHoldability
- ResultSet Holdability.- Returns:
Statement
object.- Throws:
SQLException
- In case of a database error.
-
getAutoCommit
public boolean getAutoCommit() throws SQLException
Retrieves the current auto-commit mode for the underlyingConnection
.- Specified by:
getAutoCommit
in interfaceConnection
- Returns:
- The current state of connection's auto-commit mode.
- Throws:
SQLException
- In case of a database error.
-
getCatalog
public String getCatalog() throws SQLException
Retrieves the underlyingConnection
object's catalog name.- Specified by:
getCatalog
in interfaceConnection
- Returns:
- Catalog Name.
- Throws:
SQLException
- In case of a database error.
-
getHoldability
public int getHoldability() throws SQLException
Retrieves the current holdability ofResultSet
objects created using this connection object.- Specified by:
getHoldability
in interfaceConnection
- Returns:
- holdability value.
- Throws:
SQLException
- In case of a database error.
-
getMetaData
public DatabaseMetaData getMetaData() throws SQLException
Retrieves theDatabaseMetaData
object from the underlyingConnection
object.- Specified by:
getMetaData
in interfaceConnection
- Returns:
DatabaseMetaData
object.- Throws:
SQLException
- In case of a database error.
-
getTransactionIsolation
public int getTransactionIsolation() throws SQLException
Retrieves thisConnection
object's current transaction isolation level.- Specified by:
getTransactionIsolation
in interfaceConnection
- Returns:
- Transaction level
- Throws:
SQLException
- In case of a database error.
-
getTypeMap
public Map<String,Class<?>> getTypeMap() throws SQLException
Retrieves theMap
object associated withConnection
Object.- Specified by:
getTypeMap
in interfaceConnection
- Returns:
- TypeMap set in this object.
- Throws:
SQLException
- In case of a database error.
-
getWarnings
public SQLWarning getWarnings() throws SQLException
Retrieves the the first warning reported by calls on the underlyingConnection
object.- Specified by:
getWarnings
in interfaceConnection
- Returns:
- First
SQLWarning
Object or null. - Throws:
SQLException
- In case of a database error.
-
isClosed
public boolean isClosed() throws SQLException
Retrieves whether underlyingConnection
object is closed.- Specified by:
isClosed
in interfaceConnection
- Returns:
- true if
Connection
object is closed, false if it is closed. - Throws:
SQLException
- In case of a database error.
-
setClosed
public void setClosed(boolean flag)
Set the isClosed flag based on whether the underlyingConnection
object is closed.- Parameters:
flag
- true ifConnection
object is closed, false if its not closed.
-
isReadOnly
public boolean isReadOnly() throws SQLException
Retrieves whether thisConnection
object is read-only.- Specified by:
isReadOnly
in interfaceConnection
- Returns:
- true if
Connection
is read-only, false other-wise - Throws:
SQLException
- In case of a database error.
-
nativeSQL
public String nativeSQL(String sql) throws SQLException
Converts the given SQL statement into the system's native SQL grammer.- Specified by:
nativeSQL
in interfaceConnection
- Parameters:
sql
- SQL statement , to be converted.- Returns:
- Converted SQL string.
- Throws:
SQLException
- In case of a database error.
-
prepareCall
public CallableStatement prepareCall(String sql) throws SQLException
Creates aCallableStatement
object for calling database stored procedures.- Specified by:
prepareCall
in interfaceConnection
- Parameters:
sql
- SQL Statement- Returns:
CallableStatement
object.- Throws:
SQLException
- In case of a database error.
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
Creates aCallableStatement
object for calling database stored procedures.- Specified by:
prepareCall
in interfaceConnection
- Parameters:
sql
- SQL StatementresultSetType
- Type of the ResultSetresultSetConcurrency
- ResultSet Concurrency.- Returns:
CallableStatement
object.- Throws:
SQLException
- In case of a database error.
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
Creates aCallableStatement
object for calling database stored procedures.- Specified by:
prepareCall
in interfaceConnection
- Parameters:
sql
- SQL StatementresultSetType
- Type of the ResultSetresultSetConcurrency
- ResultSet Concurrency.resultSetHoldability
- ResultSet Holdability.- Returns:
CallableStatement
object.- Throws:
SQLException
- In case of a database error.
-
prepareStatement
public PreparedStatement prepareStatement(String sql) throws SQLException
Creates aPreparedStatement
object for sending paramterized SQL statements to database- Specified by:
prepareStatement
in interfaceConnection
- Parameters:
sql
- SQL Statement- Returns:
PreparedStatement
object.- Throws:
SQLException
- In case of a database error.
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException
Creates aPreparedStatement
object for sending paramterized SQL statements to database- Specified by:
prepareStatement
in interfaceConnection
- Parameters:
sql
- SQL StatementautoGeneratedKeys
- a flag indicating AutoGeneratedKeys need to be returned.- Returns:
PreparedStatement
object.- Throws:
SQLException
- In case of a database error.
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException
Creates aPreparedStatement
object for sending paramterized SQL statements to database- Specified by:
prepareStatement
in interfaceConnection
- Parameters:
sql
- SQL StatementcolumnIndexes
- an array of column indexes indicating the columns that should be returned from the inserted row or rows.- Returns:
PreparedStatement
object.- Throws:
SQLException
- In case of a database error.
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
Creates aPreparedStatement
object for sending paramterized SQL statements to database- Specified by:
prepareStatement
in interfaceConnection
- Parameters:
sql
- SQL StatementresultSetType
- Type of the ResultSetresultSetConcurrency
- ResultSet Concurrency.- Returns:
PreparedStatement
object.- Throws:
SQLException
- In case of a database error.
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
Creates aPreparedStatement
object for sending paramterized SQL statements to database- Specified by:
prepareStatement
in interfaceConnection
- Parameters:
sql
- SQL StatementresultSetType
- Type of the ResultSetresultSetConcurrency
- ResultSet Concurrency.resultSetHoldability
- ResultSet Holdability.- Returns:
PreparedStatement
object.- Throws:
SQLException
- In case of a database error.
-
prepareStatement
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException
Creates aPreparedStatement
object for sending paramterized SQL statements to database- Specified by:
prepareStatement
in interfaceConnection
- Parameters:
sql
- SQL StatementcolumnNames
- Name of bound columns.- Returns:
PreparedStatement
object.- Throws:
SQLException
- In case of a database error.
-
releaseSavepoint
public void releaseSavepoint(Savepoint savepoint) throws SQLException
Removes the givenSavepoint
object from the current transaction.- Specified by:
releaseSavepoint
in interfaceConnection
- Parameters:
savepoint
-Savepoint
object- Throws:
SQLException
- In case of a database error.
-
rollback
public void rollback() throws SQLException
Rolls back the changes made in the current transaction.- Specified by:
rollback
in interfaceConnection
- Throws:
SQLException
- In case of a database error.
-
rollback
public void rollback(Savepoint savepoint) throws SQLException
Rolls back the changes made after the savepoint.- Specified by:
rollback
in interfaceConnection
- Throws:
SQLException
- In case of a database error.
-
setAutoCommit
public void setAutoCommit(boolean autoCommit) throws SQLException
Sets the auto-commmit mode of theConnection
object.- Specified by:
setAutoCommit
in interfaceConnection
- Parameters:
autoCommit
- boolean value indicating the auto-commit mode.- Throws:
SQLException
- In case of a database error.
-
setCatalog
public void setCatalog(String catalog) throws SQLException
Sets the catalog name to theConnection
object- Specified by:
setCatalog
in interfaceConnection
- Parameters:
catalog
- Catalog name.- Throws:
SQLException
- In case of a database error.
-
setHoldability
public void setHoldability(int holdability) throws SQLException
Sets the holdability ofResultSet
objects created using thisConnection
object.- Specified by:
setHoldability
in interfaceConnection
- Parameters:
holdability
- AResultSet
holdability constant- Throws:
SQLException
- In case of a database error.
-
setReadOnly
public void setReadOnly(boolean readOnly) throws SQLException
Puts the connection in read-only mode as a hint to the driver to perform database optimizations.- Specified by:
setReadOnly
in interfaceConnection
- Parameters:
readOnly
- true enables read-only mode, false disables it.- Throws:
SQLException
- In case of a database error.
-
setSavepoint
public Savepoint setSavepoint() throws SQLException
Creates and unnamed savepoint and returns an object corresponding to that.- Specified by:
setSavepoint
in interfaceConnection
- Returns:
Savepoint
object.- Throws:
SQLException
- In case of a database error.
-
setSavepoint
public Savepoint setSavepoint(String name) throws SQLException
Creates a savepoint with the name and returns an object corresponding to that.- Specified by:
setSavepoint
in interfaceConnection
- Parameters:
name
- Name of the savepoint.- Returns:
Savepoint
object.- Throws:
SQLException
- In case of a database error.
-
setTransactionIsolation
public void setTransactionIsolation(int level) throws SQLException
Creates the transaction isolation level.- Specified by:
setTransactionIsolation
in interfaceConnection
- Parameters:
level
- transaction isolation level.- Throws:
SQLException
- In case of a database error.
-
checkValidity
protected void checkValidity() throws SQLException
Checks the validity of this object- Throws:
SQLException
-
setActive
public void setActive(boolean actv)
Sets the active flag to true- Parameters:
actv
- boolean
-
jdbcPreInvoke
protected void jdbcPreInvoke() throws SQLException
- Throws:
SQLException
-
performLazyEnlistment
protected void performLazyEnlistment() throws SQLException
- Throws:
SQLException
-
performLazyAssociation
protected void performLazyAssociation() throws SQLException
- Throws:
SQLException
-
setConnectionType
public void setConnectionType(ConnectionHolder.ConnectionType type)
-
getConnectionType
public ConnectionHolder.ConnectionType getConnectionType()
-
setLazyAssociatableConnectionManager
public void setLazyAssociatableConnectionManager(jakarta.resource.spi.LazyAssociatableConnectionManager cm)
-
setLazyEnlistableConnectionManager
public void setLazyEnlistableConnectionManager(jakarta.resource.spi.LazyEnlistableConnectionManager cm)
-
setTypeMap
public void setTypeMap(Map<String,Class<?>> map) throws SQLException
Installs the givenMap
object as the tyoe map for thisConnection
object.- Specified by:
setTypeMap
in interfaceConnection
- Parameters:
map
-Map
a Map object to install.- Throws:
SQLException
- In case of a database error.
-
getMethodExecutor
protected MethodExecutor getMethodExecutor()
-
-