Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
1f7ef808
Commit
1f7ef808
authored
Dec 19, 2011
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'MasterSlave'
parents
a9eb7b48
e7d6fc2c
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
443 additions
and
21 deletions
+443
-21
MasterSlaveConnection.php
lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php
+328
-0
DriverManager.php
lib/Doctrine/DBAL/DriverManager.php
+22
-19
LoggingTest.php
tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php
+0
-2
MasterSlaveConnectionTest.php
...trine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php
+82
-0
MasterSlaveTest.php
tests/Doctrine/Tests/DBAL/Functional/MasterSlaveTest.php
+11
-0
No files found.
lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php
0 → 100644
View file @
1f7ef808
This diff is collapsed.
Click to expand it.
lib/Doctrine/DBAL/DriverManager.php
View file @
1f7ef808
...
...
@@ -56,37 +56,40 @@ final class DriverManager
* driver connection.
*
* $params must contain at least one of the following.
*
*
* Either 'driver' with one of the following values:
* pdo_mysql
* pdo_sqlite
* pdo_pgsql
* pdo_oracle
* pdo_sqlsrv
*
*
* OR 'driverClass' that contains the full class name (with namespace) of the
* driver class to instantiate.
*
*
* Other (optional) parameters:
*
*
* <b>user (string)</b>:
* The username to use when connecting.
*
* The username to use when connecting.
*
* <b>password (string)</b>:
* The password to use when connecting.
*
*
* <b>driverOptions (array)</b>:
* Any additional driver-specific options for the driver. These are just passed
* through to the driver.
*
*
* <b>pdo</b>:
* You can pass an existing PDO instance through this parameter. The PDO
* instance will be wrapped in a Doctrine\DBAL\Connection.
*
*
* <b>wrapperClass</b>:
* You may specify a custom wrapper class through the 'wrapperClass'
* parameter but this class MUST inherit from Doctrine\DBAL\Connection.
*
*
* <b>driverClass</b>:
* The driver class to use.
*
* @param array $params The parameters.
* @param Doctrine\DBAL\Configuration The configuration to use.
* @param Doctrine\Common\EventManager The event manager to use.
...
...
@@ -104,7 +107,7 @@ final class DriverManager
if
(
!
$eventManager
)
{
$eventManager
=
new
EventManager
();
}
// check for existing pdo object
if
(
isset
(
$params
[
'pdo'
])
&&
!
$params
[
'pdo'
]
instanceof
\PDO
)
{
throw
DBALException
::
invalidPdoInstance
();
...
...
@@ -119,9 +122,9 @@ final class DriverManager
}
else
{
$className
=
self
::
$_driverMap
[
$params
[
'driver'
]];
}
$driver
=
new
$className
();
$wrapperClass
=
'Doctrine\DBAL\Connection'
;
if
(
isset
(
$params
[
'wrapperClass'
]))
{
if
(
is_subclass_of
(
$params
[
'wrapperClass'
],
$wrapperClass
))
{
...
...
@@ -130,7 +133,7 @@ final class DriverManager
throw
DBALException
::
invalidWrapperClass
(
$params
[
'wrapperClass'
]);
}
}
return
new
$wrapperClass
(
$params
,
$driver
,
$config
,
$eventManager
);
}
...
...
@@ -140,16 +143,16 @@ final class DriverManager
* @param array $params
*/
private
static
function
_checkParams
(
array
$params
)
{
{
// check existance of mandatory parameters
// driver
if
(
!
isset
(
$params
[
'driver'
])
&&
!
isset
(
$params
[
'driverClass'
]))
{
throw
DBALException
::
driverRequired
();
}
// check validity of parameters
// driver
if
(
isset
(
$params
[
'driver'
])
&&
!
isset
(
self
::
$_driverMap
[
$params
[
'driver'
]]))
{
throw
DBALException
::
unknownDriver
(
$params
[
'driver'
],
array_keys
(
self
::
$_driverMap
));
...
...
@@ -159,4 +162,4 @@ final class DriverManager
throw
DBALException
::
invalidDriverClass
(
$params
[
'driverClass'
]);
}
}
}
\ No newline at end of file
}
tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php
View file @
1f7ef808
...
...
@@ -2,8 +2,6 @@
namespace
Doctrine\Tests\DBAL\Functional
;
require_once
__DIR__
.
'/../../TestInit.php'
;
class
LoggingTest
extends
\Doctrine\Tests\DbalFunctionalTestCase
{
public
function
testLogExecuteQuery
()
...
...
tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php
0 → 100644
View file @
1f7ef808
<?php
namespace
Doctrine\Tests\DBAL\Functional
;
use
Doctrine\Tests\DbalFunctionalTestCase
;
use
Doctrine\DBAL\DriverManager
;
/**
* @group DBAL-20
*/
class
MasterSlaveConnectionTest
extends
DbalFunctionalTestCase
{
public
function
setUp
()
{
parent
::
setUp
();
if
(
$this
->
_conn
->
getDatabasePlatform
()
->
getName
()
==
"sqlite"
)
{
$this
->
markTestSkipped
(
'Test does not work on sqlite.'
);
}
try
{
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
$table
=
new
\Doctrine\DBAL\Schema\Table
(
"master_slave_table"
);
$table
->
addColumn
(
'test_int'
,
'integer'
);
$table
->
setPrimaryKey
(
array
(
'test_int'
));
$sm
=
$this
->
_conn
->
getSchemaManager
();
$sm
->
createTable
(
$table
);
$this
->
_conn
->
insert
(
'master_slave_table'
,
array
(
'test_int'
=>
1
));
}
catch
(
\Exception
$e
)
{
}
}
public
function
createMasterSlaveConnection
()
{
$params
=
$this
->
_conn
->
getParams
();
$params
[
'master'
]
=
$params
;
$params
[
'slaves'
]
=
array
(
$params
,
$params
);
$params
[
'wrapperClass'
]
=
'Doctrine\DBAL\Connections\MasterSlaveConnection'
;
return
DriverManager
::
getConnection
(
$params
);
}
public
function
testMasterOnConnect
()
{
$conn
=
$this
->
createMasterSlaveConnection
();
$this
->
assertFalse
(
$conn
->
isConnectedToMaster
());
$conn
->
connect
(
'slave'
);
$this
->
assertFalse
(
$conn
->
isConnectedToMaster
());
$conn
->
connect
(
'master'
);
$this
->
assertTrue
(
$conn
->
isConnectedToMaster
());
}
public
function
testNoMasterOnExecuteQuery
()
{
$conn
=
$this
->
createMasterSlaveConnection
();
$sql
=
"SELECT count(*) as num FROM master_slave_table"
;
$data
=
$conn
->
fetchAll
(
$sql
);
$data
[
0
]
=
array_change_key_case
(
$data
[
0
],
CASE_LOWER
);
$this
->
assertEquals
(
1
,
$data
[
0
][
'num'
]);
$this
->
assertFalse
(
$conn
->
isConnectedToMaster
());
}
public
function
testMasterOnWriteOperation
()
{
$conn
=
$this
->
createMasterSlaveConnection
();
$conn
->
insert
(
'master_slave_table'
,
array
(
'test_int'
=>
30
));
$this
->
assertTrue
(
$conn
->
isConnectedToMaster
());
$sql
=
"SELECT count(*) as num FROM master_slave_table"
;
$data
=
$conn
->
fetchAll
(
$sql
);
$data
[
0
]
=
array_change_key_case
(
$data
[
0
],
CASE_LOWER
);
$this
->
assertEquals
(
2
,
$data
[
0
][
'num'
]);
$this
->
assertTrue
(
$conn
->
isConnectedToMaster
());
}
}
tests/Doctrine/Tests/DBAL/Functional/MasterSlaveTest.php
0 → 100644
View file @
1f7ef808
<?php
namespace
Doctrine\Tests\DBAL\Functional
;
class
MasterSlaveTest
extends
\Doctrine\Tests\DbalFunctionalTestCase
{
public
function
test
()
{
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment