123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
-
-
- namespace Doctrine\ORM\Id;
-
- use Serializable, Doctrine\ORM\EntityManager;
-
-
- class SequenceGenerator extends AbstractIdGenerator implements Serializable
- {
- private $_allocationSize;
- private $_sequenceName;
- private $_nextValue = 0;
- private $_maxValue = null;
-
-
-
- public function __construct($sequenceName, $allocationSize)
- {
- $this->_sequenceName = $sequenceName;
- $this->_allocationSize = $allocationSize;
- }
-
-
-
- public function generate(EntityManager $em, $entity)
- {
- if ($this->_maxValue === null || $this->_nextValue == $this->_maxValue) {
-
- $conn = $em->getConnection();
- $sql = $conn->getDatabasePlatform()->getSequenceNextValSQL($this->_sequenceName);
- $this->_nextValue = $conn->fetchColumn($sql);
- $this->_maxValue = $this->_nextValue + $this->_allocationSize;
- }
- return $this->_nextValue++;
- }
-
-
-
- public function getCurrentMaxValue()
- {
- return $this->_maxValue;
- }
-
-
-
- public function getNextValue()
- {
- return $this->_nextValue;
- }
-
- public function serialize()
- {
- return serialize(array(
- 'allocationSize' => $this->_allocationSize,
- 'sequenceName' => $this->_sequenceName
- ));
- }
-
- public function unserialize($serialized)
- {
- $array = unserialize($serialized);
- $this->_sequenceName = $array['sequenceName'];
- $this->_allocationSize = $array['allocationSize'];
- }
- }
|