[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:
parent
8562c80890
commit
25c9588592
@ -598,13 +598,10 @@ abstract class AbstractPlatform
|
|||||||
/**
|
/**
|
||||||
* Gets the SQL to create a sequence on this platform.
|
* Gets the SQL to create a sequence on this platform.
|
||||||
*
|
*
|
||||||
* @param string $sequenceName
|
* @param \Doctrine\DBAL\Schema\Sequence $sequence
|
||||||
* @param integer $start
|
|
||||||
* @param integer $allocationSize
|
|
||||||
* @return string
|
|
||||||
* @throws DoctrineException
|
* @throws DoctrineException
|
||||||
*/
|
*/
|
||||||
public function getCreateSequenceSql($sequenceName, $start = 1, $allocationSize = 1)
|
public function getCreateSequenceSql(\Doctrine\DBAL\Schema\Sequence $sequence)
|
||||||
{
|
{
|
||||||
throw DBALException::notSupported(__METHOD__);
|
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
|
* Therefore we can use MINVALUE to be able to get a hint what START WITH was for later introspection
|
||||||
* in {@see listSequences()}
|
* in {@see listSequences()}
|
||||||
*
|
*
|
||||||
* @param string $sequenceName
|
* @param \Doctrine\DBAL\Schema\Sequence $sequence
|
||||||
* @param integer $start
|
* @throws DoctrineException
|
||||||
* @param integer $allocationSize
|
|
||||||
* @return string The SQL.
|
|
||||||
*/
|
*/
|
||||||
public function getCreateSequenceSql($sequenceName, $start = 1, $allocationSize = 1)
|
public function getCreateSequenceSql(\Doctrine\DBAL\Schema\Sequence $sequence)
|
||||||
{
|
{
|
||||||
return 'CREATE SEQUENCE ' . $sequenceName
|
return 'CREATE SEQUENCE ' . $sequence->getName() .
|
||||||
. ' START WITH ' . $start . ' MINVALUE ' . $start . ' INCREMENT BY ' . $allocationSize;
|
' START WITH ' . $sequence->getInitialValue() .
|
||||||
|
' MINVALUE ' . $sequence->getInitialValue() .
|
||||||
|
' INCREMENT BY ' . $sequence->getAllocationSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -366,7 +366,8 @@ BEGIN
|
|||||||
END;';
|
END;';
|
||||||
|
|
||||||
$sequenceName = $table . '_SEQ';
|
$sequenceName = $table . '_SEQ';
|
||||||
$sql[] = $this->getCreateSequenceSql($sequenceName, $start);
|
$sequence = new \Doctrine\DBAL\Schema\Sequence($sequenceName, $start);
|
||||||
|
$sql[] = $this->getCreateSequenceSql($sequence);
|
||||||
|
|
||||||
$triggerName = $table . '_AI_PK';
|
$triggerName = $table . '_AI_PK';
|
||||||
$sql[] = 'CREATE TRIGGER ' . $triggerName . '
|
$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
|
* @param \Doctrine\DBAL\Schema\Sequence $sequence
|
||||||
* @override
|
* @throws DoctrineException
|
||||||
*/
|
*/
|
||||||
public function getCreateSequenceSql($sequenceName, $start = 1, $allocationSize = 1)
|
public function getCreateSequenceSql(\Doctrine\DBAL\Schema\Sequence $sequence)
|
||||||
{
|
{
|
||||||
return 'CREATE SEQUENCE ' . $sequenceName
|
return 'CREATE SEQUENCE ' . $sequence->getName() .
|
||||||
. ' INCREMENT BY ' . $allocationSize . ' START ' . $start;
|
' INCREMENT BY ' . $sequence->getAllocationSize() .
|
||||||
|
' START ' . $sequence->getInitialValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -418,14 +418,12 @@ abstract class AbstractSchemaManager
|
|||||||
/**
|
/**
|
||||||
* Create a new sequence
|
* Create a new sequence
|
||||||
*
|
*
|
||||||
* @param string $seqName name of the sequence to be created
|
* @param Sequence $sequence
|
||||||
* @param string $start start value of the sequence; default is 1
|
|
||||||
* @param array $allocationSize The size to allocate for sequence
|
|
||||||
* @throws Doctrine\DBAL\ConnectionException if something fails at database level
|
* @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)
|
public function acceptSequence(Sequence $sequence)
|
||||||
{
|
{
|
||||||
$this->_createSequenceQueries = array_merge($this->_createSequenceQueries,
|
$this->_createSequenceQueries = array_merge(
|
||||||
(array)$this->_platform->getCreateSequenceSql(
|
$this->_createSequenceQueries, (array)$this->_platform->getCreateSequenceSql($sequence)
|
||||||
$sequence->getName(),
|
|
||||||
$sequence->getInitialValue(),
|
|
||||||
$sequence->getAllocationSize()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,8 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
|
|||||||
$this->markTestSkipped($this->_conn->getDriver()->getName().' does not support sequences.');
|
$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();
|
$sequences = $this->_sm->listSequences();
|
||||||
|
|
||||||
|
@ -143,9 +143,10 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase
|
|||||||
|
|
||||||
public function testGeneratesSequenceSqlCommands()
|
public function testGeneratesSequenceSqlCommands()
|
||||||
{
|
{
|
||||||
|
$sequence = new \Doctrine\DBAL\Schema\Sequence('myseq', 20, 1);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'CREATE SEQUENCE myseq INCREMENT BY 20 START 1',
|
'CREATE SEQUENCE myseq INCREMENT BY 20 START 1',
|
||||||
$this->_platform->getCreateSequenceSql('myseq', 1, 20)
|
$this->_platform->getCreateSequenceSql($sequence)
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'DROP SEQUENCE myseq',
|
'DROP SEQUENCE myseq',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user