Skip to content

Commit 12f381f

Browse files
committed
Refactor Synchronizers to use an AbstractSchemaSynchronizer
1 parent 29b2623 commit 12f381f

File tree

3 files changed

+63
-50
lines changed

3 files changed

+63
-50
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/*
3+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14+
*
15+
* This software consists of voluntary contributions made by many individuals
16+
* and is licensed under the MIT license. For more information, see
17+
* <http://www.doctrine-project.org>.
18+
*/
19+
20+
namespace Doctrine\DBAL\Schema\Synchronizer;
21+
22+
use Doctrine\DBAL\Connection;
23+
24+
/**
25+
* Abstract schema synchronizer with methods for executing batches of SQL.
26+
*/
27+
abstract class AbstractSchemaSynchronizer implements SchemaSynchronizer
28+
{
29+
/**
30+
* @var Connection
31+
*/
32+
protected $conn;
33+
34+
public function __construct(Connection $conn)
35+
{
36+
$this->conn = $conn;
37+
}
38+
39+
protected function processSqlSafely(array $sql)
40+
{
41+
foreach ($sql as $s) {
42+
try {
43+
$this->conn->exec($s);
44+
} catch(\Exception $e) {
45+
46+
}
47+
}
48+
}
49+
50+
protected function processSql(array $sql)
51+
{
52+
foreach ($sql as $s) {
53+
$this->conn->exec($s);
54+
}
55+
}
56+
57+
}
58+

lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,16 @@
2828
*
2929
* @author Benjamin Eberlei <[email protected]>
3030
*/
31-
class SingleDatabaseSynchronizer implements SchemaSynchronizer
31+
class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
3232
{
33-
/**
34-
* @var Doctrine\DBAL\Connection
35-
*/
36-
private $conn;
37-
3833
/**
3934
* @var Doctrine\DBAL\Platforms\AbstractPlatform
4035
*/
4136
private $platform;
4237

4338
public function __construct(Connection $conn)
4439
{
45-
$this->conn = $conn;
40+
parent::__construct($conn);
4641
$this->platform = $conn->getDatabasePlatform();
4742
}
4843

@@ -198,23 +193,5 @@ public function dropAllSchema()
198193
{
199194
$this->processSql($this->getDropAllSchema());
200195
}
201-
202-
private function processSqlSafely(array $sql)
203-
{
204-
foreach ($sql as $s) {
205-
try {
206-
$this->conn->exec($s);
207-
} catch(\Exception $e) {
208-
209-
}
210-
}
211-
}
212-
213-
private function processSql(array $sql)
214-
{
215-
foreach ($sql as $s) {
216-
$this->conn->exec($s);
217-
}
218-
}
219196
}
220197

lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use Doctrine\DBAL\Connection;
2424
use Doctrine\DBAL\Types\Type;
2525

26-
use Doctrine\DBAL\Schema\Synchronizer\SchemaSynchronizer;
26+
use Doctrine\DBAL\Schema\Synchronizer\AbstractSchemaSynchronizer;
2727
use Doctrine\DBAL\Sharding\SingleDatabaseSynchronizer;
2828

2929
/**
@@ -36,15 +36,11 @@
3636
*
3737
* @author Benjamin Eberlei <[email protected]>
3838
*/
39-
class SQLAzureFederationsSynchronizer implements SchemaSynchronizer
39+
class SQLAzureFederationsSynchronizer implements AbstractSchemaSynchronizer
4040
{
4141
const FEDERATION_TABLE_FEDERATED = 'azure.federated';
4242
const FEDERATION_DISTRIBUTION_NAME = 'azure.federatedOnDistributionName';
4343

44-
/**
45-
* @var Connection
46-
*/
47-
private $conn;
4844

4945
/**
5046
* @var SQLAzureShardManager
@@ -58,7 +54,7 @@ class SQLAzureFederationsSynchronizer implements SchemaSynchronizer
5854

5955
public function __construct(Connection $conn, SQLAzureShardManager $shardManager, SchemaSynchronizer $sync = null)
6056
{
61-
$this->conn = $conn;
57+
parent::__construct($conn);
6258
$this->shardManager = $shardManager;
6359
$this->synchronizer = $sync ?: new SingleDatabaseSynchronizer($conn);
6460
}
@@ -230,24 +226,6 @@ private function extractSchemaFederation(Schema $schema, $isFederation)
230226
return $partionedSchema;
231227
}
232228

233-
private function processSqlSafely(array $sql)
234-
{
235-
foreach ($sql as $s) {
236-
try {
237-
$this->conn->exec($s);
238-
} catch(\Exception $e) {
239-
240-
}
241-
}
242-
}
243-
244-
private function processSql(array $sql)
245-
{
246-
foreach ($sql as $s) {
247-
$this->conn->exec($s);
248-
}
249-
}
250-
251229
/**
252230
* Work on the Global/Federation based on currently existing shards and
253231
* perform the given operation on the underyling schema synchronizer given

0 commit comments

Comments
 (0)