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