Implementation of releasing the connection from transactional context
339947
public void release() {
        try {
            if(hasCoreConnection()) {
                checkThreadBinding();
                this.setClosed(true);
                this.getCoreConnection().reset();
                this.fireConnectionReleased();

            }
        } finally {
            this.setClosed(true);

            // state may be important for Stat-Listener, so its set after the listener did their work
            setTransactionalData(false);

            this.releaseThreadBinding();
        }
    }
692218
def close(self):
        """"""

        if self.closed:
            return

        # Make sure no one minds the connection to be closed
        # This will help avoid MemoryError in other threads,
        # they will get sqlite3.ProgrammingError instead
        if not self.personal_lock.acquire(timeout=self.lock_timeout):
            raise LockTimeoutError(self)

        try:
            try:
                if self.in_transaction:
                    self.db_state.active_connection = None
                    self.db_state.transaction_lock.release()
            except sqlite3.ProgrammingError:
                pass

            if self._cursor is not None and not self._cursor.closed:
                self._cursor._cursor.close()
                self._cursor.closed = True

            if self.connection is not None:
                self.connection.close()

            self.closed = True
        finally:
            self.personal_lock.release()
730581
void release(DatasourceConnection dc) {
	if (dc != null) {

	    try {
		dc.getConnection().commit();
		dc.getConnection().setAutoCommit(true);
		dc.getConnection().setTransactionIsolation(Connection.TRANSACTION_NONE);
	    }
	    catch (SQLException e) {}

	    getManager().releaseConnection(ThreadLocalPageContext.get(), dc);
	}
    }
271710
public void releaseConnection(Connection<T> connection)
    {
        if(connection!=null)
        {
            try
            {
                //log info
                this.LOGGER.logInfo(new Object[]{"Closing connection using factory type: ",this.getClass().getName()},null);

                //get resource
                T resource=connection.getResource();
                
                //release resource
                this.releaseResource(resource);
                
                //unregister connection
                CloseableResourceManager.unregisterCloseable(connection);

                //log info
                this.LOGGER.logInfo(new Object[]{"Connection closed."},null);
            }
            catch(Exception exception)
            {
                //log error
                this.LOGGER.logInfo(new Object[]{"Unable to close connection."},exception);
            }
        }
    }
138206
@Override
	public void connectionFreed(IManagedConnectionEvent<C> event) {
		// physical connection is already set free
		if (!event.getManagedConnection().hasCoreConnection()) {
			return;
		}
		C con = event.getManagedConnection().getCoreConnection();
		if (con == null || !(con instanceof IXADataRecorderAware)) {
			return;
		}

		IXADataRecorderAware messageAwareConnection = (IXADataRecorderAware) con;
		// Transaction is closed and the xaDataRecorder is destroyed ...
		IXADataRecorder xaDataRecorder = messageAwareConnection
				.getXADataRecorder();
		if (xaDataRecorder == null) {
			return;
		}

		// if commit/rollback was performed, nothing happend. If no the logged
		// data is closed but not destroy. So recovery can happen

		if (event.getManagedConnection().hasTransactionalData()) {
			xaRecorderRepository.close(); // close without removing the recover
											// data
		} else {
			xaDataRecorder.destroy();
		}
		messageAwareConnection.setXADataRecorder(null);

	}
459603
public void doFinally() {
        if (conn != null) {
            try {
                if ((isolation != Connection.TRANSACTION_NONE)
                        && (isolation != origIsolation)) {
                    conn.setTransactionIsolation(origIsolation);
                }
                conn.setAutoCommit(true);
                conn.close();
            } catch (SQLException e) {
                // Not much we can do
            }
        }
        conn = null;
        isolation = Connection.TRANSACTION_NONE;
    }
409000
function (callback) {
        var conn = this.connection(),
            id = this._id; // use the raw ID object

        // prevent new transactions from using this connection.
        this.disconnect();

        // if commit was called with no active conn, it implies, no transact action
        // was called. as such it is an error.
        if (!conn) {
            // allow one pseudo commit even without connection, so that programmatic call of repeated commits or
            // rollbacks can be trapped.
            // note that the absence of `_id` indicates that a `.disconnect` was called.
            return callback && callback(id ? null : new AdapterError(AdapterError.TRANSACTION_UNINITIATED_ROLL));
        }

        conn.rollback(function (error) {
            // try releasing the connection.
            // if that fails then treat it as a major error.
            try {
                conn.release();
            }
            // if there was an error during release, set that as the main error.
            catch (err) {
                !error && (error = err);
            }

            // disassociate the connection from transaction and execute callback
            Transaction.disassociateConnection(conn);
            callback && callback(error);
        });
    }
575348
private static void release(Connection connection) {
        Connection con = tl_conn.get();
        try {
            // 若不是事务连接则直接关闭，若是事务连接不执行任何操作，事务连接由提交事务方法关闭
            if (con == null || con != connection) {
                connection.close();
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
77138
protected void deactivate(ComponentContext context) {
        transactionInflowManagerRef.deactivate(context);

        // TODO remove the following temporary code once the transaction manager provides a proper mechanism to prevent a transaction on multiple threads at once
        SuspendCount suspendCount = suspendCountRef.get();
        if (suspendCount != null)
            ((UOWCurrent) transactionManager).unsetUOWEventListener(suspendCount);
    }
152089
@Override
    protected void onSessionClose(long sessionId, Map<Long, Object> responses) {
        removeInvocationRefUids(sessionId);

        if (owner != null && owner.sessionId() == sessionId) {
            ReleaseResult result = doRelease(owner.endpoint(), newUnsecureUUID(), lockCount);
            for (LockInvocationKey key : result.completedWaitKeys()) {
                responses.put(key.commitIndex(), result.ownership().getFence());
            }
        }
    }
519807
Connection getConnectionForTxn(IsolationLevel level) throws FetchException {
        try {
            if (mOpenConnections == null) {
                throw new FetchException("Repository is closed");
            }

            // Get connection outside lock section since it may block.
            Connection con = mDataSource.getConnection();

            if (level == IsolationLevel.NONE) {
                con.setAutoCommit(true);
            } else {
                con.setAutoCommit(false);
                if (level != mDefaultIsolationLevel) {
                    con.setTransactionIsolation(mapIsolationLevelToJdbc(level));
                }
            }

            mOpenConnectionsLock.lock();
            try {
                if (mOpenConnections == null) {
                    con.close();
                    throw new FetchException("Repository is closed");
                }
                mOpenConnections.put(con, null);
            } finally {
                mOpenConnectionsLock.unlock();
            }

            return con;
        } catch (Exception e) {
            throw toFetchException(e);
        }
    }
80508
public void tx(VoidFunc1<Session> func) throws SQLException {
		try {
			beginTransaction();
			func.call(this);
			commit();
		} catch (Throwable e) {
			quietRollback();
			throw (e instanceof SQLException) ? (SQLException) e : new SQLException(e);
		}
	}
1041854
public void connect(TransactionOutput out) {
        outpoint.fromTx = out.getParentTransaction();
        out.markAsSpent(this);
        value = out.getValue();
    }
316369
void connectionCloses(final Session connection) {
        synchronized (connections) {
            final ExecutorService executorService = connectionThreads.get(connection);
            if (executorService != null) {
                executorService.shutdownNow();
            }
            connectionThreads.remove(connection);
            connections.remove(connection);
        }
    }
978387
public void execute(TransactionCommon t) throws Throwable
    {
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
        SibTr.entry(tc, "execute", t);

      _aiStream.removeCompletedPrefix(
        t,
        _messageProcessor.getMessageStore().getUniqueLockID(AbstractItem.STORE_NEVER));
      synchronized (_persistentStreamState)
      {
        if (_streamStateRemoveNeedsToWait)
        {
          _persistentStreamState.wait();
        }

        long lockID = _messageProcessor.getMessageStore().getUniqueLockID(AbstractItem.STORE_NEVER);
        _persistentStreamState.lockItemIfAvailable(lockID);
        Transaction msTran = _messageProcessor.resolveAndEnlistMsgStoreTransaction(t);
        _persistentStreamState.remove(msTran, lockID);
      }

      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
        SibTr.exit(tc, "execute");
    }
924262
public void release() 
    {
    	IPhynixxManagedConnection<C> con= this.connection;
        if (connection != null) {
            this.connection.removeConnectionListener(this);
        }
        this.connection = null;
        
        // return con; 
    }
923818
final public void releaseConnection(C connection) throws E {
		// Find the associated PooledConnection
		PooledConnection<C> pooledConnection = null;
		List<PooledConnection<C>> threadConnections = currentThreadConnections.get();
		for(int c=threadConnections.size()-1; c>=0; c--) {
			PooledConnection<C> threadConnection = threadConnections.get(c);
			synchronized(threadConnection) {
				if(threadConnection.connection==connection) {
					pooledConnection = threadConnection;
					threadConnections.remove(c);
					break;
				}
			}
		}
		if(pooledConnection==null) {
			logger.log(Level.WARNING, "PooledConnection not found during releaseConnection");
		} else {
			try {
				boolean closeConnection = false;
				boolean connIsClosed;
				try {
					connIsClosed = isClosed(connection);
				} catch(Exception err) {
					logger.log(Level.SEVERE, null, err);
					connIsClosed = false;
					closeConnection = true; // Force closure due to error on isClosed
				}
				if(connIsClosed) {
					// Already closed
					synchronized(pooledConnection) {
						pooledConnection.connection = null;
					}
				} else {
					if(maxConnectionAge!=UNLIMITED_MAX_CONNECTION_AGE) {
						long age = System.currentTimeMillis()-pooledConnection.createTime;
						if(age<0 || age>=maxConnectionAge) closeConnection = true;
					}
					if(closeConnection) {
						// Error on isClosed or max age reached, close the connection
						try {
							close(connection);
						} catch(Exception err) {
							logger.log(Level.SEVERE, null, err);
						}
						synchronized(pooledConnection) {
							pooledConnection.connection = null;
						}
					} else {
						// Reset connections as they are released
						try {
							resetConnection(connection);
						} catch(Exception err) {
							// Close the connection when error during reset
							logger.log(Level.SEVERE, null, err);
							try {
								close(connection);
							} catch(Exception err2) {
								logger.log(Level.SEVERE, null, err2);
							}
							synchronized(pooledConnection) {
								pooledConnection.connection = null;
							}
						}
					}
				}
			} finally {
				// Unallocate the connection from the pool
				release(pooledConnection);
			}
		}
	}