* @author Daniel Kinzler
*/
abstract class DBAccessBase implements IDBAccessObject {
- /**
- * @var string|bool $wiki The target wiki's name. This must be an ID
- * that LBFactory can understand.
- */
- protected $wiki = false;
+ /** @var ILoadBalancer */
+ private $lb;
+
+ /** @var string|bool The target wiki's DB domain */
+ protected $dbDomain = false;
/**
- * @param string|bool $wiki The target wiki's name. This must be an ID
- * that LBFactory can understand.
+ * @param string|bool $dbDomain The target wiki's DB domain
*/
- public function __construct( $wiki = false ) {
- $this->wiki = $wiki;
+ public function __construct( $dbDomain = false ) {
+ $this->dbDomain = $dbDomain;
+ $this->lb = MediaWikiServices::getInstance()->getDBLoadBalancerFactory()
+ ->getMainLB( $dbDomain );
}
/**
* Returns a database connection.
*
- * @see wfGetDB()
* @see LoadBalancer::getConnection()
*
* @since 1.21
* @return IDatabase
*/
protected function getConnection( $id, array $groups = [] ) {
- $loadBalancer = $this->getLoadBalancer();
-
- return $loadBalancer->getConnection( $id, $groups, $this->wiki );
+ return $this->getLoadBalancer()->getConnectionRef( $id, $groups, $this->dbDomain );
}
/**
* @since 1.21
*
* @param IDatabase $db The database connection to release.
+ * @deprecated Since 1.34
*/
protected function releaseConnection( IDatabase $db ) {
- if ( $this->wiki !== false ) {
- $loadBalancer = $this->getLoadBalancer();
- $loadBalancer->reuseConnection( $db );
- }
+ // no-op
}
/**
*
* @return ILoadBalancer The database load balancer object
*/
- public function getLoadBalancer() {
- $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
- return $lbFactory->getMainLB( $this->wiki );
+ protected function getLoadBalancer() {
+ return $this->lb;
}
}