Methods Summary |
---|
void | XAEndOccurred()This method is called by the XAResource object when its end method
has been invoked.
try {
actualConnection.setAutoCommit(true);
} catch (Exception e) {
e.printStackTrace();
connectionErrorOccurred(e, null);
}
|
void | XAStartOccurred()This method is called by the XAResource object when its start method
has been invoked.
try {
actualConnection.setAutoCommit(false);
} catch (Exception e) {
e.printStackTrace();
connectionErrorOccurred(e, null);
}
|
public void | addConnectionEventListener(ConnectionEventListener listener)Adds a connection event listener to the ManagedConnection instance.
this.listener = listener;
|
public void | associateConnection(java.lang.Object connection)Used by the container to change the association of an application-level
connection handle with a ManagedConnection instance.
if (logWriter != null) {
logWriter.println("In associateConnection");
}
checkIfValid();
if (connection == null) {
String i18nMsg = localStrings.getString(
"jdbc.conn_handle_null");
throw new ResourceException(i18nMsg);
}
ConnectionHolder ch = (ConnectionHolder) connection;
com.sun.gjc.spi.ManagedConnection mc = ch.getManagedConnection();
isClean = false;
ch.associateConnection(actualConnection, this);
/**
* The expectation from the above method is that the connection holder
* replaces the actual sql connection it holds with the sql connection
* handle being passed in this method call. Also, it replaces the reference
* to the ManagedConnection instance with this ManagedConnection instance.
* Any previous statements and result sets also need to be removed.
*/
ch.setActive(true);
incrementCount();
//mc will be null in case we are lazily associating
if (mc != null) {
mc.decrementCount();
}
|
public void | checkIfActive(com.sun.gjc.spi.base.ConnectionHolder ch)This method is called by a Connection Handle to check if it is
the active Connection Handle. If it is not the active Connection
Handle, this method throws an SQLException. Else, it
returns setting the active Connection Handle to the calling
Connection Handle object to this object if the active Connection
Handle is null.
if (isDestroyed || !isUsable) {
String i18nMsg = localStrings.getString(
"jdbc.conn_not_usable");
throw new SQLException(i18nMsg);
}
|
void | checkIfValid()Checks if this ManagedConnection is valid or not and throws an
exception if it is not valid. A ManagedConnection is not valid if
destroy has not been called and no physical connection error has
occurred rendering the physical connection unusable.
if (isDestroyed || !isUsable) {
String i18nMsg = localStrings.getString(
"jdbc.mc_not_usable");
throw new ResourceException(i18nMsg);
}
|
public void | cleanup()Application server calls this method to force any cleanup on the
ManagedConnection instance. This method calls the invalidate
method on all ConnectionHandles associated with this ManagedConnection .
if (logWriter != null) {
logWriter.println("In cleanup");
}
checkIfValid();
/**
* may need to set the autocommit to true for the non-pooled case.
*/
//GJCINT
isClean = true;
|
public void | connectionClosed(java.lang.Exception e, com.sun.gjc.spi.base.ConnectionHolder connHolder30Object)This method is called by the ConnectionHolder30 when its close method is
called. This ManagedConnection instance invalidates the connection handle
and sends a CONNECTION_CLOSED event to all the registered event listeners.
connHolder30Object.invalidate();
decrementCount();
ce.setConnectionHandle(connHolder30Object);
if (markedForRemoval && !transactionInProgress) {
BadConnectionEventListener bcel = (BadConnectionEventListener)listener;
bcel.badConnectionClosed(ce);
_logger.log(Level.INFO, "jdbc.markedForRemoval_conClosed");
markedForRemoval = false;
}else{
listener.connectionClosed(ce);
}
|
void | connectionErrorOccurred(java.lang.Exception e, com.sun.gjc.spi.base.ConnectionHolder connHolderObject)This method is called by the ConnectionHolder30 when it detects a connecion
related error.
ConnectionEventListener cel = this.listener;
ConnectionEvent ce = null;
ce = e == null ? new ConnectionEvent(this, ConnectionEvent.CONNECTION_ERROR_OCCURRED)
: new ConnectionEvent(this, ConnectionEvent.CONNECTION_ERROR_OCCURRED, e);
if (connHolderObject != null) {
ce.setConnectionHandle(connHolderObject);
}
cel.connectionErrorOccurred(ce);
isUsable = false;
|
public void | decrementCount()
connectionCount--;
|
public void | destroy()Destroys the physical connection to the underlying resource manager.
if (logWriter != null) {
logWriter.println("In destroy");
}
//GJCINT
if (isDestroyed) {
return;
}
try {
if (connectionType == ISXACONNECTION || connectionType == ISPOOLEDCONNECTION) {
pc.close();
pc = null;
actualConnection = null;
} else {
actualConnection.close();
actualConnection = null;
}
} catch (SQLException sqle) {
isDestroyed = true;
passwdCredential = null;
connectionHandles = null;
String i18nMsg = localStrings.getString(
"jdbc.error_in_destroy");
ResourceException re = new ResourceException(
i18nMsg + sqle.getMessage(), sqle);
throw re;
}
isDestroyed = true;
passwdCredential = null;
connectionHandles = null;
|
public void | dissociateConnections()
myLogicalConnection.setManagedConnection(null);
|
java.sql.Connection | getActualConnection()Returns the actual sql connection for this ManagedConnection .
//GJCINT
if (connectionType == ISXACONNECTION || connectionType == ISPOOLEDCONNECTION) {
try {
if (actualConnection == null) {
actualConnection = pc.getConnection();
//re-initialize lastAutoCommitValue such that resetAutoCommit() wont
// affect autoCommit of actualConnection
setLastAutoCommitValue(defaultAutoCommitValue);
}
} catch (SQLException sqle) {
throw new ResourceException(sqle.getMessage(), sqle);
}
}
return actualConnection;
|
public java.lang.Object | getConnection(javax.security.auth.Subject sub, javax.resource.spi.ConnectionRequestInfo cxReqInfo)Creates a new connection handle for the underlying physical
connection represented by the ManagedConnection instance.
if (logWriter != null) {
logWriter.println("In getConnection");
}
checkIfValid();
/** Appserver any way doesnt bother about re-authentication today. So commenting this out now.
com.sun.gjc.spi.ConnectionRequestInfo cxRequestInfo = (com.sun.gjc.spi.ConnectionRequestInfo) cxReqInfo;
PasswordCredential passwdCred = SecurityUtils.getPasswordCredential(this.mcf, sub, cxRequestInfo);
if(SecurityUtils.isPasswordCredentialEqual(this.passwdCredential, passwdCred) == false) {
throw new javax.resource.spi.SecurityException("Re-authentication not supported");
}
**/
//GJCINT
getActualConnection();
ManagedConnectionFactory spiMCF = (ManagedConnectionFactory) mcf;
resetConnectionProperties(spiMCF);
myLogicalConnection = spiMCF.getJdbcObjectsFactory().getConnection(
actualConnection, this, cxReqInfo, spiMCF.isStatementWrappingEnabled());
incrementCount();
isClean = false;
myLogicalConnection.setActive(true);
return myLogicalConnection;
|
protected int | getConnectionType(javax.sql.PooledConnection pooledConn)This method determines the type of the connection being held
in this ManagedConnection .
if (pooledConn == null) {
return ISNOTAPOOLEDCONNECTION;
} else if (pooledConn instanceof XAConnection) {
return ISXACONNECTION;
} else {
return ISPOOLEDCONNECTION;
}
|
public boolean | getLastAutoCommitValue()
return lastAutoCommitValue;
|
public javax.resource.spi.LocalTransaction | getLocalTransaction()Returns an LocalTransaction instance. The LocalTransaction interface
is used by the container to manage local transactions for a RM instance.
if (logWriter != null) {
logWriter.println("In getLocalTransaction");
}
checkIfValid();
return new com.sun.gjc.spi.LocalTransaction(this);
|
public java.io.PrintWriter | getLogWriter()Gets the log writer for this ManagedConnection instance.
if (logWriter != null) {
logWriter.println("In getLogWriter");
}
checkIfValid();
return logWriter;
|
public com.sun.gjc.spi.ManagedConnectionFactory | getManagedConnectionFactory()Returns the ManagedConnectionFactory instance that
created this ManagedConnection instance.
return (com.sun.gjc.spi.ManagedConnectionFactory) mcf;
|
public javax.resource.spi.ManagedConnectionFactory | getMcf()
return mcf;
|
public javax.resource.spi.ManagedConnectionMetaData | getMetaData()Gets the metadata information for this connection's underlying EIS
resource manager instance.
if (logWriter != null) {
logWriter.println("In getMetaData");
}
checkIfValid();
return new com.sun.gjc.spi.ManagedConnectionMetaData(this);
|
javax.resource.spi.security.PasswordCredential | getPasswordCredential()Returns the PasswordCredential object associated with this ManagedConnection .
return passwdCredential;
|
public int | getStatementTimeout()
return statementTimeout;
|
public javax.transaction.xa.XAResource | getXAResource()Returns an XAResource instance.
if (logWriter != null) {
logWriter.println("In getXAResource");
}
checkIfValid();
if (connectionType == ISXACONNECTION) {
try {
if (xar == null) {
/**
* Using the wrapper XAResource.
*/
xar = new com.sun.gjc.spi.XAResourceImpl(((XAConnection) pc).getXAResource(), this);
}
return xar;
} catch (SQLException sqle) {
throw new ResourceException(sqle.getMessage(), sqle);
}
} else {
throw new NotSupportedException("Cannot get an XAResource from a non XA connection");
}
|
public void | incrementCount()
connectionCount++;
|
public void | initializeConnectionType(int _connectionType)sets the connection type of this connection. This method is called
by the MCF while creating this ManagedConnection. Saves us a costly
instanceof operation in the getConnectionType
connectionType = _connectionType;
|
protected void | invalidateAllConnectionHandles()This method removes all the connection handles from the table
of connection handles and invalidates all of them so that any
operation on those connection handles throws an exception.
Set handles = connectionHandles.keySet();
Iterator iter = handles.iterator();
try {
while (iter.hasNext()) {
ConnectionHolder ch = (ConnectionHolder) iter.next();
ch.invalidate();
}
} catch (java.util.NoSuchElementException nsee) {
throw new ResourceException("Could not find the connection handle: " + nsee.getMessage());
}
connectionHandles.clear();
|
public boolean | isTransactionInProgress()Checks if a this ManagedConnection is involved in a transaction
or not.
return transactionInProgress;
|
public void | markForRemoval(boolean flag)
markedForRemoval = flag;
|
public void | removeConnectionEventListener(ConnectionEventListener listener)Removes an already registered connection event listener from the
ManagedConnection instance.
|
private void | resetAutoCommit()To reset AutoCommit of actual connection.
If the last-auto-commit value is different from default-auto-commit value, reset will happen.
If there is a transaction in progress (because of connection sharing), reset will not happen.
if (defaultAutoCommitValue != getLastAutoCommitValue() && !(isTransactionInProgress())) {
try {
actualConnection.setAutoCommit(defaultAutoCommitValue);
} catch (SQLException sqle) {
String i18nMsg = localStrings.getString(
"jdbc.error_during_setAutoCommit");
throw new ResourceException(i18nMsg + sqle.getMessage(), sqle);
}
setLastAutoCommitValue(defaultAutoCommitValue);
}
|
private void | resetConnectionProperties(javax.resource.spi.ManagedConnectionFactory spiMCF)Resett connection properties as connections are pooled by application server
/**
* The following code in the if statement first checks if this ManagedConnection
* is clean or not. If it is, it resets the transaction isolation level to what
* it was when it was when this ManagedConnection was cleaned up depending on the
* ConnectionRequestInfo passed.
*/
if (isClean) {
spiMCF.resetIsolation(this, lastTransactionIsolationLevel);
}
// reset the autocommit value of the connection if application has modified it.
resetAutoCommit();
String statementTimeoutString = spiMCF.getStatementTimeout();
if (statementTimeoutString != null ){
int timeoutValue = Integer.valueOf(statementTimeoutString);
if(timeoutValue >= 0){
statementTimeout = timeoutValue;
}
}
|
public void | setLastAutoCommitValue(boolean lastAutoCommitValue)To keep track of last auto commit value.
Helps to reset the auto-commit-value while giving new connection-handle.
this.lastAutoCommitValue = lastAutoCommitValue;
|
public void | setLastTransactionIsolationLevel(int isolationLevel)
lastTransactionIsolationLevel = isolationLevel;
|
public void | setLogWriter(java.io.PrintWriter out)Sets the log writer for this ManagedConnection instance.
checkIfValid();
logWriter = out;
|
void | transactionCompleted()This method is called from XAResource wrapper object
when its XAResource.end() has been called or from
LocalTransaction object when its end() method is called.
try {
transactionInProgress = false;
if (connectionType == ISPOOLEDCONNECTION || connectionType == ISXACONNECTION) {
if (connectionCount <= 0) {
try {
actualConnection.close();
actualConnection = null;
} catch (SQLException sqle) {
actualConnection = null;
}
}
}
} catch (java.lang.NullPointerException e) {
_logger.log(Level.FINE, "jdbc.duplicateTxCompleted");
}
if (markedForRemoval) {
connectionErrorOccurred(null, null);
_logger.log(Level.INFO, "jdbc.markedForRemoval_txCompleted");
markedForRemoval = false;
}
isClean = true;
|
void | transactionStarted()This method is called from XAResource wrapper object
when its XAResource.start() has been called or from
LocalTransaction object when its begin() method is called.
transactionInProgress = true;
|