Skip to content

Commit

Permalink
[doctrineGH-4052] Rename to PrimaryReadReplicaConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Jun 8, 2020
1 parent cbf2827 commit 3e87bf2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Upgrade to 2.11

## Deprecated `MasterSlaveConnection` use `PrimaryReplicaConnection`
## Deprecated `MasterSlaveConnection` use `PrimaryReadReplicaConnection`

The `Doctrine\DBAL\Connections\MasterSlaveConnection` class is renamed to `Doctrine\DBAL\Connections\PrimaryReplicaConnection`.
The `Doctrine\DBAL\Connections\MasterSlaveConnection` class is renamed to `Doctrine\DBAL\Connections\PrimaryReadReplicaConnection`.
In addition its configuration parameters `master`, `slaves` and `keepSlave` are renamed to `primary`, `replica` and `keepReplica`.

Before:
Expand All @@ -24,7 +24,7 @@ Before:
After:

$connection = DriverManager::getConnection(array(
'wrapperClass' => 'Doctrine\DBAL\Connections\PrimaryReplicaConnection',
'wrapperClass' => 'Doctrine\DBAL\Connections\PrimaryReadReplicaConnection',
'driver' => 'pdo_mysql',
'primary' => array('user' => '', 'password' => '', 'host' => '', 'dbname' => ''),
'replica' => array(
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
use const E_USER_DEPRECATED;

/**
* @deprecated Use PrimaryReplicaConnection instead
* @deprecated Use PrimaryReadReplicaConnection instead
*/
class MasterSlaveConnection extends PrimaryReplicaConnection
class MasterSlaveConnection extends PrimaryReadReplicaConnection
{
/**
* Creates Primary Replica Connection.
Expand All @@ -26,7 +26,7 @@ class MasterSlaveConnection extends PrimaryReplicaConnection
*/
public function __construct(array $params, Driver $driver, ?Configuration $config = null, ?EventManager $eventManager = null)
{
$this->deprecated(self::class, PrimaryReplicaConnection::class);
$this->deprecated(self::class, PrimaryReadReplicaConnection::class);

if (isset($params['master'])) {
$this->deprecated('Params key "master"', '"primary"');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
* @example
*
* $conn = DriverManager::getConnection(array(
* 'wrapperClass' => 'Doctrine\DBAL\Connections\PrimaryReplicaConnection',
* 'wrapperClass' => 'Doctrine\DBAL\Connections\PrimaryReadReplicaConnection',
* 'driver' => 'pdo_mysql',
* 'primary' => array('user' => '', 'password' => '', 'host' => '', 'dbname' => ''),
* 'replica' => array(
Expand All @@ -70,7 +70,7 @@
*
* You can also pass 'driverOptions' and any other documented option to each of this drivers to pass additional information.
*/
class PrimaryReplicaConnection extends Connection
class PrimaryReadReplicaConnection extends Connection
{
/**
* Primary and Replica connection (one of the randomly picked replicas).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Doctrine\Tests\DBAL\Functional;

use Doctrine\DBAL\Connections\PrimaryReplicaConnection;
use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Schema\Table;
Expand All @@ -20,7 +20,7 @@
/**
* @group DBAL-20
*/
class PrimaryReplicaConnectionTest extends DbalFunctionalTestCase
class PrimaryReadReplicaConnectionTest extends DbalFunctionalTestCase
{
protected function setUp(): void
{
Expand All @@ -47,21 +47,21 @@ protected function setUp(): void
$this->connection->insert('primary_replica_table', ['test_int' => 1]);
}

private function createPrimaryReplicaConnection(bool $keepReplica = false): PrimaryReplicaConnection
private function createPrimaryReadReplicaConnection(bool $keepReplica = false): PrimaryReadReplicaConnection
{
return DriverManager::getConnection($this->createPrimaryReplicaConnectionParams($keepReplica));
return DriverManager::getConnection($this->createPrimaryReadReplicaConnectionParams($keepReplica));
}

/**
* @return mixed[]
*/
private function createPrimaryReplicaConnectionParams(bool $keepReplica = false): array
private function createPrimaryReadReplicaConnectionParams(bool $keepReplica = false): array
{
$params = $this->connection->getParams();
$params['primary'] = $params;
$params['replica'] = [$params, $params];
$params['keepReplica'] = $keepReplica;
$params['wrapperClass'] = PrimaryReplicaConnection::class;
$params['wrapperClass'] = PrimaryReadReplicaConnection::class;

return $params;
}
Expand All @@ -74,7 +74,7 @@ public function testInheritCharsetFromPrimary(): void
];

foreach ($charsets as $charset) {
$params = $this->createPrimaryReplicaConnectionParams();
$params = $this->createPrimaryReadReplicaConnectionParams();
$params['primary']['charset'] = $charset;

foreach ($params['replica'] as $index => $replicaParams) {
Expand All @@ -86,7 +86,7 @@ public function testInheritCharsetFromPrimary(): void
}

$conn = DriverManager::getConnection($params);
self::assertInstanceOf(PrimaryReplicaConnection::class, $conn);
self::assertInstanceOf(PrimaryReadReplicaConnection::class, $conn);
$conn->ensureConnectedToReplica();

self::assertFalse($conn->isConnectedToPrimary());
Expand All @@ -102,7 +102,7 @@ public function testInheritCharsetFromPrimary(): void

public function testPrimaryOnConnect(): void
{
$conn = $this->createPrimaryReplicaConnection();
$conn = $this->createPrimaryReadReplicaConnection();

self::assertFalse($conn->isConnectedToPrimary());
$conn->ensureConnectedToReplica();
Expand All @@ -113,7 +113,7 @@ public function testPrimaryOnConnect(): void

public function testNoPrimaryrOnExecuteQuery(): void
{
$conn = $this->createPrimaryReplicaConnection();
$conn = $this->createPrimaryReadReplicaConnection();

$sql = 'SELECT count(*) as num FROM primary_replica_table';
$data = $conn->fetchAll($sql);
Expand All @@ -125,7 +125,7 @@ public function testNoPrimaryrOnExecuteQuery(): void

public function testPrimaryOnWriteOperation(): void
{
$conn = $this->createPrimaryReplicaConnection();
$conn = $this->createPrimaryReadReplicaConnection();
$conn->insert('primary_replica_table', ['test_int' => 30]);

self::assertTrue($conn->isConnectedToPrimary());
Expand All @@ -143,7 +143,7 @@ public function testPrimaryOnWriteOperation(): void
*/
public function testKeepReplicaBeginTransactionStaysOnPrimary(): void
{
$conn = $this->createPrimaryReplicaConnection($keepReplica = true);
$conn = $this->createPrimaryReadReplicaConnection($keepReplica = true);
$conn->ensureConnectedToReplica();

$conn->beginTransaction();
Expand All @@ -164,7 +164,7 @@ public function testKeepReplicaBeginTransactionStaysOnPrimary(): void
*/
public function testKeepReplicaInsertStaysOnPrimary(): void
{
$conn = $this->createPrimaryReplicaConnection($keepReplica = true);
$conn = $this->createPrimaryReadReplicaConnection($keepReplica = true);
$conn->ensureConnectedToReplica();

$conn->insert('primary_replica_table', ['test_int' => 30]);
Expand All @@ -178,9 +178,9 @@ public function testKeepReplicaInsertStaysOnPrimary(): void
self::assertFalse($conn->isConnectedToPrimary());
}

public function testPrimaryReplicaConnectionCloseAndReconnect(): void
public function testPrimaryReadReplicaConnectionCloseAndReconnect(): void
{
$conn = $this->createPrimaryReplicaConnection();
$conn = $this->createPrimaryReadReplicaConnection();
$conn->ensureConnectedToPrimary();
self::assertTrue($conn->isConnectedToPrimary());

Expand All @@ -193,7 +193,7 @@ public function testPrimaryReplicaConnectionCloseAndReconnect(): void

public function testQueryOnPrimary(): void
{
$conn = $this->createPrimaryReplicaConnection();
$conn = $this->createPrimaryReadReplicaConnection();

$query = 'SELECT count(*) as num FROM primary_replica_table';

Expand All @@ -217,7 +217,7 @@ public function testQueryOnPrimary(): void

public function testQueryOnReplica(): void
{
$conn = $this->createPrimaryReplicaConnection();
$conn = $this->createPrimaryReadReplicaConnection();
$conn->ensureConnectedToReplica();

$query = 'SELECT count(*) as num FROM primary_replica_table';
Expand Down

0 comments on commit 3e87bf2

Please sign in to comment.