From 3e54d7768c3fe6974e0e737ebc6fca45eec0ebe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Sat, 5 Sep 2020 03:20:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- System/Pool/Connection.php | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/System/Pool/Connection.php b/System/Pool/Connection.php index e59aab27..4dae7d19 100644 --- a/System/Pool/Connection.php +++ b/System/Pool/Connection.php @@ -51,10 +51,10 @@ class Connection extends Pool public function inTransaction($cds) { [$coroutineId, $coroutineName] = $this->getIndex($cds, true); - if (!Context::hasContext('begin_' . $coroutineName, $coroutineId)) { + if (!Context::hasContext('begin_' . $coroutineName)) { return false; } - return Context::getContext('begin_' . $coroutineName, $coroutineId) == 0; + return Context::getContext('begin_' . $coroutineName) == 0; } /** @@ -63,16 +63,16 @@ class Connection extends Pool public function beginTransaction($coroutineName) { [$coroutineId, $coroutineName] = $this->getIndex($coroutineName, true); - if (!Context::hasContext('begin_' . $coroutineName, $coroutineId)) { - Context::setContext('begin_' . $coroutineName, 0, $coroutineId); + if (!Context::hasContext('begin_' . $coroutineName)) { + Context::setContext('begin_' . $coroutineName, 0); } - if (Context::getContext('begin_' . $coroutineName, $coroutineId) === 0) { + if (Context::getContext('begin_' . $coroutineName) === 0) { $connection = Context::getContext($coroutineName); if ($connection instanceof PDO && !$connection->inTransaction()) { $connection->beginTransaction(); } } - Context::autoIncr('begin_' . $coroutineName, $coroutineId); + Context::autoIncr('begin_' . $coroutineName); } /** @@ -81,10 +81,10 @@ class Connection extends Pool public function commit($coroutineName) { [$coroutineId, $coroutineName] = $this->getIndex($coroutineName, true); - if (!Context::hasContext('begin_' . $coroutineName, $coroutineId)) { + if (!Context::hasContext('begin_' . $coroutineName)) { return; } - if (Context::autoDecr('begin_' . $coroutineName, $coroutineId) > 0) { + if (Context::autoDecr('begin_' . $coroutineName) > 0) { return; } $connection = Context::getContext($coroutineName); @@ -93,7 +93,7 @@ class Connection extends Pool $this->info('connection commit.'); $connection->commit(); } - Context::setContext('begin_' . $coroutineName, 0, $coroutineId); + Context::setContext('begin_' . $coroutineName, 0); } } @@ -123,10 +123,10 @@ class Connection extends Pool public function rollback($coroutineName) { [$coroutineId, $coroutineName] = $this->getIndex($coroutineName, true); - if (!Context::hasContext('begin_' . $coroutineName, $coroutineId)) { + if (!Context::hasContext('begin_' . $coroutineName)) { return; } - if (Context::autoDecr('begin_' . $coroutineName, $coroutineId) > 0) { + if (Context::autoDecr('begin_' . $coroutineName) > 0) { return; } if ($this->hasClient($coroutineName)) { @@ -137,7 +137,7 @@ class Connection extends Pool $connection->rollBack(); } } - Context::setContext('begin_' . $coroutineName, 0, $coroutineId); + Context::setContext('begin_' . $coroutineName, 0); } @@ -189,8 +189,7 @@ class Connection extends Pool { $this->success('create db client -> ' . $config['cds'] . ':' . $this->hasCreate[$coroutineName] . ':' . $this->size($coroutineName)); $client = $this->createConnect($coroutineName, $config['cds'], $config['username'], $config['password']); - if (isset(Context::getContext('begin_' . $coroutineName)[Coroutine::getCid()])) { - $number = Context::getContext('begin_' . $coroutineName)[Coroutine::getCid()]; + if ($number = Context::getContext('begin_' . $coroutineName)) { $number > 0 && $client->beginTransaction(); } return $client;