1
0
mirror of synced 2025-01-09 18:47:10 +03:00

Merge branch 'hotfix/#1204-metadata-xml-exporter-should-export-sequence-generator-info'

Close #1204
This commit is contained in:
Marco Pivetta 2014-12-04 14:00:34 +01:00
commit 8d4b46d014
2 changed files with 68 additions and 0 deletions

View File

@ -171,6 +171,8 @@ class XmlExporter extends AbstractExporter
if ($idGeneratorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) {
$generatorXml = $idXml->addChild('generator');
$generatorXml->addAttribute('strategy', $idGeneratorType);
$this->exportSequenceInformation($idXml, $metadata);
}
}
}
@ -411,6 +413,29 @@ class XmlExporter extends AbstractExporter
}
}
/**
* Export sequence information (if available/configured) into the current identifier XML node
*
* @param \SimpleXMLElement $identifierXmlNode
* @param ClassMetadataInfo $metadata
*
* @return void
*/
private function exportSequenceInformation(\SimpleXMLElement $identifierXmlNode, ClassMetadataInfo $metadata)
{
$sequenceDefinition = $metadata->sequenceGeneratorDefinition;
if (! ($metadata->generatorType === ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE && $sequenceDefinition)) {
return;
}
$sequenceGeneratorXml = $identifierXmlNode->addChild('sequence-generator');
$sequenceGeneratorXml->addAttribute('sequence-name', $sequenceDefinition['sequenceName']);
$sequenceGeneratorXml->addAttribute('allocation-size', $sequenceDefinition['allocationSize']);
$sequenceGeneratorXml->addAttribute('initial-value', $sequenceDefinition['initialValue']);
}
/**
* @param \SimpleXMLElement $simpleXml
*

View File

@ -20,6 +20,9 @@
*/
namespace Doctrine\Tests\ORM\Tools\Export;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Tools\Export\Driver\XmlExporter;
/**
* Test case for XmlClassMetadataExporterTest
@ -37,4 +40,44 @@ class XmlClassMetadataExporterTest extends AbstractClassMetadataExporterTest
{
return 'xml';
}
/**
* @group DDC-3428
*/
public function testSequenceGenerator() {
$exporter = new XmlExporter();
$metadata = new ClassMetadata('entityTest');
$metadata->mapField(array(
"fieldName" => 'id',
"type" => 'integer',
"columnName" => 'id',
"id" => true,
));
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE);
$metadata->setSequenceGeneratorDefinition(array(
'sequenceName' => 'seq_entity_test_id',
'allocationSize' => 5,
'initialValue' => 1
));
$expectedFileContent = <<<'XML'
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping
xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
>
<entity name="entityTest">
<id name="id" type="integer" column="id">
<generator strategy="SEQUENCE"/>
<sequence-generator sequence-name="seq_entity_test_id" allocation-size="5" initial-value="1"/>
</id>
</entity>
</doctrine-mapping>
XML;
$this->assertXmlStringEqualsXmlString($expectedFileContent, $exporter->exportClassMetadata($metadata));
}
}