Пример #1
0
 /**
  * Completes the ID generator mapping. If "auto" is specified we choose the generator
  * most appropriate for the targeted database platform.
  *
  * @param Doctrine\ORM\Mapping\ClassMetadata $class
  */
 private function completeIdGeneratorMapping(ClassMetadataInfo $class)
 {
     $idGenType = $class->generatorType;
     if ($idGenType == ClassMetadata::GENERATOR_TYPE_AUTO) {
         if ($this->targetPlatform->prefersSequences()) {
             $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_SEQUENCE);
         } else {
             if ($this->targetPlatform->prefersIdentityColumns()) {
                 $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_IDENTITY);
             } else {
                 $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_TABLE);
             }
         }
     }
     // Create & assign an appropriate ID generator instance
     switch ($class->generatorType) {
         case ClassMetadata::GENERATOR_TYPE_IDENTITY:
             // For PostgreSQL IDENTITY (SERIAL) we need a sequence name. It defaults to
             // <table>_<column>_seq in PostgreSQL for SERIAL columns.
             // Not pretty but necessary and the simplest solution that currently works.
             $seqName = $this->targetPlatform instanceof Platforms\PostgreSQLPlatform ? $class->table['name'] . '_' . $class->columnNames[$class->identifier[0]] . '_seq' : null;
             $class->setIdGenerator(new \Doctrine\ORM\Id\IdentityGenerator($seqName));
             break;
         case ClassMetadata::GENERATOR_TYPE_SEQUENCE:
             // If there is no sequence definition yet, create a default definition
             $definition = $class->sequenceGeneratorDefinition;
             if (!$definition) {
                 $sequenceName = $class->getTableName() . '_' . $class->getSingleIdentifierColumnName() . '_seq';
                 $definition['sequenceName'] = $this->targetPlatform->fixSchemaElementName($sequenceName);
                 $definition['allocationSize'] = 1;
                 $definition['initialValue'] = 1;
                 $class->setSequenceGeneratorDefinition($definition);
             }
             $sequenceGenerator = new \Doctrine\ORM\Id\SequenceGenerator($definition['sequenceName'], $definition['allocationSize']);
             $class->setIdGenerator($sequenceGenerator);
             break;
         case ClassMetadata::GENERATOR_TYPE_NONE:
             $class->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator());
             break;
         case ClassMetadata::GENERATOR_TYPE_TABLE:
             throw new ORMException("TableGenerator not yet implemented.");
             break;
         default:
             throw new ORMException("Unknown generator type: " . $class->generatorType);
     }
 }
Пример #2
0
 /**
  * Inherits the ID generator mapping from a parent class.
  *
  * @param ClassMetadataInfo $class
  * @param ClassMetadataInfo $parent
  */
 private function inheritIdGeneratorMapping(ClassMetadataInfo $class, ClassMetadataInfo $parent)
 {
     if ($parent->isIdGeneratorSequence()) {
         $class->setSequenceGeneratorDefinition($parent->sequenceGeneratorDefinition);
     } elseif ($parent->isIdGeneratorTable()) {
         $class->tableGeneratorDefinition = $parent->tableGeneratorDefinition;
     }
     if ($parent->generatorType) {
         $class->setIdGeneratorType($parent->generatorType);
     }
     if ($parent->idGenerator) {
         $class->setIdGenerator($parent->idGenerator);
     }
 }
Пример #3
0
 /**
  * Completes the ID generator mapping. If "auto" is specified we choose the generator
  * most appropriate for the targeted database platform.
  *
  * @param Doctrine\ORM\Mapping\ClassMetadata $class
  */
 private function _completeIdGeneratorMapping(ClassMetadataInfo $class)
 {
     $idGenType = $class->generatorType;
     if ($idGenType == ClassMetadata::GENERATOR_TYPE_AUTO) {
         if ($this->_targetPlatform->prefersSequences()) {
             $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_SEQUENCE);
         } else {
             if ($this->_targetPlatform->prefersIdentityColumns()) {
                 $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_IDENTITY);
             } else {
                 $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_TABLE);
             }
         }
     }
     // Create & assign an appropriate ID generator instance
     switch ($class->generatorType) {
         case ClassMetadata::GENERATOR_TYPE_IDENTITY:
             $class->setIdGenerator(new \Doctrine\ORM\Id\IdentityGenerator());
             break;
         case ClassMetadata::GENERATOR_TYPE_SEQUENCE:
             // If there is no sequence definition yet, create a default definition
             $definition = $class->sequenceGeneratorDefinition;
             if (!$definition) {
                 $sequenceName = $class->getTableName() . '_' . $class->getSingleIdentifierColumnName() . '_seq';
                 $definition['sequenceName'] = $this->_targetPlatform->fixSchemaElementName($sequenceName);
                 $definition['allocationSize'] = 10;
                 $definition['initialValue'] = 1;
                 $class->setSequenceGeneratorDefinition($definition);
             }
             $sequenceGenerator = new \Doctrine\ORM\Id\SequenceGenerator($definition['sequenceName'], $definition['allocationSize']);
             $class->setIdGenerator($sequenceGenerator);
             break;
         case ClassMetadata::GENERATOR_TYPE_NONE:
             $class->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator());
             break;
         case ClassMetadata::GENERATOR_TYPE_TABLE:
             throw new ORMException("TableGenerator not yet implemented.");
             break;
         default:
             throw new ORMException("Unknown generator type: " . $class->generatorType);
     }
 }