12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
-
-
- namespace Doctrine\ORM\Id;
-
- use Doctrine\ORM\EntityManager;
-
-
- class TableGenerator extends AbstractIdGenerator
- {
- private $_tableName;
- private $_sequenceName;
- private $_allocationSize;
- private $_nextValue;
- private $_maxValue;
-
- public function __construct($tableName, $sequenceName = 'default', $allocationSize = 10)
- {
- $this->_tableName = $tableName;
- $this->_sequenceName = $sequenceName;
- $this->_allocationSize = $allocationSize;
- }
-
- public function generate(EntityManager $em, $entity)
- {
- if ($this->_maxValue === null || $this->_nextValue == $this->_maxValue) {
-
- $conn = $em->getConnection();
- if ($conn->getTransactionNestingLevel() == 0) {
-
-
- $sql = $conn->getDatabasePlatform()->getTableHiLoCurrentValSql($this->_tableName, $this->_sequenceName);
- $currentLevel = $conn->fetchColumn($sql);
- if ($currentLevel != null) {
- $this->_nextValue = $currentLevel;
- $this->_maxValue = $this->_nextValue + $this->_allocationSize;
-
- $updateSql = $conn->getDatabasePlatform()->getTableHiLoUpdateNextValSql(
- $this->_tableName, $this->_sequenceName, $this->_allocationSize
- );
-
- if ($conn->executeUpdate($updateSql, array(1 => $currentLevel, 2 => $currentLevel+1)) !== 1) {
-
- }
- } else {
-
- }
- } else {
-
-
- }
- }
- return $this->_nextValue++;
- }
- }
|