Wikibase
MediaWiki Wikibase extension
Loading...
Searching...
No Matches
Wikibase\Repo\Store\Sql\UpsertSqlIdGenerator Class Reference

Unique Id generator implemented using an SQL table and an UPSERT query. More...

+ Inheritance diagram for Wikibase\Repo\Store\Sql\UpsertSqlIdGenerator:
+ Collaboration diagram for Wikibase\Repo\Store\Sql\UpsertSqlIdGenerator:

Public Member Functions

 __construct (RepoDomainDb $db, array $reservedIds=[], $separateDbConnection=false)
 
 getNewId ( $type)
 

Private Member Functions

 idIsReserved ( $type, $id)
 
 generateNewId (IDatabase $database, $type)
 Generates and returns a new ID.
 
 upsertId (IDatabase $database, $type)
 

Private Attributes

 $db
 
 $reservedIds
 
const MAX_ATTEMPTS = 10
 
 $separateDbConnection
 

Detailed Description

Unique Id generator implemented using an SQL table and an UPSERT query.

The table needs to have the fields id_value and id_type.

The UPSERT approach was created in https://phabricator.wikimedia.org/T194299 as wikidata.org was having issues with the old SqlIdGenerator.

LAST_INSERT_ID from mysql is used in this class, which means that this IdGenerator can only be used with MySQL. This class depends on the upsert implementation within the RDBMS library for different DB backends.

Author
Addshore

Constructor & Destructor Documentation

◆ __construct()

Wikibase\Repo\Store\Sql\UpsertSqlIdGenerator::__construct ( RepoDomainDb $db,
array $reservedIds = [],
$separateDbConnection = false )
Parameters
RepoDomainDb$db
int[][]$reservedIds
bool$separateDbConnection

Member Function Documentation

◆ generateNewId()

Wikibase\Repo\Store\Sql\UpsertSqlIdGenerator::generateNewId ( IDatabase $database,
$type )
private

Generates and returns a new ID.

Parameters
IDatabase$database
string$type
Exceptions
RuntimeException
Returns
int

◆ getNewId()

Wikibase\Repo\Store\Sql\UpsertSqlIdGenerator::getNewId ( $type)
See also
IdGenerator::getNewId
Parameters
string$typenormally is content model id (e.g. wikibase-item or wikibase-property)
Returns
int
Exceptions
RuntimeException

Implements Wikibase\Repo\Store\IdGenerator.

◆ idIsReserved()

Wikibase\Repo\Store\Sql\UpsertSqlIdGenerator::idIsReserved ( $type,
$id )
private

◆ upsertId()

Wikibase\Repo\Store\Sql\UpsertSqlIdGenerator::upsertId ( IDatabase $database,
$type )
private
Parameters
IDatabase$database
string$type

Member Data Documentation

◆ $db

Wikibase\Repo\Store\Sql\UpsertSqlIdGenerator::$db
private

◆ $reservedIds

Wikibase\Repo\Store\Sql\UpsertSqlIdGenerator::$reservedIds
private

◆ $separateDbConnection

Wikibase\Repo\Store\Sql\UpsertSqlIdGenerator::$separateDbConnection
private

◆ MAX_ATTEMPTS

const Wikibase\Repo\Store\Sql\UpsertSqlIdGenerator::MAX_ATTEMPTS = 10
private

The documentation for this class was generated from the following file: