3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the MIT license. For more information, see
17 * <http://www.doctrine-project.org>.
20 namespace Doctrine\DBAL\Schema;
22 use Doctrine\DBAL\Schema\Visitor\Visitor;
28 * @link www.doctrine-project.org
31 * @author Benjamin Eberlei <kontakt@beberlei.de>
33 class Sequence extends AbstractAsset
38 protected $_allocationSize = 1;
43 protected $_initialValue = 1;
48 * @param int $allocationSize
49 * @param int $initialValue
51 public function __construct($name, $allocationSize=1, $initialValue=1)
53 $this->_setName($name);
54 $this->_allocationSize = (is_numeric($allocationSize))?$allocationSize:1;
55 $this->_initialValue = (is_numeric($initialValue))?$initialValue:1;
58 public function getAllocationSize()
60 return $this->_allocationSize;
63 public function getInitialValue()
65 return $this->_initialValue;
68 public function setAllocationSize($allocationSize)
70 $this->_allocationSize = (is_numeric($allocationSize))?$allocationSize:1;
73 public function setInitialValue($initialValue)
75 $this->_initialValue = (is_numeric($initialValue))?$initialValue:1;
79 * Check if this sequence is an autoincrement sequence for a given table.
81 * This is used inside the comparator to not report sequences as missing,
82 * when the "from" schema implicitly creates the sequences.
88 public function isAutoIncrementsFor(Table $table)
90 if ( ! $table->hasPrimaryKey()) {
94 $pkColumns = $table->getPrimaryKey()->getColumns();
96 if (count($pkColumns) != 1) {
100 $column = $table->getColumn($pkColumns[0]);
102 if ( ! $column->getAutoincrement()) {
106 $sequenceName = $this->getShortestName($table->getNamespaceName());
107 $tableName = $table->getShortestName($table->getNamespaceName());
108 $tableSequenceName = sprintf('%s_%s_seq', $tableName, $pkColumns[0]);
110 return $tableSequenceName === $sequenceName;
114 * @param Visitor $visitor
116 public function visit(Visitor $visitor)
118 $visitor->acceptSequence($this);