88use Doctrine \DBAL \Schema \Name \OptionallyQualifiedName ;
99use Doctrine \DBAL \Schema \Name \Parser ;
1010use 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}
0 commit comments