当前位置: 首页>>代码示例>>PHP>>正文


PHP ClassMetadataInfo::getSequencePrefix方法代码示例

本文整理汇总了PHP中Doctrine\ORM\Mapping\ClassMetadataInfo::getSequencePrefix方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadataInfo::getSequencePrefix方法的具体用法?PHP ClassMetadataInfo::getSequencePrefix怎么用?PHP ClassMetadataInfo::getSequencePrefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\ORM\Mapping\ClassMetadataInfo的用法示例。


在下文中一共展示了ClassMetadataInfo::getSequencePrefix方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: completeIdGeneratorMapping

 /**
  * Completes the ID generator mapping. If "auto" is specified we choose the generator
  * most appropriate for the targeted database platform.
  *
  * @param ClassMetadataInfo $class
  *
  * @return void
  *
  * @throws ORMException
  */
 private function completeIdGeneratorMapping(ClassMetadataInfo $class)
 {
     $idGenType = $class->generatorType;
     if ($idGenType == ClassMetadata::GENERATOR_TYPE_AUTO) {
         if ($this->getTargetPlatform()->prefersSequences()) {
             $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_SEQUENCE);
         } else {
             if ($this->getTargetPlatform()->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:
             $sequenceName = null;
             $fieldName = $class->identifier ? $class->getSingleIdentifierFieldName() : null;
             // Platforms that do not have native IDENTITY support need a sequence to emulate this behaviour.
             if ($this->getTargetPlatform()->usesSequenceEmulatedIdentityColumns()) {
                 $columnName = $class->getSingleIdentifierColumnName();
                 $quoted = isset($class->fieldMappings[$fieldName]['quoted']) || isset($class->table['quoted']);
                 $sequencePrefix = $class->getSequencePrefix($this->getTargetPlatform());
                 $sequenceName = $this->getTargetPlatform()->getIdentitySequenceName($sequencePrefix, $columnName);
                 $definition = array('sequenceName' => $this->getTargetPlatform()->fixSchemaElementName($sequenceName));
                 if ($quoted) {
                     $definition['quoted'] = true;
                 }
                 $sequenceName = $this->em->getConfiguration()->getQuoteStrategy()->getSequenceName($definition, $class, $this->getTargetPlatform());
             }
             $generator = $fieldName && $class->fieldMappings[$fieldName]['type'] === 'bigint' ? new BigIntegerIdentityGenerator($sequenceName) : new IdentityGenerator($sequenceName);
             $class->setIdGenerator($generator);
             break;
         case ClassMetadata::GENERATOR_TYPE_SEQUENCE:
             // If there is no sequence definition yet, create a default definition
             $definition = $class->sequenceGeneratorDefinition;
             if (!$definition) {
                 $fieldName = $class->getSingleIdentifierFieldName();
                 $sequenceName = $class->getSequenceName($this->getTargetPlatform());
                 $quoted = isset($class->fieldMappings[$fieldName]['quoted']) || isset($class->table['quoted']);
                 $definition = array('sequenceName' => $this->getTargetPlatform()->fixSchemaElementName($sequenceName), 'allocationSize' => 1, 'initialValue' => 1);
                 if ($quoted) {
                     $definition['quoted'] = true;
                 }
                 $class->setSequenceGeneratorDefinition($definition);
             }
             $sequenceGenerator = new \Doctrine\ORM\Id\SequenceGenerator($this->em->getConfiguration()->getQuoteStrategy()->getSequenceName($definition, $class, $this->getTargetPlatform()), $definition['allocationSize']);
             $class->setIdGenerator($sequenceGenerator);
             break;
         case ClassMetadata::GENERATOR_TYPE_NONE:
             $class->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator());
             break;
         case ClassMetadata::GENERATOR_TYPE_UUID:
             $class->setIdGenerator(new \Doctrine\ORM\Id\UuidGenerator());
             break;
         case ClassMetadata::GENERATOR_TYPE_TABLE:
             throw new ORMException("TableGenerator not yet implemented.");
             break;
         case ClassMetadata::GENERATOR_TYPE_CUSTOM:
             $definition = $class->customGeneratorDefinition;
             if (!class_exists($definition['class'])) {
                 throw new ORMException("Can't instantiate custom generator : " . $definition['class']);
             }
             $class->setIdGenerator(new $definition['class']());
             break;
         default:
             throw new ORMException("Unknown generator type: " . $class->generatorType);
     }
 }
开发者ID:StoshSeb,项目名称:doctrine2,代码行数:80,代码来源:ClassMetadataFactory.php


注:本文中的Doctrine\ORM\Mapping\ClassMetadataInfo::getSequencePrefix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。