FileDocCategorySizeDatePackage
ConnectionHolder.javaAPI DocGlassfish v2 API23811Fri May 04 22:36:04 BST 2007com.sun.gjc.spi

ConnectionHolder

public 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

Fields Summary
protected Connection
con
protected ManagedConnection
mc
protected boolean
wrappedAlready
protected boolean
isClosed
protected boolean
valid
protected boolean
active
private javax.resource.spi.LazyAssociatableConnectionManager
lazyAssocCm_
private javax.resource.spi.LazyEnlistableConnectionManager
lazyEnlistCm_
private javax.resource.spi.ConnectionRequestInfo
cxReqInfo_
private javax.resource.spi.ManagedConnectionFactory
mcf_
private ConnectionType
myType_
protected static com.sun.enterprise.util.i18n.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.
Constructors Summary
public ConnectionHolder(Connection con, ManagedConnection mc, javax.resource.spi.ConnectionRequestInfo cxRequestInfo)
Constructs a Connection holder.

param
con java.sql.Connection object.



          		      
         
           
        this.con = con;
        this.mc  = mc;
        mcf_ = mc.mcf;
        cxReqInfo_ = cxRequestInfo;
    
Methods Summary
voidactualClose()
Closes the physical connection involved in this.

throws
SQLException In case of a database error.

    
        con.close();
    
voidassociateConnection(java.sql.Connection con, ManagedConnection mc)
Replace the actual java.sql.Connection object with the one supplied. Also replace ManagedConnection link.

param
con Connection object.
param
mc ManagedConnection object.

    	this.mc = mc;
    	this.con = con;
    
protected voidcheckValidity()
Checks the validity of this object

    	if (isClosed) throw new SQLException ("Connection closed");
    	if (!valid) throw new SQLException ("Invalid Connection");
    	if(active == false) {
    	    mc.checkIfActive(this);
    	}
    
public voidclearWarnings()
Clears all warnings reported for the underlying connection object.

throws
SQLException In case of a database error.

    
	checkValidity();
        con.clearWarnings();
    
public voidclose()
Closes the logical connection.

throws
SQLException In case of a database error.

        isClosed = true;
        if ( mc != null ) {
            //mc might be null if this is a lazyAssociatable connection
            //and has not been associated yet or has been disassociated
            mc.connectionClosed(null, this);        
        }
    
public voidcommit()
Commit the changes in the underlying Connection.

throws
SQLException In case of a database error.

	checkValidity();    
    	con.commit();
    
public java.sql.StatementcreateStatement()
Creates a statement from the underlying Connection

return
Statement object.
throws
SQLException In case of a database error.

	checkValidity();    
        jdbcPreInvoke();
        return con.createStatement();
    
public java.sql.StatementcreateStatement(int resultSetType, int resultSetConcurrency)
Creates a statement from the underlying Connection.

param
resultSetType Type of the ResultSet
param
resultSetConcurrency ResultSet Concurrency.
return
Statement object.
throws
SQLException In case of a database error.

	checkValidity();    
        jdbcPreInvoke();
        return con.createStatement(resultSetType, resultSetConcurrency);
    
public java.sql.StatementcreateStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldabilty)
Creates a statement from the underlying Connection.

param
resultSetType Type of the ResultSet
param
resultSetConcurrency ResultSet Concurrency.
param
resultSetHoldability ResultSet Holdability.
return
Statement object.
throws
SQLException In case of a database error.

	checkValidity();    				     
        jdbcPreInvoke(); 
        return con.createStatement(resultSetType, resultSetConcurrency,
        			   resultSetHoldabilty);
    
public booleangetAutoCommit()
Retrieves the current auto-commit mode for the underlying Connection.

return
The current state of connection's auto-commit mode.
throws
SQLException In case of a database error.

	checkValidity();    
    	return con.getAutoCommit();
    
public java.lang.StringgetCatalog()
Retrieves the underlying Connection object's catalog name.

return
Catalog Name.
throws
SQLException In case of a database error.

	checkValidity();    
        return con.getCatalog();
    
java.sql.ConnectiongetConnection()
Returns the actual connection in this holder object.

return
Connection object.

    	return con;
    
public com.sun.gjc.spi.ConnectionHolder$ConnectionTypegetConnectionType()

        return myType_;
    
public intgetHoldability()
Retrieves the current holdability of ResultSet objects created using this connection object.

return
holdability value.
throws
SQLException In case of a database error.

	checkValidity();    
    	return	con.getHoldability();
    
ManagedConnectiongetManagedConnection()
Returns the ManagedConnection instance responsible for this connection.

return
ManagedConnection instance.

        return mc;
    
public java.sql.DatabaseMetaDatagetMetaData()
Retrieves the DatabaseMetaDataobject from the underlying Connection object.

return
DatabaseMetaData object.
throws
SQLException In case of a database error.

	checkValidity();    
    	return con.getMetaData();
    
public intgetTransactionIsolation()
Retrieves this Connection object's current transaction isolation level.

return
Transaction level
throws
SQLException In case of a database error.

	checkValidity();    
        return con.getTransactionIsolation();
    
public java.util.MapgetTypeMap()
Retrieves the Map object associated with Connection Object.

return
TypeMap set in this object.
throws
SQLException In case of a database error.

	checkValidity();    
    	return con.getTypeMap();
    
public java.sql.SQLWarninggetWarnings()
Retrieves the the first warning reported by calls on the underlying Connection object.

return
First SQLWarning Object or null.
throws
SQLException In case of a database error.

	checkValidity();    
    	return con.getWarnings();
    
public voidinvalidate()
Invalidates this object.

    	valid = false;
    
public booleanisClosed()
Retrieves whether underlying Connection object is closed.

return
true if Connection object is closed, false if it is closed.
throws
SQLException In case of a database error.

    	return isClosed;
    
public booleanisReadOnly()
Retrieves whether this Connection object is read-only.

return
true if Connection is read-only, false other-wise
throws
SQLException In case of a database error.

	checkValidity();    
    	return con.isReadOnly();
    
booleanisWrapped()
Returns whether it is wrapped already or not.

return
wrapped flag.

        return wrappedAlready;
    
protected voidjdbcPreInvoke()

        if ( myType_ == ConnectionType.LAZY_ASSOCIATABLE ) {
            performLazyAssociation();
        } else if ( myType_ == ConnectionType.LAZY_ENLISTABLE ) {
            performLazyEnlistment();
        }

    
public java.lang.StringnativeSQL(java.lang.String sql)
Converts the given SQL statement into the system's native SQL grammer.

param
sql SQL statement , to be converted.
return
Converted SQL string.
throws
SQLException In case of a database error.

	checkValidity();    
    	return con.nativeSQL(sql);
    
protected voidperformLazyAssociation()

        try {
            this.lazyAssocCm_.associateConnection( this, mcf_, cxReqInfo_);
        } catch( ResourceException re ) {
	    String msg = sm.getString( 
                "jdbc.cannot_enlist",   re.getMessage() +
                " Cannnot Enlist ManagedConnection");
                
            SQLException sqle = new SQLException( msg);
            sqle.initCause( re );
            throw sqle;
        }

    
protected voidperformLazyEnlistment()

        try {
            this.lazyEnlistCm_.lazyEnlist(mc); 
        } catch( ResourceException re ) {
	    String msg = sm.getString( 
                "jdbc.cannot_enlist" ,  re.getMessage() +
                " Cannnot Enlist ManagedConnection");
                
            SQLException sqle = new SQLException( msg );
            sqle.initCause( re );
            throw sqle;
        }

    
public java.sql.CallableStatementprepareCall(java.lang.String sql)
Creates a CallableStatement object for calling database stored procedures.

param
sql SQL Statement
return
CallableStatement object.
throws
SQLException In case of a database error.

	checkValidity();    
        jdbcPreInvoke();
    	return con.prepareCall(sql);
    
public java.sql.CallableStatementprepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency)
Creates a CallableStatement object for calling database stored procedures.

param
sql SQL Statement
param
resultSetType Type of the ResultSet
param
resultSetConcurrency ResultSet Concurrency.
return
CallableStatement object.
throws
SQLException In case of a database error.

	checkValidity();    					
        jdbcPreInvoke();
    	return con.prepareCall(sql, resultSetType, resultSetConcurrency);
    
public java.sql.CallableStatementprepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldabilty)
Creates a CallableStatement object for calling database stored procedures.

param
sql SQL Statement
param
resultSetType Type of the ResultSet
param
resultSetConcurrency ResultSet Concurrency.
param
resultSetHoldability ResultSet Holdability.
return
CallableStatement object.
throws
SQLException In case of a database error.

	checkValidity();    					 
        jdbcPreInvoke();
    	return con.prepareCall(sql, resultSetType, resultSetConcurrency,
    			       resultSetHoldabilty);
    
public java.sql.PreparedStatementprepareStatement(java.lang.String sql)
Creates a PreparedStatement object for sending paramterized SQL statements to database

param
sql SQL Statement
return
PreparedStatement object.
throws
SQLException In case of a database error.

	checkValidity();    
        jdbcPreInvoke();
    	return con.prepareStatement(sql);
    
public java.sql.PreparedStatementprepareStatement(java.lang.String sql, int autoGeneratedKeys)
Creates a PreparedStatement object for sending paramterized SQL statements to database

param
sql SQL Statement
param
autoGeneratedKeys a flag indicating AutoGeneratedKeys need to be returned.
return
PreparedStatement object.
throws
SQLException In case of a database error.

	checkValidity();    
        jdbcPreInvoke();
    	return con.prepareStatement(sql,autoGeneratedKeys);
    
public java.sql.PreparedStatementprepareStatement(java.lang.String sql, int[] columnIndexes)
Creates a PreparedStatement object for sending paramterized SQL statements to database

param
sql SQL Statement
param
columnIndexes an array of column indexes indicating the columns that should be returned from the inserted row or rows.
return
PreparedStatement object.
throws
SQLException In case of a database error.

	checkValidity();    
        jdbcPreInvoke();
    	return con.prepareStatement(sql,columnIndexes);
    
public java.sql.PreparedStatementprepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)
Creates a PreparedStatement object for sending paramterized SQL statements to database

param
sql SQL Statement
param
resultSetType Type of the ResultSet
param
resultSetConcurrency ResultSet Concurrency.
return
PreparedStatement object.
throws
SQLException In case of a database error.

	checkValidity();    					
        jdbcPreInvoke();
    	return con.prepareStatement(sql, resultSetType, resultSetConcurrency);
    
public java.sql.PreparedStatementprepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldabilty)
Creates a PreparedStatement object for sending paramterized SQL statements to database

param
sql SQL Statement
param
resultSetType Type of the ResultSet
param
resultSetConcurrency ResultSet Concurrency.
param
resultSetHoldability ResultSet Holdability.
return
PreparedStatement object.
throws
SQLException In case of a database error.

	checkValidity();    					 
        jdbcPreInvoke();
    	return con.prepareStatement(sql, resultSetType, resultSetConcurrency,
    				    resultSetHoldabilty);
    
public java.sql.PreparedStatementprepareStatement(java.lang.String sql, java.lang.String[] columnNames)
Creates a PreparedStatement object for sending paramterized SQL statements to database

param
sql SQL Statement
param
columnNames Name of bound columns.
return
PreparedStatement object.
throws
SQLException In case of a database error.

	checkValidity();    
        jdbcPreInvoke();
    	return con.prepareStatement(sql,columnNames);
    
public voidreleaseSavepoint(java.sql.Savepoint savepoint)
Removes the given Savepoint object from the current transaction.

param
savepoint Savepoint object
throws
SQLException In case of a database error.

	checkValidity();    
    	con.releaseSavepoint(savepoint);
    
public voidrollback()
Rolls back the changes made in the current transaction.

throws
SQLException In case of a database error.

	checkValidity();    
    	con.rollback();
    
public voidrollback(java.sql.Savepoint savepoint)
Rolls back the changes made after the savepoint.

throws
SQLException In case of a database error.

	checkValidity();    
    	con.rollback(savepoint);
    
voidsetActive(boolean actv)
Sets the active flag to true

param
actv boolean

        active = actv;
    
public voidsetAutoCommit(boolean autoCommit)
Sets the auto-commmit mode of the Connection object.

param
autoCommit boolean value indicating the auto-commit mode.
throws
SQLException In case of a database error.

	checkValidity();    
    	con.setAutoCommit(autoCommit);
        mc.setLastAutoCommitValue(autoCommit);
    
public voidsetCatalog(java.lang.String catalog)
Sets the catalog name to the Connection object

param
catalog Catalog name.
throws
SQLException In case of a database error.

	checkValidity();    
    	con.setCatalog(catalog);
    
public voidsetConnectionType(com.sun.gjc.spi.ConnectionHolder$ConnectionType type)

        myType_ = type;
    
public voidsetHoldability(int holdability)
Sets the holdability of ResultSet objects created using this Connection object.

param
holdability A ResultSet holdability constant
throws
SQLException In case of a database error.

	checkValidity();    
     	con.setHoldability(holdability);
    
public voidsetLazyAssociatableConnectionManager(javax.resource.spi.LazyAssociatableConnectionManager cm)

        
        lazyAssocCm_ = cm;
    
public voidsetLazyEnlistableConnectionManager(javax.resource.spi.LazyEnlistableConnectionManager cm)

        
        lazyEnlistCm_ = cm;
    
public voidsetManagedConnection(ManagedConnection con)

        this.mc = con;
    
public voidsetReadOnly(boolean readOnly)
Puts the connection in read-only mode as a hint to the driver to perform database optimizations.

param
readOnly true enables read-only mode, false disables it.
throws
SQLException In case of a database error.

	checkValidity();    
    	con.setReadOnly(readOnly);
    
public java.sql.SavepointsetSavepoint()
Creates and unnamed savepoint and returns an object corresponding to that.

return
Savepoint object.
throws
SQLException In case of a database error.

	checkValidity();    
    	return con.setSavepoint();
    
public java.sql.SavepointsetSavepoint(java.lang.String name)
Creates a savepoint with the name and returns an object corresponding to that.

param
name Name of the savepoint.
return
Savepoint object.
throws
SQLException In case of a database error.

	checkValidity();    
    	return con.setSavepoint(name);
    
public voidsetTransactionIsolation(int level)
Creates the transaction isolation level.

param
level transaction isolation level.
throws
SQLException In case of a database error.

	checkValidity();    
    	con.setTransactionIsolation(level);
    
public voidsetTypeMap(java.util.Map map)
Installs the given Map object as the tyoe map for this Connection object.

param
map Map a Map object to install.
throws
SQLException In case of a database error.

	checkValidity();
    	con.setTypeMap(map);
    
voidwrapped(boolean wrapFlag)
Sets the flag to indicate that, the connection is wrapped already or not.

param
wrapFlag

        this.wrappedAlready = wrapFlag;