00001 #include <config/Configuration.h>
00002
00003 #include <boost/bind.hpp>
00004 #include <boost/thread.hpp>
00005
00006 #include "DAL/GeographyMUR.h"
00007 #include "DAL/Row.h"
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 SCTDAL::Row *createRow(int barrel, int row);
00020 SCTDAL::GeographyMUR *createMUR(int mur, std::string position);
00021 void linkRowToMur(SCTDAL::Row *rowObj, SCTDAL::GeographyMUR *murObj);
00022
00023 const SCTDAL::Row *getBackLink(SCTDAL::GeographyMUR *murObj);
00024 const SCTDAL::GeographyMUR *getForwardLink(SCTDAL::Row *rowObj);
00025
00026 std::string testFilename("reverseTest.data.xml");
00027 Configuration conf("oksconfig");
00028
00029 int main() {
00030
00031 system(("rm .oks-lock-" + testFilename).c_str());
00032 system(("rm " + testFilename).c_str());
00033
00034 std::list<std::string> includes;
00035 includes.push_back("SCT.schema.xml");
00036
00037 if(conf.create("", testFilename, includes) == false) {
00038 std::cerr << "ERROR: failed to create file \'" << testFilename << "\'\n";
00039 conf.abort();
00040 return 1;
00041 }
00042
00043 SCTDAL::Row *rowObj = createRow(0, 10);
00044 std::cout << "Created row\n";
00045 if(rowObj)
00046 rowObj->print(2, true, std::cout);
00047 SCTDAL::GeographyMUR *murObj = createMUR(1000, "-1");
00048 std::cout << "Created MUR\n";
00049 if(murObj)
00050 murObj->print(2, true, std::cout);
00051 linkRowToMur(rowObj, murObj);
00052 std::cout << "Created link\n";
00053 if(rowObj)
00054 rowObj->print(2, true, std::cout);
00055
00056 const SCTDAL::GeographyMUR *forwardMur = getForwardLink(rowObj);
00057 if(forwardMur)
00058 forwardMur->print(2, true, std::cout);
00059
00060 const SCTDAL::Row *backRowObj = getBackLink(murObj);
00061 if(backRowObj)
00062 backRowObj->print(2, true, std::cout);
00063 }
00064
00065 SCTDAL::Row *createRow(int barrel, int row) {
00066 SCTDAL::Row *rowOb = const_cast<SCTDAL::Row*>(conf.create<SCTDAL::Row>(testFilename, ""));
00067
00068 if(!rowOb) {
00069 std::cerr << "Can't create row\n";
00070 conf.abort();
00071 return 0;
00072 }
00073
00074 rowOb->set_id(row);
00075
00076 conf.commit();
00077
00078 return rowOb;
00079 }
00080
00081 SCTDAL::GeographyMUR *createMUR(int mur, std::string position) {
00082 SCTDAL::GeographyMUR *murOb = const_cast<SCTDAL::GeographyMUR*>(conf.create<SCTDAL::GeographyMUR>(testFilename, ""));
00083
00084 if(!murOb) {
00085 std::cerr << "Can't create Geog MUR\n";
00086 conf.abort();
00087 return 0;
00088 }
00089
00090 murOb->set_id(mur);
00091 murOb->set_position(position);
00092
00093 conf.commit();
00094
00095 return murOb;
00096 }
00097
00098 void linkRowToMur(SCTDAL::Row *rowObj, SCTDAL::GeographyMUR *murObj) {
00099 std::vector<const SCTDAL::GeographyMUR *> murs(rowObj->get_murs());
00100 murs.push_back(murObj);
00101 rowObj->set_murs(murs);
00102 conf.commit();
00103 }
00104
00105 const SCTDAL::Row *getBackLink(SCTDAL::GeographyMUR *murObj) {
00106 std::vector<const SCTDAL::Row *> possibles;
00107 conf.referenced_by(*murObj, "murs", possibles);
00108
00109 if(possibles.size() == 1) {
00110 const SCTDAL::Row *theRow = possibles.front();
00111
00112 std::cout << "Found back link " << theRow << std::endl;
00113 return theRow;
00114 } else {
00115 std::cout << "Something wrong, size " << possibles.size() << std::endl;
00116 }
00117 return 0;
00118 }
00119
00120 const SCTDAL::GeographyMUR *getForwardLink(SCTDAL::Row *rowObj) {
00121 std::vector<const SCTDAL::GeographyMUR *> possibles(rowObj->get_murs());
00122
00123 if(possibles.size() == 1) {
00124 const SCTDAL::GeographyMUR *murObj = possibles.front();
00125
00126 std::cout << "Found Forward link " << murObj << std::endl;
00127 return murObj;
00128 } else {
00129 std::cout << "Something wrong, size " << possibles.size() << std::endl;
00130 }
00131 return 0;
00132 }