3 * ARC2 RDF Store Query Handler
5 * @author Benjamin Nowack
6 * @license <http://arc.semsol.org/license>
7 * @homepage <http://arc.semsol.org/>
14 class ARC2_StoreQueryHandler extends ARC2_Class {
16 function __construct($a = '', &$caller) {
17 parent::__construct($a, $caller);
20 function ARC2_StoreQueryHandler($a = '', &$caller) {
21 $this->__construct($a, $caller);
24 function __init() {/* db_con */
26 $this->xsd = 'http://www.w3.org/2001/XMLSchema#';
27 $this->allow_extension_functions = $this->v('store_allow_extension_functions', 1, $this->a);
28 $this->keep_time_limit = $this->v('keep_time_limit', 0, $this->a);
29 $this->handler_type = '';
34 function getTermID($val, $term = '') {
35 return $this->store->getTermID($val, $term);
38 function hasHashColumn($tbl) {
39 return $this->store->hasHashColumn($tbl);
42 function getValueHash($val) {
43 return $this->store->getValueHash($val);
48 function getTripleTable() {
49 $r = $this->store->getTablePrefix() . 'triple';
55 function createMergeTable() {
56 $split_ps = $this->store->getSetting('split_predicates', array());
57 if (!$split_ps) return 1;
58 $this->mrg_table_id = 'MRG_' . $this->store->getTablePrefix() . crc32(uniqid(rand()));
59 $con = $this->store->getDBCon();
60 $this->queryDB("FLUSH TABLES", $con);
61 $indexes = $this->v('store_indexes', array('sp (s,p)', 'os (o,s)', 'po (p,o)'), $this->a);
62 $index_code = $indexes ? 'KEY ' . join(', KEY ', $indexes) . ', ' : '';
63 $prefix = $this->store->getTablePrefix();
65 CREATE TEMPORARY TABLE IF NOT EXISTS " . $prefix . "triple_all (
66 t mediumint UNSIGNED NOT NULL,
67 s mediumint UNSIGNED NOT NULL,
68 p mediumint UNSIGNED NOT NULL,
69 o mediumint UNSIGNED NOT NULL,
70 o_lang_dt mediumint UNSIGNED NOT NULL,
71 o_comp char(35) NOT NULL, /* normalized value for ORDER BY operations */
72 s_type tinyint(1) NOT NULL default 0, /* uri/bnode => 0/1 */
73 o_type tinyint(1) NOT NULL default 0, /* uri/bnode/literal => 0/1/2 */
74 misc tinyint(1) NOT NULL default 0, /* temporary flags */
75 UNIQUE KEY (t), " . $index_code . " KEY (misc)
78 $v = $this->store->getDBVersion();
79 $sql .= (($v < '04-01-00') && ($v >= '04-00-18')) ? 'ENGINE' : (($v >= '04-01-02') ? 'ENGINE' : 'TYPE');
80 $sql .= "=MERGE UNION=(" . $prefix . "triple" ;
81 foreach ($split_ps as $pos => $p) {
82 $sql .= ',' . $prefix . 'triple_' . abs(crc32($p));
85 //$sql .= ($v >= '04-00-00') ? " CHARACTER SET utf8" : "";
86 //$sql .= ($v >= '04-01-00') ? " COLLATE utf8_unicode_ci" : "";
88 return $this->queryDB($sql, $con);
91 function dropMergeTable() {
93 $sql = "DROP TABLE IF EXISTS " . $this->store->getTablePrefix() . "triple_all";
95 return $this->queryDB($sql, $this->store->getDBCon());