Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove calls to prefersSequences() #8870

Merged
merged 1 commit into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,13 +548,7 @@ private function completeIdGeneratorMapping(ClassMetadataInfo $class): void
{
$idGenType = $class->generatorType;
if ($idGenType === ClassMetadata::GENERATOR_TYPE_AUTO) {
if ($this->getTargetPlatform()->prefersSequences()) {
$class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_SEQUENCE);
} elseif ($this->getTargetPlatform()->prefersIdentityColumns()) {
$class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_IDENTITY);
} else {
$class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_TABLE);
}
$class->setIdGeneratorType($this->determineIdGeneratorStrategy($this->getTargetPlatform()));
}

// Create & assign an appropriate ID generator instance
Expand Down Expand Up @@ -658,6 +652,23 @@ private function completeIdGeneratorMapping(ClassMetadataInfo $class): void
}
}

private function determineIdGeneratorStrategy(AbstractPlatform $platform): int
{
if ($platform->getName() === 'oracle' || $platform->getName() === 'postgresql') {
return ClassMetadata::GENERATOR_TYPE_SEQUENCE;
}

if ($platform->supportsIdentityColumns()) {
return ClassMetadata::GENERATOR_TYPE_IDENTITY;
}

if ($platform->supportsSequences()) {
return ClassMetadata::GENERATOR_TYPE_SEQUENCE;
}

return ClassMetadata::GENERATOR_TYPE_TABLE;
}

/**
* Inherits the ID generator mapping from a parent class.
*/
Expand Down
48 changes: 23 additions & 25 deletions tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,47 @@

namespace Doctrine\Tests\Mocks;

use BadMethodCallException;
use Doctrine\DBAL\Exception as DBALException;
use Doctrine\DBAL\Platforms\AbstractPlatform;

/**
* Mock class for DatabasePlatform.
*/
class DatabasePlatformMock extends AbstractPlatform
{
/** @var string */
private $_sequenceNextValSql = '';

/** @var bool */
private $_prefersIdentityColumns = true;
private $supportsIdentityColumns = true;

/** @var bool */
private $_prefersSequences = false;
private $supportsSequences = false;

/**
* {@inheritdoc}
*/
public function prefersIdentityColumns()
public function prefersIdentityColumns(): bool
{
return $this->_prefersIdentityColumns;
throw new BadMethodCallException('Call to deprecated method.');
}

/**
* {@inheritdoc}
*/
public function prefersSequences()
public function supportsIdentityColumns(): bool
{
return $this->supportsIdentityColumns;
}

public function prefersSequences(): bool
{
throw new BadMethodCallException('Call to deprecated method.');
}

public function supportsSequences(): bool
{
return $this->_prefersSequences;
return $this->supportsSequences;
}

/**
* {@inheritdoc}
*/
public function getSequenceNextValSQL($sequenceName)
{
return $this->_sequenceNextValSql;
return '';
}

/**
Expand Down Expand Up @@ -95,19 +98,14 @@ public function getClobTypeDeclarationSQL(array $field)

/* MOCK API */

public function setPrefersIdentityColumns(bool $bool): void
{
$this->_prefersIdentityColumns = $bool;
}

public function setPrefersSequences(bool $bool): void
public function setSupportsIdentityColumns(bool $bool): void
{
$this->_prefersSequences = $bool;
$this->supportsIdentityColumns = $bool;
}

public function setSequenceNextValSql(string $sql): void
public function setSupportsSequences(bool $bool): void
{
$this->_sequenceNextValSql = $sql;
$this->supportsSequences = $bool;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public function testGetMetadataForSingleClass(): void

$conn = $entityManager->getConnection();
$mockPlatform = $conn->getDatabasePlatform();
$mockPlatform->setPrefersSequences(true);
$mockPlatform->setPrefersIdentityColumns(false);
$mockPlatform->setSupportsSequences(true);
$mockPlatform->setSupportsIdentityColumns(false);

$cm1 = $this->createValidClassMetadata();

Expand Down