3 use Wikimedia\Rdbms\IDatabase
;
4 use Wikimedia\Rdbms\LoadBalancer
;
7 * Base class for objects that allow access to other wiki's databases using
8 * the foreign database access mechanism implemented by LBFactoryMulti.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * http://www.gnu.org/copyleft/gpl.html
30 * @licence GNU GPL v2+
31 * @author Daniel Kinzler
33 abstract class DBAccessBase
implements IDBAccessObject
{
35 * @var string|bool $wiki The target wiki's name. This must be an ID
36 * that LBFactory can understand.
38 protected $wiki = false;
41 * @param string|bool $wiki The target wiki's name. This must be an ID
42 * that LBFactory can understand.
44 public function __construct( $wiki = false ) {
49 * Returns a database connection.
52 * @see LoadBalancer::getConnection()
56 * @param int $id Which connection to use
57 * @param array $groups Query groups
61 protected function getConnection( $id, $groups = [] ) {
62 $loadBalancer = wfGetLB( $this->wiki
);
64 return $loadBalancer->getConnection( $id, $groups, $this->wiki
);
68 * Releases a database connection and makes it available for recycling.
70 * @see LoadBalancer::reuseConnection()
74 * @param IDatabase $db The database connection to release.
76 protected function releaseConnection( IDatabase
$db ) {
77 if ( $this->wiki
!== false ) {
78 $loadBalancer = $this->getLoadBalancer();
79 $loadBalancer->reuseConnection( $db );
84 * Get the database type used for read operations.
90 * @return LoadBalancer The database load balancer object
92 public function getLoadBalancer() {
93 return wfGetLB( $this->wiki
);