John Erling Blad has submitted this change and it was merged.

Change subject: Added base of GeoCoordinateHandler
......................................................................


Added base of GeoCoordinateHandler

Change-Id: Ibdf6679b3a0e657cef65cc77e525aec883bc047f
---
M repo/config/Wikibase.experimental.php
M repo/includes/Database/FieldDefinition.php
A repo/includes/Query/SQLStore/DVHandler/GeoCoordinateHandler.php
M repo/includes/Query/SQLStore/DataValueHandler.php
M repo/tests/phpunit/includes/Database/FieldDefinitionTest.php
M repo/tests/phpunit/includes/Database/TableDefinitionTest.php
A 
repo/tests/phpunit/includes/Query/SQLStore/DVHandler/GeoCoordinateHandlerTest.php
M repo/tests/phpunit/includes/Query/SQLStore/DataValueHandlerTest.php
8 files changed, 182 insertions(+), 17 deletions(-)

Approvals:
  John Erling Blad: Verified; Looks good to me, approved



diff --git a/repo/config/Wikibase.experimental.php 
b/repo/config/Wikibase.experimental.php
index 57193a5..e5e52d8 100644
--- a/repo/config/Wikibase.experimental.php
+++ b/repo/config/Wikibase.experimental.php
@@ -59,6 +59,8 @@
        'Wikibase\Repo\Query\QueryResult',
        'Wikibase\Repo\Query\QueryStore',
 
+       'Wikibase\Repo\Query\SQLStore\DVHandler\GeoCoordinateHandler',
+
        'Wikibase\Repo\Query\SQLStore\DataValueHandler',
        'Wikibase\Repo\Query\SQLStore\Engine',
        'Wikibase\Repo\Query\SQLStore\Setup',
@@ -79,6 +81,9 @@
 }
 
 if ( defined( 'MW_PHPUNIT_TEST' ) ) {
+       
$wgAutoloadClasses['Wikibase\Repo\Test\Query\SQLStore\DataValueHandlerTest']
+               = $dir . 
'tests/phpunit/includes/Query/SQLStore/DataValueHandlerTest.php';
+
        $wgAutoloadClasses['Wikibase\Repo\Test\Query\QueryEngineTest']
                = $dir . 'tests/phpunit/includes/Query/QueryEngineTest.php';
 
@@ -124,6 +129,8 @@
 
                'Query/QueryEngineResult',
 
+               'Query/SQLStore/DVHandler/GeoCoordinateHandler',
+
                'Query/SQLStore/DataValueHandler',
                'Query/SQLStore/Engine',
                'Query/SQLStore/Setup',
diff --git a/repo/includes/Database/FieldDefinition.php 
b/repo/includes/Database/FieldDefinition.php
index e1d3301..d280e5c 100644
--- a/repo/includes/Database/FieldDefinition.php
+++ b/repo/includes/Database/FieldDefinition.php
@@ -93,15 +93,15 @@
        /**
         * @param string $name
         * @param string $type
+        * @param boolean $null
         * @param mixed $default
         * @param string|null $attributes
-        * @param boolean $null
         * @param string|null $index
         * @param boolean $autoIncrement
         *
         * @throws InvalidArgumentException
         */
-       public function __construct( $name, $type, $default = null, $attributes 
= null, $null = true, $index = null, $autoIncrement = false ) {
+       public function __construct( $name, $type, $null = true, $default = 
null, $attributes = null, $index = null, $autoIncrement = false ) {
                if ( !is_string( $name ) ) {
                        throw new InvalidArgumentException( 'The field $name 
needs to be a string' );
                }
diff --git a/repo/includes/Query/SQLStore/DVHandler/GeoCoordinateHandler.php 
b/repo/includes/Query/SQLStore/DVHandler/GeoCoordinateHandler.php
new file mode 100644
index 0000000..62c9d98
--- /dev/null
+++ b/repo/includes/Query/SQLStore/DVHandler/GeoCoordinateHandler.php
@@ -0,0 +1,103 @@
+<?php
+
+namespace Wikibase\Repo\Query\SQLStore\DVHandler;
+
+use Wikibase\Repo\Query\SQLStore\DataValueHandler;
+use Wikibase\Repo\Database\TableDefinition;
+use Wikibase\Repo\Database\FieldDefinition;
+use DataValues\DataValue;
+
+/**
+ * Represents the mapping between DataValues\GeoCoordinateValue and
+ * the corresponding table in the store.
+ *
+ * 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 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( '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::newDataValueFromDbValue
+        *
+        * @since wd.qe
+        *
+        * @param $dbValue // TODO: mixed or string?
+        *
+        * @return DataValue
+        */
+       public function newDataValueFromDbValue( $dbValue ) {
+               // TODO
+       }
+
+       /**
+        * @see DataValueHandler::getLabelFieldName
+        *
+        * @since wd.qe
+        *
+        * @return string|null
+        */
+       public function getLabelFieldName() {
+               return null;
+       }
+
+}
\ No newline at end of file
diff --git a/repo/includes/Query/SQLStore/DataValueHandler.php 
b/repo/includes/Query/SQLStore/DataValueHandler.php
index a9e30c4..7012370 100644
--- a/repo/includes/Query/SQLStore/DataValueHandler.php
+++ b/repo/includes/Query/SQLStore/DataValueHandler.php
@@ -81,11 +81,11 @@
         */
        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
+        * 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
diff --git a/repo/tests/phpunit/includes/Database/FieldDefinitionTest.php 
b/repo/tests/phpunit/includes/Database/FieldDefinitionTest.php
index 5566a95..82f9ab6 100644
--- a/repo/tests/phpunit/includes/Database/FieldDefinitionTest.php
+++ b/repo/tests/phpunit/includes/Database/FieldDefinitionTest.php
@@ -52,26 +52,26 @@
                $instances[] = new FieldDefinition(
                        'stuffs',
                        FieldDefinition::TYPE_INTEGER,
+                       false,
                        42,
-                       FieldDefinition::ATTRIB_UNSIGNED,
-                       false
+                       FieldDefinition::ATTRIB_UNSIGNED
                );
 
                $instances[] = new FieldDefinition(
                        'stuffs',
                        FieldDefinition::TYPE_INTEGER,
-                       null,
-                       null,
-                       true
-               );
-
-               $instances[] = new FieldDefinition(
-                       'stuffs',
-                       FieldDefinition::TYPE_INTEGER,
-                       null,
-                       null,
                        true,
                        null,
+                       null
+               );
+
+               $instances[] = new FieldDefinition(
+                       'stuffs',
+                       FieldDefinition::TYPE_INTEGER,
+                       true,
+                       null,
+                       null,
+                       null,
                        true
                );
 
diff --git a/repo/tests/phpunit/includes/Database/TableDefinitionTest.php 
b/repo/tests/phpunit/includes/Database/TableDefinitionTest.php
index 393a795..9d546ce 100644
--- a/repo/tests/phpunit/includes/Database/TableDefinitionTest.php
+++ b/repo/tests/phpunit/includes/Database/TableDefinitionTest.php
@@ -52,7 +52,7 @@
                        array(
                                new FieldDefinition( 'o', 
FieldDefinition::TYPE_TEXT ),
                                new FieldDefinition( 'h', 
FieldDefinition::TYPE_TEXT ),
-                               new FieldDefinition( 'i', 
FieldDefinition::TYPE_INTEGER, 42 ),
+                               new FieldDefinition( 'i', 
FieldDefinition::TYPE_INTEGER, false, 42 ),
                        )
                );
 
diff --git 
a/repo/tests/phpunit/includes/Query/SQLStore/DVHandler/GeoCoordinateHandlerTest.php
 
b/repo/tests/phpunit/includes/Query/SQLStore/DVHandler/GeoCoordinateHandlerTest.php
new file mode 100644
index 0000000..b49d9fd
--- /dev/null
+++ 
b/repo/tests/phpunit/includes/Query/SQLStore/DVHandler/GeoCoordinateHandlerTest.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace Wikibase\Repo\Test\Query\SQLStore\DVHandler;
+
+use Wikibase\Repo\Query\SQLStore\DataValueHandler;
+use Wikibase\Repo\Query\SQLStore\DVHandler\GeoCoordinateHandler;
+use Wikibase\Repo\Test\Query\SQLStore\DataValueHandlerTest;
+
+/**
+ * Unit tests for the 
Wikibase\Repo\Query\SQLStore\DVHandler\GeoCoordinateHandler class.
+ *
+ * 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
+ *
+ * @file
+ * @since wd.qe
+ *
+ * @ingroup WikibaseRepoTest
+ *
+ * @group Wikibase
+ * @group WikibaseRepo
+ * @group WikibaseQuery
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class GeoCoordinateHandlerTest extends DataValueHandlerTest {
+
+       /**
+        * @since wd.qe
+        *
+        * @return DataValueHandler[]
+        */
+       protected function getInstances() {
+               $instances = array();
+
+               $instances[] = new GeoCoordinateHandler();
+
+               return $instances;
+       }
+
+}
diff --git 
a/repo/tests/phpunit/includes/Query/SQLStore/DataValueHandlerTest.php 
b/repo/tests/phpunit/includes/Query/SQLStore/DataValueHandlerTest.php
index dd248a2..9f5c9e7 100644
--- a/repo/tests/phpunit/includes/Query/SQLStore/DataValueHandlerTest.php
+++ b/repo/tests/phpunit/includes/Query/SQLStore/DataValueHandlerTest.php
@@ -105,6 +105,7 @@
         */
        public function testNewDataValueFromDbValue( DataValueHandler 
$dvHandler ) {
                // TODO
+               $this->assertTrue( true );
        }
 
        /**

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ibdf6679b3a0e657cef65cc77e525aec883bc047f
Gerrit-PatchSet: 3
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

Reply via email to