1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\QueryEngine\SQLStore; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Connection; |
6
|
|
|
use Doctrine\DBAL\Schema\AbstractSchemaManager; |
7
|
|
|
use Psr\Log\LoggerInterface; |
8
|
|
|
use Psr\Log\NullLogger; |
9
|
|
|
use Wikibase\DataModel\Entity\EntityIdParser; |
10
|
|
|
use Wikibase\DataModel\Snak\SnakRole; |
11
|
|
|
use Wikibase\QueryEngine\PropertyDataValueTypeLookup; |
12
|
|
|
use Wikibase\QueryEngine\QueryEngine; |
13
|
|
|
use Wikibase\QueryEngine\QueryStoreWriter; |
14
|
|
|
use Wikibase\QueryEngine\SQLStore\Engine\DescriptionMatchFinder; |
15
|
|
|
use Wikibase\QueryEngine\SQLStore\Engine\Engine; |
16
|
|
|
use Wikibase\QueryEngine\SQLStore\EntityStore\BasicEntityInserter; |
17
|
|
|
use Wikibase\QueryEngine\SQLStore\EntityStore\BasicEntityRemover; |
18
|
|
|
use Wikibase\QueryEngine\SQLStore\EntityStore\EntityInserter; |
19
|
|
|
use Wikibase\QueryEngine\SQLStore\EntityStore\EntityRemover; |
20
|
|
|
use Wikibase\QueryEngine\SQLStore\Setup\Installer; |
21
|
|
|
use Wikibase\QueryEngine\SQLStore\Setup\Uninstaller; |
22
|
|
|
use Wikibase\QueryEngine\SQLStore\Setup\Updater; |
23
|
|
|
use Wikibase\QueryEngine\SQLStore\SnakStore\SnakInserter; |
24
|
|
|
use Wikibase\QueryEngine\SQLStore\SnakStore\SnakRemover; |
25
|
|
|
use Wikibase\QueryEngine\SQLStore\SnakStore\SnakRowBuilder; |
26
|
|
|
use Wikibase\QueryEngine\SQLStore\SnakStore\SnakStore; |
27
|
|
|
use Wikibase\QueryEngine\SQLStore\SnakStore\ValuelessSnakStore; |
28
|
|
|
use Wikibase\QueryEngine\SQLStore\SnakStore\ValueSnakStore; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Simple query store for relational SQL databases. |
32
|
|
|
* |
33
|
|
|
* This class is the top level factory able to construct |
34
|
|
|
* the high level services that form the public interface |
35
|
|
|
* of the store. |
36
|
|
|
* |
37
|
|
|
* @since 0.1 |
38
|
|
|
* |
39
|
|
|
* @licence GNU GPL v2+ |
40
|
|
|
* @author Jeroen De Dauw < [email protected] > |
41
|
|
|
*/ |
42
|
|
|
class SQLStore { |
43
|
|
|
|
44
|
|
|
private $config; |
45
|
|
|
private $schema; |
46
|
|
|
private $logger; |
47
|
|
|
|
48
|
|
|
public function __construct( StoreSchema $schema, StoreConfig $config, LoggerInterface $logger = null ) { |
49
|
|
|
$this->schema = $schema; |
50
|
|
|
$this->config = $config; |
51
|
|
|
$this->logger = $logger === null ? new NullLogger() : $logger; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param Connection $connection |
56
|
|
|
* @param PropertyDataValueTypeLookup $lookup |
57
|
|
|
* @param EntityIdParser $idParser |
58
|
|
|
* |
59
|
|
|
* @return QueryEngine |
60
|
|
|
*/ |
61
|
|
|
public function newQueryEngine( |
62
|
|
|
Connection $connection, |
63
|
|
|
PropertyDataValueTypeLookup $lookup, |
64
|
|
|
EntityIdParser $idParser |
65
|
|
|
) { |
66
|
|
|
return new Engine( |
67
|
|
|
$this->newDescriptionMatchFinder( $connection, $lookup, $idParser ) |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param Connection $connection |
73
|
|
|
* |
74
|
|
|
* @return QueryStoreWriter |
75
|
|
|
*/ |
76
|
|
|
public function newWriter( Connection $connection ) { |
77
|
|
|
return new Writer( |
78
|
|
|
$connection, |
79
|
|
|
new EntityInserter( $connection, $this->newEntityInserters( $connection ) ), |
80
|
|
|
new EntityRemover( $connection, $this->newEntityRemovers( $connection ) ) |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function newInstaller( AbstractSchemaManager $schemaManager ) { |
85
|
|
|
return new Installer( |
86
|
|
|
$this->logger, |
87
|
|
|
$this->schema, |
88
|
|
|
$schemaManager |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function newUninstaller( AbstractSchemaManager $schemaManager ) { |
93
|
|
|
return new Uninstaller( |
94
|
|
|
$this->logger, |
95
|
|
|
$this->schema, |
96
|
|
|
$schemaManager |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function newUpdater( AbstractSchemaManager $schemaManager ) { |
101
|
|
|
return new Updater( |
102
|
|
|
$this->logger, |
103
|
|
|
$this->schema, |
104
|
|
|
$schemaManager |
105
|
|
|
); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
private function newEntityInserters( Connection $connection ) { |
109
|
|
|
return array( |
110
|
|
|
new BasicEntityInserter( $this->newSnakInserter( $connection ) ), |
111
|
|
|
); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
private function newEntityRemovers( Connection $connection ) { |
115
|
|
|
return array( |
116
|
|
|
new BasicEntityRemover( $this->newSnakRemover( $connection ) ) |
117
|
|
|
); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
private function newSnakRemover( Connection $connection ) { |
121
|
|
|
return new SnakRemover( $this->getSnakStores( $connection ) ); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
private function newSnakInserter( Connection $connection ) { |
125
|
|
|
return new SnakInserter( |
126
|
|
|
$this->getSnakStores( $connection ), |
127
|
|
|
new SnakRowBuilder() |
128
|
|
|
); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param Connection $connection |
133
|
|
|
* |
134
|
|
|
* @return SnakStore[] |
135
|
|
|
*/ |
136
|
|
|
private function getSnakStores( Connection $connection ) { |
137
|
|
|
return array( |
138
|
|
|
new ValueSnakStore( |
139
|
|
|
$connection, |
140
|
|
|
$this->schema->getDataValueHandlers()->getMainSnakHandlers(), |
141
|
|
|
SnakRole::MAIN_SNAK |
142
|
|
|
), |
143
|
|
|
new ValueSnakStore( |
144
|
|
|
$connection, |
145
|
|
|
$this->schema->getDataValueHandlers()->getQualifierHandlers(), |
146
|
|
|
SnakRole::QUALIFIER |
147
|
|
|
), |
148
|
|
|
new ValuelessSnakStore( |
149
|
|
|
$connection, |
150
|
|
|
$this->schema->getValuelessSnaksTable()->getName() |
151
|
|
|
) |
152
|
|
|
); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
private function newDescriptionMatchFinder( Connection $connection, |
156
|
|
|
PropertyDataValueTypeLookup $lookup, EntityIdParser $idParser ) { |
157
|
|
|
|
158
|
|
|
return new DescriptionMatchFinder( |
159
|
|
|
$connection, |
160
|
|
|
$this->schema, |
161
|
|
|
$lookup, |
162
|
|
|
$idParser |
163
|
|
|
); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
} |
167
|
|
|
|