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