SQLBundleStore.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 "SQLBundleStore.h"
00023 #include "SQLStore.h"
00024 #include "StorageConfig.h"
00025 #include "bundling/Bundle.h"
00026 
00027 namespace dtn {
00028 
00029 /******************************************************************************
00030  *
00031  * SQLBundleStore
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 } // namespace dtn
00124 
00125 #endif /* SQL_ENABLED */

Generated on Sat Sep 8 08:43:34 2007 for DTN Reference Implementation by  doxygen 1.5.3