|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Wikibase\QueryEngine\SQLStore; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Connection; |
|
6
|
|
|
use Wikibase\DataModel\Entity\EntityDocument; |
|
7
|
|
|
use Wikibase\QueryEngine\QueryEngineException; |
|
8
|
|
|
use Wikibase\QueryEngine\QueryStoreWriter; |
|
9
|
|
|
use Wikibase\QueryEngine\SQLStore\EntityStore\EntityInserter; |
|
10
|
|
|
use Wikibase\QueryEngine\SQLStore\EntityStore\EntityRemover; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class responsible for writing information to the SQLStore. |
|
14
|
|
|
* |
|
15
|
|
|
* @since 0.1 |
|
16
|
|
|
* |
|
17
|
|
|
* @licence GNU GPL v2+ |
|
18
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
19
|
|
|
*/ |
|
20
|
|
|
class Writer implements QueryStoreWriter { |
|
21
|
|
|
|
|
22
|
|
|
private $connection; |
|
23
|
|
|
private $entityInserter; |
|
24
|
|
|
private $entityRemover; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param Connection $connection |
|
28
|
|
|
* @param EntityInserter $inserter |
|
29
|
|
|
* @param EntityRemover $remover |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct( Connection $connection, EntityInserter $inserter, EntityRemover $remover ) { |
|
32
|
|
|
$this->connection = $connection; |
|
33
|
|
|
$this->entityInserter = $inserter; |
|
34
|
|
|
$this->entityRemover = $remover; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @see QueryStoreUpdater::insertEntity |
|
39
|
|
|
* |
|
40
|
|
|
* @param EntityDocument $entity |
|
41
|
|
|
*/ |
|
42
|
|
|
public function insertEntity( EntityDocument $entity ) { |
|
43
|
|
|
$this->entityInserter->insertEntity( $entity ); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @see QueryStoreUpdater::updateEntity |
|
48
|
|
|
* |
|
49
|
|
|
* @param EntityDocument $entity |
|
50
|
|
|
* |
|
51
|
|
|
* @throws QueryEngineException |
|
52
|
|
|
*/ |
|
53
|
|
|
public function updateEntity( EntityDocument $entity ) { |
|
54
|
|
|
$this->connection->beginTransaction(); |
|
55
|
|
|
|
|
56
|
|
|
try { |
|
57
|
|
|
$this->entityRemover->removeEntity( $entity ); |
|
58
|
|
|
$this->entityInserter->insertEntity( $entity ); |
|
59
|
|
|
} |
|
60
|
|
|
catch ( QueryEngineException $ex ) { |
|
61
|
|
|
$this->connection->rollBack(); |
|
62
|
|
|
throw $ex; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$this->connection->commit(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @see QueryStoreUpdater::deleteEntity |
|
70
|
|
|
* |
|
71
|
|
|
* @param EntityDocument $entity |
|
72
|
|
|
*/ |
|
73
|
|
|
public function deleteEntity( EntityDocument $entity ) { |
|
74
|
|
|
$this->entityRemover->removeEntity( $entity ); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|