From 36897c78465be587772396d2168858ca95dbab52 Mon Sep 17 00:00:00 2001 From: "Bruno O. Notario" Date: Wed, 27 Mar 2024 21:36:29 -0300 Subject: [PATCH] Fix ORDS multiple instances --- .../Connectors/Oracle/ORDS/Api/Query.php | 6 ++++ .../Connectors/Oracle/ORDS/Connector.php | 32 +++++++++++++++++++ .../Connectors/Oracle/ORDS/Model/Query.php | 29 +++++++++++++++-- .../database/Databases/Driver/OracleORDS.php | 2 +- 4 files changed, 65 insertions(+), 4 deletions(-) diff --git a/system/database/Databases/Connectors/Oracle/ORDS/Api/Query.php b/system/database/Databases/Connectors/Oracle/ORDS/Api/Query.php index 4141d54..a850c28 100644 --- a/system/database/Databases/Connectors/Oracle/ORDS/Api/Query.php +++ b/system/database/Databases/Connectors/Oracle/ORDS/Api/Query.php @@ -42,4 +42,10 @@ interface Query { /** @return string */ public function getError(); + + /** + * @param \Phacil\Framework\Databases\Connectors\Oracle\ORDS\Connector $connector + * @return $this + */ + public function setConnector(\Phacil\Framework\Databases\Connectors\Oracle\ORDS\Connector $connector); } \ No newline at end of file diff --git a/system/database/Databases/Connectors/Oracle/ORDS/Connector.php b/system/database/Databases/Connectors/Oracle/ORDS/Connector.php index aa437c9..17fee65 100644 --- a/system/database/Databases/Connectors/Oracle/ORDS/Connector.php +++ b/system/database/Databases/Connectors/Oracle/ORDS/Connector.php @@ -23,6 +23,18 @@ class Connector { private $pass; + /** + * + * @var \Phacil\Framework\Databases\Connectors\Oracle\ORDS\Api\Query + */ + private $queryExecutor; + + /** + * + * @var \Phacil\Framework\Databases\Connectors\Oracle\ORDS\Api\HandleInterface + */ + private $queryHandler; + public function __construct($url = 'localhost', $port = 8181, $user = null, $pass = null){ $this->host = $url; @@ -32,6 +44,9 @@ class Connector { $this->pass = $pass; + /** @var \Phacil\Framework\Databases\Connectors\Oracle\ORDS\Api\Query */ + //$this->queryExecutor = \Phacil\Framework\Registry::getInstance()->create(\Phacil\Framework\Databases\Connectors\Oracle\ORDS\Api\Query::class); + return $this; } @@ -50,4 +65,21 @@ class Connector { public function getPass(){ return $this->pass; } + + /** + * @return \Phacil\Framework\Databases\Connectors\Oracle\ORDS\Api\Query + * @throws \Phacil\Framework\Exception + * @throws \Phacil\Framework\Exception\ReflectionException + */ + public function createStatement(){ + /** @var \Phacil\Framework\Databases\Connectors\Oracle\ORDS\Api\Query */ + $this->queryExecutor = \Phacil\Framework\Registry::getInstance()->create(\Phacil\Framework\Databases\Connectors\Oracle\ORDS\Api\Query::class); + + return $this->queryExecutor->setConnector($this); + } + + /** @return \Phacil\Framework\Databases\Connectors\Oracle\ORDS\Api\Query */ + public function getStatement() { + return $this->queryExecutor; + } } \ No newline at end of file diff --git a/system/database/Databases/Connectors/Oracle/ORDS/Model/Query.php b/system/database/Databases/Connectors/Oracle/ORDS/Model/Query.php index 5079747..95429b2 100644 --- a/system/database/Databases/Connectors/Oracle/ORDS/Model/Query.php +++ b/system/database/Databases/Connectors/Oracle/ORDS/Model/Query.php @@ -45,21 +45,42 @@ class Query implements QueryApi { */ private $helper; + /** + * + * @var \Phacil\Framework\Databases\Connectors\Oracle\ORDS\Connector + */ + private $connector; + + /** + * + * @var \Phacil\Framework\Factory + */ + private $handleFactory; + /** * @param \Phacil\Framework\Databases\Connectors\Oracle\ORDS\Connector $conector * @param \Phacil\Framework\Databases\Connectors\Oracle\ORDS\Api\HandleInterface $handle * @return $this */ public function __construct( - HandleInterface $handle, + \Phacil\Framework\Databases\Connectors\Oracle\ORDS\Api\HandleInterfaceFactory $handle, DataHelper $helper ) { - $this->handle = $handle; + $this->handleFactory = $handle; $this->helper = $helper; return $this; } + /** + * @param \Phacil\Framework\Databases\Connectors\Oracle\ORDS\Connector $connector + * @return $this + */ + public function setConnector(\Phacil\Framework\Databases\Connectors\Oracle\ORDS\Connector $connector){ + $this->connector = $connector; + return $this; + } + /** * @inheritdoc */ @@ -90,6 +111,8 @@ class Query implements QueryApi { throw new \Phacil\Framework\Exception\RuntimeException('Query is empty'); } + $this->handle = $this->handleFactory->create([$this->connector]); + $executed = $this->handle->execute($this->sql); if($executed){ @@ -129,7 +152,7 @@ class Query implements QueryApi { $this->handle->close(); unset($this->handle); - $this->handle = \Phacil\Framework\Registry::getInstance()->create(HandleInterface::class); + //$this->handle = \Phacil\Framework\Registry::getInstance()->create(HandleInterface::class); } /** @inheritdoc */ diff --git a/system/database/Databases/Driver/OracleORDS.php b/system/database/Databases/Driver/OracleORDS.php index b7e5dea..7c06c7c 100644 --- a/system/database/Databases/Driver/OracleORDS.php +++ b/system/database/Databases/Driver/OracleORDS.php @@ -79,7 +79,7 @@ class OracleORDS implements DriverInterface $this->rowCount = 0; /** @var \Phacil\Framework\Databases\Connectors\Oracle\ORDS\Api\Query */ - $this->statement = \Phacil\Framework\Registry::getInstance()->create(\Phacil\Framework\Databases\Connectors\Oracle\ORDS\Api\Query::class); + $this->statement = $this->connection->createStatement(); } /** {@inheritdoc} */