blob: 164b9a03ab48e839180bbd9685b43cd3a0142273 (
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
95
96
97
98
99
100
|
// file : tracer/transaction/driver.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 <cassert>
#include <iostream>
#include <odb/exceptions.hxx>
#include <odb/session.hxx>
#include <odb/transaction.hxx>
#include <odb/tracer/database.hxx>
#include <odb/tracer/transaction.hxx>
using namespace std;
using namespace odb;
int
main ()
{
tracer::database db;
assert (!transaction::has_current ());
// Current and db accessors.
//
cout << "test 001" << endl;
{
transaction t (db.begin_transaction ());
assert (&t.database () == &db);
assert (transaction::has_current ());
assert (&transaction::current () == &t);
}
// Commit.
//
cout << "test 002" << endl;
{
transaction t (db.begin_transaction ());
t.commit ();
}
// Rollback.
//
cout << "test 003" << endl;
{
transaction t (db.begin_transaction ());
t.rollback ();
}
// Auto rollback.
//
cout << "test 004" << endl;
{
transaction t (db.begin_transaction ());
}
// Nested transaction.
//
cout << "test 005" << endl;
{
transaction t (db.begin_transaction ());
try
{
transaction n (db.begin_transaction ());
}
catch (const already_in_transaction&)
{
cout << "already_in_transaction" << endl;
}
}
// Existing session via current.
//
cout << "test 006" << endl;
{
session s;
transaction t (db.begin_transaction ());
assert (&t.session () == &s);
}
// Existing session passed explicitly.
//
cout << "test 007" << endl;
{
session s;
transaction t (db.begin_transaction (s));
assert (&t.session () == &s);
}
// Concrete transaction type.
//
cout << "test 008" << endl;
{
assert (sizeof (tracer::transaction) == sizeof (transaction));
tracer::transaction t (db.begin_transaction ());
tracer::transaction& r (tracer::transaction::current ());
}
}
|