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 "SQLBundleStore.h"
00024 #include "SQLStore.h"
00025 #include "StorageConfig.h"
00026 #include "bundling/Bundle.h"
00027
00028 namespace dtn {
00029
00030
00031
00032
00033
00034
00035
00040 SQLBundleStore::SQLBundleStore(oasys::SQLImplementation* db, const char* table_name)
00041 : BundleStore()
00042 {
00043 Bundle tmpobj(this);
00044
00045 store_ = new SQLStore(table_name, db);
00046 store_->create_table(&tmpobj);
00047 store_->set_key_name("bundleid");
00048 }
00049
00056 Bundle*
00057 SQLBundleStore::get(int bundle_id)
00058 {
00059 Bundle* bundle = new Bundle();
00060 if (store_->get(bundle, bundle_id) != 0) {
00061 delete bundle;
00062 return NULL;
00063 }
00064
00065 return bundle;
00066 }
00067
00071 bool
00072 SQLBundleStore::insert(Bundle* bundle)
00073 {
00074 return store_->insert(bundle) == 0;
00075 }
00076
00080 bool
00081 SQLBundleStore::update(Bundle* bundle)
00082 {
00083 return store_->update(bundle, bundle->bundleid_) == 0;
00084 }
00085
00089 bool
00090 SQLBundleStore::del(int bundle_id)
00091 {
00092 return store_->del(bundle_id) == 0;
00093 }
00094
00095
00096
00097 int
00098 SQLBundleStore::delete_expired(const time_t now)
00099 {
00100 const char* field = "expiration";
00101 oasys::StringBuffer query ;
00102 query.appendf("DELETE FROM %s WHERE %s > %lu", store_->table_name(), field, now);
00103
00104 int retval = store_->exec_query(query.c_str());
00105 return retval;
00106 }
00107
00108
00109
00110 bool
00111 SQLBundleStore::is_custodian(int bundle_id)
00112 {
00113 NOTIMPLEMENTED ;
00114
00122 }
00123
00124 }
00125
00126 #endif