变更
This commit is contained in:
@@ -44,7 +44,7 @@ class Connection extends Component
|
|||||||
public function inTransaction($name): bool
|
public function inTransaction($name): bool
|
||||||
{
|
{
|
||||||
$connection = Context::getContext($name);
|
$connection = Context::getContext($name);
|
||||||
if ($connection instanceof PDO) {
|
if ($connection instanceof \Database\Mysql\PDO) {
|
||||||
return $connection->inTransaction();
|
return $connection->inTransaction();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -58,7 +58,7 @@ class Connection extends Component
|
|||||||
public function beginTransaction($coroutineName)
|
public function beginTransaction($coroutineName)
|
||||||
{
|
{
|
||||||
$connection = $this->get($coroutineName);
|
$connection = $this->get($coroutineName);
|
||||||
if ($connection instanceof PDO) {
|
if ($connection instanceof \Database\Mysql\PDO) {
|
||||||
$connection->beginTransaction();
|
$connection->beginTransaction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ class Connection extends Component
|
|||||||
public function commit($coroutineName)
|
public function commit($coroutineName)
|
||||||
{
|
{
|
||||||
$connection = Context::getContext($coroutineName);
|
$connection = Context::getContext($coroutineName);
|
||||||
if ($connection instanceof PDO) {
|
if ($connection instanceof \Database\Mysql\PDO) {
|
||||||
$connection->commit();
|
$connection->commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,7 +83,7 @@ class Connection extends Component
|
|||||||
public function rollback($coroutineName)
|
public function rollback($coroutineName)
|
||||||
{
|
{
|
||||||
$connection = Context::getContext($coroutineName);
|
$connection = Context::getContext($coroutineName);
|
||||||
if ($connection instanceof PDO) {
|
if ($connection instanceof \Database\Mysql\PDO) {
|
||||||
$connection->rollBack();
|
$connection->rollBack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,12 +94,12 @@ class Connection extends Component
|
|||||||
* @return PDO|null
|
* @return PDO|null
|
||||||
* @throws ConfigException
|
* @throws ConfigException
|
||||||
*/
|
*/
|
||||||
public function get(mixed $config): ?\PDO
|
public function get(mixed $config): ?\Database\Mysql\PDO
|
||||||
{
|
{
|
||||||
if (!$this->pool->hasChannel($config['cds'])) {
|
if (!$this->pool->hasChannel($config['cds'])) {
|
||||||
$this->pool->initConnections($config['cds'], $config['pool']['max']);
|
$this->pool->initConnections($config['cds'], $config['pool']['max']);
|
||||||
}
|
}
|
||||||
return $this->pool->get($config['cds'], $this->generate($config));
|
return $this->pool->get($config['cds'], $this->create($config));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -145,26 +145,24 @@ class Connection extends Component
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $coroutineName
|
|
||||||
* @param $config
|
* @param $config
|
||||||
* @return Closure
|
* @return Closure
|
||||||
*/
|
*/
|
||||||
public function create($coroutineName, $config): Closure
|
public function create($config): Closure
|
||||||
{
|
{
|
||||||
return static function () use ($coroutineName, $config) {
|
return static function () use ($config) {
|
||||||
return new PDO($config);
|
return new \Database\Mysql\PDO($config);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param PDO $PDO
|
* @param \Database\Mysql\PDO $PDO $PDO
|
||||||
* @return void
|
* @return void
|
||||||
* @throws Kiri\Exception\ConfigException
|
* @throws ConfigException
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public function addItem(string $name, PDO $PDO): void
|
public function addItem(string $name, \Database\Mysql\PDO $PDO): void
|
||||||
{
|
{
|
||||||
$this->pool->push($name, $PDO);
|
$this->pool->push($name, $PDO);
|
||||||
}
|
}
|
||||||
@@ -189,7 +187,7 @@ class Connection extends Component
|
|||||||
public function release($coroutineName)
|
public function release($coroutineName)
|
||||||
{
|
{
|
||||||
$client = Context::getContext($coroutineName);
|
$client = Context::getContext($coroutineName);
|
||||||
if (!($client instanceof PDO) || $client->inTransaction()) {
|
if (!($client instanceof \Database\Mysql\PDO) || $client->inTransaction()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user