1
0
mirror of synced 2024-12-13 06:46:03 +03:00

[2.0] Refactoring ClassExporter to allow the getting of the generated sql as well as executing it

This commit is contained in:
jwage 2009-02-17 01:54:11 +00:00
parent 438d970f40
commit 45079a1e98
3 changed files with 28 additions and 6 deletions

4
UPGRADE_TO_2_0 Normal file
View File

@ -0,0 +1,4 @@
Upgrade to Doctrine 2.0
#######################
More information coming soon...

View File

@ -58,12 +58,27 @@ class ClassExporter
} }
/** /**
* Exports entity classes to a database, according to the specified mappings. * Exports an array of class meta data instances to your database
* *
* @param array $classes * @param array $classes
*/ */
public function exportClasses(array $classes) public function exportClasses(array $classes)
{ {
$exportClassesSql = $this->getExportClassesSql($classes);
foreach ($exportClassesSql as $sql) {
$this->_em->getConnection()->execute($sql);
}
}
/**
* Get an array of sql statements for the specified array of class meta data instances
*
* @param array $classes
* @return array $sql
*/
public function getExportClassesSql(array $classes)
{
$sql = array();
$foreignKeyConstraints = array(); $foreignKeyConstraints = array();
// First we create the tables // First we create the tables
@ -143,18 +158,20 @@ class ClassExporter
} }
$foreignKeyConstraints[] = $constraint2; $foreignKeyConstraints[] = $constraint2;
$this->_sm->createTable($joinTable['name'], $joinTableColumns, array()); $sql = array_merge($sql, $this->_platform->getCreateTableSql($joinTable['name'], $joinTableColumns, array()));
} }
} }
$this->_sm->createTable($class->getTableName(), $columns, $options); $sql = array_merge($sql, $this->_platform->getCreateTableSql($class->getTableName(), $columns, $options));
} }
// Now create the foreign key constraints // Now create the foreign key constraints
if ($this->_platform->supportsForeignKeyConstraints()) { if ($this->_platform->supportsForeignKeyConstraints()) {
foreach ($foreignKeyConstraints as $fkConstraint) { foreach ($foreignKeyConstraints as $fkConstraint) {
$this->_sm->createForeignKey($fkConstraint['tableName'], $fkConstraint); $sql = array_merge($sql, $this->_platform->getCreateForeignKeySql($fkConstraint['tableName'], $fkConstraint));
} }
} }
return $sql;
} }
} }

View File

@ -32,10 +32,11 @@ class AllTests
$suite->addTestSuite('Doctrine\Tests\ORM\EntityManagerTest'); $suite->addTestSuite('Doctrine\Tests\ORM\EntityManagerTest');
$suite->addTestSuite('Doctrine\Tests\ORM\EntityPersisterTest'); $suite->addTestSuite('Doctrine\Tests\ORM\EntityPersisterTest');
$suite->addTestSuite('Doctrine\Tests\ORM\CommitOrderCalculatorTest'); $suite->addTestSuite('Doctrine\Tests\ORM\CommitOrderCalculatorTest');
$suite->addTest(Query\AllTests::suite()); $suite->addTest(Query\AllTests::suite());
$suite->addTest(Hydration\AllTests::suite()); $suite->addTest(Hydration\AllTests::suite());
$suite->addTest(Entity\AllTests::suite()); $suite->addTest(Entity\AllTests::suite());
$suite->addTest(Export\AllTests::suite());
$suite->addTest(Associations\AllTests::suite()); $suite->addTest(Associations\AllTests::suite());
$suite->addTest(Mapping\AllTests::suite()); $suite->addTest(Mapping\AllTests::suite());
$suite->addTest(Functional\AllTests::suite()); $suite->addTest(Functional\AllTests::suite());