Jeroen De Dauw has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/53784


Change subject: Work on data value tables access [DO NOT MERGE]
......................................................................

Work on data value tables access [DO NOT MERGE]

Change-Id: Idd882b70fb96cc68e3261849756e19698b05f84b
---
M repo/includes/Query/SQLStore/DVHandler/BooleanHandler.php
M repo/includes/Query/SQLStore/DVHandler/EntityIdHandler.php
M repo/includes/Query/SQLStore/DVHandler/GeoCoordinateHandler.php
M repo/includes/Query/SQLStore/DVHandler/IriHandler.php
M repo/includes/Query/SQLStore/DVHandler/MonolingualTextHandler.php
M repo/includes/Query/SQLStore/DVHandler/NumberHandler.php
M repo/includes/Query/SQLStore/DVHandler/StringHandler.php
M repo/includes/Query/SQLStore/DataValueHandler.php
A repo/includes/Query/SQLStore/DataValueTable.php
A repo/includes/Query/SQLStore/DataValueTables.php
M repo/includes/Query/SQLStore/Setup.php
M repo/includes/Query/SQLStore/StoreConfig.php
M repo/includes/Query/SQLStore/Updater.php
13 files changed, 404 insertions(+), 384 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/84/53784/1

diff --git a/repo/includes/Query/SQLStore/DVHandler/BooleanHandler.php 
b/repo/includes/Query/SQLStore/DVHandler/BooleanHandler.php
index 60b8a21..886cda4 100644
--- a/repo/includes/Query/SQLStore/DVHandler/BooleanHandler.php
+++ b/repo/includes/Query/SQLStore/DVHandler/BooleanHandler.php
@@ -39,43 +39,6 @@
 class BooleanHandler extends DataValueHandler {
 
        /**
-        * @see DataValueHandler::getTableDefinition
-        *
-        * @since wd.qe
-        *
-        * @return TableDefinition
-        */
-       public function getTableDefinition() {
-               $fields = array(
-                       new FieldDefinition( 'value', 
FieldDefinition::TYPE_BOOLEAN, false ),
-               );
-
-               return new TableDefinition( 'boolean', $fields );
-       }
-
-       /**
-        * @see DataValueHandler::getValueFieldName
-        *
-        * @since wd.qe
-        *
-        * @return string
-        */
-       public function getValueFieldName() {
-               return 'value';
-       }
-
-       /**
-        * @see DataValueHandler::getSortFieldName
-        *
-        * @since wd.qe
-        *
-        * @return string
-        */
-       public function getSortFieldName() {
-               return 'value';
-       }
-
-       /**
         * @see DataValueHandler::newDataValueFromValueField
         *
         * @since wd.qe
diff --git a/repo/includes/Query/SQLStore/DVHandler/EntityIdHandler.php 
b/repo/includes/Query/SQLStore/DVHandler/EntityIdHandler.php
index 49f0447..75ced1d 100644
--- a/repo/includes/Query/SQLStore/DVHandler/EntityIdHandler.php
+++ b/repo/includes/Query/SQLStore/DVHandler/EntityIdHandler.php
@@ -39,45 +39,6 @@
 class EntityIdHandler extends DataValueHandler {
 
        /**
-        * @see DataValueHandler::getTableDefinition
-        *
-        * @since wd.qe
-        *
-        * @return TableDefinition
-        */
-       public function getTableDefinition() {
-               $fields = array(
-                       new FieldDefinition( 'type', 
FieldDefinition::TYPE_TEXT, false ),
-                       new FieldDefinition( 'number', 
FieldDefinition::TYPE_INTEGER, false ),
-                       new FieldDefinition( 'json', 
FieldDefinition::TYPE_TEXT, false ),
-               );
-
-               return new TableDefinition( 'entityid', $fields );
-       }
-
-       /**
-        * @see DataValueHandler::getValueFieldName
-        *
-        * @since wd.qe
-        *
-        * @return string
-        */
-       public function getValueFieldName() {
-               return 'json';
-       }
-
-       /**
-        * @see DataValueHandler::getSortFieldName
-        *
-        * @since wd.qe
-        *
-        * @return string
-        */
-       public function getSortFieldName() {
-               return 'number';
-       }
-
-       /**
         * @see DataValueHandler::newDataValueFromValueField
         *
         * @since wd.qe
diff --git a/repo/includes/Query/SQLStore/DVHandler/GeoCoordinateHandler.php 
b/repo/includes/Query/SQLStore/DVHandler/GeoCoordinateHandler.php
index 722fcbc..26586ae 100644
--- a/repo/includes/Query/SQLStore/DVHandler/GeoCoordinateHandler.php
+++ b/repo/includes/Query/SQLStore/DVHandler/GeoCoordinateHandler.php
@@ -39,47 +39,6 @@
 class GeoCoordinateHandler extends DataValueHandler {
 
        /**
-        * @see DataValueHandler::getTableDefinition
-        *
-        * @since wd.qe
-        *
-        * @return TableDefinition
-        */
-       public function getTableDefinition() {
-               $fields = array(
-                       new FieldDefinition( 'lat', 
FieldDefinition::TYPE_FLOAT, false ),
-                       new FieldDefinition( 'lon', 
FieldDefinition::TYPE_FLOAT, false ),
-                       new FieldDefinition( 'alt', 
FieldDefinition::TYPE_FLOAT, true ),
-                       new FieldDefinition( 'globe', 
FieldDefinition::TYPE_TEXT, true ),
-                       new FieldDefinition( 'json', 
FieldDefinition::TYPE_TEXT, false ),
-               );
-
-               return new TableDefinition( 'geo', $fields );
-       }
-
-       /**
-        * @see DataValueHandler::getValueFieldName
-        *
-        * @since wd.qe
-        *
-        * @return string
-        */
-       public function getValueFieldName() {
-               return 'json';
-       }
-
-       /**
-        * @see DataValueHandler::getSortFieldName
-        *
-        * @since wd.qe
-        *
-        * @return string
-        */
-       public function getSortFieldName() {
-               return 'lat';
-       }
-
-       /**
         * @see DataValueHandler::newDataValueFromValueField
         *
         * @since wd.qe
diff --git a/repo/includes/Query/SQLStore/DVHandler/IriHandler.php 
b/repo/includes/Query/SQLStore/DVHandler/IriHandler.php
index e507134..6bf2490 100644
--- a/repo/includes/Query/SQLStore/DVHandler/IriHandler.php
+++ b/repo/includes/Query/SQLStore/DVHandler/IriHandler.php
@@ -40,60 +40,6 @@
 class IriHandler extends DataValueHandler {
 
        /**
-        * @see DataValueHandler::getTableDefinition
-        *
-        * @since wd.qe
-        *
-        * @return TableDefinition
-        */
-       public function getTableDefinition() {
-               $fields = array(
-                       new FieldDefinition( 'scheme', FD::TYPE_TEXT, 
FD::NOT_NULL ),
-                       new FieldDefinition( 'fragment', FD::TYPE_TEXT, 
FD::NOT_NULL ),
-                       new FieldDefinition( 'query', FD::TYPE_TEXT, 
FD::NOT_NULL ),
-                       new FieldDefinition( 'hierp', FD::TYPE_TEXT, 
FD::NOT_NULL ),
-
-                       new FieldDefinition( 'iri', FD::TYPE_TEXT, FD::NOT_NULL 
),
-                       new FieldDefinition( 'json', FD::TYPE_TEXT, 
FD::NOT_NULL ),
-               );
-
-               return new TableDefinition( 'iri', $fields );
-       }
-
-       /**
-        * @see DataValueHandler::getValueFieldName
-        *
-        * @since wd.qe
-        *
-        * @return string
-        */
-       public function getValueFieldName() {
-               return 'json';
-       }
-
-       /**
-        * @see DataValueHandler::getSortFieldName
-        *
-        * @since wd.qe
-        *
-        * @return string
-        */
-       public function getSortFieldName() {
-               return 'iri';
-       }
-
-       /**
-        * @see DataValueHandler::getLabelFieldName
-        *
-        * @since wd.qe
-        *
-        * @return string|null
-        */
-       public function getLabelFieldName() {
-               return 'iri';
-       }
-
-       /**
         * @see DataValueHandler::newDataValueFromValueField
         *
         * @since wd.qe
diff --git a/repo/includes/Query/SQLStore/DVHandler/MonolingualTextHandler.php 
b/repo/includes/Query/SQLStore/DVHandler/MonolingualTextHandler.php
index 24e2522..09db481 100644
--- a/repo/includes/Query/SQLStore/DVHandler/MonolingualTextHandler.php
+++ b/repo/includes/Query/SQLStore/DVHandler/MonolingualTextHandler.php
@@ -39,56 +39,6 @@
 class MonolingualTextHandler extends DataValueHandler {
 
        /**
-        * @see DataValueHandler::getTableDefinition
-        *
-        * @since wd.qe
-        *
-        * @return TableDefinition
-        */
-       public function getTableDefinition() {
-               $fields = array(
-                       new FieldDefinition( 'text', 
FieldDefinition::TYPE_TEXT, false ),
-                       new FieldDefinition( 'language', 
FieldDefinition::TYPE_TEXT, false ),
-                       new FieldDefinition( 'json', 
FieldDefinition::TYPE_TEXT, false ),
-               );
-
-               return new TableDefinition( 'mono_text', $fields );
-       }
-
-       /**
-        * @see DataValueHandler::getValueFieldName
-        *
-        * @since wd.qe
-        *
-        * @return string
-        */
-       public function getValueFieldName() {
-               return 'json';
-       }
-
-       /**
-        * @see DataValueHandler::getSortFieldName
-        *
-        * @since wd.qe
-        *
-        * @return string
-        */
-       public function getSortFieldName() {
-               return 'text';
-       }
-
-       /**
-        * @see DataValueHandler::getLabelFieldName
-        *
-        * @since wd.qe
-        *
-        * @return string|null
-        */
-       public function getLabelFieldName() {
-               return 'text';
-       }
-
-       /**
         * @see DataValueHandler::newDataValueFromValueField
         *
         * @since wd.qe
diff --git a/repo/includes/Query/SQLStore/DVHandler/NumberHandler.php 
b/repo/includes/Query/SQLStore/DVHandler/NumberHandler.php
index e3fd22b..cbe6f5d 100644
--- a/repo/includes/Query/SQLStore/DVHandler/NumberHandler.php
+++ b/repo/includes/Query/SQLStore/DVHandler/NumberHandler.php
@@ -39,44 +39,6 @@
 class NumberHandler extends DataValueHandler {
 
        /**
-        * @see DataValueHandler::getTableDefinition
-        *
-        * @since wd.qe
-        *
-        * @return TableDefinition
-        */
-       public function getTableDefinition() {
-               $fields = array(
-                       new FieldDefinition( 'value', 
FieldDefinition::TYPE_FLOAT, false ),
-                       new FieldDefinition( 'json', 
FieldDefinition::TYPE_TEXT, false ),
-               );
-
-               return new TableDefinition( 'number', $fields );
-       }
-
-       /**
-        * @see DataValueHandler::getValueFieldName
-        *
-        * @since wd.qe
-        *
-        * @return string
-        */
-       public function getValueFieldName() {
-               return 'json';
-       }
-
-       /**
-        * @see DataValueHandler::getSortFieldName
-        *
-        * @since wd.qe
-        *
-        * @return string
-        */
-       public function getSortFieldName() {
-               return 'value';
-       }
-
-       /**
         * @see DataValueHandler::newDataValueFromValueField
         *
         * @since wd.qe
@@ -87,17 +49,6 @@
         */
        public function newDataValueFromValueField( $valueFieldValue ) {
                return new NumberValue( $valueFieldValue );
-       }
-
-       /**
-        * @see DataValueHandler::getLabelFieldName
-        *
-        * @since wd.qe
-        *
-        * @return string|null
-        */
-       public function getLabelFieldName() {
-               return 'value';
        }
 
        /**
diff --git a/repo/includes/Query/SQLStore/DVHandler/StringHandler.php 
b/repo/includes/Query/SQLStore/DVHandler/StringHandler.php
index cee3186..1e79712 100644
--- a/repo/includes/Query/SQLStore/DVHandler/StringHandler.php
+++ b/repo/includes/Query/SQLStore/DVHandler/StringHandler.php
@@ -39,43 +39,6 @@
 class StringHandler extends DataValueHandler {
 
        /**
-        * @see DataValueHandler::getTableDefinition
-        *
-        * @since wd.qe
-        *
-        * @return TableDefinition
-        */
-       public function getTableDefinition() {
-               $fields = array(
-                       new FieldDefinition( 'value', 
FieldDefinition::TYPE_TEXT, false ),
-               );
-
-               return new TableDefinition( 'string', $fields );
-       }
-
-       /**
-        * @see DataValueHandler::getValueFieldName
-        *
-        * @since wd.qe
-        *
-        * @return string
-        */
-       public function getValueFieldName() {
-               return 'value';
-       }
-
-       /**
-        * @see DataValueHandler::getSortFieldName
-        *
-        * @since wd.qe
-        *
-        * @return string
-        */
-       public function getSortFieldName() {
-               return 'value';
-       }
-
-       /**
         * @see DataValueHandler::newDataValueFromValueField
         *
         * @since wd.qe
@@ -86,17 +49,6 @@
         */
        public function newDataValueFromValueField( $valueFieldValue ) {
                return new StringValue( $valueFieldValue );
-       }
-
-       /**
-        * @see DataValueHandler::getLabelFieldName
-        *
-        * @since wd.qe
-        *
-        * @return string|null
-        */
-       public function getLabelFieldName() {
-               return 'value';
        }
 
        /**
diff --git a/repo/includes/Query/SQLStore/DataValueHandler.php 
b/repo/includes/Query/SQLStore/DataValueHandler.php
index 7d58927..7bc9d60 100644
--- a/repo/includes/Query/SQLStore/DataValueHandler.php
+++ b/repo/includes/Query/SQLStore/DataValueHandler.php
@@ -38,40 +38,6 @@
 abstract class DataValueHandler {
 
        /**
-        * Returns the definition of a table to hold DataValue objects of
-        * the type handled by this DataValueHandler.
-        *
-        * @since wd.qe
-        *
-        * @return TableDefinition
-        */
-       abstract public function getTableDefinition();
-
-       /**
-        * Returns the name of the field that holds the value from which
-        * a DataValue instance can be (re)constructed.
-        *
-        * The field should clearly be part of the table returned
-        * by @see getTableDefinition.
-        *
-        * @since wd.qe
-        *
-        * @return string
-        */
-       abstract public function getValueFieldName();
-
-       /**
-        * Return the field used to select this type of DataValue. In
-        * particular, this identifies the column that is used to sort values
-        * of this kind. Every type of data returns a non-empty string here.
-        *
-        * @since wd.qe
-        *
-        * @return string
-        */
-       abstract public function getSortFieldName();
-
-       /**
         * Create a DataValue from a cell value in the tables value field.
         *
         * @since wd.qe
@@ -81,24 +47,6 @@
         * @return DataValue
         */
        abstract public function newDataValueFromValueField( $valueFieldValue );
-
-       /**
-        * Return the label field for this type of DataValue. This should be
-        * a string column in the database table that can be used for selecting
-        * values using criteria such as "starts with". The return value can be
-        * empty if this is not supported. This is preferred for DataValue
-        * classes that do not have an obvious canonical string writing anyway.
-        *
-        * The return value can be a column name or the empty string (if the
-        * give type of DataValue does not have a label field).
-        *
-        * @since wd.qe
-        *
-        * @return string|null
-        */
-       public function getLabelFieldName() {
-               return null;
-       }
 
        /**
         * Return an array of fields=>values to conditions (WHERE part) in SQL
diff --git a/repo/includes/Query/SQLStore/DataValueTable.php 
b/repo/includes/Query/SQLStore/DataValueTable.php
new file mode 100644
index 0000000..26f51dd
--- /dev/null
+++ b/repo/includes/Query/SQLStore/DataValueTable.php
@@ -0,0 +1,129 @@
+<?php
+
+namespace Wikibase\Repo\Query\SQLStore;
+
+use Wikibase\Repo\Database\TableDefinition;
+
+/**
+ * Declaration of a table in which data values can be stored.
+ *
+ * Based on, and containing snippets from, SMWDataItemHandler from Semantic 
MediaWiki.
+ * SMWDataItemHandler was written by Nischay Nahata and Markus Krötzsch.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @since wd.qe
+ *
+ * @file
+ * @ingroup WikibaseSQLStore
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class DataValueTable {
+
+       /**
+        * @since wd.qe
+        *
+        * @var TableDefinition
+        */
+       private $tableDefinition;
+
+       /**
+        * @since wd.qe
+        *
+        * @var string
+        */
+       private $valueFieldName;
+
+       /**
+        * @since wd.qe
+        *
+        * @var string
+        */
+       private $sortFieldName;
+
+       /**
+        * @since wd.qe
+        *
+        * @var null|string
+        */
+       private $labelFieldName;
+
+       /**
+        * Constructor.
+        *
+        * @since wd.qe
+        *
+        * @param TableDefinition $table
+        * @param string $valueFieldName
+        * @param string $sortFieldName
+        * @param string|null $labelFieldName
+        */
+       public function __construct( TableDefinition $table, $valueFieldName, 
$sortFieldName, $labelFieldName = null ) {
+               $this->tableDefinition = $table;
+               $this->valueFieldName = $valueFieldName;
+               $this->sortFieldName = $sortFieldName;
+               $this->labelFieldName = $labelFieldName;
+       }
+
+       /**
+        * Returns the name of the field that holds the value from which
+        * a DataValue instance can be (re)constructed.
+        *
+        * The field should clearly be part of the table returned
+        * by @see getTableDefinition.
+        *
+        * @since wd.qe
+        *
+        * @return string
+        */
+       public function getValueFieldName() {
+               return $this->valueFieldName;
+       }
+
+       /**
+        * Return the field used to select this type of DataValue. In
+        * particular, this identifies the column that is used to sort values
+        * of this kind. Every type of data returns a non-empty string here.
+        *
+        * @since wd.qe
+        *
+        * @return string
+        */
+       public function getSortFieldName() {
+               return $this->sortFieldName;
+       }
+
+       /**
+        * Return the label field for this type of DataValue. This should be
+        * a string column in the database table that can be used for selecting
+        * values using criteria such as "starts with". The return value can be
+        * empty if this is not supported. This is preferred for DataValue
+        * classes that do not have an obvious canonical string writing anyway.
+        *
+        * The return value can be a column name or the empty string (if the
+        * give type of DataValue does not have a label field).
+        *
+        * @since wd.qe
+        *
+        * @return string|null
+        */
+       public function getLabelFieldName() {
+               return $this->labelFieldName;
+       }
+
+}
\ No newline at end of file
diff --git a/repo/includes/Query/SQLStore/DataValueTables.php 
b/repo/includes/Query/SQLStore/DataValueTables.php
new file mode 100644
index 0000000..0b877d3
--- /dev/null
+++ b/repo/includes/Query/SQLStore/DataValueTables.php
@@ -0,0 +1,145 @@
+<?php
+
+namespace Wikibase\Repo\Query\SQLStore;
+
+use Wikibase\Repo\Database\FieldDefinition;
+use Wikibase\Repo\Database\FieldDefinition as FD;
+use Wikibase\Repo\Database\TableDefinition;
+use Wikibase\Repo\Query\SQLStore\DataValueTable;
+
+/**
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @since wd.qe
+ *
+ * @file
+ * @ingroup WikibaseSQLStore
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class DataValueTables {
+
+       /**
+        * @since wd.qe
+        *
+        * @return DataValueTable[]
+        */
+       public function getTables() {
+               $tables = array();
+
+               $tables[] = new DataValueTable(
+                       new TableDefinition(
+                               'boolean',
+                               array(
+                                       new FieldDefinition( 'value', 
FD::TYPE_BOOLEAN, false ),
+                               )
+                       ),
+                       'value',
+                       'value'
+               );
+
+               $tables[] = new DataValueTable(
+                       new TableDefinition(
+                               'string',
+                               array(
+                                       new FieldDefinition( 'value', 
FD::TYPE_TEXT, false ),
+                               )
+                       ),
+                       'value',
+                       'value',
+                       'value'
+               );
+
+               $tables[] = new DataValueTable(
+                       new TableDefinition(
+                               'mono_text',
+                               array(
+                                       new FieldDefinition( 'text', 
FD::TYPE_TEXT, false ),
+                                       new FieldDefinition( 'language', 
FD::TYPE_TEXT, false ),
+                                       new FieldDefinition( 'json', 
FD::TYPE_TEXT, false ),
+                               )
+                       ),
+                       'json',
+                       'text',
+                       'text'
+               );
+
+               $tables[] = new DataValueTable(
+                       new TableDefinition(
+                               'geo',
+                               array(
+                                       new FieldDefinition( 'lat', 
FD::TYPE_FLOAT, false ),
+                                       new FieldDefinition( 'lon', 
FD::TYPE_FLOAT, false ),
+                                       new FieldDefinition( 'alt', 
FD::TYPE_FLOAT, true ),
+                                       new FieldDefinition( 'globe', 
FD::TYPE_TEXT, true ),
+                                       new FieldDefinition( 'json', 
FD::TYPE_TEXT, false ),
+                               )
+                       ),
+                       'json',
+                       'lat'
+               );
+
+               $tables[] = new DataValueTable(
+                       new TableDefinition(
+                               'number',
+                               array(
+                                       new FieldDefinition( 'value', 
FD::TYPE_FLOAT, false ),
+                                       new FieldDefinition( 'json', 
FD::TYPE_TEXT, false ),
+                               )
+                       ),
+                       'json',
+                       'value',
+                       'value'
+               );
+
+               $tables[] = new DataValueTable(
+                       new TableDefinition(
+                               'iri',
+                               array(
+                                       new FieldDefinition( 'scheme', 
FD::TYPE_TEXT, FD::NOT_NULL ),
+                                       new FieldDefinition( 'fragment', 
FD::TYPE_TEXT, FD::NOT_NULL ),
+                                       new FieldDefinition( 'query', 
FD::TYPE_TEXT, FD::NOT_NULL ),
+                                       new FieldDefinition( 'hierp', 
FD::TYPE_TEXT, FD::NOT_NULL ),
+
+                                       new FieldDefinition( 'iri', 
FD::TYPE_TEXT, FD::NOT_NULL ),
+                                       new FieldDefinition( 'json', 
FD::TYPE_TEXT, FD::NOT_NULL ),
+                               )
+                       ),
+                       'json',
+                       'iri',
+                       'iri'
+               );
+
+               $tables[] = new DataValueTable(
+                       new TableDefinition(
+                               'entityid',
+                               array(
+                                       new FieldDefinition( 'type', 
FD::TYPE_TEXT, false ),
+                                       new FieldDefinition( 'number', 
FD::TYPE_INTEGER, false ),
+                                       new FieldDefinition( 'json', 
FD::TYPE_TEXT, false ),
+                               )
+                       ),
+                       'json',
+                       'number'
+               );
+
+               return $tables;
+       }
+
+}
diff --git a/repo/includes/Query/SQLStore/Setup.php 
b/repo/includes/Query/SQLStore/Setup.php
index c77af45..139f244 100644
--- a/repo/includes/Query/SQLStore/Setup.php
+++ b/repo/includes/Query/SQLStore/Setup.php
@@ -135,7 +135,12 @@
                 * @var DataValueHandler $dataValueHandler
                 */
                foreach ( $this->config->getDataValueHandlers() as 
$dataValueHandler ) {
-                       foreach ( array( 'msnak_', 'qualifier_' ) as $snakLevel 
) {
+                       $snakLevels = array(
+                               $this->config->getMainSnakPrefix(),
+                               $this->config->getQualifierPrefix(),
+                       );
+
+                       foreach ( $snakLevels as $snakLevel ) {
                                $table = 
$dataValueHandler->getTableDefinition();
                                $table = $table->mutateName( $snakLevel . 
$table->getName() );
 
diff --git a/repo/includes/Query/SQLStore/StoreConfig.php 
b/repo/includes/Query/SQLStore/StoreConfig.php
index 8813f58..15d00d9 100644
--- a/repo/includes/Query/SQLStore/StoreConfig.php
+++ b/repo/includes/Query/SQLStore/StoreConfig.php
@@ -48,14 +48,17 @@
 
        /**
         * The DataValueHandlers for the DataValue types supported by this 
configuration.
-        * Array keys are DataValue type identifiers (string) pointing to the 
corresponding
-        * DataValueHandler.
+        * Array keys are DataValue type identifiers (string) pointing to the 
corresponding DataValueHandler.
         *
         * @since wd.qe
         *
         * @var DataValueHandler[]
         */
-       private $dvHandlers;
+       private $dvHandlers = array();
+
+
+       const SNAK_MAIN = 0;
+       const SNAK_QUALIFIER = 1;
 
        /**
         * Constructor.
@@ -70,15 +73,6 @@
                $this->name = $storeName;
                $this->tablePrefix = $tablePrefix;
                $this->dvHandlers = $dataValueHandlers;
-       }
-
-       /**
-        * @since wd.qe
-        *
-        * @return DataValueHandler[]
-        */
-       public function getDataValueHandlers() {
-               return $this->dvHandlers;
        }
 
        /**
@@ -99,6 +93,87 @@
                return $this->tablePrefix;
        }
 
+       /**
+        * @since wd.qe
+        *
+        * @return DataValueHandler[]
+        */
+       public function getDataValueHandlers() {
+               return $this->dvHandlers;
+       }
+
        // TODO
 
+}
+
+
+class Schema {
+
+       /**
+        * @since wd.qe
+        *
+        * @var StoreConfig
+        */
+       private $config;
+
+       /**
+        * The DataValueHandlers for the DataValue types supported by this 
configuration.
+        * Array keys are snak types pointing to arrays where array keys are 
DataValue type
+        * identifiers (string) pointing to the corresponding DataValueHandler.
+        *
+        * @since wd.qe
+        *
+        * @var DataValueHandler[]
+        */
+       private $dvHandlers = array();
+
+       /**
+        * @since wd.qe
+        *
+        * @param StoreConfig $config
+        */
+       public function __construct( StoreConfig $config ) {
+               $this->config = $config;
+               $this->expandDataValueHandlers( $config->getDataValueHandlers() 
);
+       }
+
+       /**
+        * @since wd.qe
+        *
+        * @param DataValueHandler[] $dataValueHandlers
+        */
+       private function expandDataValueHandlers( array $dataValueHandlers ) {
+               foreach ( $this->snakTypes as $snakType => $snakPrefix ) {
+                       $handlers = array();
+
+                       foreach ( $dataValueHandlers as $dataValueHandler ) {
+                               $table = 
$dataValueHandler->getTableDefinition();
+                               $table = $table->mutateName( $snakPrefix . 
$table->getName() );
+
+
+                       }
+
+                       $this->dvHandlers[$snakType] = $handlers;
+               }
+       }
+
+       public function getHandlerForType( $dataType, $snakType ) {
+
+
+               // TODO: checks
+
+
+
+
+       }
+
+       /**
+        * @since wd.qe
+        *
+        * @return DataValueHandler[]
+        */
+       public function getDataValueHandlers() {
+               return $this->dvHandlers;
+       }
+
 }
\ No newline at end of file
diff --git a/repo/includes/Query/SQLStore/Updater.php 
b/repo/includes/Query/SQLStore/Updater.php
index 535b557..9ea22b8 100644
--- a/repo/includes/Query/SQLStore/Updater.php
+++ b/repo/includes/Query/SQLStore/Updater.php
@@ -2,9 +2,12 @@
 
 namespace Wikibase\Repo\Query\SQLStore;
 
+use Wikibase\Claim;
 use Wikibase\Entity;
+use Wikibase\EntityId;
 use Wikibase\Repo\Database\QueryInterface;
 use Wikibase\Repo\Query\QueryStoreUpdater;
+use Wikibase\Snak;
 
 /**
  * Class responsible for writing information to the SQLStore.
@@ -69,9 +72,42 @@
         * @param Entity $entity
         */
        public function insertEntity( Entity $entity ) {
-               // TODO
+               // TODO: insert entity info into entities table
+               // TODO: insert info of linked entities into entities table
+
+               foreach ( $entity->getClaims() as $claim ) {
+                       $this->insertClaim( $entity->getId(), $claim );
+               }
+
+               // TODO: obtain and insert virtual claims
        }
 
+       private function insertClaim( EntityId $entityId, Claim $claim ) {
+               // TODO: insert claim info into claims table
+
+               $this->insertSnak(
+                       $claim->getMainSnak(),
+                       $this->storeConfig->getMainSnakPrefix(),
+                       42, // TODO
+                       9001 // TODO
+               );
+
+               foreach ( $claim->getQualifiers() as $qualifierSnak ) {
+                       $this->insertSnak(
+                               $qualifierSnak,
+                               $this->storeConfig->getQualifierPrefix(),
+                               42, // TODO
+                               9001 // TODO
+                       );
+               }
+       }
+
+       private function insertSnak( Snak $snak, $tablePrefix, 
$internalClaimId, $internalPropertyId ) {
+
+       }
+
+
+
        /**
         * @see QueryStoreUpdater::updateEntity
         *

-- 
To view, visit https://gerrit.wikimedia.org/r/53784
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idd882b70fb96cc68e3261849756e19698b05f84b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to