X-Git-Url: https://git.cyclocoop.org/%242?a=blobdiff_plain;f=includes%2Flibs%2Frdbms%2Fdatabase%2FDBConnRef.php;h=2cc2c90d69ae331575cb86dfc2dd0fd8571ae250;hb=04d591935cf117a890ae890912ec59b560da4f54;hp=8af6bb3ff361059e70e0ba1787633d85b0b9743f;hpb=67d01c452da591faced0a4be7940acf4f3292928;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/rdbms/database/DBConnRef.php b/includes/libs/rdbms/database/DBConnRef.php index 8af6bb3ff3..2cc2c90d69 100644 --- a/includes/libs/rdbms/database/DBConnRef.php +++ b/includes/libs/rdbms/database/DBConnRef.php @@ -5,8 +5,23 @@ namespace Wikimedia\Rdbms; use InvalidArgumentException; /** - * Helper class to handle automatically marking connections as reusable (via RAII pattern) - * as well handling deferring the actual network connection until the handle is used + * Helper class used for automatically marking an IDatabase connection as reusable (once it no + * longer matters which DB domain is selected) and for deferring the actual network connection + * + * This uses an RAII-style pattern where calling code is expected to keep the returned reference + * handle as a function variable that falls out of scope when no longer needed. This avoids the + * need for matching reuseConnection() calls for every "return" statement as well as the tedious + * use of try/finally. + * + * @par Example: + * @code + * function getRowData() { + * $conn = $this->lb->getConnectedRef( DB_REPLICA ); + * $row = $conn->select( ... ); + * return $row ? (array)$row : false; + * // $conn falls out of scope and $this->lb->reuseConnection() gets called + * } + * @endcode * * @ingroup Database * @since 1.22 @@ -28,7 +43,7 @@ class DBConnRef implements IDatabase { /** * @param ILoadBalancer $lb Connection manager for $conn - * @param Database|array $conn Database or (server index, query groups, domain, flags) + * @param IDatabase|array $conn Database or (server index, query groups, domain, flags) * @param int $role The type of connection asked for; one of DB_MASTER/DB_REPLICA * @internal This method should not be called outside of LoadBalancer */ @@ -598,6 +613,10 @@ class DBConnRef implements IDatabase { return $this->__call( __FUNCTION__, func_get_args() ); } + public function onAtomicSectionCancel( callable $callback, $fname = __METHOD__ ) { + return $this->__call( __FUNCTION__, func_get_args() ); + } + public function setTransactionListener( $name, callable $callback = null ) { return $this->__call( __FUNCTION__, func_get_args() ); } @@ -630,15 +649,15 @@ class DBConnRef implements IDatabase { return $this->__call( __FUNCTION__, func_get_args() ); } - public function commit( $fname = __METHOD__, $flush = '' ) { + public function commit( $fname = __METHOD__, $flush = self::FLUSHING_ONE ) { return $this->__call( __FUNCTION__, func_get_args() ); } - public function rollback( $fname = __METHOD__, $flush = '' ) { + public function rollback( $fname = __METHOD__, $flush = self::FLUSHING_ONE ) { return $this->__call( __FUNCTION__, func_get_args() ); } - public function flushSnapshot( $fname = __METHOD__ ) { + public function flushSnapshot( $fname = __METHOD__, $flush = self::FLUSHING_ONE ) { return $this->__call( __FUNCTION__, func_get_args() ); }