blob: bafbe9932276756346b44b512e00b4545f00a6f2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
// file : odb/transaction.cxx
// author : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying LICENSE file
#include <odb/exceptions.hxx>
#include <odb/transaction.hxx>
#include <odb/details/tls.hxx>
namespace odb
{
using namespace details;
//
// transaction
//
static ODB_TLS_POINTER (transaction) current_transaction;
transaction::
transaction (transaction_impl* impl)
: finalized_ (false), impl_ (impl)
{
tls_set (current_transaction, this);
}
transaction::
~transaction ()
{
if (!finalized_)
{
try
{
rollback ();
}
catch (...)
{
}
}
delete impl_;
}
bool transaction::
has_current ()
{
return tls_get (current_transaction) != 0;
}
transaction& transaction::
current ()
{
transaction* cur (tls_get (current_transaction));
if (cur == 0)
throw not_in_transaction ();
return *cur;
}
void transaction::
commit ()
{
if (finalized_)
throw transaction_already_finalized ();
finalized_ = true;
transaction* t (0);
tls_set (current_transaction, t);
impl_->commit ();
}
void transaction::
rollback ()
{
if (finalized_)
throw transaction_already_finalized ();
finalized_ = true;
transaction* t (0);
tls_set (current_transaction, t);
impl_->rollback ();
}
//
// transaction_impl
//
transaction_impl::
~transaction_impl ()
{
}
}
|