SQLGlobalStore.cc

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2004-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
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 } // namespace dtn
00088 
00089 #endif /* SQL_ENABLED */

Generated on Thu Jun 7 12:54:29 2007 for DTN Reference Implementation by  doxygen 1.5.1