55 return new SQLiteBundleSet(create(_sqldb, name),
true, listener, bf_size, _sqldb);
69 }
while (__exists(db, name,
false));
71 return __create(db, name,
false);
77 return __create(db, name,
true);
84 sqlite3_bind_text(*st1, 1, name.c_str(),
static_cast<int>(name.length()), SQLITE_TRANSIENT);
85 sqlite3_bind_int(*st1, 2, persistent ? 1 : 0);
90 sqlite3_bind_text(*st2, 1, name.c_str(),
static_cast<int>(name.length()), SQLITE_TRANSIENT);
91 sqlite3_bind_int(*st2, 2, persistent ? 1 : 0);
93 if (st2.
step() == SQLITE_ROW) {
94 return sqlite3_column_int64(*st2, 0);
103 sqlite3_bind_text(*st, 1, name.c_str(),
static_cast<int>(name.length()), SQLITE_TRANSIENT);
104 sqlite3_bind_int(*st, 2, persistent ? 1 : 0);
106 return ( st.
step() == SQLITE_ROW);
110 : _set_id(id), _bf_size(bf_size), _bf(bf_size * 8), _listener(listener), _consistent(true),_sqldb(database), _persistent(persistant)
115 rebuild_bloom_filter();
119 SQLiteDatabase::Statement st(_sqldb._database, SQLiteDatabase::_sql_queries[SQLiteDatabase::BUNDLE_SET_EXPIRE_NEXT_TIMESTAMP]);
120 sqlite3_bind_int64(*st, 1, _set_id);
124 if (err == SQLITE_ROW)
126 _next_expiration = sqlite3_column_int64(*st, 0);
137 if (!_persistent) destroy();
140 void SQLiteBundleSet::destroy()
146 sqlite3_bind_int64(*st, 1, _set_id);
149 }
catch (
const SQLiteDatabase::SQLiteQueryException&) {
162 sqlite3_bind_int64(*st, 1, set->_set_id);
163 sqlite3_bind_int64(*st, 2, _set_id);
171 set->rebuild_bloom_filter();
185 if (set == NULL)
return;
190 sqlite3_bind_int64(*st, 1, _set_id);
191 sqlite3_bind_int64(*st, 2, set->_set_id);
199 rebuild_bloom_filter();
208 sqlite3_bind_int64(*st, 1, _set_id);
209 sqlite3_bind_text(*st, 2, bundle.source.getString().c_str(),
static_cast<int>(bundle.source.getString().length()), SQLITE_TRANSIENT);
210 sqlite3_bind_int64(*st, 3, bundle.timestamp.get<uint64_t>());
211 sqlite3_bind_int64(*st, 4, bundle.sequencenumber.get<uint64_t>());
213 if (bundle.isFragment()) {
214 sqlite3_bind_int64(*st, 5, bundle.fragmentoffset.get<uint64_t>());
215 sqlite3_bind_int64(*st, 6, bundle.getPayloadLength());
217 sqlite3_bind_int64(*st, 5, -1);
218 sqlite3_bind_int64(*st, 6, -1);
221 sqlite3_bind_int64(*st, 7, bundle.expiretime.get<uint64_t>());
226 new_expire_time(bundle.expiretime);
239 sqlite3_bind_int64(*st, 1, _set_id);
253 if (!
id.isIn(_bf))
return false;
257 if (!_consistent)
return true;
260 SQLiteDatabase::Statement st( const_cast<sqlite3*>(_sqldb._database), SQLiteDatabase::_sql_queries[SQLiteDatabase::BUNDLE_SET_GET]);
262 sqlite3_bind_int64(*st, 1, _set_id);
263 sqlite3_bind_text(*st, 2,
id.source.getString().c_str(),
static_cast<int>(
id.source.getString().length()), SQLITE_TRANSIENT);
264 sqlite3_bind_int64(*st, 3,
id.timestamp.get<uint64_t>());
265 sqlite3_bind_int64(*st, 4,
id.sequencenumber.get<uint64_t>());
267 if (
id.isFragment()) {
268 sqlite3_bind_int64(*st, 5,
id.fragmentoffset.get<uint64_t>());
269 sqlite3_bind_int64(*st, 6,
id.getPayloadLength());
271 sqlite3_bind_int64(*st, 5, -1);
272 sqlite3_bind_int64(*st, 6, -1);
275 if (st.
step() == SQLITE_ROW)
287 if (timestamp == 0)
return;
290 if (_next_expiration > timestamp)
return;
293 if (_listener != NULL) {
296 sqlite3_bind_int64(*st, 1, _set_id);
299 sqlite3_bind_int64(*st, 2, timestamp.get<uint64_t>());
301 while (st.
step() == SQLITE_ROW)
304 get_bundleid(st,
id);
309 _listener->eventBundleExpired(bundle);
319 sqlite3_bind_int64(*st, 1, _set_id);
322 sqlite3_bind_int64(*st, 2, timestamp.get<uint64_t>());
330 rebuild_bloom_filter();
339 sqlite3_bind_int64(*st, 1, _set_id);
341 if (st.
step() == SQLITE_ROW)
343 rows = sqlite3_column_int(*st, 0);
364 std::set<dtn::data::MetaBundle> ret;
368 sqlite3_bind_int64(*st, 1, _set_id);
370 std::set<dtn::data::MetaBundle> ret;
373 while (st.
step() == SQLITE_ROW)
376 get_bundleid(st,
id);
378 if ( !
id.isIn(filter) )
381 ret.insert( bundle );
396 const char *data =
reinterpret_cast<const char*
>(_bf.
table());
397 stream.write(data, _bf.
size());
407 std::vector<char> buffer(count.get<
size_t>());
409 stream.read(&buffer[0], buffer.size());
412 _bf.
load((
unsigned char*)&buffer[0], buffer.size());
422 if (_next_expiration == 0 || ttl < _next_expiration)
424 _next_expiration = ttl;
428 void SQLiteBundleSet::rebuild_bloom_filter()
434 SQLiteDatabase::Statement st(_sqldb._database, SQLiteDatabase::_sql_queries[SQLiteDatabase::BUNDLE_SET_GET_ALL]);
435 sqlite3_bind_int64(*st, 1, _set_id);
437 std::set<dtn::data::MetaBundle> ret;
440 while (st.step() == SQLITE_ROW)
443 get_bundleid(st,
id);
448 }
catch (
const SQLiteDatabase::SQLiteQueryException&) {
453 void SQLiteBundleSet::get_bundleid(SQLiteDatabase::Statement &st,
dtn::data::BundleID &
id,
int offset)
const throw (SQLiteDatabase::SQLiteQueryException)
455 id.source =
dtn::data::EID((
const char*)sqlite3_column_text(*st, offset + 0));
456 id.timestamp = sqlite3_column_int64(*st, offset + 1);
457 id.sequencenumber = sqlite3_column_int64(*st, offset + 2);
459 id.setFragment(sqlite3_column_int64(*st, offset + 2) >= 0);
461 if (
id.isFragment()) {
462 id.fragmentoffset = sqlite3_column_int64(*st, offset + 3);
463 id.setPayloadLength(sqlite3_column_int64(*st, offset + 4));
465 id.fragmentoffset = 0;
466 id.setPayloadLength(0);