Jeroen De Dauw has uploaded a new change for review. https://gerrit.wikimedia.org/r/91870
Change subject: Improve high level interfaces and intialization of the SQLStore ...................................................................... Improve high level interfaces and intialization of the SQLStore Change-Id: Ia403b652f350733ff646f94688279de1eb67166a --- D src/QueryEngineResult.php D src/QueryResult.php D src/QueryStore.php A src/QueryStoreInstaller.php D src/QueryStoreSetup.php A src/QueryStoreUninstaller.php A src/QueryStoreUpdater.php A src/QueryStoreWithDependencies.php M src/SQLStore/DVHandler/EntityIdHandler.php A src/SQLStore/SQLStore.php A src/SQLStore/SQLStoreWithDependencies.php M src/SQLStore/Setup/Installer.php D src/SQLStore/Setup/Setup.php M src/SQLStore/Setup/Uninstaller.php M src/SQLStore/Setup/Updater.php D src/SQLStore/Store.php M tests/Integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php M tests/Integration/SQLStore/IntegrationStoreBuilder.php M tests/Integration/SQLStore/WritingIntegrationTest.php R tests/Phpunit/SQLStore/SQLStoreTest.php D tests/Phpunit/SQLStore/Setup/SetupTest.php 21 files changed, 407 insertions(+), 596 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseQueryEngine refs/changes/70/91870/1 diff --git a/src/QueryEngineResult.php b/src/QueryEngineResult.php deleted file mode 100644 index 1f5a51b..0000000 --- a/src/QueryEngineResult.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php - -namespace Wikibase\QueryEngine; - -/** - * Result of running a query against the query engine. - * - * @since 0.1 - * - * @file - * @ingroup WikibaseQueryStore - * - * @licence GNU GPL v2+ - * @author Jeroen De Dauw < [email protected] > - */ -class QueryEngineResult { - - /** - * @since 0.1 - * - * @return QueryResult - */ - public function getQueryResult() { - // TODO - return new QueryResult(); - } - -} \ No newline at end of file diff --git a/src/QueryResult.php b/src/QueryResult.php deleted file mode 100644 index 9e57edc..0000000 --- a/src/QueryResult.php +++ /dev/null @@ -1,9 +0,0 @@ -<?php - -namespace Wikibase\QueryEngine; - -class QueryResult { - // TODO: this is a temporary stub - // * some preliminary query result code in other git repo - // * still need to figure out where to put it -} \ No newline at end of file diff --git a/src/QueryStore.php b/src/QueryStore.php deleted file mode 100644 index f03162f..0000000 --- a/src/QueryStore.php +++ /dev/null @@ -1,67 +0,0 @@ -<?php - -namespace Wikibase\QueryEngine; - -/** - * Interface for query stores providing access to all needed sub components - * such as updaters, query engines and setup/teardown operations. - * - * This interface somewhat acts as facade to the query component. - * All access to a specific store should typically happen via this interface. - * - * @since 0.1 - * - * @file - * @ingroup WikibaseQueryStore - * - * @licence GNU GPL v2+ - * @author Jeroen De Dauw < [email protected] > - */ -interface QueryStore { - - // TODO: create store factory and figure out how to inject dependencies - // for the typical Wikibase repo use case. - - /** - * Returns the name of the query store. This name can be configuration dependent - * and is thus not always the same for a certain store type. For instance, you can - * have "Wikibase SQL store" and "Wikibase SQL store for update to new config". - * - * @since 0.1 - * - * @return string - */ - public function getName(); - - /** - * Returns the query engine for this store. - * The query engine allows running queries against the store. - * - * @since 0.1 - * - * @return QueryEngine - */ - public function getQueryEngine(); - - /** - * Returns the updater for this store. - * The updater allows for updating the data in the store. - * - * @since 0.1 - * - * @return QueryStoreWriter - */ - public function getWriter(); - - /** - * Sets up the store. - * This means creating and initializing the storage structures - * required for storing data in the store. - * - * @since 0.1 - * - * @return QueryStoreSetup - */ - public function newSetup(); - -} diff --git a/src/QueryStoreInstaller.php b/src/QueryStoreInstaller.php new file mode 100644 index 0000000..93579da --- /dev/null +++ b/src/QueryStoreInstaller.php @@ -0,0 +1,15 @@ +<?php + +namespace Wikibase\QueryEngine; + +/** + * @since 0.1 + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < [email protected] > + */ +interface QueryStoreInstaller { + + public function install(); + +} diff --git a/src/QueryStoreSetup.php b/src/QueryStoreSetup.php deleted file mode 100644 index 8258541..0000000 --- a/src/QueryStoreSetup.php +++ /dev/null @@ -1,49 +0,0 @@ -<?php - -namespace Wikibase\QueryEngine; - -/** - * @since 0.1 - * - * @file - * @ingroup WikibaseQueryStore - * - * @licence GNU GPL v2+ - * @author Jeroen De Dauw < [email protected] > - */ -interface QueryStoreSetup { - - /** - * Install the store. - * This includes setting up all the required database tables. - * - * @since 0.1 - * - * TODO: document throws - */ - public function install(); - - /** - * Uninstall the store. - * This includes removing all the required database tables. - * - * Caution: all data held by the store will be removed - * - * @since 0.1 - * - * TODO: document throws - */ - public function uninstall(); - - /** - * Updates the store schema to the latest version. - * This includes schema modifications, rebuilding of data where needed - * and doing initial population where needed. - * - * @since 0.1 - * - * TODO: document throws - */ - public function update(); - -} diff --git a/src/QueryStoreUninstaller.php b/src/QueryStoreUninstaller.php new file mode 100644 index 0000000..0d2c372 --- /dev/null +++ b/src/QueryStoreUninstaller.php @@ -0,0 +1,15 @@ +<?php + +namespace Wikibase\QueryEngine; + +/** + * @since 0.1 + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < [email protected] > + */ +interface QueryStoreUninstaller { + + public function uninstall(); + +} diff --git a/src/QueryStoreUpdater.php b/src/QueryStoreUpdater.php new file mode 100644 index 0000000..0f19330 --- /dev/null +++ b/src/QueryStoreUpdater.php @@ -0,0 +1,15 @@ +<?php + +namespace Wikibase\QueryEngine; + +/** + * @since 0.1 + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < [email protected] > + */ +interface QueryStoreUpdater { + + public function update(); + +} diff --git a/src/QueryStoreWithDependencies.php b/src/QueryStoreWithDependencies.php new file mode 100644 index 0000000..728490e --- /dev/null +++ b/src/QueryStoreWithDependencies.php @@ -0,0 +1,59 @@ +<?php + +namespace Wikibase\QueryEngine; + +/** + * Coarse interface that provides access to the high level public interfaces + * all stores have. Instantiating an implementation likely requires instantiating + * all its collaborators. It is thus advisable to generally use just construct + * the needed service(s). + * + * @since 0.1 + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < [email protected] > + */ +interface QueryStoreWithDependencies { + + /** + * Returns the query engine for this store. + * The query engine allows running queries against the store. + * + * @since 0.1 + * + * @return QueryEngine + */ + public function newQueryEngine(); + + /** + * Returns the writer for this store. + * The updater allows for updating the data in the store. + * + * @since 0.1 + * + * @return QueryStoreWriter + */ + public function newWriter(); + + /** + * @since 0.1 + * + * @return QueryStoreInstaller + */ + public function newInstaller(); + + /** + * @since 0.1 + * + * @return QueryStoreUninstaller + */ + public function newUninstaller(); + + /** + * @since 0.1 + * + * @return QueryStoreUpdater + */ + public function newUpdater(); + +} diff --git a/src/SQLStore/DVHandler/EntityIdHandler.php b/src/SQLStore/DVHandler/EntityIdHandler.php index 4cde0e1..2a92c94 100644 --- a/src/SQLStore/DVHandler/EntityIdHandler.php +++ b/src/SQLStore/DVHandler/EntityIdHandler.php @@ -5,7 +5,6 @@ use DataValues\DataValue; use InvalidArgumentException; use Wikibase\DataModel\Entity\BasicEntityIdParser; -use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Entity\EntityIdValue; use Wikibase\QueryEngine\SQLStore\DataValueHandler; diff --git a/src/SQLStore/SQLStore.php b/src/SQLStore/SQLStore.php new file mode 100644 index 0000000..8c247a5 --- /dev/null +++ b/src/SQLStore/SQLStore.php @@ -0,0 +1,195 @@ +<?php + +namespace Wikibase\QueryEngine\SQLStore; + +use Wikibase\Database\QueryInterface\QueryInterface; +use Wikibase\Database\Schema\SchemaModifier; +use Wikibase\Database\Schema\TableBuilder; +use Wikibase\Database\Schema\TableDefinitionReader; +use Wikibase\DataModel\Entity\BasicEntityIdParser; +use Wikibase\QueryEngine\QueryEngine; +use Wikibase\QueryEngine\QueryStoreWriter; +use Wikibase\QueryEngine\SQLStore\ClaimStore\ClaimInserter; +use Wikibase\QueryEngine\SQLStore\ClaimStore\ClaimRowBuilder; +use Wikibase\QueryEngine\SQLStore\Engine\DescriptionMatchFinder; +use Wikibase\QueryEngine\SQLStore\Engine\Engine; +use Wikibase\QueryEngine\SQLStore\Setup\Installer; +use Wikibase\QueryEngine\SQLStore\Setup\Uninstaller; +use Wikibase\QueryEngine\SQLStore\Setup\Updater; +use Wikibase\QueryEngine\SQLStore\SnakStore\SnakInserter; +use Wikibase\QueryEngine\SQLStore\SnakStore\SnakRemover; +use Wikibase\QueryEngine\SQLStore\SnakStore\SnakRowBuilder; +use Wikibase\QueryEngine\SQLStore\SnakStore\SnakStore; +use Wikibase\QueryEngine\SQLStore\SnakStore\ValuelessSnakStore; +use Wikibase\QueryEngine\SQLStore\SnakStore\ValueSnakStore; +use Wikibase\SnakRole; + +/** + * Simple query store for relational SQL databases. + * + * This class is the top level factory able to construct + * the high level services that form the public interface + * of the store. + * + * @since 0.1 + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < [email protected] > + */ +class SQLStore { + + /** + * @var StoreConfig + */ + private $config; + + /** + * @var Schema|null + */ + protected $schema = null; + + public function __construct( StoreConfig $config ) { + $this->config = $config; + } + + /** + * @return Schema + */ + private function getSchema() { + if ( $this->schema === null ) { + $this->schema = new Schema( $this->config ); + } + + return $this->schema; + } + + /** + * @since 0.1 + * + * @param QueryInterface $queryInterface + * + * @return QueryEngine + */ + public function newQueryEngine( QueryInterface $queryInterface ) { + return new Engine( + $this->newDescriptionMatchFinder( $queryInterface ) + ); + } + + /** + * @since 0.1 + * + * @param QueryInterface $queryInterface + * + * @return QueryStoreWriter + */ + public function newWriter( QueryInterface $queryInterface ) { + return new Writer( + $this->newEntityInserter( $queryInterface ), + $this->newEntityUpdater( $queryInterface ), + $this->newEntityRemover( $queryInterface ) + ); + } + + public function newInstaller( TableBuilder $tableBuilder ) { + return new Installer( + $this->config, + $this->getSchema(), + $tableBuilder + ); + } + + public function newUninstaller( TableBuilder $tableBuilder ) { + return new Uninstaller( + $this->config, + $this->getSchema(), + $tableBuilder + ); + } + + public function newUpdater( TableBuilder $tableBuilder, TableDefinitionReader $tableDefinitionReader, SchemaModifier $schemaModifier ) { + return new Updater( + $this->getSchema(), + $schemaModifier, + $tableDefinitionReader, + $tableBuilder + ); + } + + private function newEntityInserter( QueryInterface $queryInterface ) { + return new EntityInserter( + $this->newClaimInserter( $queryInterface ) + ); + } + + private function newEntityUpdater( QueryInterface $queryInterface ) { + return new EntityUpdater( + $this->newEntityRemover( $queryInterface ), + $this->newEntityInserter( $queryInterface ) + ); + } + + private function newEntityRemover( QueryInterface $queryInterface ) { + return new EntityRemover( + $this->newSnakRemover( $queryInterface ) + ); + } + + private function newSnakRemover( QueryInterface $queryInterface ) { + return new SnakRemover( $this->getSnakStores( $queryInterface ) ); + } + + private function newEntityTable( QueryInterface $queryInterface ) { + return new EntityTable( + $queryInterface, + $this->getSchema()->getEntitiesTable()->getName() + ); + } + + private function newClaimInserter( QueryInterface $queryInterface ) { + return new ClaimInserter( + $this->newSnakInserter( $queryInterface ), + new ClaimRowBuilder() + ); + } + + private function newSnakInserter( QueryInterface $queryInterface ) { + return new SnakInserter( + $this->getSnakStores( $queryInterface ), + new SnakRowBuilder() + ); + } + + /** + * @param QueryInterface $queryInterface + * @return SnakStore[] + */ + private function getSnakStores( QueryInterface $queryInterface ) { + return array( + new ValueSnakStore( + $queryInterface, + $this->getSchema()->getDataValueHandlers( SnakRole::MAIN_SNAK ), + SnakRole::MAIN_SNAK + ), + new ValueSnakStore( + $queryInterface, + $this->getSchema()->getDataValueHandlers( SnakRole::QUALIFIER ), + SnakRole::QUALIFIER + ), + new ValuelessSnakStore( + $queryInterface, + $this->getSchema()->getValuelessSnaksTable()->getName() + ) + ); + } + + private function newDescriptionMatchFinder( QueryInterface $queryInterface ) { + return new DescriptionMatchFinder( + $queryInterface, + $this->getSchema(), + $this->config->getPropertyDataValueTypeLookup(), + new BasicEntityIdParser() // TODO: inject + ); + } + +} diff --git a/src/SQLStore/SQLStoreWithDependencies.php b/src/SQLStore/SQLStoreWithDependencies.php new file mode 100644 index 0000000..0d6fe6f --- /dev/null +++ b/src/SQLStore/SQLStoreWithDependencies.php @@ -0,0 +1,54 @@ +<?php + +namespace Wikibase\QueryEngine\SQLStore; + +use Wikibase\Database\QueryInterface\QueryInterface; +use Wikibase\Database\Schema\SchemaModifier; +use Wikibase\Database\Schema\TableBuilder; +use Wikibase\Database\Schema\TableDefinitionReader; +use Wikibase\QueryEngine\QueryStoreWithDependencies; + +class SQLStoreWithDependencies implements QueryStoreWithDependencies { + + protected $queryInterface; + protected $tableBuilder; + protected $tableReader; + protected $schemaModifier; + + protected $store; + + public function __construct( SQLStore $factory, QueryInterface $queryInterface, + TableBuilder $tableBuilder, TableDefinitionReader $tableReader, SchemaModifier $schemaModifier ) { + + $this->factory = $factory; + $this->queryInterface = $queryInterface; + $this->tableBuilder = $tableBuilder; + $this->tableReader = $tableReader; + $this->schemaModifier = $schemaModifier; + } + + public function newQueryEngine() { + return $this->factory->newQueryEngine( $this->queryInterface ); + } + + public function newWriter() { + return $this->factory->newWriter( $this->queryInterface ); + } + + public function newInstaller() { + return $this->factory->newInstaller( $this->tableBuilder ); + } + + public function newUninstaller() { + return $this->factory->newUninstaller( $this->tableBuilder ); + } + + public function newUpdater() { + return $this->factory->newUpdater( + $this->tableBuilder, + $this->tableReader, + $this->schemaModifier + ); + } + +} \ No newline at end of file diff --git a/src/SQLStore/Setup/Installer.php b/src/SQLStore/Setup/Installer.php index c4cf774..f83a72f 100644 --- a/src/SQLStore/Setup/Installer.php +++ b/src/SQLStore/Setup/Installer.php @@ -4,6 +4,7 @@ use Wikibase\Database\QueryInterface\QueryInterfaceException; use Wikibase\Database\Schema\TableBuilder; +use Wikibase\QueryEngine\QueryStoreInstaller; use Wikibase\QueryEngine\SQLStore\Schema; use Wikibase\QueryEngine\SQLStore\StoreConfig; @@ -11,7 +12,7 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < [email protected] > */ -class Installer { +class Installer implements QueryStoreInstaller { /** * @var StoreConfig @@ -47,7 +48,7 @@ } /** - * @see QueryStoreSetup::install + * @see QueryStoreInstaller::install * * TODO: document throws */ diff --git a/src/SQLStore/Setup/Setup.php b/src/SQLStore/Setup/Setup.php deleted file mode 100644 index feb9164..0000000 --- a/src/SQLStore/Setup/Setup.php +++ /dev/null @@ -1,59 +0,0 @@ -<?php - -namespace Wikibase\QueryEngine\SQLStore\Setup; - -use Wikibase\Database\Schema\Definitions\FieldDefinition; -use Wikibase\Database\Schema\Definitions\TableDefinition; -use Wikibase\QueryEngine\QueryStoreSetup; - -/** - * @licence GNU GPL v2+ - * @author Jeroen De Dauw < [email protected] > - */ -class Setup implements QueryStoreSetup { - - /** - * @param Installer $installer - * @param Updater $updater - * @param Uninstaller $uninstaller - */ - public function __construct( Installer $installer, Updater $updater, Uninstaller $uninstaller ) { - $this->installer = $installer; - $this->updater = $updater; - $this->uninstaller = $uninstaller; - } - - /** - * @see QueryStoreSetup::install - * - * @since 0.1 - * - * TODO: document throws - */ - public function install() { - $this->installer->install(); - } - - /** - * @see QueryStoreSetup::update - * - * @since 0.1 - * - * TODO: document throws - */ - public function update() { - $this->updater->update(); - } - - /** - * @see QueryStoreSetup::uninstall - * - * @since 0.1 - * - * TODO: document throws - */ - public function uninstall() { - $this->uninstaller->uninstall(); - } - -} diff --git a/src/SQLStore/Setup/Uninstaller.php b/src/SQLStore/Setup/Uninstaller.php index dfeaeb2..46fd653 100644 --- a/src/SQLStore/Setup/Uninstaller.php +++ b/src/SQLStore/Setup/Uninstaller.php @@ -3,6 +3,8 @@ namespace Wikibase\QueryEngine\SQLStore\Setup; use Wikibase\Database\Schema\TableBuilder; +use Wikibase\QueryEngine\QueryStoreUninstaller; +use Wikibase\QueryEngine\QueryStoreUpdater; use Wikibase\QueryEngine\SQLStore\Schema; use Wikibase\QueryEngine\SQLStore\StoreConfig; @@ -10,7 +12,7 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < [email protected] > */ -class Uninstaller { +class Uninstaller implements QueryStoreUninstaller { /** * @var StoreConfig @@ -46,7 +48,7 @@ } /** - * @see QueryStoreSetup::uninstall + * @see QueryStoreUninstaller::uninstall * * TODO: document throws */ diff --git a/src/SQLStore/Setup/Updater.php b/src/SQLStore/Setup/Updater.php index ad0dc01..068fbc5 100644 --- a/src/SQLStore/Setup/Updater.php +++ b/src/SQLStore/Setup/Updater.php @@ -5,6 +5,7 @@ use Wikibase\Database\Schema\TableBuilder; use Wikibase\Database\Schema\TableDefinitionReader; use Wikibase\Database\Schema\TableSchemaUpdater; +use Wikibase\QueryEngine\QueryStoreUpdater; use Wikibase\QueryEngine\SQLStore\Schema; /** @@ -13,7 +14,7 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < [email protected] > */ -class Updater { +class Updater implements QueryStoreUpdater { protected $storeSchema; protected $schemaUpdater; @@ -30,7 +31,7 @@ } /** - * @see QueryStoreSetup::update + * @see QueryStoreUpdater::update * * TODO: document throws */ diff --git a/src/SQLStore/Store.php b/src/SQLStore/Store.php deleted file mode 100644 index 5c57dab..0000000 --- a/src/SQLStore/Store.php +++ /dev/null @@ -1,265 +0,0 @@ -<?php - -namespace Wikibase\QueryEngine\SQLStore; - -use Wikibase\Database\QueryInterface\QueryInterface; -use Wikibase\Database\Schema\Definitions\TableDefinition; -use Wikibase\Database\Schema\SchemaModifier; -use Wikibase\Database\Schema\SimpleTableSchemaUpdater; -use Wikibase\Database\Schema\TableBuilder; -use Wikibase\Database\Schema\TableDefinitionReader; -use Wikibase\Database\Schema\TableSchemaUpdater; -use Wikibase\DataModel\Entity\BasicEntityIdParser; -use Wikibase\QueryEngine\QueryEngine; -use Wikibase\QueryEngine\QueryStore; -use Wikibase\QueryEngine\QueryStoreSetup; -use Wikibase\QueryEngine\QueryStoreWriter; -use Wikibase\QueryEngine\SQLStore\ClaimStore\ClaimInserter; -use Wikibase\QueryEngine\SQLStore\ClaimStore\ClaimRowBuilder; -use Wikibase\QueryEngine\SQLStore\Engine\DescriptionMatchFinder; -use Wikibase\QueryEngine\SQLStore\Engine\Engine; -use Wikibase\QueryEngine\SQLStore\Setup\Installer; -use Wikibase\QueryEngine\SQLStore\Setup\Setup; -use Wikibase\QueryEngine\SQLStore\Setup\Uninstaller; -use Wikibase\QueryEngine\SQLStore\Setup\Updater; -use Wikibase\QueryEngine\SQLStore\SnakStore\SnakInserter; -use Wikibase\QueryEngine\SQLStore\SnakStore\SnakRemover; -use Wikibase\QueryEngine\SQLStore\SnakStore\SnakRowBuilder; -use Wikibase\QueryEngine\SQLStore\SnakStore\SnakStore; -use Wikibase\QueryEngine\SQLStore\SnakStore\ValuelessSnakStore; -use Wikibase\QueryEngine\SQLStore\SnakStore\ValueSnakStore; -use Wikibase\SnakRole; - -/** - * Simple query store for relational SQL databases. - * - * @since 0.1 - * - * @licence GNU GPL v2+ - * @author Jeroen De Dauw < [email protected] > - */ -class Store implements QueryStore { - - /** - * @var StoreConfig - */ - private $config; - - /** - * @var QueryInterface - */ - private $queryInterface; - - /** - * @var TableBuilder - */ - private $tableBuilder; - - /** - * @var TableDefinitionReader - */ - public $tableDefinitionReader; - - /** - * @var SchemaModifier - */ - public $schemaModifier; - - /** - * @var Schema|null - */ - protected $schema = null; - - public function __construct( StoreConfig $config, QueryInterface $queryInterface, - TableBuilder $tableBuilder, TableDefinitionReader $tableDefinitionReader, SchemaModifier $schemaModifier ) { - - $this->config = $config; - - $this->queryInterface = $queryInterface; - $this->tableBuilder = $tableBuilder; - $this->tableDefinitionReader = $tableDefinitionReader; - $this->schemaModifier = $schemaModifier; - } - - /** - * @see QueryStore::getName - * - * @since 0.1 - * - * @return string - */ - public function getName() { - return $this->config->getStoreName(); - } - - /** - * @see QueryStore::getQueryEngine - * - * @since 0.1 - * - * @return QueryEngine - */ - public function getQueryEngine() { - return new Engine( - $this->newDescriptionMatchFinder() - ); - } - - /** - * @see QueryStore::getWriter - * - * @since 0.1 - * - * @return QueryStoreWriter - */ - public function getWriter() { - return $this->newWriter(); - } - - /** - * @see QueryStore::newSetup - * - * @since 0.1 - * - * @return QueryStoreSetup - */ - public function newSetup() { - return new Setup( - $this->getInstaller(), - $this->getUpdater(), - $this->getUninstaller() - ); - } - - /** - * @return Schema - */ - private function getSchema() { - if ( $this->schema === null ) { - $this->schema = new Schema( $this->config ); - } - - return $this->schema; - } - - private function newEntityInserter() { - return new EntityInserter( - $this->newClaimInserter() - ); - } - - private function newEntityUpdater() { - return new EntityUpdater( - $this->newEntityRemover(), - $this->newEntityInserter() - ); - } - - private function newEntityRemover() { - return new EntityRemover( - $this->newSnakRemover() - ); - } - - private function newSnakRemover() { - return new SnakRemover( $this->getSnakStores() ); - } - - private function newEntityTable() { - return new EntityTable( - $this->queryInterface, - $this->getSchema()->getEntitiesTable()->getName() - ); - } - - private function newClaimInserter() { - return new ClaimInserter( - $this->newSnakInserter(), - new ClaimRowBuilder() - ); - } - - private function newSnakInserter() { - return new SnakInserter( - $this->getSnakStores(), - new SnakRowBuilder() - ); - } - - /** - * @return SnakStore[] - */ - private function getSnakStores() { - return array( - new ValueSnakStore( - $this->queryInterface, - $this->getSchema()->getDataValueHandlers( SnakRole::MAIN_SNAK ), - SnakRole::MAIN_SNAK - ), - new ValueSnakStore( - $this->queryInterface, - $this->getSchema()->getDataValueHandlers( SnakRole::QUALIFIER ), - SnakRole::QUALIFIER - ), - new ValuelessSnakStore( - $this->queryInterface, - $this->getSchema()->getValuelessSnaksTable()->getName() - ) - ); - } - - private function newWriter() { - return new Writer( - $this->newEntityInserter(), - $this->newEntityUpdater(), - $this->newEntityRemover() - ); - } - - /** - * @return DescriptionMatchFinder - */ - private function newDescriptionMatchFinder() { - return new DescriptionMatchFinder( - $this->queryInterface, - $this->getSchema(), - $this->config->getPropertyDataValueTypeLookup(), - new BasicEntityIdParser() // TODO: inject - ); - } - - private function getInstaller() { - return new Installer( - $this->config, - $this->getSchema(), - $this->tableBuilder - ); - } - - private function getUninstaller() { - return new Uninstaller( - $this->config, - $this->getSchema(), - $this->tableBuilder - ); - } - - private function getUpdater() { - return new Updater( - $this->getSchema(), - $this->getTableSchemaUpdater(), - $this->tableDefinitionReader, - $this->tableBuilder - ); - } - - /** - * @return TableSchemaUpdater - */ - private function getTableSchemaUpdater() { - return new SimpleTableSchemaUpdater( - $this->schemaModifier - ); - } - -} diff --git a/tests/Integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php b/tests/Integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php index 7e372b6..f519ca2 100644 --- a/tests/Integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php +++ b/tests/Integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php @@ -16,7 +16,8 @@ use Wikibase\PropertyValueSnak; use Wikibase\QueryEngine\NullMessageReporter; use Wikibase\QueryEngine\SQLStore\DataValueTable; -use Wikibase\QueryEngine\SQLStore\Store; +use Wikibase\QueryEngine\SQLStore\SQLStore; +use Wikibase\QueryEngine\SQLStore\SQLStoreWithDependencies; use Wikibase\QueryEngine\Tests\Integration\SQLStore\IntegrationStoreBuilder; use Wikibase\Statement; @@ -33,7 +34,7 @@ class DescriptionMatchFinderIntegrationTest extends \PHPUnit_Framework_TestCase { /** - * @var Store + * @var SQLStoreWithDependencies */ protected $store; @@ -46,14 +47,14 @@ $this->store = $this->newStore(); - $this->store->newSetup( new NullMessageReporter() )->install(); + $this->store->newInstaller()->install(); $this->insertEntities(); } public function tearDown() { if ( isset( $this->store ) ) { - $this->store->newSetup( new NullMessageReporter() )->uninstall(); + $this->store->newUninstaller()->uninstall(); } } @@ -69,7 +70,7 @@ $claim->setGuid( 'claim0' ); $item->addClaim( $claim ); - $this->store->getWriter()->insertEntity( $item ); + $this->store->newWriter()->insertEntity( $item ); $item = Item::newEmpty(); @@ -79,7 +80,7 @@ $claim->setGuid( 'claim1' ); $item->addClaim( $claim ); - $this->store->getWriter()->insertEntity( $item ); + $this->store->newWriter()->insertEntity( $item ); $item = Item::newEmpty(); @@ -89,7 +90,7 @@ $claim->setGuid( 'claim2' ); $item->addClaim( $claim ); - $this->store->getWriter()->insertEntity( $item ); + $this->store->newWriter()->insertEntity( $item ); $item = Item::newEmpty(); @@ -103,14 +104,14 @@ $claim->setGuid( 'claim4' ); $item->addClaim( $claim ); - $this->store->getWriter()->insertEntity( $item ); + $this->store->newWriter()->insertEntity( $item ); } /** * @dataProvider somePropertyProvider */ public function testFindMatchingEntitiesWithSomeProperty( SomeProperty $description, array $expectedIds ) { - $matchFinder = $this->store->getQueryEngine(); + $matchFinder = $this->store->newQueryEngine(); $queryOptions = new QueryOptions( 100, diff --git a/tests/Integration/SQLStore/IntegrationStoreBuilder.php b/tests/Integration/SQLStore/IntegrationStoreBuilder.php index 435ab7b..406a5c2 100644 --- a/tests/Integration/SQLStore/IntegrationStoreBuilder.php +++ b/tests/Integration/SQLStore/IntegrationStoreBuilder.php @@ -12,7 +12,8 @@ use Wikibase\Database\Schema\Definitions\TableDefinition; use Wikibase\QueryEngine\SQLStore\DataValueTable; use Wikibase\QueryEngine\SQLStore\DVHandler\NumberHandler; -use Wikibase\QueryEngine\SQLStore\Store; +use Wikibase\QueryEngine\SQLStore\SQLStore; +use Wikibase\QueryEngine\SQLStore\SQLStoreWithDependencies; use Wikibase\QueryEngine\SQLStore\StoreConfig; /** @@ -22,6 +23,11 @@ */ class IntegrationStoreBuilder { + /** + * @param PHPUnit_Framework_TestCase $testCase + * + * @return SQLStoreWithDependencies + */ public static function newStore( PHPUnit_Framework_TestCase $testCase ) { $dbConnectionProvider = new LazyDBConnectionProvider( DB_MASTER ); @@ -65,7 +71,13 @@ $config->setPropertyDataValueTypeLookup( $propertyDvTypeLookup ); - return new Store( $config, $queryInterface, $tableBuilder, $definitionReader, $schemaModifier ); + return new SQLStoreWithDependencies( + new SQLStore( $config ), + $queryInterface, + $tableBuilder, + $definitionReader, + $schemaModifier + ); } } \ No newline at end of file diff --git a/tests/Integration/SQLStore/WritingIntegrationTest.php b/tests/Integration/SQLStore/WritingIntegrationTest.php index 3ba4f77..9cf4c7d 100644 --- a/tests/Integration/SQLStore/WritingIntegrationTest.php +++ b/tests/Integration/SQLStore/WritingIntegrationTest.php @@ -18,7 +18,8 @@ use Wikibase\PropertyValueSnak; use Wikibase\QueryEngine\NullMessageReporter; use Wikibase\QueryEngine\SQLStore\DataValueTable; -use Wikibase\QueryEngine\SQLStore\Store; +use Wikibase\QueryEngine\SQLStore\SQLStore; +use Wikibase\QueryEngine\SQLStore\SQLStoreWithDependencies; use Wikibase\Statement; /** @@ -37,7 +38,7 @@ class WritingIntegrationTest extends \PHPUnit_Framework_TestCase { /** - * @var Store + * @var SQLStoreWithDependencies */ protected $store; @@ -50,12 +51,12 @@ $this->store = $this->newStore(); - $this->store->newSetup( new NullMessageReporter() )->install(); + $this->store->newInstaller()->install(); } public function tearDown() { if ( isset( $this->store ) ) { - $this->store->newSetup( new NullMessageReporter() )->uninstall(); + $this->store->newUninstaller( new NullMessageReporter() )->uninstall(); } } @@ -71,7 +72,7 @@ $claim->setGuid( 'a claim' ); $item->addClaim( $claim ); - $this->store->getWriter()->insertEntity( $item ); + $this->store->newWriter()->insertEntity( $item ); $propertyDescription = new SomeProperty( new EntityIdValue( new PropertyId( 'P42' ) ), @@ -83,7 +84,7 @@ $this->findMatchingEntities( $propertyDescription ) ); - $this->store->getWriter()->deleteEntity( $item ); + $this->store->newWriter()->deleteEntity( $item ); $this->assertEquals( array(), @@ -96,7 +97,7 @@ * @return EntityId[] */ protected function findMatchingEntities( Description $description ) { - $matchFinder = $this->store->getQueryEngine(); + $matchFinder = $this->store->newQueryEngine(); $queryOptions = new QueryOptions( 100, @@ -114,7 +115,7 @@ $claim->setGuid( 'foo claim' ); $item->addClaim( $claim ); - $this->store->getWriter()->insertEntity( $item ); + $this->store->newWriter()->insertEntity( $item ); $claim = new Statement( new PropertyValueSnak( 42, new NumberValue( 9000 ) ) ); $claim->setGuid( 'bar claim' ); @@ -123,7 +124,7 @@ $claim ) ) ); - $this->store->getWriter()->updateEntity( $item ); + $this->store->newWriter()->updateEntity( $item ); $propertyDescription = new SomeProperty( new EntityIdValue( new PropertyId( 'P42' ) ), diff --git a/tests/Phpunit/SQLStore/StoreTest.php b/tests/Phpunit/SQLStore/SQLStoreTest.php similarity index 70% rename from tests/Phpunit/SQLStore/StoreTest.php rename to tests/Phpunit/SQLStore/SQLStoreTest.php index ffacae4..c94fa59 100644 --- a/tests/Phpunit/SQLStore/StoreTest.php +++ b/tests/Phpunit/SQLStore/SQLStoreTest.php @@ -2,13 +2,11 @@ namespace Wikibase\QueryEngine\Tests\Phpunit\SQLStore; -use Wikibase\QueryEngine\SQLStore\Store; +use Wikibase\QueryEngine\SQLStore\SQLStore; use Wikibase\QueryEngine\SQLStore\StoreConfig; /** - * @covers Wikibase\QueryEngine\SQLStore\Store - * - * @ingroup WikibaseQueryEngineTest + * @covers Wikibase\QueryEngine\SQLStore\SQLStore * * @group Wikibase * @group WikibaseQueryEngine @@ -16,7 +14,7 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < [email protected] > */ -class StoreTest extends \PHPUnit_Framework_TestCase { +class SQLStoreTest extends \PHPUnit_Framework_TestCase { protected function newInstance() { $storeConfig = new StoreConfig( 'foo', 'bar', array() ); @@ -34,27 +32,24 @@ $definitionReader = $this->getMock( 'Wikibase\Database\Schema\TableDefinitionReader' ); $schemaModifier = $this->getMock( 'Wikibase\Database\Schema\SchemaModifier' ); - return new Store( $storeConfig, $queryInterface, $tableBuilder, $definitionReader, $schemaModifier ); - } - - public function testGetNameReturnType() { - $this->assertInternalType( - 'string', - $this->newInstance()->getName() - ); + return new SQLStore( $storeConfig, $queryInterface, $tableBuilder, $definitionReader, $schemaModifier ); } public function testGetUpdaterReturnType() { $this->assertInstanceOf( 'Wikibase\QueryEngine\QueryStoreWriter', - $this->newInstance()->getWriter() + $this->newInstance()->newWriter( $this->newMockQueryInterface() ) ); + } + + protected function newMockQueryInterface() { + return $this->getMock( 'Wikibase\Database\QueryInterface\QueryInterface' ); } public function testGetQueryEngineReturnType() { $this->assertInstanceOf( 'Wikibase\QueryEngine\QueryEngine', - $this->newInstance()->getQueryEngine() + $this->newInstance()->newQueryEngine( $this->newMockQueryInterface() ) ); } diff --git a/tests/Phpunit/SQLStore/Setup/SetupTest.php b/tests/Phpunit/SQLStore/Setup/SetupTest.php deleted file mode 100644 index 16ff145..0000000 --- a/tests/Phpunit/SQLStore/Setup/SetupTest.php +++ /dev/null @@ -1,77 +0,0 @@ -<?php - -namespace Wikibase\QueryEngine\Tests\Phpunit\SQLStore\Setup; - -use PHPUnit_Framework_MockObject_MockObject; -use Wikibase\QueryEngine\SQLStore\Setup\Setup; - -/** - * @covers Wikibase\QueryEngine\SQLStore\Setup\Setup - * - * @ingroup WikibaseQueryEngineTest - * - * @group Wikibase - * @group WikibaseQueryEngine - * - * @licence GNU GPL v2+ - * @author Jeroen De Dauw < [email protected] > - */ -class SetupTest extends \PHPUnit_Framework_TestCase { - - /** - * @var PHPUnit_Framework_MockObject_MockObject - */ - protected $installer; - - /** - * @var PHPUnit_Framework_MockObject_MockObject - */ - protected $updater; - - /** - * @var PHPUnit_Framework_MockObject_MockObject - */ - protected $uninstaller; - - public function setUp() { - parent::setUp(); - - $this->installer = $this->getMockBuilder( 'Wikibase\QueryEngine\SQLStore\Setup\Installer' ) - ->disableOriginalConstructor()->getMock(); - - $this->uninstaller = $this->getMockBuilder( 'Wikibase\QueryEngine\SQLStore\Setup\Uninstaller' ) - ->disableOriginalConstructor()->getMock(); - - $this->updater = $this->getMockBuilder( 'Wikibase\QueryEngine\SQLStore\Setup\Updater' ) - ->disableOriginalConstructor()->getMock(); - } - - protected function newSetupFromDependencies() { - return new Setup( - $this->installer, - $this->updater, - $this->uninstaller - ); - } - - public function testInstall() { - $this->installer->expects( $this->once() ) - ->method( 'install' ); - - $this->newSetupFromDependencies()->install(); - } - - public function testUpdate() { - $this->updater->expects( $this->once() ) - ->method( 'update' ); - - $this->newSetupFromDependencies()->update(); - } - public function testUninstall() { - $this->uninstaller->expects( $this->once() ) - ->method( 'uninstall' ); - - $this->newSetupFromDependencies()->uninstall(); - } - -} -- To view, visit https://gerrit.wikimedia.org/r/91870 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia403b652f350733ff646f94688279de1eb67166a Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseQueryEngine Gerrit-Branch: master Gerrit-Owner: Jeroen De Dauw <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
