Commit Transaction
@param $xid
@throws DbException
@internal param TransactionID $string from beginTransaction
502535
public function commit($xid)
    {
        if ($this->activeTransaction != $xid || $this->activeTransaction === false) {
            return;
        }

        $this->activeTransaction = false;

        if (!$this->connection->commit()) {
            throw new DbException("Commit failed");
        }
    }
1346008
public static function startTransaction(callable $callback = null)
    {
        static::verifyConnection();

        if (!static::$adapter->getConnection()->inTransaction()) {
            static::$adapter->getConnection()->beginTransaction();
        }

        if (is_callable($callback)) {
            try {
                call_user_func_array($callback, []);

                static::commit();
            } catch (DatabaseException $e) {
                static::rollback();
            }
        }
    }
46362
@Override
    public final synchronized void commit(ContainerTx tx)
                    throws RemoteException
    {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(tc, "commit: " + getStateName(state), tx);

        if (removed) {
            if (isTraceOn && tc.isEntryEnabled())
                Tr.exit(tc, "commit: removed");
            return;
        }

        if (tx.ivRemoveBeanO == this)
        {
            completeRemoveMethod(tx); // d647928
        }
        else
        {
            // Perform normal afterCompletion processing.... calling
            // afterCompletion if present.
            setState(COMMITTING_OUTSIDE_METHOD, AFTER_COMPLETION); // d159152

            // Session Synchronization AfterCompletion needs to be called if either
            // the annotation (or XML) was specified or the bean implemented
            // the interface and a global transaction is active.        F743-25855
            if ((ivAfterCompletion != null || sessionSync != null) &&
                tx.isTransactionGlobal())
            {
                EJBThreadData threadData = EJSContainer.getThreadData();

                threadData.pushContexts(this);
                try
                {
                    if (ivAfterCompletion != null) {
                        invokeSessionSynchMethod(ivAfterCompletion, new Object[] { true });
                    } else {
                        sessionSync.afterCompletion(true);
                    }
                } finally
                {
                    threadData.popContexts();
                }
            }

            setState(AFTER_COMPLETION, METHOD_READY); // d159152
        }

        // currentTx is now reset in atCommit/atRollback AFTER the final pin
        // is undone.                                                      d258770
        // currentTx = null;                                            // PQ99986

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(tc, "commit: " + getStateName(state));
    }
900860
public function transaction($callback)
    {
        if (!is_callable($callback, false)) {
            throw new ConnectionException('Callback should be either closure or object-method array format');
        }
        
        $this->start();
        
        try {
            $result = call_user_func_array($callback, [$this]);
            $this->commit();
            
            return $result;
        } catch (\Exception $exception) {
            $this->rollback();
            throw $exception;
        }
    }
1108954
@Override
  public int prepare(Xid xid) throws XAException {
    if (logger.logDebug()) {
      debug("preparing transaction xid = " + xid);
    }

    // Check preconditions
    if (!currentXid.equals(xid)) {
      throw new CloudSpannerXAException(CloudSpannerXAException.PREPARE_WITH_SAME,
          Code.UNIMPLEMENTED, XAException.XAER_RMERR);
    }
    if (state != STATE_ENDED) {
      throw new CloudSpannerXAException(CloudSpannerXAException.PREPARE_BEFORE_END,
          Code.FAILED_PRECONDITION, XAException.XAER_INVAL);
    }

    state = STATE_IDLE;
    currentXid = null;

    try {
      String s = RecoveredXid.xidToString(xid);
      conn.prepareTransaction(s);
      conn.setAutoCommit(localAutoCommitMode);

      return XA_OK;
    } catch (CloudSpannerSQLException ex) {
      throw new CloudSpannerXAException(CloudSpannerXAException.ERROR_PREPARING, ex,
          XAException.XAER_RMERR);
    } catch (SQLException ex) {
      throw new CloudSpannerXAException(CloudSpannerXAException.ERROR_PREPARING, ex, Code.UNKNOWN,
          XAException.XAER_RMERR);
    }
  }
180767
public function commit($transactionId = null)
    {
        return $this->client->sendFrame($this->getProtocol()->getCommitFrame($transactionId));
    }
852602
public void commit(Xid xid, boolean onePhase) throws XAException {

        // Comment out following debug statement before public release:
        System.err.println("Performing a " + (onePhase ? "1-phase"
                                                       : "2-phase") + " commit on "
                                                       + xid);

        JDBCXAResource resource = xaDataSource.getResource(xid);

        if (resource == null) {
            throw new XAException("The XADataSource has no such Xid:  " + xid);
        }

        resource.commitThis(onePhase);
    }
1156777
public function commitTransaction() {
        // check that a transaction is really active - do not check/renew the connection - renewing a connection breaks the transaction
        if (!$this->getConnection(false)->inTransaction())
            throw new \Exception("Not inside a DB transaction. Cannot commit.");

        try {
            $this->getConnection(false)->commit();
        } catch (Exception $_e) {
            throw new \Exception("Error while committing DB transaction: ".$pe->getMessage());
        }
    }
594693
public function afterCommit(TransactionEvent $event) {
    if ($this->liveUpdate && $event->getPhase() == TransactionEvent::AFTER_COMMIT) {
      $persistenceFacade = ObjectFactory::getInstance('persistenceFacade');
      // add inserted/updated objects
      foreach (array_merge(array_values($event->getInsertedOids()), $event->getUpdatedOids()) as $oid) {
        $object = $persistenceFacade->load(ObjectId::parse($oid));
        if ($object) {
          $this->addToIndex($object);
        }
        else {
          self::$logger->warn("Could not index object with oid ".$oid." because it does not exist");
        }
      }
      // remove deleted objects
      foreach ($event->getDeletedOids() as $oid) {
        $this->deleteFromIndex(ObjectId::parse($oid));
      }
    }
  }
401136
public function transactional(callable $fn)
    {
        $pdo = $this->getPdo();
        $pdo->beginTransaction();
        try {
            call_user_func($fn);
            $pdo->commit();
        } catch (\Exception $e) {
            $pdo->rollBack();
            throw $e;
        }
    }
513756
public void commit(Xid xid, boolean onePhase) throws XAException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.entry(this, tc, "commit", new Object[] 
                     {
                      ivManagedConnection,
                      AdapterUtil.toString(xid), 
                      onePhase ? "ONE PHASE" : "TWO PHASE" }
                            );

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) { 
            String cId = null;
            try {
                cId = ivManagedConnection.mcf.getCorrelator(ivManagedConnection); 
            } catch (SQLException x) {
                // will just log the exception here and ignore it since its in trace
                Tr.debug(this, tc, "got an exception trying to get the correlator in commit, exception is: ", x);
            }
            if (cId != null) {
                StringBuffer stbuf = new StringBuffer(200);
                stbuf.append("Correlator: DB2, ID: ");
                stbuf.append(cId);
                if (xid != null) {
                    stbuf.append("Transaction ID : ");
                    stbuf.append(xid);
                }
                stbuf.append(" COMMIT");
                Tr.debug(this, tc, stbuf.toString());
            }
        }

        if (dsConfig.get().enableMultithreadedAccessDetection) 
            ivManagedConnection.detectMultithreadedAccess(); 

        if (!onePhase) {
            XAException xaX = new XAException(XAException.XA_RBPROTO);
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                Tr.exit(this, tc, "commit", xaX); 
            throw xaX;
        }

        boolean commitFailed = false;
        boolean rollbackFailed = false;
        boolean setStateFailed = false;

        // Reset so we can deferred enlist in a future global transaction. 
        ivManagedConnection.wasLazilyEnlistedInGlobalTran = false; 

        try {
            // If no work was done during the transaction, the autoCommit value may still
            // be on.  In this case, just no-op, since some drivers like ConnectJDBC 3.1
            // don't allow commit/rollback when autoCommit is on.  

            ivSqlConn.commit(); 
            ivStateManager.setState(WSStateManager.XA_COMMIT);
        } catch (SQLException sqeC)
        {
            FFDCFilter.processException(sqeC, "com.ibm.ws.rsadapter.spi.WSRdbOnePhaseXaResourceImpl.commit", "105", this);
            commitFailed = true;
            Tr.error(tc, "DSA_INTERNAL_ERROR", new Object[] { "Exception caught during commit on the OnePhaseXAResource", sqeC });

            // If no work was done during the transaction, the autoCommit value may still
            // be on.  In this case, just no-op, since some drivers like ConnectJDBC 3.1
            // don't allow commit/rollback when autoCommit is on.  

            try
            { // autoCommit is off
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())  
                    Tr.debug(this, tc, "issue a rollback due to commit failure");
                ivSqlConn.rollback();
            } catch (SQLException sqeR)
            {
                FFDCFilter.processException(sqeR, "com.ibm.ws.rsadapter.spi.WSRdbOnePhaseXaResourceImpl.commit", "197", this);
                rollbackFailed = true;
                Tr.error(tc, "DSA_INTERNAL_ERROR", new Object[] { "Exception caught during rollback on the OnePhaseXAResource after a commit failed", sqeR });
            }
            catch (java.lang.RuntimeException x)
            {
                FFDCFilter.processException(x, "com.ibm.ws.rsadapter.spi.WSRdbOnePhaseXaResourceImpl.commit", "204", this);
                rollbackFailed = true;
                Tr.error(tc, "DSA_INTERNAL_ERROR", new Object[] { "Exception caught during rollback on the OnePhaseXAResource after a commit failed", x });
            }

        } catch (TransactionException te) {
            //Exception means setState failed because it was invalid to set the state in this case
            FFDCFilter.processException(te, "com.ibm.ws.rsadapter.spi.WSRdbOnePhaseXaResourceImpl.commit", "123", this);
            Tr.error(tc, "INVALID_TX_STATE", new Object[] { "OnePhaseXAResource.commit()", ivManagedConnection.getTransactionStateAsString() });
            setStateFailed = false;

        }
        catch (java.lang.RuntimeException x)
        {
            FFDCFilter.processException(x, "com.ibm.ws.rsadapter.spi.WSRdbOnePhaseXaResourceImpl.commit", "221", this);
            Tr.error(tc, "DSA_INTERNAL_ERROR", new Object[] { "Exception caught during commit on the OnePhaseXAResource", x });

            XAException xae = new XAException(XAException.XA_HEURHAZ); // throwing Heurhaz sine we don't really know f the commit failed or not.             
            traceXAException(xae, currClass);
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                Tr.exit(this, tc, "commit", "Exception"); 
            throw xae;

        }

        if (rollbackFailed) {
            XAException xae = new XAException(XAException.XAER_RMERR);
            traceXAException(xae, currClass);
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                Tr.exit(this, tc, "commit", "Exception"); 
            throw xae;
        } else if (commitFailed) {
            XAException xae = new XAException(XAException.XA_HEURHAZ); //  we don't know if the commit really failed, or the failure in communication after the commit succeeded             
            traceXAException(xae, currClass);
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                Tr.exit(this, tc, "commit", "Exception"); 
            throw xae;
        } else if (setStateFailed) {
            XAException xae = new XAException(XAException.XAER_RMERR);
            traceXAException(xae, currClass);
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                Tr.exit(this, tc, "commit", "Exception"); 
            throw xae;
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.exit(this, tc, "commit"); 
    }
1118350
public void doCommit(DefaultTransactionStatus status) throws TransactionException {
		CompensatingTransactionObject txObject = (CompensatingTransactionObject) status.getTransaction();
		txObject.getHolder().getTransactionOperationManager().commit();

	}
324736
public function commit()
    {
        if ($this->_active && $this->_db->getActive()) {
            $this->_db->getPdoInstance()->commit();
            $this->_active = false;
        } else {
            throw new Exception('"Transaction"尚属未激活状态，不能执行"commit"和"rollback"操作', 101300601);
        }
    }
1206135
@Override
	public void onTxCommit(Transaction tx) {
		if (!tx.isReadOnly() && enableLogging) {
			LogSeqNum lsn = new CommitRecord(txNum).writeToLog();
			VanillaDb.logMgr().flush(lsn);
		}
	}
613394
public void commit(Xid xid, boolean onePhase) throws XAException {
    String command = "XA COMMIT " + xidToString(xid);
    if (onePhase) {
      command += " ONE PHASE";
    }
    execute(command);
  }
929419
private void visitTxId() throws IOException {
    if (LayoutVersion.supports(Feature.STORED_TXIDS, editsVersion)) {
      v.visitLong(EditsElement.TRANSACTION_ID);
    }
  }
1244217
protected function _commit( $fname = false )
    {
        if ( $fname )
            $fname .= "::_commit";
        else
            $fname = "_commit";
        $this->transactionCount--;
        if ( $this->transactionCount == 0 )
           oci_commit( $this->db );
    }