1 | <?php |
||
21 | class MongoDBEntityStore extends EntityStore { |
||
22 | |||
23 | /** |
||
24 | * Option to set the time limit for query operations in milliseconds. |
||
25 | */ |
||
26 | const OPTION_QUERY_TIME_LIMIT = 'mongodb-query-time-limit'; |
||
27 | |||
28 | /** |
||
29 | * @var Database |
||
30 | */ |
||
31 | private $database; |
||
32 | |||
33 | /** |
||
34 | * @var DispatchingEntityLookup |
||
35 | */ |
||
36 | private $entityLookup; |
||
37 | |||
38 | /** |
||
39 | * @var DispatchingEntityIdForTermLookup |
||
40 | */ |
||
41 | private $entityForTermLookup; |
||
42 | |||
43 | /** |
||
44 | * @var DispatchingEntityIdForQueryLookup |
||
45 | */ |
||
46 | private $entityForQueryLookup; |
||
47 | |||
48 | /** |
||
49 | * @var EntityDocumentSaver |
||
50 | */ |
||
51 | private $entitySaver; |
||
52 | |||
53 | /** |
||
54 | * @param Database $database |
||
55 | * @param EntityStoreOptions $options |
||
56 | */ |
||
57 | 10 | public function __construct( Database $database, EntityStoreOptions $options = null ) { |
|
58 | 10 | $this->database = $database; |
|
59 | |||
60 | 10 | parent::__construct( $options ); |
|
61 | 10 | $this->defaultOption( self::OPTION_QUERY_TIME_LIMIT, null ); |
|
62 | |||
63 | 10 | $entityDatabase = $this->newEntityDatabase( $database ); |
|
64 | 10 | $this->entityLookup = new DispatchingEntityLookup( $entityDatabase ); |
|
65 | 10 | $this->entityForTermLookup = new DispatchingEntityIdForTermLookup( $this->newEntityIdForTermLookup( $database ) ); |
|
66 | 10 | $this->entityForQueryLookup = new DispatchingEntityIdForQueryLookup( $this->newEntityIdForQueryLookup( $database ) ); |
|
67 | 10 | $this->entitySaver = $entityDatabase; |
|
68 | 10 | } |
|
69 | |||
70 | 10 | private function newEntityDatabase( Database $database ) { |
|
73 | |||
74 | 10 | private function newEntityIdForTermLookup( Database $database ) { |
|
77 | |||
78 | 10 | private function newEntityIdForQueryLookup( Database $database ) { |
|
79 | 10 | return new MongoDBEntityIdForQueryLookup( |
|
80 | 10 | $database, |
|
81 | 10 | $this->newDocumentBuilder(), |
|
82 | 10 | $this->getOption( self::OPTION_QUERY_TIME_LIMIT ) |
|
83 | 10 | ); |
|
84 | } |
||
85 | |||
86 | 10 | private function newDocumentBuilder() { |
|
87 | 10 | $serialization = new EntitySerializationFactory(); |
|
88 | 10 | return new MongoDBDocumentBuilder( |
|
89 | 10 | $serialization->newEntitySerializer(), |
|
90 | 10 | $serialization->newEntityDeserializer(), |
|
91 | 10 | new BasicEntityIdParser(), |
|
92 | 10 | $this->getOptions() |
|
93 | 10 | ); |
|
94 | } |
||
95 | |||
96 | /** |
||
97 | * @see EntityStore::getEntityLookup |
||
98 | */ |
||
99 | 1 | public function getEntityLookup() { |
|
102 | |||
103 | /** |
||
104 | * @see EntityStore::getEntityDocumentLookup |
||
105 | */ |
||
106 | 2 | public function getEntityDocumentLookup() { |
|
109 | |||
110 | /** |
||
111 | * @see EntityStore::getItemLookup |
||
112 | */ |
||
113 | 2 | public function getItemLookup() { |
|
116 | |||
117 | /** |
||
118 | * @see EntityStore::getPropertyLookup |
||
119 | */ |
||
120 | 2 | public function getPropertyLookup() { |
|
123 | |||
124 | /** |
||
125 | * @see EntityStore::getEntityDocumentSaver |
||
126 | */ |
||
127 | 2 | public function getEntityDocumentSaver() { |
|
130 | |||
131 | /** |
||
132 | * @see EntityStore::getItemIdForTermLookup |
||
133 | */ |
||
134 | 2 | public function getItemIdForTermLookup() { |
|
137 | |||
138 | /** |
||
139 | * @see EntityStore::getPropertyIdForTermLookup |
||
140 | */ |
||
141 | 2 | public function getPropertyIdForTermLookup() { |
|
144 | |||
145 | /** |
||
146 | * @see EntityStore::getItemIdForQueryLookup |
||
147 | */ |
||
148 | 2 | public function getItemIdForQueryLookup() { |
|
151 | |||
152 | /** |
||
153 | * @see EntityStore::getPropertyIdForQueryLookup |
||
154 | */ |
||
155 | 2 | public function getPropertyIdForQueryLookup() { |
|
158 | |||
159 | /** |
||
160 | * @see EntityStore::setupStore |
||
161 | */ |
||
162 | 1 | public function setupStore() { |
|
163 | 1 | foreach( MongoDBDocumentBuilder::$SUPPORTED_ENTITY_TYPES as $type ) { |
|
164 | 1 | $this->database->command( [ |
|
165 | 1 | 'collMod' => $type, |
|
166 | 'usePowerOf2Sizes' => true |
||
167 | 1 | ] ); |
|
168 | 1 | } |
|
169 | 1 | } |
|
170 | |||
171 | /** |
||
172 | * @see EntityStore::setupIndexes |
||
173 | */ |
||
174 | 1 | public function setupIndexes() { |
|
178 | |||
179 | 1 | private function setupTermIndexes() { |
|
180 | 1 | $languagesOption = $this->getOption( EntityStore::OPTION_LANGUAGES ); |
|
181 | |||
182 | 1 | if( $languagesOption === null ) { |
|
197 | |||
198 | 1 | private function setupClaimsIndexes() { |
|
211 | } |
||
212 |