Commit 25c95885 authored by beberlei's avatar beberlei

[2.0] DDC-169 - Changed AbstractPlatform and AbstractSchemaManager and...

[2.0] DDC-169 - Changed AbstractPlatform and AbstractSchemaManager and children to accept Sequences in their create and get sql methods.
parent 8562c808
......@@ -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__);
}
......
......@@ -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 . '
......
......@@ -559,15 +559,16 @@ class PostgreSqlPlatform extends AbstractPlatform
}
/**
* {@inheritdoc}
* Gets the SQL to create a sequence on this platform.
*
* @return string
* @override
* @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();
}
/**
......
......@@ -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));
}
/**
......
......@@ -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)
);
}
......
......@@ -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();
......
......@@ -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',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment