00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 Dataquay 00005 00006 A C++/Qt library for simple RDF datastore management with Redland. 00007 Copyright 2009 Chris Cannam. 00008 00009 Permission is hereby granted, free of charge, to any person 00010 obtaining a copy of this software and associated documentation 00011 files (the "Software"), to deal in the Software without 00012 restriction, including without limitation the rights to use, copy, 00013 modify, merge, publish, distribute, sublicense, and/or sell copies 00014 of the Software, and to permit persons to whom the Software is 00015 furnished to do so, subject to the following conditions: 00016 00017 The above copyright notice and this permission notice shall be 00018 included in all copies or substantial portions of the Software. 00019 00020 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00021 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00022 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00023 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR 00024 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 00025 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00026 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00027 00028 Except as contained in this notice, the name of Chris Cannam 00029 shall not be used in advertising or otherwise to promote the sale, 00030 use or other dealings in this Software without prior written 00031 authorization. 00032 */ 00033 00034 #include "Connection.h" 00035 00036 #include "TransactionalStore.h" 00037 #include "Transaction.h" 00038 00039 namespace Dataquay 00040 { 00041 00042 class Connection::D 00043 { 00044 public: 00045 D(TransactionalStore *ts); 00046 ~D(); 00047 00048 bool add(Triple t); 00049 bool remove(Triple t); 00050 void change(ChangeSet changes); 00051 void revert(ChangeSet changes); 00052 bool contains(Triple t) const; 00053 Triples match(Triple t) const; 00054 ResultSet query(QString sparql) const; 00055 Triple matchFirst(Triple t) const; 00056 Node queryFirst(QString sparql, QString bindingName) const; 00057 QUrl getUniqueUri(QString prefix) const; 00058 QUrl expand(QString uri) const; 00059 00060 void commit(); 00061 void rollback(); 00062 00063 private: 00064 TransactionalStore *m_ts; 00065 Transaction *m_tx; 00066 00067 Store *getStore() const; 00068 void start(); 00069 }; 00070 00071 Connection::D::D(TransactionalStore *ts) : 00072 m_ts(ts), 00073 m_tx(NoTransaction) 00074 { 00075 } 00076 00077 Connection::D::~D() 00078 { 00079 commit(); 00080 } 00081 00082 bool 00083 Connection::D::add(Triple t) 00084 { 00085 start(); 00086 return m_tx->add(t); 00087 } 00088 00089 bool 00090 Connection::D::remove(Triple t) 00091 { 00092 start(); 00093 return m_tx->remove(t); 00094 } 00095 00096 void 00097 Connection::D::change(ChangeSet cs) 00098 { 00099 start(); 00100 return m_tx->change(cs); 00101 } 00102 00103 void 00104 Connection::D::revert(ChangeSet cs) 00105 { 00106 start(); 00107 return m_tx->revert(cs); 00108 } 00109 00110 void 00111 Connection::D::start() 00112 { 00113 if (m_tx != NoTransaction) return; 00114 m_tx = m_ts->startTransaction(); 00115 } 00116 00117 void 00118 Connection::D::commit() 00119 { 00120 delete m_tx; 00121 m_tx = NoTransaction; 00122 } 00123 00124 void 00125 Connection::D::rollback() 00126 { 00127 if (m_tx) { 00128 m_tx->rollback(); 00129 delete m_tx; 00130 m_tx = NoTransaction; 00131 } 00132 } 00133 00134 Store * 00135 Connection::D::getStore() const 00136 { 00137 if (m_tx) return m_tx; 00138 else return m_ts; 00139 } 00140 00141 bool 00142 Connection::D::contains(Triple t) const 00143 { 00144 return getStore()->contains(t); 00145 } 00146 00147 Triples 00148 Connection::D::match(Triple t) const 00149 { 00150 return getStore()->match(t); 00151 } 00152 00153 ResultSet 00154 Connection::D::query(QString sparql) const 00155 { 00156 return getStore()->query(sparql); 00157 } 00158 00159 Triple 00160 Connection::D::matchFirst(Triple t) const 00161 { 00162 return getStore()->matchFirst(t); 00163 } 00164 00165 Node 00166 Connection::D::queryFirst(QString sparql, QString bindingName) const 00167 { 00168 return getStore()->queryFirst(sparql, bindingName); 00169 } 00170 00171 QUrl 00172 Connection::D::getUniqueUri(QString prefix) const 00173 { 00174 return getStore()->getUniqueUri(prefix); 00175 } 00176 00177 QUrl 00178 Connection::D::expand(QString uri) const 00179 { 00180 return getStore()->expand(uri); 00181 } 00182 00183 Connection::Connection(TransactionalStore *ts) : 00184 m_d(new D(ts)) 00185 { 00186 } 00187 00188 Connection::~Connection() 00189 { 00190 delete m_d; 00191 } 00192 00193 bool 00194 Connection::add(Triple t) 00195 { 00196 return m_d->add(t); 00197 } 00198 00199 bool 00200 Connection::remove(Triple t) 00201 { 00202 return m_d->remove(t); 00203 } 00204 00205 void 00206 Connection::change(ChangeSet changes) 00207 { 00208 m_d->change(changes); 00209 } 00210 00211 void 00212 Connection::revert(ChangeSet changes) 00213 { 00214 m_d->revert(changes); 00215 } 00216 00217 bool 00218 Connection::contains(Triple t) const 00219 { 00220 return m_d->contains(t); 00221 } 00222 00223 Triples 00224 Connection::match(Triple t) const 00225 { 00226 return m_d->match(t); 00227 } 00228 00229 ResultSet 00230 Connection::query(QString sparql) const 00231 { 00232 return m_d->query(sparql); 00233 } 00234 00235 Triple 00236 Connection::matchFirst(Triple t) const 00237 { 00238 return m_d->matchFirst(t); 00239 } 00240 00241 Node 00242 Connection::queryFirst(QString sparql, QString bindingName) const 00243 { 00244 return m_d->queryFirst(sparql, bindingName); 00245 } 00246 00247 QUrl 00248 Connection::getUniqueUri(QString prefix) const 00249 { 00250 return m_d->getUniqueUri(prefix); 00251 } 00252 00253 QUrl 00254 Connection::expand(QString uri) const 00255 { 00256 return m_d->expand(uri); 00257 } 00258 00259 void 00260 Connection::commit() 00261 { 00262 m_d->commit(); 00263 } 00264 00265 void 00266 Connection::rollback() 00267 { 00268 m_d->rollback(); 00269 } 00270 00271 } 00272
1.5.7.1