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 classConnectionHolder.ConnectionType
-
Field Summary
Fields Modifier and Type Field Description protected booleanactiveprotected Connectionconprotected booleanisClosedprotected ManagedConnectionImplmcprotected static StringManagersmThe active flag is false when the connection handle is created.protected intstatementTimeoutprotected booleanstatementTimeoutEnabledprotected booleanvalidprotected booleanwrappedAlready-
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 voidassociateConnection(Connection con, ManagedConnectionImpl mc)Replace the actualjava.sql.Connectionobject with the one supplied.protected voidcheckValidity()Checks the validity of this objectvoidclearWarnings()Clears all warnings reported for the underlying connection object.voidclose()Closes the logical connection.voidcommit()Commit the changes in the underlying Connection.StatementcreateStatement()Creates a statement from the underlying ConnectionStatementcreateStatement(int resultSetType, int resultSetConcurrency)Creates a statement from the underlying Connection.StatementcreateStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)Creates a statement from the underlying Connection.voiddissociateConnection()Dis-associate ManagedConnection and actual-connection from this user connection.booleangetAutoCommit()Retrieves the current auto-commit mode for the underlyingConnection.StringgetCatalog()Retrieves the underlyingConnectionobject's catalog name.ConnectiongetConnection()Returns the actual connection in this holder object.ConnectionHolder.ConnectionTypegetConnectionType()intgetHoldability()Retrieves the current holdability ofResultSetobjects created using this connection object.ManagedConnectionImplgetManagedConnection()Returns theManagedConnectioninstance responsible for this connection.DatabaseMetaDatagetMetaData()Retrieves theDatabaseMetaDataobject from the underlyingConnectionobject.protected MethodExecutorgetMethodExecutor()intgetTransactionIsolation()Retrieves thisConnectionobject's current transaction isolation level.Map<String,Class<?>>getTypeMap()Retrieves theMapobject associated withConnectionObject.SQLWarninggetWarnings()Retrieves the the first warning reported by calls on the underlyingConnectionobject.voidinvalidate()Invalidates this object.booleanisClosed()Retrieves whether underlyingConnectionobject is closed.booleanisReadOnly()Retrieves whether thisConnectionobject is read-only.booleanisWrapped()Returns whether it is wrapped already or not.protected voidjdbcPreInvoke()StringnativeSQL(String sql)Converts the given SQL statement into the system's native SQL grammer.protected voidperformLazyAssociation()protected voidperformLazyEnlistment()CallableStatementprepareCall(String sql)Creates aCallableStatementobject for calling database stored procedures.CallableStatementprepareCall(String sql, int resultSetType, int resultSetConcurrency)Creates aCallableStatementobject for calling database stored procedures.CallableStatementprepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)Creates aCallableStatementobject for calling database stored procedures.PreparedStatementprepareStatement(String sql)Creates aPreparedStatementobject for sending paramterized SQL statements to databasePreparedStatementprepareStatement(String sql, int autoGeneratedKeys)Creates aPreparedStatementobject for sending paramterized SQL statements to databasePreparedStatementprepareStatement(String sql, int[] columnIndexes)Creates aPreparedStatementobject for sending paramterized SQL statements to databasePreparedStatementprepareStatement(String sql, int resultSetType, int resultSetConcurrency)Creates aPreparedStatementobject for sending paramterized SQL statements to databasePreparedStatementprepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)Creates aPreparedStatementobject for sending paramterized SQL statements to databasePreparedStatementprepareStatement(String sql, String[] columnNames)Creates aPreparedStatementobject for sending paramterized SQL statements to databasevoidreleaseSavepoint(Savepoint savepoint)Removes the givenSavepointobject from the current transaction.voidrollback()Rolls back the changes made in the current transaction.voidrollback(Savepoint savepoint)Rolls back the changes made after the savepoint.voidsetActive(boolean actv)Sets the active flag to truevoidsetAutoCommit(boolean autoCommit)Sets the auto-commmit mode of theConnectionobject.voidsetCatalog(String catalog)Sets the catalog name to theConnectionobjectvoidsetClosed(boolean flag)Set the isClosed flag based on whether the underlyingConnectionobject is closed.voidsetConnectionType(ConnectionHolder.ConnectionType type)voidsetHoldability(int holdability)Sets the holdability ofResultSetobjects created using thisConnectionobject.voidsetLazyAssociatableConnectionManager(jakarta.resource.spi.LazyAssociatableConnectionManager cm)voidsetLazyEnlistableConnectionManager(jakarta.resource.spi.LazyEnlistableConnectionManager cm)voidsetReadOnly(boolean readOnly)Puts the connection in read-only mode as a hint to the driver to perform database optimizations.SavepointsetSavepoint()Creates and unnamed savepoint and returns an object corresponding to that.SavepointsetSavepoint(String name)Creates a savepoint with the name and returns an object corresponding to that.voidsetTransactionIsolation(int level)Creates the transaction isolation level.voidsetTypeMap(Map<String,Class<?>> map)Installs the givenMapobject as the tyoe map for thisConnectionobject.voidwrapped(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.Connectionobject.
-
-
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 theManagedConnectioninstance responsible for this connection.- Returns:
ManagedConnectioninstance.
-
associateConnection
public void associateConnection(Connection con, ManagedConnectionImpl mc)
Replace the actualjava.sql.Connectionobject with the one supplied. Also replaceManagedConnectionlink.- Parameters:
con-Connectionobject.mc-ManagedConnectionobject.
-
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 SQLExceptionClears all warnings reported for the underlying connection object.- Specified by:
clearWarningsin interfaceConnection- Throws:
SQLException- In case of a database error.
-
close
public void close() throws SQLExceptionCloses the logical connection.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection- Throws:
SQLException- In case of a database error.
-
invalidate
public void invalidate()
Invalidates this object.
-
commit
public void commit() throws SQLExceptionCommit the changes in the underlying Connection.- Specified by:
commitin interfaceConnection- Throws:
SQLException- In case of a database error.
-
createStatement
public Statement createStatement() throws SQLException
Creates a statement from the underlying Connection- Specified by:
createStatementin interfaceConnection- Returns:
Statementobject.- 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:
createStatementin interfaceConnection- Parameters:
resultSetType- Type of the ResultSetresultSetConcurrency- ResultSet Concurrency.- Returns:
Statementobject.- 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:
createStatementin interfaceConnection- Parameters:
resultSetType- Type of the ResultSetresultSetConcurrency- ResultSet Concurrency.resultSetHoldability- ResultSet Holdability.- Returns:
Statementobject.- Throws:
SQLException- In case of a database error.
-
getAutoCommit
public boolean getAutoCommit() throws SQLExceptionRetrieves the current auto-commit mode for the underlyingConnection.- Specified by:
getAutoCommitin 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 underlyingConnectionobject's catalog name.- Specified by:
getCatalogin interfaceConnection- Returns:
- Catalog Name.
- Throws:
SQLException- In case of a database error.
-
getHoldability
public int getHoldability() throws SQLExceptionRetrieves the current holdability ofResultSetobjects created using this connection object.- Specified by:
getHoldabilityin interfaceConnection- Returns:
- holdability value.
- Throws:
SQLException- In case of a database error.
-
getMetaData
public DatabaseMetaData getMetaData() throws SQLException
Retrieves theDatabaseMetaDataobject from the underlyingConnectionobject.- Specified by:
getMetaDatain interfaceConnection- Returns:
DatabaseMetaDataobject.- Throws:
SQLException- In case of a database error.
-
getTransactionIsolation
public int getTransactionIsolation() throws SQLExceptionRetrieves thisConnectionobject's current transaction isolation level.- Specified by:
getTransactionIsolationin interfaceConnection- Returns:
- Transaction level
- Throws:
SQLException- In case of a database error.
-
getTypeMap
public Map<String,Class<?>> getTypeMap() throws SQLException
Retrieves theMapobject associated withConnectionObject.- Specified by:
getTypeMapin 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 underlyingConnectionobject.- Specified by:
getWarningsin interfaceConnection- Returns:
- First
SQLWarningObject or null. - Throws:
SQLException- In case of a database error.
-
isClosed
public boolean isClosed() throws SQLExceptionRetrieves whether underlyingConnectionobject is closed.- Specified by:
isClosedin interfaceConnection- Returns:
- true if
Connectionobject 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 underlyingConnectionobject is closed.- Parameters:
flag- true ifConnectionobject is closed, false if its not closed.
-
isReadOnly
public boolean isReadOnly() throws SQLExceptionRetrieves whether thisConnectionobject is read-only.- Specified by:
isReadOnlyin interfaceConnection- Returns:
- true if
Connectionis 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:
nativeSQLin 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 aCallableStatementobject for calling database stored procedures.- Specified by:
prepareCallin interfaceConnection- Parameters:
sql- SQL Statement- Returns:
CallableStatementobject.- Throws:
SQLException- In case of a database error.
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
Creates aCallableStatementobject for calling database stored procedures.- Specified by:
prepareCallin interfaceConnection- Parameters:
sql- SQL StatementresultSetType- Type of the ResultSetresultSetConcurrency- ResultSet Concurrency.- Returns:
CallableStatementobject.- Throws:
SQLException- In case of a database error.
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
Creates aCallableStatementobject for calling database stored procedures.- Specified by:
prepareCallin interfaceConnection- Parameters:
sql- SQL StatementresultSetType- Type of the ResultSetresultSetConcurrency- ResultSet Concurrency.resultSetHoldability- ResultSet Holdability.- Returns:
CallableStatementobject.- Throws:
SQLException- In case of a database error.
-
prepareStatement
public PreparedStatement prepareStatement(String sql) throws SQLException
Creates aPreparedStatementobject for sending paramterized SQL statements to database- Specified by:
prepareStatementin interfaceConnection- Parameters:
sql- SQL Statement- Returns:
PreparedStatementobject.- Throws:
SQLException- In case of a database error.
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException
Creates aPreparedStatementobject for sending paramterized SQL statements to database- Specified by:
prepareStatementin interfaceConnection- Parameters:
sql- SQL StatementautoGeneratedKeys- a flag indicating AutoGeneratedKeys need to be returned.- Returns:
PreparedStatementobject.- Throws:
SQLException- In case of a database error.
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException
Creates aPreparedStatementobject for sending paramterized SQL statements to database- Specified by:
prepareStatementin interfaceConnection- Parameters:
sql- SQL StatementcolumnIndexes- an array of column indexes indicating the columns that should be returned from the inserted row or rows.- Returns:
PreparedStatementobject.- Throws:
SQLException- In case of a database error.
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
Creates aPreparedStatementobject for sending paramterized SQL statements to database- Specified by:
prepareStatementin interfaceConnection- Parameters:
sql- SQL StatementresultSetType- Type of the ResultSetresultSetConcurrency- ResultSet Concurrency.- Returns:
PreparedStatementobject.- Throws:
SQLException- In case of a database error.
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
Creates aPreparedStatementobject for sending paramterized SQL statements to database- Specified by:
prepareStatementin interfaceConnection- Parameters:
sql- SQL StatementresultSetType- Type of the ResultSetresultSetConcurrency- ResultSet Concurrency.resultSetHoldability- ResultSet Holdability.- Returns:
PreparedStatementobject.- Throws:
SQLException- In case of a database error.
-
prepareStatement
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException
Creates aPreparedStatementobject for sending paramterized SQL statements to database- Specified by:
prepareStatementin interfaceConnection- Parameters:
sql- SQL StatementcolumnNames- Name of bound columns.- Returns:
PreparedStatementobject.- Throws:
SQLException- In case of a database error.
-
releaseSavepoint
public void releaseSavepoint(Savepoint savepoint) throws SQLException
Removes the givenSavepointobject from the current transaction.- Specified by:
releaseSavepointin interfaceConnection- Parameters:
savepoint-Savepointobject- Throws:
SQLException- In case of a database error.
-
rollback
public void rollback() throws SQLExceptionRolls back the changes made in the current transaction.- Specified by:
rollbackin 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:
rollbackin interfaceConnection- Throws:
SQLException- In case of a database error.
-
setAutoCommit
public void setAutoCommit(boolean autoCommit) throws SQLExceptionSets the auto-commmit mode of theConnectionobject.- Specified by:
setAutoCommitin 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 theConnectionobject- Specified by:
setCatalogin interfaceConnection- Parameters:
catalog- Catalog name.- Throws:
SQLException- In case of a database error.
-
setHoldability
public void setHoldability(int holdability) throws SQLExceptionSets the holdability ofResultSetobjects created using thisConnectionobject.- Specified by:
setHoldabilityin interfaceConnection- Parameters:
holdability- AResultSetholdability constant- Throws:
SQLException- In case of a database error.
-
setReadOnly
public void setReadOnly(boolean readOnly) throws SQLExceptionPuts the connection in read-only mode as a hint to the driver to perform database optimizations.- Specified by:
setReadOnlyin 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:
setSavepointin interfaceConnection- Returns:
Savepointobject.- 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:
setSavepointin interfaceConnection- Parameters:
name- Name of the savepoint.- Returns:
Savepointobject.- Throws:
SQLException- In case of a database error.
-
setTransactionIsolation
public void setTransactionIsolation(int level) throws SQLExceptionCreates the transaction isolation level.- Specified by:
setTransactionIsolationin interfaceConnection- Parameters:
level- transaction isolation level.- Throws:
SQLException- In case of a database error.
-
checkValidity
protected void checkValidity() throws SQLExceptionChecks 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 givenMapobject as the tyoe map for thisConnectionobject.- Specified by:
setTypeMapin interfaceConnection- Parameters:
map-Mapa Map object to install.- Throws:
SQLException- In case of a database error.
-
getMethodExecutor
protected MethodExecutor getMethodExecutor()
-
-