1
0
mirror of synced 2024-12-12 22:36:02 +03:00

[2.0] DDC-169 - Changed AbstractPlatform and AbstractSchemaManager and children to accept Sequences in their create and get sql methods.

This commit is contained in:
beberlei 2009-12-02 19:07:38 +00:00
parent 8562c80890
commit 25c9588592
7 changed files with 28 additions and 33 deletions

View File

@ -598,13 +598,10 @@ abstract class AbstractPlatform
/**
* Gets the SQL to create a sequence on this platform.
*
* @param string $sequenceName
* @param integer $start
* @param integer $allocationSize
* @return string
* @param \Doctrine\DBAL\Schema\Sequence $sequence
* @throws DoctrineException
*/
public function getCreateSequenceSql($sequenceName, $start = 1, $allocationSize = 1)
public function getCreateSequenceSql(\Doctrine\DBAL\Schema\Sequence $sequence)
{
throw DBALException::notSupported(__METHOD__);
}

View File

@ -110,15 +110,15 @@ class OraclePlatform extends AbstractPlatform
* Therefore we can use MINVALUE to be able to get a hint what START WITH was for later introspection
* in {@see listSequences()}
*
* @param string $sequenceName
* @param integer $start
* @param integer $allocationSize
* @return string The SQL.
* @param \Doctrine\DBAL\Schema\Sequence $sequence
* @throws DoctrineException
*/
public function getCreateSequenceSql($sequenceName, $start = 1, $allocationSize = 1)
public function getCreateSequenceSql(\Doctrine\DBAL\Schema\Sequence $sequence)
{
return 'CREATE SEQUENCE ' . $sequenceName
. ' START WITH ' . $start . ' MINVALUE ' . $start . ' INCREMENT BY ' . $allocationSize;
return 'CREATE SEQUENCE ' . $sequence->getName() .
' START WITH ' . $sequence->getInitialValue() .
' MINVALUE ' . $sequence->getInitialValue() .
' INCREMENT BY ' . $sequence->getAllocationSize();
}
/**
@ -366,7 +366,8 @@ BEGIN
END;';
$sequenceName = $table . '_SEQ';
$sql[] = $this->getCreateSequenceSql($sequenceName, $start);
$sequence = new \Doctrine\DBAL\Schema\Sequence($sequenceName, $start);
$sql[] = $this->getCreateSequenceSql($sequence);
$triggerName = $table . '_AI_PK';
$sql[] = 'CREATE TRIGGER ' . $triggerName . '

View File

@ -559,15 +559,16 @@ class PostgreSqlPlatform extends AbstractPlatform
}
/**
* {@inheritdoc}
*
* @return string
* @override
* Gets the SQL to create a sequence on this platform.
*
* @param \Doctrine\DBAL\Schema\Sequence $sequence
* @throws DoctrineException
*/
public function getCreateSequenceSql($sequenceName, $start = 1, $allocationSize = 1)
public function getCreateSequenceSql(\Doctrine\DBAL\Schema\Sequence $sequence)
{
return 'CREATE SEQUENCE ' . $sequenceName
. ' INCREMENT BY ' . $allocationSize . ' START ' . $start;
return 'CREATE SEQUENCE ' . $sequence->getName() .
' INCREMENT BY ' . $sequence->getAllocationSize() .
' START ' . $sequence->getInitialValue();
}
/**

View File

@ -418,14 +418,12 @@ abstract class AbstractSchemaManager
/**
* Create a new sequence
*
* @param string $seqName name of the sequence to be created
* @param string $start start value of the sequence; default is 1
* @param array $allocationSize The size to allocate for sequence
* @param Sequence $sequence
* @throws Doctrine\DBAL\ConnectionException if something fails at database level
*/
public function createSequence($seqName, $start = 1, $allocationSize = 1)
public function createSequence($sequence)
{
$this->_execSql($this->_platform->getCreateSequenceSql($seqName, $start, $allocationSize));
$this->_execSql($this->_platform->getCreateSequenceSql($sequence));
}
/**

View File

@ -123,12 +123,8 @@ class CreateSchemaSqlCollector implements Visitor
*/
public function acceptSequence(Sequence $sequence)
{
$this->_createSequenceQueries = array_merge($this->_createSequenceQueries,
(array)$this->_platform->getCreateSequenceSql(
$sequence->getName(),
$sequence->getInitialValue(),
$sequence->getAllocationSize()
)
$this->_createSequenceQueries = array_merge(
$this->_createSequenceQueries, (array)$this->_platform->getCreateSequenceSql($sequence)
);
}

View File

@ -14,7 +14,8 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$this->markTestSkipped($this->_conn->getDriver()->getName().' does not support sequences.');
}
$this->_sm->createSequence('list_sequences_test_seq', 10, 20);
$sequence = new \Doctrine\DBAL\Schema\Sequence('list_sequences_test_seq', 20, 10);
$this->_sm->createSequence($sequence);
$sequences = $this->_sm->listSequences();

View File

@ -143,9 +143,10 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase
public function testGeneratesSequenceSqlCommands()
{
$sequence = new \Doctrine\DBAL\Schema\Sequence('myseq', 20, 1);
$this->assertEquals(
'CREATE SEQUENCE myseq INCREMENT BY 20 START 1',
$this->_platform->getCreateSequenceSql('myseq', 1, 20)
$this->_platform->getCreateSequenceSql($sequence)
);
$this->assertEquals(
'DROP SEQUENCE myseq',