/sqlite3cc

To get this branch, use:
bzr branch http://bzr.ed.am/sqlite3cc

« back to all changes in this revision

Viewing changes to include/sqlite3cc/transaction.h

  • Committer: edam
  • Date: 2010-02-07 14:39:18 UTC
  • Revision ID: edam@waxworlds.org-20100207143918-gi030ojecbska8hw
- updated README
- set up project for use with autotools

Show diffs side-by-side

added added

removed removed

25
25
 
26
26
 
27
27
#include <boost/utility.hpp>
28
 
#include <string>
29
28
 
30
29
 
31
30
namespace sqlite
32
31
{
33
32
 
34
33
 
35
 
class connection;
36
 
 
37
 
 
38
 
namespace detail
39
 
{
40
 
 
41
 
        /**
42
 
         * A basic (default, deferred) transaction.
43
 
         */
44
 
        class basic_transaction
45
 
                :
46
 
                private boost::noncopyable
47
 
        {
48
 
        //__________________________________________________________________________
49
 
        //                                                             instantiation
50
 
        public:
51
 
 
52
 
                /**
53
 
                 * Constructor that provides a connection upon which to act
54
 
                 * @param connection a connection
55
 
                 */
56
 
                explicit basic_transaction(
57
 
                        connection &connection );
58
 
 
59
 
        //__________________________________________________________________________
60
 
        //                                                          public interface
61
 
        public:
62
 
 
63
 
                /**
64
 
                 * Begin the transaction
65
 
                 */
66
 
                virtual void begin();
67
 
 
68
 
                /**
69
 
                 * Commit the transaction
70
 
                 */
71
 
                virtual void commit();
72
 
 
73
 
                /**
74
 
                 * Rollback the transaction
75
 
                 */
76
 
                virtual void rollback();
77
 
 
78
 
        //__________________________________________________________________________
79
 
        //                                                            implementation
80
 
        protected:
81
 
 
82
 
                /** reset any in-progress statements */
83
 
                void reset_active_queries();
84
 
 
85
 
                /** the connection on which to act */
86
 
                connection &_connection;
87
 
 
88
 
        };
89
 
 
90
 
} // namespace detail
91
 
 
92
 
 
93
 
////////////////////////////////////////////////////////////////////////////////
94
 
 
95
 
 
96
 
/**
97
 
 * A deferred transaction (the default)
98
 
 */
99
 
typedef detail::basic_transaction deferred_tranaction;
100
 
 
101
 
 
102
 
////////////////////////////////////////////////////////////////////////////////
103
 
 
104
 
 
105
 
/**
106
 
 * An immediate transaction
107
 
 */
108
 
class immediate_transaction
 
34
class database;
 
35
 
 
36
 
 
37
class basic_transaction
109
38
        :
110
 
        public detail::basic_transaction
 
39
        private boost::noncopyable
111
40
{
112
41
//______________________________________________________________________________
113
42
//                                                                 instantiation
114
43
public:
115
44
 
116
45
        /**
117
 
         * Constructor that provides a connection upon which to act
118
 
         * @param connection a connection
 
46
         * Constructor that provides a database upon which to act
 
47
         * @param database a database
119
48
         */
120
 
        explicit immediate_transaction(
121
 
                connection &connection );
 
49
        explicit basic_transaction(
 
50
                database &database );
122
51
 
123
52
//______________________________________________________________________________
124
53
//                                                              public interface
129
58
         */
130
59
        virtual void begin();
131
60
 
 
61
        /**
 
62
         * Commit the transaction
 
63
         */
 
64
        virtual void commit();
 
65
 
 
66
        /**
 
67
         * Rollback the transaction
 
68
         */
 
69
        virtual void rollback();
 
70
 
 
71
//______________________________________________________________________________
 
72
//                                                                implementation
 
73
protected:
 
74
 
 
75
        /* the database on which to act */
 
76
        database &_database;
 
77
 
132
78
};
133
79
 
134
80
 
135
81
////////////////////////////////////////////////////////////////////////////////
136
82
 
137
83
 
138
 
/**
139
 
 * An exclusive transaction
140
 
 */
141
84
class exclusive_transaction
142
85
        :
143
 
        public detail::basic_transaction
 
86
        public basic_transaction
144
87
{
145
88
//______________________________________________________________________________
146
89
//                                                                 instantiation
147
90
public:
148
91
 
149
92
        /**
150
 
         * Constructor that provides a connection upon which to act
151
 
         * @param connection a connection
 
93
         * Constructor that provides a database upon which to act
 
94
         * @param database a database
152
95
         */
153
96
        explicit exclusive_transaction(
154
 
                connection &connection );
 
97
                database &database );
155
98
 
156
99
//______________________________________________________________________________
157
100
//                                                              public interface
168
111
////////////////////////////////////////////////////////////////////////////////
169
112
 
170
113
 
171
 
/**
172
 
 * A recursive transaction, allowing transactions to be nested.
173
 
 */
174
114
class recursive_transaction
175
115
        :
176
 
        public detail::basic_transaction
 
116
        public basic_transaction
177
117
{
178
118
//______________________________________________________________________________
179
119
//                                                                 instantiation
180
120
public:
181
121
 
182
122
        /**
183
 
         * Constructor that provides a connection upon which to act
184
 
         * @param connection a connection
 
123
         * Constructor that provides a database upon which to act
 
124
         * @param database a database
185
125
         */
186
126
        explicit recursive_transaction(
187
 
                connection &connection );
 
127
                database &database );
188
128
 
189
129
//______________________________________________________________________________
190
130
//                                                              public interface
218
158
////////////////////////////////////////////////////////////////////////////////
219
159
 
220
160
 
221
 
/**
222
 
 * A scope guard (sentinel) for use with one of the transaction classes to
223
 
 * provide RIAA-style transactions.
224
 
 */
225
 
template< class T = deferred_tranaction >
 
161
template< class T = basic_transaction >
226
162
class transaction_guard
227
163
        :
228
164
        private boost::noncopyable
232
168
public:
233
169
 
234
170
        /**
235
 
         * Constructor that provides a connection upon which to act
236
 
         * @param connection a connection
 
171
         * Constructor that provides a database upon which to act
 
172
         * @param database a database
237
173
         */
238
174
        explicit transaction_guard(
239
 
                connection &connection )
 
175
                database &database )
240
176
                :
241
 
                _transaction( connection ),
 
177
                _transaction( database ),
242
178
                _released( false )
243
179
        {
244
180
                _transaction.begin();
265
201
                }
266
202
        }
267
203
 
268
 
        /**
269
 
         * Rollback the transaction early
270
 
         */
271
 
        void rollback()
272
 
        {
273
 
                if( !_released ) {
274
 
                        _transaction.rollback();
275
 
                        _released = true;
276
 
                }
277
 
        }
278
 
 
279
204
//______________________________________________________________________________
280
205
//                                                                implementation
281
206
protected:
282
207
 
283
 
        /** the transaction */
 
208
        /* the transaction */
284
209
        T _transaction;
285
210
 
286
 
        /** have we released the transaction yet? */
 
211
        /* have we released the transaction yet? */
287
212
        bool _released;
288
213
 
289
214
};