Skip to content

Commit f6f984c

Browse files
committed
Merge branch '4.4.x' into 5.0.x
2 parents c02daab + 4d0224f commit f6f984c

18 files changed

+439
-42
lines changed

UPGRADE.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,18 @@ all drivers and middleware.
364364

365365
# Upgrade to 4.4
366366

367+
## Deprecated `View` features
368+
369+
The `View` constructor has been marked as internal. Use `View::editor()` to instantiate an editor and
370+
`ViewEditor::create()` to create a view.
371+
372+
## Deprecated `Sequence` features
373+
374+
1. The `Sequence` constructor has been marked as internal. Use `Sequence::editor()` to instantiate an editor and
375+
`SequenceEditor::create()` to create a sequence.
376+
2. Passing a negative value as sequence cache size has been deprecated.
377+
3. The `Sequence::getCache()` method has been deprecated. Use `Sequence::getCacheSize()` instead.
378+
367379
## Deprecated extension of schema classes
368380

369381
Extending the following classes has been deprecated. Use them directly.

src/Platforms/OraclePlatform.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,31 +145,27 @@ public function getCreateSequenceSQL(Sequence $sequence): string
145145
' START WITH ' . $sequence->getInitialValue() .
146146
' MINVALUE ' . $sequence->getInitialValue() .
147147
' INCREMENT BY ' . $sequence->getAllocationSize() .
148-
$this->getSequenceCacheSQL($sequence);
148+
$this->getSequenceCacheSQL($sequence->getCacheSize());
149149
}
150150

151151
public function getAlterSequenceSQL(Sequence $sequence): string
152152
{
153153
return 'ALTER SEQUENCE ' . $sequence->getObjectName()->toSQL($this) .
154154
' INCREMENT BY ' . $sequence->getAllocationSize()
155-
. $this->getSequenceCacheSQL($sequence);
155+
. $this->getSequenceCacheSQL($sequence->getCacheSize());
156156
}
157157

158158
/**
159159
* Cache definition for sequences
160160
*/
161-
private function getSequenceCacheSQL(Sequence $sequence): string
161+
private function getSequenceCacheSQL(?int $cacheSize): string
162162
{
163-
if ($sequence->getCache() === 0) {
163+
if ($cacheSize === 0 || $cacheSize === 1) {
164164
return ' NOCACHE';
165165
}
166166

167-
if ($sequence->getCache() === 1) {
168-
return ' NOCACHE';
169-
}
170-
171-
if ($sequence->getCache() > 1) {
172-
return ' CACHE ' . $sequence->getCache();
167+
if ($cacheSize > 1) {
168+
return ' CACHE ' . $cacheSize;
173169
}
174170

175171
return '';

src/Platforms/PostgreSQLPlatform.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,23 +343,23 @@ public function getCreateSequenceSQL(Sequence $sequence): string
343343
' INCREMENT BY ' . $sequence->getAllocationSize() .
344344
' MINVALUE ' . $sequence->getInitialValue() .
345345
' START ' . $sequence->getInitialValue() .
346-
$this->getSequenceCacheSQL($sequence);
346+
$this->getSequenceCacheSQL($sequence->getCacheSize());
347347
}
348348

349349
public function getAlterSequenceSQL(Sequence $sequence): string
350350
{
351351
return 'ALTER SEQUENCE ' . $sequence->getObjectName()->toSQL($this) .
352352
' INCREMENT BY ' . $sequence->getAllocationSize() .
353-
$this->getSequenceCacheSQL($sequence);
353+
$this->getSequenceCacheSQL($sequence->getCacheSize());
354354
}
355355

356356
/**
357357
* Cache definition for sequences
358358
*/
359-
private function getSequenceCacheSQL(Sequence $sequence): string
359+
private function getSequenceCacheSQL(?int $cacheSize): string
360360
{
361-
if ($sequence->getCache() > 1) {
362-
return ' CACHE ' . $sequence->getCache();
361+
if ($cacheSize > 1) {
362+
return ' CACHE ' . $cacheSize;
363363
}
364364

365365
return '';
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\DBAL\Schema\Exception;
6+
7+
use Doctrine\DBAL\Schema\SchemaException;
8+
use LogicException;
9+
10+
use function sprintf;
11+
12+
final class InvalidSequenceDefinition extends LogicException implements SchemaException
13+
{
14+
public static function nameNotSet(): self
15+
{
16+
return new self('Sequence name is not set.');
17+
}
18+
19+
public static function fromNegativeCacheSize(int $cacheSize): self
20+
{
21+
return new self(sprintf('Sequence cache size must be a non-negative integer, %d given.', $cacheSize));
22+
}
23+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\DBAL\Schema\Exception;
6+
7+
use Doctrine\DBAL\Schema\Name\OptionallyQualifiedName;
8+
use Doctrine\DBAL\Schema\SchemaException;
9+
use LogicException;
10+
11+
use function sprintf;
12+
13+
final class InvalidViewDefinition extends LogicException implements SchemaException
14+
{
15+
public static function nameNotSet(): self
16+
{
17+
return new self('View name is not set.');
18+
}
19+
20+
public static function sqlNotSet(OptionallyQualifiedName $viewName): self
21+
{
22+
return new self(sprintf('SQL is not set for view %s.', $viewName->toString()));
23+
}
24+
}

src/Schema/Sequence.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\DBAL\Schema\Name\OptionallyQualifiedName;
99
use Doctrine\DBAL\Schema\Name\Parser;
1010
use Doctrine\DBAL\Schema\Name\Parsers;
11+
use Doctrine\Deprecations\Deprecation;
1112

1213
/**
1314
* Sequence structure.
@@ -20,6 +21,12 @@ final class Sequence extends AbstractNamedObject
2021

2122
private int $initialValue = 1;
2223

24+
/**
25+
* @internal Use {@link Sequence::editor()} to instantiate an editor and {@link SequenceEditor::create()} to create
26+
* a sequence.
27+
*
28+
* @param ?non-negative-int $cache
29+
*/
2330
public function __construct(
2431
string $name,
2532
int $allocationSize = 1,
@@ -36,6 +43,14 @@ public function __construct(
3643

3744
parent::__construct($parsedName);
3845

46+
if ($cache < 0) {
47+
Deprecation::triggerIfCalledFromOutside(
48+
'doctrine/dbal',
49+
'https://github.com/doctrine/dbal/pull/7108',
50+
'Passing a negative value as sequence cache size is deprecated.',
51+
);
52+
}
53+
3954
$this->setAllocationSize($allocationSize);
4055
$this->setInitialValue($initialValue);
4156
}
@@ -50,11 +65,29 @@ public function getInitialValue(): int
5065
return $this->initialValue;
5166
}
5267

68+
/**
69+
* @deprecated Use {@see getCacheSize()} instead.
70+
*
71+
* @return ?non-negative-int
72+
*/
5373
public function getCache(): ?int
5474
{
75+
Deprecation::triggerIfCalledFromOutside(
76+
'doctrine/dbal',
77+
'https://github.com/doctrine/dbal/pull/7108',
78+
'%s is deprecated, use `getCacheSize()` instead.',
79+
__METHOD__,
80+
);
81+
5582
return $this->cache;
5683
}
5784

85+
/** @return ?non-negative-int */
86+
public function getCacheSize(): ?int
87+
{
88+
return $this->getCache();
89+
}
90+
5891
public function setAllocationSize(int $allocationSize): self
5992
{
6093
$this->allocationSize = $allocationSize;
@@ -69,10 +102,31 @@ public function setInitialValue(int $initialValue): self
69102
return $this;
70103
}
71104

105+
/** @param non-negative-int $cache */
72106
public function setCache(int $cache): self
73107
{
74108
$this->cache = $cache;
75109

76110
return $this;
77111
}
112+
113+
/**
114+
* Instantiates a new sequence editor.
115+
*/
116+
public static function editor(): SequenceEditor
117+
{
118+
return new SequenceEditor();
119+
}
120+
121+
/**
122+
* Instantiates a new sequence editor and initializes it with the sequence's properties.
123+
*/
124+
public function edit(): SequenceEditor
125+
{
126+
return self::editor()
127+
->setName($this->getObjectName())
128+
->setAllocationSize($this->getAllocationSize())
129+
->setInitialValue($this->getInitialValue())
130+
->setCacheSize($this->getCacheSize());
131+
}
78132
}

src/Schema/SequenceEditor.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\DBAL\Schema;
6+
7+
use Doctrine\DBAL\Schema\Exception\InvalidSequenceDefinition;
8+
use Doctrine\DBAL\Schema\Name\OptionallyQualifiedName;
9+
10+
final class SequenceEditor
11+
{
12+
private ?OptionallyQualifiedName $name = null;
13+
14+
private int $allocationSize = 1;
15+
16+
private int $initialValue = 1;
17+
18+
/** @var ?non-negative-int */
19+
private ?int $cacheSize = null;
20+
21+
/** @internal Use {@link Sequence::editor()} or {@link Sequence::edit()} to create an instance */
22+
public function __construct()
23+
{
24+
}
25+
26+
public function setName(OptionallyQualifiedName $name): self
27+
{
28+
$this->name = $name;
29+
30+
return $this;
31+
}
32+
33+
/**
34+
* @param non-empty-string $unqualifiedName
35+
* @param ?non-empty-string $qualifier
36+
*/
37+
public function setUnquotedName(string $unqualifiedName, ?string $qualifier = null): self
38+
{
39+
$this->name = OptionallyQualifiedName::unquoted($unqualifiedName, $qualifier);
40+
41+
return $this;
42+
}
43+
44+
/**
45+
* @param non-empty-string $unqualifiedName
46+
* @param ?non-empty-string $qualifier
47+
*/
48+
public function setQuotedName(string $unqualifiedName, ?string $qualifier = null): self
49+
{
50+
$this->name = OptionallyQualifiedName::quoted($unqualifiedName, $qualifier);
51+
52+
return $this;
53+
}
54+
55+
public function setAllocationSize(int $allocationSize): self
56+
{
57+
$this->allocationSize = $allocationSize;
58+
59+
return $this;
60+
}
61+
62+
public function setInitialValue(int $initialValue): self
63+
{
64+
$this->initialValue = $initialValue;
65+
66+
return $this;
67+
}
68+
69+
/** @param ?non-negative-int $cacheSize */
70+
public function setCacheSize(?int $cacheSize): self
71+
{
72+
if ($cacheSize < 0) {
73+
throw InvalidSequenceDefinition::fromNegativeCacheSize($cacheSize);
74+
}
75+
76+
$this->cacheSize = $cacheSize;
77+
78+
return $this;
79+
}
80+
81+
public function create(): Sequence
82+
{
83+
if ($this->name === null) {
84+
throw InvalidSequenceDefinition::nameNotSet();
85+
}
86+
87+
return new Sequence(
88+
$this->name->toString(),
89+
$this->allocationSize,
90+
$this->initialValue,
91+
$this->cacheSize,
92+
);
93+
}
94+
}

src/Schema/View.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
final class View extends AbstractNamedObject
1818
{
19+
/** @internal Use {@link View::editor()} to instantiate an editor and {@link ViewEditor::create()} to create a view. */
1920
public function __construct(string $name, private readonly string $sql)
2021
{
2122
$parser = Parsers::getOptionallyQualifiedNameParser();
@@ -33,4 +34,22 @@ public function getSql(): string
3334
{
3435
return $this->sql;
3536
}
37+
38+
/**
39+
* Instantiates a new view editor.
40+
*/
41+
public static function editor(): ViewEditor
42+
{
43+
return new ViewEditor();
44+
}
45+
46+
/**
47+
* Instantiates a new view editor and initializes it with the view's properties.
48+
*/
49+
public function edit(): ViewEditor
50+
{
51+
return self::editor()
52+
->setName($this->getObjectName())
53+
->setSQL($this->sql);
54+
}
3655
}

0 commit comments

Comments
 (0)