Completed
Push — master ( 89e759...3a13dd )
by mw
99:35 queued 64:30
created

SPARQLStoreFactory::newTurtleTriplesBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 10
ccs 2
cts 2
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SMW\SPARQLStore;
4
5
use SMW\ApplicationFactory;
6
use SMW\Utils\CircularReferenceGuard;
7
use SMW\ConnectionManager;
8
use SMW\SPARQLStore\QueryEngine\CompoundConditionBuilder;
9
use SMW\SPARQLStore\QueryEngine\DescriptionInterpreterFactory;
10
use SMW\SPARQLStore\QueryEngine\EngineOptions;
11
use SMW\SPARQLStore\QueryEngine\QueryEngine;
12
use SMW\SPARQLStore\QueryEngine\QueryResultFactory;
13
use SMW\Store;
14
use SMW\StoreFactory;
15
16
/**
17
 * @license GNU GPL v2+
18
 * @since 2.2
19
 *
20
 * @author mwjames
21
 */
22
class SPARQLStoreFactory {
23
24
	/**
25
	 * @var SPARQLStore
26
	 */
27
	private $store;
28
29
	/**
30
	 * @since 2.2
31
	 *
32
	 * @param SPARQLStore $store
33
	 */
34
	public function __construct( SPARQLStore $store ) {
35
		$this->store = $store;
36
	}
37
38
	/**
39 10
	 * @since 2.2
40 10
	 *
41 10
	 * @param string $storeClass
42 10
	 *
43
	 * @return Store
44
	 */
45
	public function getBaseStore( $storeClass ) {
46
		return StoreFactory::getStore( $storeClass );
47
	}
48
49
	/**
50
	 * @since 2.2
51 6
	 *
52 6
	 * @return QueryEngine
53
	 */
54
	public function newMasterQueryEngine() {
55
56
		$engineOptions = new EngineOptions();
57
58
		$circularReferenceGuard = new CircularReferenceGuard( 'sparql-queryengine' );
59
		$circularReferenceGuard->setMaxRecursionDepth( 2 );
60 6
61
		$compoundConditionBuilder = new CompoundConditionBuilder(
62 6
			new DescriptionInterpreterFactory(),
63
			$engineOptions
64 6
		);
65 6
66
		$compoundConditionBuilder->setCircularReferenceGuard(
67 6
			$circularReferenceGuard
68 6
		);
69
70
		$compoundConditionBuilder->setPropertyHierarchyLookup(
71
			ApplicationFactory::getInstance()->newPropertyHierarchyLookup()
72 6
		);
73
74
		$queryEngine = new QueryEngine(
75
			$this->store->getConnection( 'sparql' ),
76 6
			$compoundConditionBuilder,
77 6
			new QueryResultFactory( $this->store ),
78
			$engineOptions
79
		);
80 6
81 6
		return $queryEngine;
82
	}
83 6
84
	/**
85
	 * @since 2.5
86
	 *
87 6
	 * @return RepositoryRedirectLookup
88
	 */
89
	public function newRepositoryRedirectLookup() {
90
		return new RepositoryRedirectLookup( $this->store->getConnection( 'sparql' ) );
91
	}
92
93
	/**
94
	 * @since 2.5
95 1
	 *
96 1
	 * @return TurtleTriplesBuilder
97
	 */
98
	public function newTurtleTriplesBuilder() {
99
100
		$turtleTriplesBuilder = new TurtleTriplesBuilder(
101
			$this->newRepositoryRedirectLookup()
102
		);
103
104 6
		$turtleTriplesBuilder->setTriplesChunkSize( 80 );
105
106 6
		return $turtleTriplesBuilder;
107
	}
108 6
109 6
	/**
110 6
	 * @since 2.5
111
	 *
112
	 * @return ReplicationDataTruncator
113 6
	 */
114 6
	public function newReplicationDataTruncator() {
115
116
		$replicationDataTruncator = new ReplicationDataTruncator();
117
118 6
		$replicationDataTruncator->setPropertyExemptionList(
119
			ApplicationFactory::getInstance()->getSettings()->get( 'smwgSparqlReplicationPropertyExemptionList' )
120
		);
121
122
		return $replicationDataTruncator;
123
	}
124
125
	/**
126
	 * @since 2.2
127
	 *
128
	 * @return ConnectionManager
129
	 */
130
	public function newConnectionManager() {
131
132
		$connectionManager = new ConnectionManager();
133
134
		$repositoryConnectionProvider = new RepositoryConnectionProvider();
135
		$repositoryConnectionProvider->setHttpVersionTo(
136
			ApplicationFactory::getInstance()->getSettings()->get( 'smwgSparqlRepositoryConnectorForcedHttpVersion' )
137
		);
138
139
		$connectionManager->registerConnectionProvider(
140
			'sparql',
141
			$repositoryConnectionProvider
142
		);
143
144
		return $connectionManager;
145
	}
146
147
}
148