use of org.apache.derby.iapi.jdbc.BrokeredConnection in project derby by apache.
the class EmbedXAResource method returnConnectionToResource.
/**
* Return an underlying connection object back to its XAResource
* if possible. If not close the connection.
* @param tranState
* @param xid_im
*/
void returnConnectionToResource(XATransactionState tranState, XAXactId xid_im) {
removeXATransaction(xid_im);
synchronized (tranState) {
// global transaction is over.
tranState.associationState = XATransactionState.TC_COMPLETED;
tranState.notifyAll();
EmbedConnection conn = tranState.conn;
// or can it be returned to its original resource?
if ((tranState.creatingResource.con.realConnection == conn) || (tranState.creatingResource.con.realConnection == null)) {
tranState.creatingResource.con.realConnection = conn;
BrokeredConnection handle = tranState.creatingResource.con.currentConnectionHandle;
conn.setApplicationConnection(handle);
if (handle != null) {
try {
handle.setState(true);
} catch (SQLException sqle) {
// couldn't reset the connection
closeUnusedConnection(tranState.conn);
tranState.creatingResource.con.realConnection = null;
}
}
return;
}
}
// nowhere to place it, close it.
closeUnusedConnection(tranState.conn);
}
Aggregations