aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-02-08 12:55:28 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-02-08 12:55:28 +0200
commit42123e65fab590f5b052f53ad755fba9bded0c24 (patch)
treee4339f4e0591c26483d34d265e91cf6191288ac8
parent261863a5037ba892ec33eb037d77736c8e599369 (diff)
Add callback_ prefix to transaction callback functions
Also test callback_update().
-rw-r--r--common/session/custom/session.cxx5
-rw-r--r--common/transaction/callback/driver.cxx33
-rw-r--r--common/transaction/callback/test.std2
3 files changed, 30 insertions, 10 deletions
diff --git a/common/session/custom/session.cxx b/common/session/custom/session.cxx
index 0009d79..d82ab3d 100644
--- a/common/session/custom/session.cxx
+++ b/common/session/custom/session.cxx
@@ -22,7 +22,7 @@ session::
// Unregister from transaction.
//
if (tran_ != 0)
- tran_->unregister (this);
+ tran_->callback_unregister (this);
assert (current == this);
current = 0;
@@ -44,7 +44,8 @@ flush (odb::database& db)
if (flushed)
{
tran_ = &odb::transaction::current ();
- tran_->register_ (&mark, this, odb::transaction::event_all, 0, &tran_);
+ tran_->callback_register (
+ &mark, this, odb::transaction::event_all, 0, &tran_);
}
}
diff --git a/common/transaction/callback/driver.cxx b/common/transaction/callback/driver.cxx
index b74df4c..b4c3d85 100644
--- a/common/transaction/callback/driver.cxx
+++ b/common/transaction/callback/driver.cxx
@@ -27,17 +27,24 @@ struct callback
register_ (transaction& t)
{
t_ = &t;
- t.register_ (&func, this, transaction::event_all, v_, &t_);
+ t.callback_register (&func, this, transaction::event_all, v_, &t_);
}
void
unregister ()
{
cout << " unregister callback " << v_ << endl;
- t_->unregister (this);
+ t_->callback_unregister (this);
t_ = 0;
}
+ void
+ update (unsigned short v)
+ {
+ v_ = v;
+ t_->callback_update (this, transaction::event_all, v_, &t_);
+ }
+
private:
static void
func (unsigned short event, void* key, unsigned long long data)
@@ -87,10 +94,10 @@ fill (transaction& t)
// 20 is from odb/transaction.hxx.
//
for (size_t i (0); i < 20; ++i)
- t.register_ (&dummy_func,
- reinterpret_cast<void*> (i),
- transaction::event_all,
- i);
+ t.callback_register (&dummy_func,
+ reinterpret_cast<void*> (i),
+ transaction::event_all,
+ i);
}
int
@@ -150,7 +157,7 @@ main (int argc, char* argv[])
if (i == 2) fill (t);
callback c1 (1, t);
c1.unregister ();
- t.unregister (&c1); // Test unregistering non-registered key.
+ t.callback_unregister (&c1); // Test unregistering non-registered key.
t.commit ();
}
@@ -195,13 +202,23 @@ main (int argc, char* argv[])
transaction t (db->begin ());
if (i == 2) fill (t);
callback c1 (1, t);
- t.register_ (&throw_func, 0);
+ t.callback_register (&throw_func, 0);
callback c2 (2, t);
t.commit ();
}
catch (const failed&)
{
}
+
+ // Test callback_update().
+ //
+ {
+ transaction t (db->begin ());
+ if (i == 2) fill (t);
+ callback c (1, t);
+ c.update (2);
+ t.commit ();
+ }
}
}
catch (const odb::exception& e)
diff --git a/common/transaction/callback/test.std b/common/transaction/callback/test.std
index f86579b..4298c1e 100644
--- a/common/transaction/callback/test.std
+++ b/common/transaction/callback/test.std
@@ -15,6 +15,7 @@ test 1/002
callback 3 commit
test 1/003
callback 1 commit
+ callback 2 commit
test 2/001
callback 1 commit
callback 1 rollback
@@ -32,3 +33,4 @@ test 2/002
callback 3 commit
test 2/003
callback 1 commit
+ callback 2 commit