44
55namespace Doctrine \DBAL \Schema ;
66
7- use Doctrine \DBAL \Schema \Exception \InvalidName ;
7+ use Doctrine \DBAL \Schema \Exception \InvalidSequenceDefinition ;
88use Doctrine \DBAL \Schema \Name \OptionallyQualifiedName ;
9- use Doctrine \DBAL \Schema \Name \Parser ;
10- use Doctrine \DBAL \Schema \Name \Parsers ;
11- use Doctrine \Deprecations \Deprecation ;
129
1310/**
1411 * Sequence structure.
1714 */
1815final class Sequence extends AbstractNamedObject
1916{
20- private int $ allocationSize = 1 ;
21-
22- private int $ initialValue = 1 ;
23-
2417 /**
2518 * @internal Use {@link Sequence::editor()} to instantiate an editor and {@link SequenceEditor::create()} to create
2619 * a sequence.
2720 *
28- * @param ?non-negative-int $cache
21+ * @param ?non-negative-int $cacheSize
2922 */
3023 public function __construct (
31- string $ name ,
32- int $ allocationSize = 1 ,
33- int $ initialValue = 1 ,
34- private ?int $ cache = null ,
24+ OptionallyQualifiedName $ name ,
25+ private readonly int $ allocationSize ,
26+ private readonly int $ initialValue ,
27+ private readonly ?int $ cacheSize = null ,
3528 ) {
36- $ parser = Parsers:: getOptionallyQualifiedNameParser ( );
29+ parent :: __construct ( $ name );
3730
38- try {
39- $ parsedName = $ parser ->parse ($ name );
40- } catch (Parser \Exception $ e ) {
41- throw InvalidName::fromParserException ($ name , $ e );
31+ if ($ cacheSize < 0 ) {
32+ throw InvalidSequenceDefinition::fromNegativeCacheSize ($ cacheSize );
4233 }
43-
44- parent ::__construct ($ parsedName );
45-
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-
54- $ this ->setAllocationSize ($ allocationSize );
55- $ this ->setInitialValue ($ initialValue );
5634 }
5735
5836 public function getAllocationSize (): int
@@ -65,49 +43,10 @@ public function getInitialValue(): int
6543 return $ this ->initialValue ;
6644 }
6745
68- /**
69- * @deprecated Use {@see getCacheSize()} instead.
70- *
71- * @return ?non-negative-int
72- */
73- public function getCache (): ?int
74- {
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-
82- return $ this ->cache ;
83- }
84-
8546 /** @return ?non-negative-int */
8647 public function getCacheSize (): ?int
8748 {
88- return $ this ->getCache ();
89- }
90-
91- public function setAllocationSize (int $ allocationSize ): self
92- {
93- $ this ->allocationSize = $ allocationSize ;
94-
95- return $ this ;
96- }
97-
98- public function setInitialValue (int $ initialValue ): self
99- {
100- $ this ->initialValue = $ initialValue ;
101-
102- return $ this ;
103- }
104-
105- /** @param non-negative-int $cache */
106- public function setCache (int $ cache ): self
107- {
108- $ this ->cache = $ cache ;
109-
110- return $ this ;
49+ return $ this ->cacheSize ;
11150 }
11251
11352 /**
@@ -124,9 +63,9 @@ public static function editor(): SequenceEditor
12463 public function edit (): SequenceEditor
12564 {
12665 return self ::editor ()
127- ->setName ($ this ->getObjectName () )
128- ->setAllocationSize ($ this ->getAllocationSize () )
129- ->setInitialValue ($ this ->getInitialValue () )
130- ->setCacheSize ($ this ->getCacheSize () );
66+ ->setName ($ this ->name )
67+ ->setAllocationSize ($ this ->allocationSize )
68+ ->setInitialValue ($ this ->initialValue )
69+ ->setCacheSize ($ this ->cacheSize );
13170 }
13271}
0 commit comments