diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 089780775..020f9962c 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -96,7 +96,6 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory protected function initialize() { $this->driver = $this->em->getConfiguration()->getMetadataDriverImpl(); - $this->targetPlatform = $this->em->getConnection()->getDatabasePlatform(); $this->evm = $this->em->getEventManager(); $this->initialized = true; } @@ -613,9 +612,9 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory { $idGenType = $class->generatorType; if ($idGenType == ClassMetadata::GENERATOR_TYPE_AUTO) { - if ($this->targetPlatform->prefersSequences()) { + if ($this->getTargetPlatform()->prefersSequences()) { $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_SEQUENCE); - } else if ($this->targetPlatform->prefersIdentityColumns()) { + } else if ($this->getTargetPlatform()->prefersIdentityColumns()) { $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_IDENTITY); } else { $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_TABLE); @@ -629,13 +628,13 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory $fieldName = $class->identifier ? $class->getSingleIdentifierFieldName() : null; // Platforms that do not have native IDENTITY support need a sequence to emulate this behaviour. - if ($this->targetPlatform->usesSequenceEmulatedIdentityColumns()) { + if ($this->getTargetPlatform()->usesSequenceEmulatedIdentityColumns()) { $columnName = $class->getSingleIdentifierColumnName(); $quoted = isset($class->fieldMappings[$fieldName]['quoted']) || isset($class->table['quoted']); - $sequencePrefix = $class->getSequencePrefix($this->targetPlatform); - $sequenceName = $this->targetPlatform->getIdentitySequenceName($sequencePrefix, $columnName); + $sequencePrefix = $class->getSequencePrefix($this->getTargetPlatform()); + $sequenceName = $this->getTargetPlatform()->getIdentitySequenceName($sequencePrefix, $columnName); $definition = array( - 'sequenceName' => $this->targetPlatform->fixSchemaElementName($sequenceName) + 'sequenceName' => $this->getTargetPlatform()->fixSchemaElementName($sequenceName) ); if ($quoted) { @@ -646,7 +645,7 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory ->em ->getConfiguration() ->getQuoteStrategy() - ->getSequenceName($definition, $class, $this->targetPlatform); + ->getSequenceName($definition, $class, $this->getTargetPlatform()); } $generator = ($fieldName && $class->fieldMappings[$fieldName]['type'] === 'bigint') @@ -663,11 +662,11 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory if ( ! $definition) { $fieldName = $class->getSingleIdentifierFieldName(); - $sequenceName = $class->getSequenceName($this->targetPlatform); + $sequenceName = $class->getSequenceName($this->getTargetPlatform()); $quoted = isset($class->fieldMappings[$fieldName]['quoted']) || isset($class->table['quoted']); $definition = array( - 'sequenceName' => $this->targetPlatform->fixSchemaElementName($sequenceName), + 'sequenceName' => $this->getTargetPlatform()->fixSchemaElementName($sequenceName), 'allocationSize' => 1, 'initialValue' => 1, ); @@ -680,7 +679,7 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory } $sequenceGenerator = new \Doctrine\ORM\Id\SequenceGenerator( - $this->em->getConfiguration()->getQuoteStrategy()->getSequenceName($definition, $class, $this->targetPlatform), + $this->em->getConfiguration()->getQuoteStrategy()->getSequenceName($definition, $class, $this->getTargetPlatform()), $definition['allocationSize'] ); $class->setIdGenerator($sequenceGenerator); @@ -753,4 +752,13 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory { return isset($class->isMappedSuperclass) && $class->isMappedSuperclass === false; } + + private function getTargetPlatform() + { + if ($this->targetPlatform === null) { + $this->targetPlatform = $this->em->getConnection()->getDatabasePlatform(); + } + + return $this->targetPlatform; + } }