/
Query.php
85 lines (72 loc) · 1.96 KB
/
Query.php
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
<?php
/**
*
* A Query object.
* @author
* @version 1.0
*
*/
class Query {
private $pm;
private $statement;
private $workspace;
/**
*
* Creates a new Query object, given an active PersistenceManager and valid query statement.
* @param generic $pm the active PersistenceManager.
* @param string $statement the query statement.
*
*/
public function __construct(&$pm, $statement) {
$this->pm =& $pm;
$this->statement = $statement;
$this->workspace = $pm->getWorkspace();
}
/**
*
* Executes this query and returns a QueryResult.
* @return QueryResult a query result.
*
*/
public function execute() {
$statement = '';
foreach ($this->statement as $value)
{
$statement .= '{' . implode ( ',', $value ) . '}';
}
Log4PCR::info ( 'Executed query: ' . $this->workspace . '=>' . $statement );
return new QueryResult($this->pm, $this->pm->query($this->statement));
}
/**
*
* Returns the statement set for this query.
* This could be anything (string, object, airplane) - so beware.
* @return generic the query statement.
*
*/
public function getStatement() {
return $this->statement;
}
/**
*
* Creates a node representing this Query in content.
* An ItemExistsException will be thrown immediately if an item at the specified path already exists.
* A PathNotFoundException will be thrown immediately if the specified path implies intermediary nodes that do not exist.
* @param string $path the absolute path of the node to be created.
* @return Node the newly created node.
*
*/
public function storeAsNode($path) {
$statement = '';
foreach ($this->statement as $value)
{
$statement .= '{' . implode ( ',', $value ) . '}';
}
$node = new Node($this->pm, 'pcr:root');
$node = $node->addNode(substr($path, strlen('pcr:root/')));
$node->setProperty('pcr:statement', $statement);
Log4PCR::info("Stored query as node: $this->workspace=>" . $node->getPath());
return $node;
}
}
?>