John Erling Blad has submitted this change and it was merged.
Change subject: Added BooleanHandler
......................................................................
Added BooleanHandler
Change-Id: I682e73db0954df2393d07814f89440b6096af9df
---
M repo/config/Wikibase.experimental.php
A repo/includes/Query/SQLStore/DVHandler/BooleanHandler.php
A repo/tests/phpunit/includes/Query/SQLStore/DVHandler/BooleanHandlerTest.php
3 files changed, 208 insertions(+), 0 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 58760d6..32dc947 100644
--- a/repo/config/Wikibase.experimental.php
+++ b/repo/config/Wikibase.experimental.php
@@ -62,6 +62,7 @@
'Wikibase\Repo\Query\QueryResult',
'Wikibase\Repo\Query\QueryStore',
+ 'Wikibase\Repo\Query\SQLStore\DVHandler\BooleanHandler',
'Wikibase\Repo\Query\SQLStore\DVHandler\EntityIdHandler',
'Wikibase\Repo\Query\SQLStore\DVHandler\GeoCoordinateHandler',
'Wikibase\Repo\Query\SQLStore\DVHandler\NumberHandler',
@@ -142,6 +143,7 @@
'Query/QueryEngineResult',
+ 'Query/SQLStore/DVHandler/BooleanHandler',
'Query/SQLStore/DVHandler/EntityIdHandler',
'Query/SQLStore/DVHandler/GeoCoordinateHandler',
'Query/SQLStore/DVHandler/NumberHandler',
diff --git a/repo/includes/Query/SQLStore/DVHandler/BooleanHandler.php
b/repo/includes/Query/SQLStore/DVHandler/BooleanHandler.php
new file mode 100644
index 0000000..e073cb8
--- /dev/null
+++ b/repo/includes/Query/SQLStore/DVHandler/BooleanHandler.php
@@ -0,0 +1,133 @@
+<?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;
+use DataValues\BooleanValue;
+use InvalidArgumentException;
+
+/**
+ * Represents the mapping between Wikibase\BooleanValue 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 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
+ *
+ * @param $valueFieldValue // TODO: mixed or string?
+ *
+ * @return DataValue
+ */
+ public function newDataValueFromValueField( $valueFieldValue ) {
+ return new BooleanValue( $valueFieldValue );
+ }
+
+ /**
+ * @see DataValueHandler::getWhereConditions
+ *
+ * @since wd.qe
+ *
+ * @param DataValue $value
+ *
+ * @return array
+ * @throws InvalidArgumentException
+ */
+ public function getWhereConditions( DataValue $value ) {
+ if ( !( $value instanceof BooleanValue ) ) {
+ throw new InvalidArgumentException( 'Value is not a
BooleanValue' );
+ }
+
+ return array(
+ 'value' => $value->getValue(),
+ );
+ }
+
+ /**
+ * @see DataValueHandler::getInsertValues
+ *
+ * @since wd.qe
+ *
+ * @param DataValue $value
+ *
+ * @return array
+ * @throws InvalidArgumentException
+ */
+ public function getInsertValues( DataValue $value ) {
+ if ( !( $value instanceof BooleanValue ) ) {
+ throw new InvalidArgumentException( 'Value is not a
BooleanValue' );
+ }
+
+ $values = array(
+ 'value' => $value->getValue(),
+ );
+
+ return $values;
+ }
+
+}
\ No newline at end of file
diff --git
a/repo/tests/phpunit/includes/Query/SQLStore/DVHandler/BooleanHandlerTest.php
b/repo/tests/phpunit/includes/Query/SQLStore/DVHandler/BooleanHandlerTest.php
new file mode 100644
index 0000000..7eaf4d9
--- /dev/null
+++
b/repo/tests/phpunit/includes/Query/SQLStore/DVHandler/BooleanHandlerTest.php
@@ -0,0 +1,73 @@
+<?php
+
+namespace Wikibase\Repo\Test\Query\SQLStore\DVHandler;
+
+use Wikibase\Repo\Query\SQLStore\DataValueHandler;
+use Wikibase\Repo\Query\SQLStore\DVHandler\BooleanHandler;
+use Wikibase\Repo\Test\Query\SQLStore\DataValueHandlerTest;
+use DataValues\BooleanValue;
+
+/**
+ * Unit tests for the Wikibase\Repo\Query\SQLStore\DVHandler\BooleanHandler
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 BooleanHandlerTest extends DataValueHandlerTest {
+
+ /**
+ * @see DataValueHandlerTest::getInstances
+ *
+ * @since wd.qe
+ *
+ * @return DataValueHandler[]
+ */
+ protected function getInstances() {
+ $instances = array();
+
+ $instances[] = new BooleanHandler();
+
+ return $instances;
+ }
+
+ /**
+ * @see DataValueHandlerTest::getValues
+ *
+ * @since wd.qe
+ *
+ * @return BooleanValue[]
+ */
+ protected function getValues() {
+ $values = array();
+
+ $values[] = new BooleanValue( true );
+ $values[] = new BooleanValue( false );
+
+ return $values;
+ }
+
+}
--
To view, visit https://gerrit.wikimedia.org/r/52209
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I682e73db0954df2393d07814f89440b6096af9df
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[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