00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifdef HAVE_CONFIG_H
00018 # include <dtn-config.h>
00019 #endif
00020
00021 #if SQL_ENABLED
00022
00023 #include "SQLGlobalStore.h"
00024 #include "SQLStore.h"
00025 #include "StorageConfig.h"
00026
00027 namespace dtn {
00028
00029 static const char* TABLENAME = "globals";
00030
00031 SQLGlobalStore::SQLGlobalStore(oasys::SQLImplementation* impl)
00032 {
00033 store_ = new SQLStore(TABLENAME, impl);
00034 store_->create_table(this);
00035 }
00036
00037 SQLGlobalStore::~SQLGlobalStore()
00038 {
00039 NOTREACHED;
00040 }
00041
00042 bool
00043 SQLGlobalStore::load()
00044 {
00045 log_debug("loading global store");
00046
00047 oasys::SerializableObjectVector elements;
00048 elements.push_back(this);
00049
00050 int cnt = store_->elements(&elements);
00051
00052 if (cnt == 1) {
00053 log_debug("loaded next bundle id %d next reg id %d",
00054 next_bundleid_, next_regid_);
00055
00056 } else if (cnt == 0 && StorageConfig::instance()->tidy_) {
00057 log_info("globals table does not exist... initializing it");
00058
00059 next_bundleid_ = 0;
00060 next_regid_ = 0;
00061
00062 if (store_->insert(this) != 0) {
00063 log_err("error initializing globals table");
00064 exit(1);
00065 }
00066
00067 } else {
00068 log_err("error loading globals table");
00069 exit(1);
00070 }
00071
00072 return true;
00073 }
00074
00075 bool
00076 SQLGlobalStore::update()
00077 {
00078 log_debug("updating global store");
00079
00080 if (store_->update(this, -1) == -1) {
00081 log_err("error updating global store");
00082 return false;
00083 }
00084
00085 return true;
00086 }
00087
00088 }
00089
00090 #endif