John Erling Blad has submitted this change and it was merged.
Change subject: Defined most of the DataValueHandler interface
......................................................................
Defined most of the DataValueHandler interface
Change-Id: I8db83806520372f7fc479b1fce207e2c99d2e3e8
---
M repo/includes/Database/TableDefinition.php
M repo/includes/Query/SQLStore/DataValueHandler.php
M repo/tests/phpunit/includes/Query/SQLStore/DataValueHandlerTest.php
3 files changed, 143 insertions(+), 6 deletions(-)
Approvals:
John Erling Blad: Verified; Looks good to me, approved
jenkins-bot: Verified
diff --git a/repo/includes/Database/TableDefinition.php
b/repo/includes/Database/TableDefinition.php
index 37e9006..f558738 100644
--- a/repo/includes/Database/TableDefinition.php
+++ b/repo/includes/Database/TableDefinition.php
@@ -47,6 +47,10 @@
private $fields;
/**
+ * Constructor.
+ *
+ * @since wd.db
+ *
* @param string $name
* @param FieldDefinition[] $fields
*
@@ -66,6 +70,10 @@
}
/**
+ * Returns the name of the table.
+ *
+ * @since wd.db
+ *
* @return string
*/
public function getName() {
@@ -73,10 +81,16 @@
}
/**
+ * Returns the fields that make up this table.
+ *
+ * @since wd.db
+ *
* @return FieldDefinition[]
*/
public function getFields() {
return $this->fields;
}
+ // TODO: multiple field indices
+
}
\ No newline at end of file
diff --git a/repo/includes/Query/SQLStore/DataValueHandler.php
b/repo/includes/Query/SQLStore/DataValueHandler.php
index 86f5045..2f10e0b 100644
--- a/repo/includes/Query/SQLStore/DataValueHandler.php
+++ b/repo/includes/Query/SQLStore/DataValueHandler.php
@@ -2,6 +2,9 @@
namespace Wikibase\Repo\Query\SQLStore;
+use Wikibase\Repo\Database\TableDefinition;
+use DataValues\DataValue;
+
/**
* Represents the mapping between a DataValue type and the
* associated implementation in the store.
@@ -33,4 +36,69 @@
*/
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 getSortField();
+
+ /**
+ * Create a DataValue from a cell value in the tables value field.
+ *
+ * @since wd.qe
+ *
+ * @param $dbValue // TODO: mixed or string?
+ *
+ * @return DataValue
+ */
+ abstract public function newDataValueFromDbValue( $dbValue );
+
+ /**
+ * 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 SMWDataItem
+ * 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 getLabelField() {
+ return null;
+ }
+
+ // TODO: getInsertValues and getWhereConds
+
}
\ No newline at end of file
diff --git
a/repo/tests/phpunit/includes/Query/SQLStore/DataValueHandlerTest.php
b/repo/tests/phpunit/includes/Query/SQLStore/DataValueHandlerTest.php
index 1744f97..8514a7d 100644
--- a/repo/tests/phpunit/includes/Query/SQLStore/DataValueHandlerTest.php
+++ b/repo/tests/phpunit/includes/Query/SQLStore/DataValueHandlerTest.php
@@ -27,15 +27,70 @@
*
* @ingroup WikibaseRepoTest
*
- * @group Wikibase
- * @group WikibaseRepo
- * @group WikibaseQuery
- *
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
*/
-class DataValueHandlerTest extends \MediaWikiTestCase {
+abstract class DataValueHandlerTest extends \MediaWikiTestCase {
- // TODO
+ /**
+ * @since wd.qe
+ *
+ * @return DataValueHandler[]
+ */
+ protected abstract function getInstances();
+
+ /**
+ * @since wd.qe
+ *
+ * @return DataValueHandler[][]
+ */
+ public function instanceProvider() {
+ return $this->arrayWrap( $this->getInstances() );
+ }
+
+ /**
+ * @dataProvider instanceProvider
+ *
+ * @param DataValueHandler $dvHandler
+ */
+ public function testGetTableDefinitionReturnType( DataValueHandler
$dvHandler ) {
+ // TODO
+ }
+
+ /**
+ * @dataProvider instanceProvider
+ *
+ * @param DataValueHandler $dvHandler
+ */
+ public function testGetValueFieldReturnValue( DataValueHandler
$dvHandler ) {
+ // TODO
+ }
+
+ /**
+ * @dataProvider instanceProvider
+ *
+ * @param DataValueHandler $dvHandler
+ */
+ public function testGetSortFieldReturnValue( DataValueHandler
$dvHandler ) {
+ // TODO
+ }
+
+ /**
+ * @dataProvider instanceProvider
+ *
+ * @param DataValueHandler $dvHandler
+ */
+ public function testNewDataValueFromDbValue( DataValueHandler
$dvHandler ) {
+ // TODO
+ }
+
+ /**
+ * @dataProvider instanceProvider
+ *
+ * @param DataValueHandler $dvHandler
+ */
+ public function testGetLabelFieldReturnValue( DataValueHandler
$dvHandler ) {
+ // TODO
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/51162
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8db83806520372f7fc479b1fce207e2c99d2e3e8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Jens Ohlig <[email protected]>
Gerrit-Reviewer: John Erling Blad <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits