3 use MediaWiki\MediaWikiServices
;
4 use Wikimedia\Rdbms\IDatabase
;
5 use Wikimedia\Rdbms\ILoadBalancer
;
8 * Base class for objects that allow access to other wiki's databases using
9 * the foreign database access mechanism implemented by LBFactoryMulti.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 * http://www.gnu.org/copyleft/gpl.html
31 * @license GPL-2.0-or-later
32 * @author Daniel Kinzler
34 abstract class DBAccessBase
implements IDBAccessObject
{
35 /** @var ILoadBalancer */
38 /** @var string|bool The target wiki's DB domain */
39 protected $dbDomain = false;
42 * @param string|bool $dbDomain The target wiki's DB domain
44 public function __construct( $dbDomain = false ) {
45 $this->dbDomain
= $dbDomain;
46 $this->lb
= MediaWikiServices
::getInstance()->getDBLoadBalancerFactory()
47 ->getMainLB( $dbDomain );
51 * Returns a database connection.
53 * @see LoadBalancer::getConnection()
57 * @param int $id Which connection to use
58 * @param array $groups Query groups
62 protected function getConnection( $id, array $groups = [] ) {
63 return $this->getLoadBalancer()->getConnectionRef( $id, $groups, $this->dbDomain
);
67 * Releases a database connection and makes it available for recycling.
69 * @see LoadBalancer::reuseConnection()
73 * @param IDatabase $db The database connection to release.
74 * @deprecated Since 1.34
76 protected function releaseConnection( IDatabase
$db ) {
81 * Get the database type used for read operations.
83 * @see MediaWikiServices::getInstance()->getDBLoadBalancer
87 * @return ILoadBalancer The database load balancer object
89 protected function getLoadBalancer() {