Change DatabaseBase => IDatabase in /db where possible
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 15 Sep 2016 02:04:21 +0000 (19:04 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 15 Sep 2016 02:31:51 +0000 (19:31 -0700)
Change-Id: Ia0a049cd4294c5a39aa9ed228d4eb5b15736ea1f

12 files changed:
includes/db/CloneDatabase.php
includes/db/Database.php
includes/db/DatabaseMssql.php
includes/db/DatabaseMysqlBase.php
includes/db/DatabaseOracle.php
includes/db/DatabasePostgres.php
includes/db/DatabaseSqlite.php
includes/db/DatabaseUtility.php
includes/db/loadbalancer/LBFactorySingle.php
includes/db/loadbalancer/LoadBalancer.php
includes/libs/rdbms/database/IDatabase.php
includes/libs/rdbms/database/RBConnRef.php

index 97d59d8..caca7e2 100644 (file)
@@ -43,13 +43,13 @@ class CloneDatabase {
        /**
         * Constructor
         *
-        * @param DatabaseBase $db A database subclass
+        * @param IDatabase $db A database subclass
         * @param array $tablesToClone An array of tables to clone, unprefixed
         * @param string $newTablePrefix Prefix to assign to the tables
         * @param string $oldTablePrefix Prefix on current tables, if not $wgDBprefix
         * @param bool $dropCurrentTables
         */
-       public function __construct( DatabaseBase $db, array $tablesToClone,
+       public function __construct( IDatabase $db, array $tablesToClone,
                $newTablePrefix, $oldTablePrefix = '', $dropCurrentTables = true
        ) {
                $this->db = $db;
@@ -131,7 +131,7 @@ class CloneDatabase {
                global $wgDBprefix;
                wfGetLBFactory()->forEachLB( function( LoadBalancer $lb ) use ( $prefix ) {
                        $lb->setDomainPrefix( $prefix );
-                       $lb->forEachOpenConnection( function ( DatabaseBase $db ) use ( $prefix ) {
+                       $lb->forEachOpenConnection( function ( IDatabase $db ) use ( $prefix ) {
                                $db->tablePrefix( $prefix );
                        } );
                } );
index 109dbfe..e68a8f2 100644 (file)
@@ -231,7 +231,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface {
         * connection object, by specifying no parameters to __construct(). This
         * feature is deprecated and should be removed.
         *
-        * DatabaseBase subclasses should not be constructed directly in external
+        * IDatabase classes should not be constructed directly in external
         * code. DatabaseBase::factory() should be used instead.
         *
         * @param array $params Parameters passed from DatabaseBase::factory()
@@ -301,7 +301,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface {
 
        /**
         * Given a DB type, construct the name of the appropriate child class of
-        * DatabaseBase. This is designed to replace all of the manual stuff like:
+        * IDatabase. This is designed to replace all of the manual stuff like:
         *    $class = 'Database' . ucfirst( strtolower( $dbType ) );
         * as well as validate against the canonical list of DB types we have
         *
@@ -318,8 +318,8 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface {
         * @param string $dbType A possible DB type
         * @param array $p An array of options to pass to the constructor.
         *    Valid options are: host, user, password, dbname, flags, tablePrefix, schema, driver
-        * @throws MWException If the database driver or extension cannot be found
-        * @return DatabaseBase|null DatabaseBase subclass or null
+        * @return IDatabase|null If the database driver or extension cannot be found
+        * @throws MWException
         */
        final public static function factory( $dbType, $p = [] ) {
                global $wgCommandLineMode;
@@ -368,7 +368,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface {
                ];
 
                $class = 'Database' . ucfirst( $driver );
-               if ( class_exists( $class ) && is_subclass_of( $class, 'DatabaseBase' ) ) {
+               if ( class_exists( $class ) && is_subclass_of( $class, 'IDatabase' ) ) {
                        // Resolve some defaults for b/c
                        $p['host'] = isset( $p['host'] ) ? $p['host'] : false;
                        $p['user'] = isset( $p['user'] ) ? $p['user'] : false;
@@ -398,7 +398,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface {
        }
 
        public function setLogger( LoggerInterface $logger ) {
-               $this->quertLogger = $logger;
+               $this->queryLogger = $logger;
        }
 
        public function getServerInfo() {
@@ -494,12 +494,6 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface {
                }
        }
 
-       /**
-        * Set a lazy-connecting DB handle to the master DB (for replication status purposes)
-        *
-        * @param IDatabase $conn
-        * @since 1.27
-        */
        public function setLazyMasterHandle( IDatabase $conn ) {
                $this->lazyMasterHandle = $conn;
        }
@@ -995,9 +989,9 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface {
                # generalizeSQL() will probably cut down the query to reasonable
                # logging size most of the time. The substr is really just a sanity check.
                if ( $isMaster ) {
-                       $queryProf = 'query-m: ' . substr( DatabaseBase::generalizeSQL( $sql ), 0, 255 );
+                       $queryProf = 'query-m: ' . substr( self::generalizeSQL( $sql ), 0, 255 );
                } else {
-                       $queryProf = 'query: ' . substr( DatabaseBase::generalizeSQL( $sql ), 0, 255 );
+                       $queryProf = 'query: ' . substr( self::generalizeSQL( $sql ), 0, 255 );
                }
 
                # Include query transaction state
@@ -1132,7 +1126,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface {
         *
         * @return array
         */
-       protected function prepare( $sql, $func = 'DatabaseBase::prepare' ) {
+       protected function prepare( $sql, $func = __METHOD__ ) {
                /* MySQL doesn't support prepared statements (yet), so just
                 * pack up the query for reference. We'll manually replace
                 * the bits later.
@@ -1705,7 +1699,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface {
 
        public function makeList( $a, $mode = LIST_COMMA ) {
                if ( !is_array( $a ) ) {
-                       throw new DBUnexpectedError( $this, 'DatabaseBase::makeList called with incorrect parameters' );
+                       throw new DBUnexpectedError( $this, __METHOD__ . ' called with incorrect parameters' );
                }
 
                $first = true;
@@ -2417,8 +2411,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface {
                $fname = __METHOD__
        ) {
                if ( !$conds ) {
-                       throw new DBUnexpectedError( $this,
-                               'DatabaseBase::deleteJoin() called with empty $conds' );
+                       throw new DBUnexpectedError( $this, __METHOD__ . ' called with empty $conds' );
                }
 
                $delTable = $this->tableName( $delTable );
@@ -2442,7 +2435,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface {
        public function textFieldSize( $table, $field ) {
                $table = $this->tableName( $table );
                $sql = "SHOW COLUMNS FROM $table LIKE \"$field\";";
-               $res = $this->query( $sql, 'DatabaseBase::textFieldSize' );
+               $res = $this->query( $sql, __METHOD__ );
                $row = $this->fetchObject( $res );
 
                $m = [];
@@ -2470,7 +2463,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface {
 
        public function delete( $table, $conds, $fname = __METHOD__ ) {
                if ( !$conds ) {
-                       throw new DBUnexpectedError( $this, 'DatabaseBase::delete() called with no conditions' );
+                       throw new DBUnexpectedError( $this, __METHOD__ . ' called with no conditions' );
                }
 
                $table = $this->tableName( $table );
@@ -3132,12 +3125,11 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface {
        public function duplicateTableStructure( $oldName, $newName, $temporary = false,
                $fname = __METHOD__
        ) {
-               throw new RuntimeException(
-                       'DatabaseBase::duplicateTableStructure is not implemented in descendant class' );
+               throw new RuntimeException( __METHOD__ . ' is not implemented in descendant class' );
        }
 
        function listTables( $prefix = null, $fname = __METHOD__ ) {
-               throw new RuntimeException( 'DatabaseBase::listTables is not implemented in descendant class' );
+               throw new RuntimeException( __METHOD__ . ' is not implemented in descendant class' );
        }
 
        /**
@@ -3161,7 +3153,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface {
         * @since 1.22
         */
        public function listViews( $prefix = null, $fname = __METHOD__ ) {
-               throw new RuntimeException( 'DatabaseBase::listViews is not implemented in descendant class' );
+               throw new RuntimeException( __METHOD__ . ' is not implemented in descendant class' );
        }
 
        /**
@@ -3173,7 +3165,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface {
         * @since 1.22
         */
        public function isView( $name ) {
-               throw new RuntimeException( 'DatabaseBase::isView is not implemented in descendant class' );
+               throw new RuntimeException( __METHOD__ . ' is not implemented in descendant class' );
        }
 
        public function timestamp( $ts = 0 ) {
index 269a248..2439c60 100644 (file)
@@ -81,7 +81,7 @@ class DatabaseMssql extends Database {
         * @param string $password
         * @param string $dbName
         * @throws DBConnectionError
-        * @return bool|DatabaseBase|null
+        * @return bool|resource|null
         */
        public function open( $server, $user, $password, $dbName ) {
                # Test for driver support, to avoid suppressed fatal error
@@ -819,8 +819,7 @@ class DatabaseMssql extends Database {
         */
        public function makeList( $a, $mode = LIST_COMMA, $binaryColumns = [] ) {
                if ( !is_array( $a ) ) {
-                       throw new DBUnexpectedError( $this,
-                               'DatabaseBase::makeList called with incorrect parameters' );
+                       throw new DBUnexpectedError( $this, __METHOD__ . ' called with incorrect parameters' );
                }
 
                if ( $mode != LIST_NAMES ) {
index 1b60ea1..af80d24 100644 (file)
@@ -1098,7 +1098,7 @@ abstract class DatabaseMysqlBase extends Database {
         */
        function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = __METHOD__ ) {
                if ( !$conds ) {
-                       throw new DBUnexpectedError( $this, 'DatabaseBase::deleteJoin() called with empty $conds' );
+                       throw new DBUnexpectedError( $this, __METHOD__ . ' called with empty $conds' );
                }
 
                $delTable = $this->tableName( $delTable );
index f401058..5d0ff44 100644 (file)
@@ -50,7 +50,7 @@ class ORAResult {
        }
 
        /**
-        * @param DatabaseBase $db
+        * @param IDatabase $db
         * @param resource $stmt A valid OCI statement identifier
         * @param bool $unique
         */
@@ -265,7 +265,7 @@ class DatabaseOracle extends Database {
         * @param string $password
         * @param string $dbName
         * @throws DBConnectionError
-        * @return DatabaseBase|null
+        * @return resource|null
         */
        function open( $server, $user, $password, $dbName ) {
                global $wgDBOracleDRCP;
index 22445c0..b1cc96b 100644 (file)
@@ -26,7 +26,7 @@ class PostgresField implements Field {
                $has_default, $default;
 
        /**
-        * @param DatabaseBase $db
+        * @param IDatabase $db
         * @param string $table
         * @param string $field
         * @return null|PostgresField
@@ -140,7 +140,7 @@ class SavepointPostgres {
        protected $didbegin;
 
        /**
-        * @param DatabaseBase $dbw
+        * @param IDatabase $dbw
         * @param int $id
         */
        public function __construct( $dbw, $id ) {
@@ -276,7 +276,7 @@ class DatabasePostgres extends Database {
         * @param string $password
         * @param string $dbName
         * @throws DBConnectionError|Exception
-        * @return DatabaseBase|null
+        * @return resource|bool|null
         */
        function open( $server, $user, $password, $dbName ) {
                # Test for Postgres support, to avoid suppressed fatal error
index ef08ab0..6bf48e2 100644 (file)
@@ -277,12 +277,6 @@ class DatabaseSqlite extends Database {
                return $this->query( "ATTACH DATABASE $file AS $name", $fname );
        }
 
-       /**
-        * @see DatabaseBase::isWriteQuery()
-        *
-        * @param string $sql
-        * @return bool
-        */
        function isWriteQuery( $sql ) {
                return parent::isWriteQuery( $sql ) && !preg_match( '/^(ATTACH|PRAGMA)\b/i', $sql );
        }
index aeaa27f..2b8c8c6 100644 (file)
@@ -78,7 +78,7 @@ class ResultWrapper implements Iterator {
        /** @var resource */
        public $result;
 
-       /** @var DatabaseBase */
+       /** @var IDatabase */
        protected $db;
 
        /** @var int */
@@ -90,7 +90,7 @@ class ResultWrapper implements Iterator {
        /**
         * Create a new result object from a result resource and a Database object
         *
-        * @param DatabaseBase $database
+        * @param IDatabase $database
         * @param resource|ResultWrapper $result
         */
        function __construct( $database, $result ) {
index de82a1f..3937dfd 100644 (file)
@@ -30,7 +30,7 @@ class LBFactorySingle extends LBFactory {
 
        /**
         * @param array $conf An associative array with one member:
-        *  - connection: The DatabaseBase connection object
+        *  - connection: The IDatabase connection object
         */
        public function __construct( array $conf ) {
                parent::__construct( $conf );
@@ -85,7 +85,7 @@ class LBFactorySingle extends LBFactory {
  * Helper class for LBFactorySingle.
  */
 class LoadBalancerSingle extends LoadBalancer {
-       /** @var DatabaseBase */
+       /** @var IDatabase */
        private $db;
 
        /**
@@ -118,7 +118,7 @@ class LoadBalancerSingle extends LoadBalancer {
         * @param string $server
         * @param bool $dbNameOverride
         *
-        * @return DatabaseBase
+        * @return IDatabase
         */
        protected function reallyOpenConnection( $server, $dbNameOverride = false ) {
                return $this->db;
index 8e5902c..6f136df 100644 (file)
@@ -30,7 +30,7 @@ use Psr\Log\LoggerInterface;
 class LoadBalancer implements ILoadBalancer {
        /** @var array[] Map of (server index => server config array) */
        private $mServers;
-       /** @var array[] Map of (local/foreignUsed/foreignFree => server index => DatabaseBase array) */
+       /** @var array[] Map of (local/foreignUsed/foreignFree => server index => IDatabase array) */
        private $mConns;
        /** @var array Map of (server index => weight) */
        private $mLoads;
@@ -62,7 +62,7 @@ class LoadBalancer implements ILoadBalancer {
        /** @var LoggerInterface */
        protected $perfLogger;
 
-       /** @var bool|DatabaseBase Database connection that caused a problem */
+       /** @var bool|IDatabase Database connection that caused a problem */
        private $mErrorConnection;
        /** @var integer The generic (not query grouped) replica DB index (of $mServers) */
        private $mReadIndex;
@@ -608,7 +608,7 @@ class LoadBalancer implements ILoadBalancer {
        /**
         * Get a database connection handle reference
         *
-        * The handle's methods wrap simply wrap those of a DatabaseBase handle
+        * The handle's methods wrap simply wrap those of a IDatabase handle
         *
         * @see LoadBalancer::getConnection() for parameter information
         *
@@ -625,7 +625,7 @@ class LoadBalancer implements ILoadBalancer {
        /**
         * Get a database connection handle reference without connecting yet
         *
-        * The handle's methods wrap simply wrap those of a DatabaseBase handle
+        * The handle's methods wrap simply wrap those of a IDatabase handle
         *
         * @see LoadBalancer::getConnection() for parameter information
         *
@@ -691,7 +691,7 @@ class LoadBalancer implements ILoadBalancer {
         *
         * @param int $i Server index
         * @param string $domain Domain ID to open
-        * @return DatabaseBase
+        * @return IDatabase
         */
        private function openForeignConnection( $i, $domain ) {
                list( $dbName, $prefix ) = explode( '-', $domain, 2 ) + [ '', '' ];
@@ -774,7 +774,7 @@ class LoadBalancer implements ILoadBalancer {
         *
         * @param array $server
         * @param bool $dbNameOverride
-        * @return DatabaseBase
+        * @return IDatabase
         * @throws DBAccessError
         * @throws MWException
         */
@@ -806,6 +806,7 @@ class LoadBalancer implements ILoadBalancer {
                // Set loggers
                $server['connLogger'] = $this->connLogger;
                $server['queryLogger'] = $this->queryLogger;
+               $server['trxProfiler'] = $this->trxProfiler;
 
                // Create a live connection object
                try {
@@ -820,7 +821,6 @@ class LoadBalancer implements ILoadBalancer {
                $db->setLazyMasterHandle(
                        $this->getLazyConnectionRef( DB_MASTER, [], $db->getWikiID() )
                );
-               $db->setTransactionProfiler( $this->trxProfiler );
 
                if ( $server['serverIndex'] === $this->getWriterIndex() ) {
                        if ( $this->trxRoundId !== false ) {
@@ -939,7 +939,7 @@ class LoadBalancer implements ILoadBalancer {
        }
 
        public function closeAll() {
-               $this->forEachOpenConnection( function ( DatabaseBase $conn ) {
+               $this->forEachOpenConnection( function ( IDatabase $conn ) {
                        $conn->close();
                } );
 
@@ -976,7 +976,7 @@ class LoadBalancer implements ILoadBalancer {
                $restore = ( $this->trxRoundId !== false );
                $this->trxRoundId = false;
                $this->forEachOpenConnection(
-                       function ( DatabaseBase $conn ) use ( $fname, $restore, &$failures ) {
+                       function ( IDatabase $conn ) use ( $fname, $restore, &$failures ) {
                                try {
                                        $conn->commit( $fname, $conn::FLUSHING_ALL_PEERS );
                                } catch ( DBError $e ) {
@@ -1021,7 +1021,7 @@ class LoadBalancer implements ILoadBalancer {
         */
        public function approveMasterChanges( array $options ) {
                $limit = isset( $options['maxWriteDuration'] ) ? $options['maxWriteDuration'] : 0;
-               $this->forEachOpenMasterConnection( function ( DatabaseBase $conn ) use ( $limit ) {
+               $this->forEachOpenMasterConnection( function ( IDatabase $conn ) use ( $limit ) {
                        // If atomic sections or explicit transactions are still open, some caller must have
                        // caught an exception but failed to properly rollback any changes. Detect that and
                        // throw and error (causing rollback).
@@ -1103,7 +1103,7 @@ class LoadBalancer implements ILoadBalancer {
                $restore = ( $this->trxRoundId !== false );
                $this->trxRoundId = false;
                $this->forEachOpenMasterConnection(
-                       function ( DatabaseBase $conn ) use ( $fname, $restore, &$failures ) {
+                       function ( IDatabase $conn ) use ( $fname, $restore, &$failures ) {
                                try {
                                        if ( $conn->writesOrCallbacksPending() ) {
                                                $conn->commit( $fname, $conn::FLUSHING_ALL_PEERS );
@@ -1177,7 +1177,7 @@ class LoadBalancer implements ILoadBalancer {
                $restore = ( $this->trxRoundId !== false );
                $this->trxRoundId = false;
                $this->forEachOpenMasterConnection(
-                       function ( DatabaseBase $conn ) use ( $fname, $restore ) {
+                       function ( IDatabase $conn ) use ( $fname, $restore ) {
                                if ( $conn->writesOrCallbacksPending() ) {
                                        $conn->rollback( $fname, $conn::FLUSHING_ALL_PEERS );
                                }
@@ -1229,7 +1229,7 @@ class LoadBalancer implements ILoadBalancer {
         * @since 1.28
         */
        public function flushReplicaSnapshots( $fname = __METHOD__ ) {
-               $this->forEachOpenReplicaConnection( function ( DatabaseBase $conn ) {
+               $this->forEachOpenReplicaConnection( function ( IDatabase $conn ) {
                        $conn->flushSnapshot( __METHOD__ );
                } );
        }
@@ -1249,7 +1249,7 @@ class LoadBalancer implements ILoadBalancer {
         */
        public function hasMasterChanges() {
                $pending = 0;
-               $this->forEachOpenMasterConnection( function ( DatabaseBase $conn ) use ( &$pending ) {
+               $this->forEachOpenMasterConnection( function ( IDatabase $conn ) use ( &$pending ) {
                        $pending |= $conn->writesOrCallbacksPending();
                } );
 
@@ -1263,7 +1263,7 @@ class LoadBalancer implements ILoadBalancer {
         */
        public function lastMasterChangeTimestamp() {
                $lastTime = false;
-               $this->forEachOpenMasterConnection( function ( DatabaseBase $conn ) use ( &$lastTime ) {
+               $this->forEachOpenMasterConnection( function ( IDatabase $conn ) use ( &$lastTime ) {
                        $lastTime = max( $lastTime, $conn->lastDoneWrites() );
                } );
 
@@ -1293,7 +1293,7 @@ class LoadBalancer implements ILoadBalancer {
         */
        public function pendingMasterChangeCallers() {
                $fnames = [];
-               $this->forEachOpenMasterConnection( function ( DatabaseBase $conn ) use ( &$fnames ) {
+               $this->forEachOpenMasterConnection( function ( IDatabase $conn ) use ( &$fnames ) {
                        $fnames = array_merge( $fnames, $conn->pendingWriteCallers() );
                } );
 
@@ -1407,7 +1407,7 @@ class LoadBalancer implements ILoadBalancer {
 
        public function pingAll() {
                $success = true;
-               $this->forEachOpenConnection( function ( DatabaseBase $conn ) use ( &$success ) {
+               $this->forEachOpenConnection( function ( IDatabase $conn ) use ( &$success ) {
                        if ( !$conn->ping() ) {
                                $success = false;
                        }
@@ -1437,7 +1437,7 @@ class LoadBalancer implements ILoadBalancer {
                $masterIndex = $this->getWriterIndex();
                foreach ( $this->mConns as $connsByServer ) {
                        if ( isset( $connsByServer[$masterIndex] ) ) {
-                               /** @var DatabaseBase $conn */
+                               /** @var IDatabase $conn */
                                foreach ( $connsByServer[$masterIndex] as $conn ) {
                                        $mergedParams = array_merge( [ $conn ], $params );
                                        call_user_func_array( $callback, $mergedParams );
@@ -1549,7 +1549,7 @@ class LoadBalancer implements ILoadBalancer {
        }
 
        /**
-        * Set a callback via DatabaseBase::setTransactionListener() on
+        * Set a callback via IDatabase::setTransactionListener() on
         * all current and future master connections of this load balancer
         *
         * @param string $name Callback name
@@ -1563,7 +1563,7 @@ class LoadBalancer implements ILoadBalancer {
                        unset( $this->trxRecurringCallbacks[$name] );
                }
                $this->forEachOpenMasterConnection(
-                       function ( DatabaseBase $conn ) use ( $name, $callback ) {
+                       function ( IDatabase $conn ) use ( $name, $callback ) {
                                $conn->setTransactionListener( $name, $callback );
                        }
                );
index f1242e4..671ce99 100644 (file)
@@ -157,6 +157,14 @@ interface IDatabase {
         */
        public function setLBInfo( $name, $value = null );
 
+       /**
+        * Set a lazy-connecting DB handle to the master DB (for replication status purposes)
+        *
+        * @param IDatabase $conn
+        * @since 1.27
+        */
+       public function setLazyMasterHandle( IDatabase $conn );
+
        /**
         * Returns true if this database does an implicit sort when doing GROUP BY
         *
index e606340..9035bbd 100644 (file)
@@ -81,6 +81,10 @@ class DBConnRef implements IDatabase {
                return $this->__call( __FUNCTION__, func_get_args() );
        }
 
+       public function setLazyMasterHandle( IDatabase $conn ) {
+               return $this->__call( __FUNCTION__, func_get_args() );
+       }
+
        public function implicitGroupby() {
                return $this->__call( __FUNCTION__, func_get_args() );
        }