Daniel Werner has submitted this change and it was merged. Change subject: Some implementation for in the SQLStore updater ......................................................................
Some implementation for in the SQLStore updater Change-Id: I5bf7af55109b06564f6b530e6e9c43105218c428 --- M QueryEngine/QueryEngine/SQLStore/Schema.php M QueryEngine/QueryEngine/SQLStore/Updater.php M QueryEngine/tests/phpunit/SQLStore/UpdaterTest.php 3 files changed, 77 insertions(+), 23 deletions(-) Approvals: Daniel Werner: Verified; Looks good to me, approved Denny Vrandecic: Looks good to me, approved diff --git a/QueryEngine/QueryEngine/SQLStore/Schema.php b/QueryEngine/QueryEngine/SQLStore/Schema.php index 1e17e66..2f0c93a 100644 --- a/QueryEngine/QueryEngine/SQLStore/Schema.php +++ b/QueryEngine/QueryEngine/SQLStore/Schema.php @@ -229,21 +229,13 @@ } /** - * TODO - * * @since 0.1 * - * @return TableDefinition[] + * @return TableDefinition */ - private function getNonDvTables() { - $tables = array(); - - // TODO: multi field indexes - // TODO: more optimal types - - // Id map with Wikibase EntityId to internal SQL store id - $tables[] = new TableDefinition( - 'entities', + public function getEntitiesTable() { + return new TableDefinition( + $this->config->getTablePrefix() . 'entities', array( // Internal id new FieldDefinition( @@ -277,10 +269,27 @@ ), ) ); + } + + /** + * TODO + * + * @since 0.1 + * + * @return TableDefinition[] + */ + private function getNonDvTables() { + $tables = array(); + + // TODO: multi field indexes + // TODO: more optimal types + + // Id map with Wikibase EntityId to internal SQL store id + $tables[] = $this->getEntitiesTable(); // Claim id table $tables[] = new TableDefinition( - 'claims', + $this->config->getTablePrefix() . 'claims', array( // Internal id new FieldDefinition( @@ -347,7 +356,7 @@ // Table for snaks without a value $tables[] = new TableDefinition( - 'valueless_snaks', + $this->config->getTablePrefix() . 'valueless_snaks', array_merge( $this->getPropertySnakFields(), array( diff --git a/QueryEngine/QueryEngine/SQLStore/Updater.php b/QueryEngine/QueryEngine/SQLStore/Updater.php index 02a6218..09d12be 100644 --- a/QueryEngine/QueryEngine/SQLStore/Updater.php +++ b/QueryEngine/QueryEngine/SQLStore/Updater.php @@ -72,7 +72,8 @@ * @param Entity $entity */ public function insertEntity( Entity $entity ) { - // TODO: insert entity info into entities table + $this->insertIntoEntitiesTable( $entity ); + // TODO: insert info of linked entities into entities table foreach ( $entity->getClaims() as $claim ) { @@ -82,6 +83,16 @@ // TODO: obtain and insert virtual claims } + private function insertIntoEntitiesTable( Entity $entity ) { + $this->queryInterface->insert( + $this->schema->getEntitiesTable()->getName(), + array( + 'type' => $entity->getType(), + 'number' => $entity->getId()->getNumericId(), + ) + ); + } + /** * @since 0.1 * diff --git a/QueryEngine/tests/phpunit/SQLStore/UpdaterTest.php b/QueryEngine/tests/phpunit/SQLStore/UpdaterTest.php index 0596ec7..d3388bd 100644 --- a/QueryEngine/tests/phpunit/SQLStore/UpdaterTest.php +++ b/QueryEngine/tests/phpunit/SQLStore/UpdaterTest.php @@ -5,10 +5,11 @@ use Wikibase\Database\FieldDefinition; use Wikibase\Database\ObservableQueryInterface; use Wikibase\Database\TableDefinition; +use Wikibase\Entity; use Wikibase\Item; +use Wikibase\Property; use Wikibase\QueryEngine\SQLStore\DVHandler\BooleanHandler; use Wikibase\QueryEngine\SQLStore\DVHandler\MonolingualTextHandler; -use Wikibase\QueryEngine\SQLStore\DVHandler\StringHandler; use Wikibase\QueryEngine\SQLStore\DataValueTable; use Wikibase\QueryEngine\SQLStore\Schema; use Wikibase\QueryEngine\SQLStore\StoreConfig; @@ -92,21 +93,54 @@ 'text' ) ); - return new Schema( new StoreConfig( 'foo', 'bar', $dataValueHandlers ) ); + return new Schema( new StoreConfig( 'foobar', 'nyan_', $dataValueHandlers ) ); } - public function testInsertEntity() { + public function entityWithoutClaimsProvider() { + $argLists = array(); + $item = Item::newEmpty(); $item->setId( 42 ); - $queryInterface = new ObservableQueryInterface(); + $argLists[] = array( $item ); + + + $item = Item::newEmpty(); + $item->setId( 31337 ); + + $argLists[] = array( $item ); + + + $property = Property::newEmpty(); + $property->setDataTypeId( 'string' ); + $property->setId( 9001 ); + + $argLists[] = array( $property ); + + return $argLists; + } + + /** + * @dataProvider entityWithoutClaimsProvider + */ + public function testInsertEntityWithoutClaims( Entity $entity ) { + $queryInterface = $this->getMock( 'Wikibase\Database\QueryInterface' ); + + $queryInterface->expects( $this->once() ) + ->method( 'insert' ) + ->with( + $this->equalTo( 'nyan_entities' ), + $this->equalTo( + array( + 'type' => $entity->getType(), + 'number' => $entity->getId()->getNumericId(), + ) + ) + ); $updater = new Updater( $this->newStoreSchema(), $queryInterface ); - $updater->insertEntity( $item ); - - // TODO: further implement - $this->assertTrue( true ); + $updater->insertEntity( $entity ); } } -- To view, visit https://gerrit.wikimedia.org/r/58525 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I5bf7af55109b06564f6b530e6e9c43105218c428 Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com> Gerrit-Reviewer: Aude <aude.w...@gmail.com> Gerrit-Reviewer: Daniel Werner <daniel.wer...@wikimedia.de> Gerrit-Reviewer: Denny Vrandecic <denny.vrande...@wikimedia.de> Gerrit-Reviewer: John Erling Blad <jeb...@gmail.com> Gerrit-Reviewer: Tobias Gritschacher <tobias.gritschac...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits