Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| common_persistence_GraphPersistence | |
0.00% |
0 / 17 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
| run | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| runStatement | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| transactional | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| getConnection | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2023 (original work) Open Assessment Technologies SA ; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | use Laudis\Neo4j\Contracts\ClientInterface; |
| 24 | use Laudis\Neo4j\Databags\Statement; |
| 25 | use Laudis\Neo4j\Databags\SummarizedResult; |
| 26 | use oat\generis\persistence\Graph\BasicTransactionManager; |
| 27 | use oat\generis\persistence\Graph\NestedTransactionWrapper; |
| 28 | use oat\generis\persistence\Graph\TransactionManagerInterface; |
| 29 | |
| 30 | class common_persistence_GraphPersistence extends common_persistence_Persistence implements |
| 31 | common_persistence_Transactional |
| 32 | { |
| 33 | private TransactionManagerInterface $transactionManager; |
| 34 | |
| 35 | public function run(string $statement, iterable $parameters = []): SummarizedResult |
| 36 | { |
| 37 | return $this->getConnection()->run($statement, $parameters); |
| 38 | } |
| 39 | |
| 40 | public function runStatement(Statement $statement): SummarizedResult |
| 41 | { |
| 42 | return $this->getConnection()->runStatement($statement); |
| 43 | } |
| 44 | |
| 45 | public function transactional(Closure $func) |
| 46 | { |
| 47 | $transactionManager = $this->getConnection(); |
| 48 | |
| 49 | $transactionManager->beginTransaction(); |
| 50 | try { |
| 51 | $res = $func(); |
| 52 | $transactionManager->commit(); |
| 53 | |
| 54 | return $res; |
| 55 | } catch (\Throwable $e) { |
| 56 | $transactionManager->rollBack(); |
| 57 | |
| 58 | throw $e; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | private function getConnection(): TransactionManagerInterface |
| 63 | { |
| 64 | if (!isset($this->transactionManager)) { |
| 65 | /** @var ClientInterface $client */ |
| 66 | $client = $this->getDriver()->getClient(); |
| 67 | $this->transactionManager = new NestedTransactionWrapper( |
| 68 | new BasicTransactionManager($client) |
| 69 | ); |
| 70 | } |
| 71 | |
| 72 | return $this->transactionManager; |
| 73 | } |
| 74 | } |