comparison rdf/SimpleSPARQLQuery.cpp @ 526:8878efd21dbc

* The main fix here is to the arguments of SVApplication -- the first one should be int& rather than int (was causing a crash! gah!) Various other tiny fixes
author Chris Cannam
date Fri, 09 Jan 2009 14:55:12 +0000
parents 7207e3eba44f
children 3c5570e3d9c5
comparison
equal deleted inserted replaced
525:7419a063878b 526:8878efd21dbc
253 QString getErrorString() const; 253 QString getErrorString() const;
254 254
255 protected: 255 protected:
256 static QMutex m_mutex; 256 static QMutex m_mutex;
257 257
258 static WredlandWorldWrapper m_redland; 258 static WredlandWorldWrapper *m_redland;
259 259
260 ResultList executeDirectParser(); 260 ResultList executeDirectParser();
261 ResultList executeDatastore(); 261 ResultList executeDatastore();
262 ResultList executeFor(QString modelUri); 262 ResultList executeFor(QString modelUri);
263 263
266 QString m_errorString; 266 QString m_errorString;
267 ProgressReporter *m_reporter; 267 ProgressReporter *m_reporter;
268 bool m_cancelled; 268 bool m_cancelled;
269 }; 269 };
270 270
271 WredlandWorldWrapper SimpleSPARQLQuery::Impl::m_redland; 271 WredlandWorldWrapper *SimpleSPARQLQuery::Impl::m_redland = 0;
272 272
273 QMutex SimpleSPARQLQuery::Impl::m_mutex; 273 QMutex SimpleSPARQLQuery::Impl::m_mutex;
274 274
275 SimpleSPARQLQuery::SimpleSPARQLQuery(QueryType type, QString query) : 275 SimpleSPARQLQuery::SimpleSPARQLQuery(QueryType type, QString query) :
276 m_impl(new Impl(type, query)) 276 m_impl(new Impl(type, query))
353 { 353 {
354 ResultList list; 354 ResultList list;
355 355
356 QMutexLocker locker(&m_mutex); 356 QMutexLocker locker(&m_mutex);
357 357
358 if (!m_redland.isOK()) { 358 if (!m_redland) {
359 m_redland = new WredlandWorldWrapper();
360 }
361
362 if (!m_redland->isOK()) {
359 cerr << "ERROR: SimpleSPARQLQuery::execute: Failed to initialise Redland datastore" << endl; 363 cerr << "ERROR: SimpleSPARQLQuery::execute: Failed to initialise Redland datastore" << endl;
360 return list; 364 return list;
361 } 365 }
362 366
363 if (m_type == QueryFromSingleSource) { 367 if (m_type == QueryFromSingleSource) {
431 #endif 435 #endif
432 436
433 { 437 {
434 Profiler p("SimpleSPARQLQuery: Prepare LIBRDF query"); 438 Profiler p("SimpleSPARQLQuery: Prepare LIBRDF query");
435 query = librdf_new_query 439 query = librdf_new_query
436 (m_redland.getWorld(), "sparql", NULL, 440 (m_redland->getWorld(), "sparql", NULL,
437 (const unsigned char *)m_query.toUtf8().data(), NULL); 441 (const unsigned char *)m_query.toUtf8().data(), NULL);
438 } 442 }
439 443
440 if (!query) { 444 if (!query) {
441 m_errorString = "Failed to construct query"; 445 m_errorString = "Failed to construct query";
443 } 447 }
444 448
445 librdf_query_results *results; 449 librdf_query_results *results;
446 { 450 {
447 Profiler p("SimpleSPARQLQuery: Execute LIBRDF query"); 451 Profiler p("SimpleSPARQLQuery: Execute LIBRDF query");
448 results = librdf_query_execute(query, m_redland.getModel(modelUri)); 452 results = librdf_query_execute(query, m_redland->getModel(modelUri));
449 } 453 }
450 454
451 if (!results) { 455 if (!results) {
452 m_errorString = "RDF query failed"; 456 m_errorString = "RDF query failed";
453 librdf_free_query(query); 457 librdf_free_query(query);
577 { 581 {
578 QString err; 582 QString err;
579 583
580 QMutexLocker locker(&m_mutex); 584 QMutexLocker locker(&m_mutex);
581 585
582 if (!m_redland.isOK()) { 586 if (!m_redland->isOK()) {
583 std::cerr << "SimpleSPARQLQuery::addSourceToModel: Failed to initialise Redland datastore" << std::endl; 587 std::cerr << "SimpleSPARQLQuery::addSourceToModel: Failed to initialise Redland datastore" << std::endl;
584 return false; 588 return false;
585 } 589 }
586 590
587 if (!m_redland.loadUriIntoDefaultModel(sourceUri, err)) { 591 if (!m_redland->loadUriIntoDefaultModel(sourceUri, err)) {
588 std::cerr << "SimpleSPARQLQuery::addSourceToModel: Failed to add source URI \"" << sourceUri.toStdString() << ": " << err.toStdString() << std::endl; 592 std::cerr << "SimpleSPARQLQuery::addSourceToModel: Failed to add source URI \"" << sourceUri.toStdString() << ": " << err.toStdString() << std::endl;
589 return false; 593 return false;
590 } 594 }
591 return true; 595 return true;
592 } 596 }
594 void 598 void
595 SimpleSPARQLQuery::Impl::closeSingleSource(QString sourceUri) 599 SimpleSPARQLQuery::Impl::closeSingleSource(QString sourceUri)
596 { 600 {
597 QMutexLocker locker(&m_mutex); 601 QMutexLocker locker(&m_mutex);
598 602
599 m_redland.freeModel(sourceUri); 603 m_redland->freeModel(sourceUri);
600 } 604 }
601 605
602 SimpleSPARQLQuery::Value 606 SimpleSPARQLQuery::Value
603 SimpleSPARQLQuery::singleResultQuery(QueryType type, 607 SimpleSPARQLQuery::singleResultQuery(QueryType type,
604 QString query, QString binding) 608 QString query, QString binding)