Skip to content

Commit 38ebb14

Browse files
authored
Refactoring (#313)
1 parent 0b2c521 commit 38ebb14

File tree

8 files changed

+28
-40
lines changed

8 files changed

+28
-40
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
- New #307: Add parameters `$ifExists` and `$cascade` to `CommandInterface::dropTable()` and
3939
`DDLQueryBuilderInterface::dropTable()` methods (@vjik)
4040
- Chg #310: Remove usage of `hasLimit()` and `hasOffset()` methods of `DQLQueryBuilder` class (@Tigrov)
41+
- Enh #313: Refactor according changes in `db` package (@Tigrov)
4142
- New #311: Add `caseSensitive` option to like condition (@vjik)
4243

4344
## 1.3.0 March 21, 2024

src/Builder/LikeConditionBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function build(LikeConditionInterface $expression, array &$params = []):
4444
* Different pdo_oci8 versions may or may not implement `PDO::quote()`, so {@see Quoter::quoteValue()} may or
4545
* may not quote `\`.
4646
*/
47-
$this->escapingReplacements['\\'] = substr($this->queryBuilder->quoter()->quoteValue('\\'), 1, -1);
47+
$this->escapingReplacements['\\'] = substr($this->queryBuilder->getQuoter()->quoteValue('\\'), 1, -1);
4848
}
4949

5050
return parent::build($expression, $params);

src/Column/ColumnDefinitionBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected function buildCheck(ColumnInterface $column): string
6262

6363
return match ($column->getType()) {
6464
ColumnType::ARRAY, ColumnType::STRUCTURED, ColumnType::JSON =>
65-
' CHECK (' . $this->queryBuilder->quoter()->quoteSimpleColumnName($name) . ' IS JSON)',
65+
' CHECK (' . $this->queryBuilder->getQuoter()->quoteSimpleColumnName($name) . ' IS JSON)',
6666
default => '',
6767
};
6868
}

src/Connection.php

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
use Yiisoft\Db\Exception\InvalidArgumentException;
1212
use Yiisoft\Db\Exception\InvalidCallException;
1313
use Yiisoft\Db\Exception\InvalidConfigException;
14+
use Yiisoft\Db\Oracle\Column\ColumnFactory;
1415
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
16+
use Yiisoft\Db\Schema\Column\ColumnFactoryInterface;
1517
use Yiisoft\Db\Schema\QuoterInterface;
1618
use Yiisoft\Db\Schema\SchemaInterface;
1719
use Yiisoft\Db\Transaction\TransactionInterface;
@@ -47,6 +49,11 @@ public function createTransaction(): TransactionInterface
4749
return new Transaction($this);
4850
}
4951

52+
public function getColumnFactory(): ColumnFactoryInterface
53+
{
54+
return new ColumnFactory();
55+
}
56+
5057
/**
5158
* Override base behaviour to support Oracle sequences.
5259
*
@@ -73,28 +80,16 @@ public function getLastInsertID(?string $sequenceName = null): string
7380

7481
public function getQueryBuilder(): QueryBuilderInterface
7582
{
76-
return $this->queryBuilder ??= new QueryBuilder(
77-
$this->getQuoter(),
78-
$this->getSchema(),
79-
$this->getServerInfo(),
80-
);
83+
return $this->queryBuilder ??= new QueryBuilder($this);
8184
}
8285

8386
public function getQuoter(): QuoterInterface
8487
{
85-
if ($this->quoter === null) {
86-
$this->quoter = new Quoter('"', '"', $this->getTablePrefix());
87-
}
88-
89-
return $this->quoter;
88+
return $this->quoter ??= new Quoter('"', '"', $this->getTablePrefix());
9089
}
9190

9291
public function getSchema(): SchemaInterface
9392
{
94-
if ($this->schema === null) {
95-
$this->schema = new Schema($this, $this->schemaCache, strtoupper($this->driver->getUsername()));
96-
}
97-
98-
return $this->schema;
93+
return $this->schema ??= new Schema($this, $this->schemaCache, strtoupper($this->driver->getUsername()));
9994
}
10095
}

src/QueryBuilder.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
namespace Yiisoft\Db\Oracle;
66

7-
use Yiisoft\Db\Connection\ServerInfoInterface;
7+
use Yiisoft\Db\Connection\ConnectionInterface;
88
use Yiisoft\Db\Oracle\Column\ColumnDefinitionBuilder;
99
use Yiisoft\Db\QueryBuilder\AbstractQueryBuilder;
10-
use Yiisoft\Db\Schema\QuoterInterface;
11-
use Yiisoft\Db\Schema\SchemaInterface;
1210

1311
use function bin2hex;
1412

@@ -17,12 +15,13 @@
1715
*/
1816
final class QueryBuilder extends AbstractQueryBuilder
1917
{
20-
public function __construct(QuoterInterface $quoter, SchemaInterface $schema, ServerInfoInterface $serverInfo)
18+
public function __construct(ConnectionInterface $db)
2119
{
20+
$quoter = $db->getQuoter();
21+
$schema = $db->getSchema();
22+
2223
parent::__construct(
23-
$quoter,
24-
$schema,
25-
$serverInfo,
24+
$db,
2625
new DDLQueryBuilder($this, $quoter, $schema),
2726
new DMLQueryBuilder($this, $quoter, $schema),
2827
new DQLQueryBuilder($this, $quoter),

src/Schema.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
use Yiisoft\Db\Exception\InvalidConfigException;
1818
use Yiisoft\Db\Exception\NotSupportedException;
1919
use Yiisoft\Db\Helper\DbArrayHelper;
20-
use Yiisoft\Db\Oracle\Column\ColumnFactory;
21-
use Yiisoft\Db\Schema\Column\ColumnFactoryInterface;
2220
use Yiisoft\Db\Schema\Column\ColumnInterface;
2321
use Yiisoft\Db\Schema\TableSchemaInterface;
2422

@@ -73,11 +71,6 @@ public function __construct(protected ConnectionInterface $db, SchemaCache $sche
7371
parent::__construct($db, $schemaCache);
7472
}
7573

76-
public function getColumnFactory(): ColumnFactoryInterface
77-
{
78-
return new ColumnFactory();
79-
}
80-
8174
protected function resolveTableName(string $name): TableSchemaInterface
8275
{
8376
$resolvedName = new TableSchema();
@@ -459,7 +452,7 @@ private function loadColumn(array $info): ColumnInterface
459452
default => null,
460453
};
461454

462-
return $this->getColumnFactory()->fromDbType($dbType, [
455+
return $this->db->getColumnFactory()->fromDbType($dbType, [
463456
'autoIncrement' => $info['identity_column'] === 'YES',
464457
'check' => $info['check'],
465458
'comment' => $info['column_comment'],

tests/ConnectionTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Yiisoft\Db\Exception\Exception;
1212
use Yiisoft\Db\Exception\InvalidConfigException;
1313
use Yiisoft\Db\Exception\NotSupportedException;
14+
use Yiisoft\Db\Oracle\Column\ColumnFactory;
1415
use Yiisoft\Db\Oracle\Tests\Support\TestTrait;
1516
use Yiisoft\Db\Tests\Common\CommonConnectionTest;
1617
use Yiisoft\Db\Transaction\TransactionInterface;
@@ -130,4 +131,11 @@ public function testSerialized(): void
130131
$this->assertEquals(123, $unserialized->createCommand('SELECT 123 FROM DUAL')->queryScalar());
131132
$this->assertNotNull($connection->getPDO());
132133
}
134+
135+
public function testGetColumnFactory(): void
136+
{
137+
$db = $this->getConnection();
138+
139+
$this->assertInstanceOf(ColumnFactory::class, $db->getColumnFactory());
140+
}
133141
}

tests/SchemaTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Yiisoft\Db\Exception\Exception;
1111
use Yiisoft\Db\Exception\InvalidConfigException;
1212
use Yiisoft\Db\Exception\NotSupportedException;
13-
use Yiisoft\Db\Oracle\Column\ColumnFactory;
1413
use Yiisoft\Db\Oracle\Schema;
1514
use Yiisoft\Db\Oracle\Tests\Support\TestTrait;
1615
use Yiisoft\Db\Tests\Common\CommonSchemaTest;
@@ -280,11 +279,4 @@ public function testNotConnectionPDO(): void
280279

281280
$schema->refresh();
282281
}
283-
284-
public function testGetColumnFactory(): void
285-
{
286-
$db = $this->getConnection();
287-
288-
$this->assertInstanceOf(ColumnFactory::class, $db->getSchema()->getColumnFactory());
289-
}
290282
}

0 commit comments

Comments
 (0)