Details
-
Type:
New Feature
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 2.2
-
Component/s: None
-
Labels:None
Description
There should be an additional, optional "connectionResolver" which returns a driver instance for differentation between different drivers in Doctrine\DBAL\Connection instead of using $this->_conn (which stays the default case)
This is useful for master/slave, master/master or failover strategies inside the application
Activity
Benjamin Eberlei
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Fix Version/s | 2.0.0-BETA3 [ 10066 ] |
Benjamin Eberlei
made changes -
| Fix Version/s | 2.0.0-BETA4 [ 10071 ] | |
| Fix Version/s | 2.0.0-BETA3 [ 10066 ] |
Benjamin Eberlei
made changes -
| Fix Version/s | 2.1.0 [ 10068 ] | |
| Fix Version/s | 2.0.0-BETA4 [ 10071 ] |
Benjamin Eberlei
made changes -
| Fix Version/s | 2.1 [ 10068 ] |
Benjamin Eberlei
made changes -
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Fix Version/s | 2.2 [ 10142 ] | |
| Resolution | Fixed [ 1 ] |
Benjamin Eberlei
made changes -
| Workflow | jira [ 11483 ] | jira-feedback2 [ 17638 ] |
Benjamin Eberlei
made changes -
| Workflow | jira-feedback2 [ 17638 ] | jira-feedback3 [ 19993 ] |
This list may be incomplete, as errors occurred whilst retrieving source from linked applications:
- Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DBAL-20, expand=changesets[-21:-1].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)
I have done some working code, I extended \Doctrine\DBAL\Connection:
From the controllers/ service layer:
$em->getConnection()->setConnection('write'); try { $em->persist($user); } catch (Exception $e) { echo $e->getMessage(); } $em->getConnection()->setConnection('read_1'); ... $em->getConnection()->setConnection('read_2');Obviously all the statements related with a unit of work will be associated with only one connection.
_________________________________________
When setting the event manager:
$connectionOptions = array( 'driver' => $doctrineConfig['conn']['driv'], 'user' => $doctrineConfig['conn']['user'], 'password' => $doctrineConfig['conn']['pass'], 'dbname' => $doctrineConfig['conn']['dbname'], 'host' => $doctrineConfig['conn']['host'], 'wrapperClass' =>'\Fishpond\Doctrine\DBAL\Connections\Multiple' ); $connectionOptions['multiple_connections']['read'] = array( "driver" => "pdo_mysql", "user" = "password" => "dbname"=> "host" => ); $connectionOptions['multiple_connections']['write'] = array( "driver" => "pdo_mysql", "user" => "password" => "dbname"=> "host" => ); $em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);_________________________________________
The new connection class itself:
..........
........
The class is working so far (need much more testing), but the idea is if is not selected a connection it will work as it is now. Also, an 'automatic' selection of the connection could happen in an event listener, where we could define rules about which connection should be used for different conditions/entities.