Mercurial > hg > classical
annotate testapp/Loader.cpp @ 7:df999875c53b classical-rdf
* Test application for load/query (beginnings of)
author | Chris Cannam |
---|---|
date | Tue, 09 Feb 2010 17:33:39 +0000 |
parents | |
children | 71cf328c2a9d |
rev | line source |
---|---|
Chris@7 | 1 |
Chris@7 | 2 #include "Objects.h" |
Chris@7 | 3 #include "TypeRegistrar.h" |
Chris@7 | 4 |
Chris@7 | 5 #include <dataquay/BasicStore.h> |
Chris@7 | 6 #include <dataquay/objectmapper/ObjectMapper.h> |
Chris@7 | 7 |
Chris@7 | 8 #include <QTemporaryFile> |
Chris@7 | 9 |
Chris@7 | 10 #include <iostream> |
Chris@7 | 11 |
Chris@7 | 12 using namespace Dataquay; |
Chris@7 | 13 using namespace ClassicalData; |
Chris@7 | 14 |
Chris@7 | 15 bool |
Chris@7 | 16 load(BasicStore *store, QString resourceName) |
Chris@7 | 17 { |
Chris@7 | 18 QTemporaryFile tf; |
Chris@7 | 19 if (!tf.open()) return false; |
Chris@7 | 20 tf.setAutoRemove(true); |
Chris@7 | 21 QFile f(resourceName); |
Chris@7 | 22 if (!f.open(QFile::ReadOnly)) return false; |
Chris@7 | 23 QByteArray buffer; |
Chris@7 | 24 int bufsiz = 10240; |
Chris@7 | 25 while (!f.atEnd()) { |
Chris@7 | 26 buffer = f.read(bufsiz); |
Chris@7 | 27 tf.write(buffer); |
Chris@7 | 28 } |
Chris@7 | 29 std::cerr << "unpacked, importing..." << std::endl; |
Chris@7 | 30 store->import("file://" + tf.fileName(), |
Chris@7 | 31 BasicStore::ImportPermitDuplicates, // fastest mode |
Chris@7 | 32 "ntriples"); |
Chris@7 | 33 return true; |
Chris@7 | 34 } |
Chris@7 | 35 |
Chris@7 | 36 int main(int argc, char **argv) |
Chris@7 | 37 { |
Chris@7 | 38 BasicStore *store = new BasicStore(); |
Chris@7 | 39 store->setBaseUri("http://dbtune.org/classical/resource/"); |
Chris@7 | 40 ObjectMapper *mapper = new ObjectMapper(store); |
Chris@7 | 41 |
Chris@7 | 42 TypeRegistrar::addMappings(store, mapper); |
Chris@7 | 43 |
Chris@7 | 44 if (!load(store, ":data.ntriples")) { |
Chris@7 | 45 std::cerr << "Failed to unpack and load resource" << std::endl; |
Chris@7 | 46 return 1; |
Chris@7 | 47 } |
Chris@7 | 48 |
Chris@7 | 49 std::cerr << "imported, mapping..." << std::endl; |
Chris@7 | 50 |
Chris@7 | 51 QObject *parent = mapper->loadAllObjects(0); |
Chris@7 | 52 |
Chris@7 | 53 delete mapper; |
Chris@7 | 54 delete store; |
Chris@7 | 55 } |
Chris@7 | 56 |