-
Notifications
You must be signed in to change notification settings - Fork 1
/
rdfdb.query_arc2.inc
114 lines (100 loc) · 3.52 KB
/
rdfdb.query_arc2.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
* @file
* Query code for ARC2 engine.
*/
class RdfdbInsertDataQuery_arc2 extends RdfdbInsertDataQuery {
/**
* Executes the insert data query.
*
* @return
* The number of inserted triples, or FALSE is there were errors.
*/
public function execute() {
// If validation fails, simply return NULL.
// Note that validation routines in preExecute() may throw exceptions instead.
if (!$this->preExecute()) {
return NULL;
}
$query = $this->toString();
$this->connection->query($query, $this->queryOptions);
}
public function toString() {
// Serializes prefixes in prologue if they are given. Otherwise ARC2 will
// use the prefixes which were defined during the remote endpoint setup.
$prologue = $this->preparePrefixes();
if (!empty($this->graph)) {
return $prologue . 'INSERT INTO <' . $this->graph . '> { ' . $this->triples . ' }';
}
else {
// ARC2 requires a graph for insertion no matter what.
return $prologue . 'INSERT INTO <http://example.org/default_graph> { ' . $this->triples . ' }';
}
}
}
class RdfdbDeleteDataQuery_arc2 extends RdfdbDeleteDataQuery {
/**
* Executes the delete data query.
*
* @return
* The number of deleted triples, or FALSE is there were errors.
*/
public function execute() {
// If validation fails, simply return NULL.
// Note that validation routines in preExecute() may throw exceptions instead.
if (!$this->preExecute()) {
return NULL;
}
$query = $this->toString();
//var_dump($query);
$this->connection->query($query, $this->queryOptions);
}
public function toString() {
// Serializes prefixes in prologue if they are given. Otherwise ARC2 will
// use the prefixes which were defined during the remote endpoint setup.
$prologue = $this->preparePrefixes();
if (!empty($this->graph)) {
return $prologue . 'DELETE FROM <' . $this->graph . '> { ' . $this->triples . ' }';
}
else {
return $prologue . 'DELETE { ' . $this->triples . ' }';
}
}
}
class RdfdbClearQuery_arc2 extends RdfdbClearQuery {
// This method only exist because of the zombie triples bug in ARC2
// @todo remove once this bug has been fixed.
public function execute() {
// If validation fails, simply return NULL.
// Note that validation routines in preExecute() may throw exceptions instead.
if (!$this->preExecute()) {
return NULL;
}
// The zombie bug in ARC2 causes the triples to reappear after attempting
// to delete them. Deletes the graphs one by one as a work around.
if (empty($this->graph)) {
$rs = rdfdb_select('DISTINCT ?g')->where('GRAPH ?g { ?s ?p ?o . } ')->execute();
foreach ($rs['result']['rows'] as $row) {
rdfdb_clear($row['g'])->execute();
}
return;
}
$query = $this->toString();
//var_dump($query);
return $this->connection->query($query, $this->queryOptions);
}
public function toString() {
// Serializes prefixes in prologue if they are given. Otherwise ARC2 will
// use the prefixes which were defined during the remote endpoint setup.
$prologue = $this->preparePrefixes();
if (!empty($this->graph)) {
return $prologue . ' DELETE FROM <' . $this->graph . '> { ?s ?p ?o . } WHERE { ?s ?p ?o . }';
}
else {
// This is not reliable and will be overridden until the zombie bug
// has been fixed in ARC2.
// @see $this->execute()
return $prologue . ' DELETE { ?s ?p ?o . } WHERE { ?s ?p ?o . }';
}
}
}