/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: 2012-01-23 13:51:26 UTC
  • Revision ID: edam@waxworlds.org-20120123135126-7gohm0mv9qwismla
typo

Show diffs side-by-side

added added

removed removed

1
1
/*
2
2
 * transaction.h
3
3
 *
4
 
 * Copyright (C) 2009 Tim Marston <tim@ed.am>
 
4
 * Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
5
5
 *
6
6
 * This file is part of sqlite3cc (hereafter referred to as "this program").
7
 
 * See http://ed.am/dev/sqlite3cc for more information.
8
 
 *
9
 
 * This program is free software: you can redistribute it and/or modify it under
10
 
 * the terms of the GNU Lesser General Public License as published by the Free
11
 
 * Software Foundation, either version 3 of the License, or (at your option) any
12
 
 * later version.
13
 
 *
14
 
 * This program is distributed in the hope that it will be useful, but WITHOUT
15
 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
 
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
17
 
 * details.
 
7
 * See http://www.waxworlds.org/edam/software/sqlite3cc for more information.
 
8
 *
 
9
 * This program is free software: you can redistribute it and/or modify
 
10
 * it under the terms of the GNU Lesser General Public License as published
 
11
 * by the Free Software Foundation, either version 3 of the License, or
 
12
 * (at your option) any later version.
 
13
 *
 
14
 * This program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU Lesser General Public License for more details.
18
18
 *
19
19
 * You should have received a copy of the GNU Lesser General Public License
20
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
50
50
        public:
51
51
 
52
52
                /**
53
 
                 * Constructor that provides a connection upon which to act.
54
 
                 *
 
53
                 * Constructor that provides a connection upon which to act
55
54
                 * @param connection a connection
56
55
                 */
57
56
                explicit basic_transaction(
95
94
 
96
95
 
97
96
/**
98
 
 * A deferred transaction.
 
97
 * A deferred transaction
99
98
 */
100
99
typedef detail::basic_transaction deferred_transaction;
101
100
 
104
103
 
105
104
 
106
105
/**
107
 
 * An immediate transaction.
 
106
 * An immediate transaction
108
107
 */
109
108
class immediate_transaction
110
109
        :
115
114
public:
116
115
 
117
116
        /**
118
 
         * Constructor that provides a connection upon which to act.
119
 
         *
 
117
         * Constructor that provides a connection upon which to act
120
118
         * @param connection a connection
121
119
         */
122
120
        explicit immediate_transaction(
127
125
public:
128
126
 
129
127
        /**
130
 
         * Begin the transaction.
 
128
         * Begin the transaction
131
129
         */
132
130
        virtual void begin();
133
131
 
138
136
 
139
137
 
140
138
/**
141
 
 * An exclusive transaction.
 
139
 * An exclusive transaction
142
140
 */
143
141
class exclusive_transaction
144
142
        :
149
147
public:
150
148
 
151
149
        /**
152
 
         * Constructor that provides a connection upon which to act.
153
 
         *
 
150
         * Constructor that provides a connection upon which to act
154
151
         * @param connection a connection
155
152
         */
156
153
        explicit exclusive_transaction(
183
180
public:
184
181
 
185
182
        /**
186
 
         * Constructor that provides a connection upon which to act.
187
 
         *
 
183
         * Constructor that provides a connection upon which to act
188
184
         * @param connection a connection
189
185
         */
190
186
        explicit recursive_transaction(
195
191
public:
196
192
 
197
193
        /**
198
 
         * Begin the transaction.
 
194
         * Begin the transaction
199
195
         */
200
196
        virtual void begin();
201
197
 
202
198
        /**
203
 
         * Commit the transaction.
 
199
         * Commit the transaction
204
200
         */
205
201
        virtual void commit();
206
202
 
207
203
        /**
208
 
         * Rollback the transaction.
 
204
         * Rollback the transaction
209
205
         */
210
206
        virtual void rollback();
211
207
 
223
219
 
224
220
 
225
221
/**
226
 
 * A scope guard (sentinel) for use with one of the transaction classes to
227
 
 * provide RAII-style transactions.  It defaults to using deferred transactions.
 
222
 * A scope guard (sentinel) for use with one of the transaction
 
223
 * classes to provide RAII-style transactions. It defaults to using
 
224
 * deferred transactions.
228
225
 */
229
226
template< class T = deferred_transaction >
230
227
class transaction_guard
236
233
public:
237
234
 
238
235
        /**
239
 
         * Constructor that provides a connection upon which to act.
240
 
         *
 
236
         * Constructor that provides a connection upon which to act
241
237
         * @param connection a connection
242
238
         */
243
239
        explicit transaction_guard(
244
240
                connection &connection )
245
241
                :
246
242
                _transaction( connection ),
247
 
                _released( true )
 
243
                _released( false )
248
244
        {
249
245
                _transaction.begin();
250
 
                _released = false;
251
246
        }
252
247
 
253
248
        ~transaction_guard()
261
256
public:
262
257
 
263
258
        /**
264
 
         * Begin the transaction. Note that this is done automatically in the
265
 
         * constructor.
266
 
         */
267
 
        void begin()
268
 
        {
269
 
                if( _released ) {
270
 
                        _transaction.begin();
271
 
                        _released = false;
272
 
                }
273
 
        }
274
 
 
275
 
        /**
276
 
         * Commit the transaction.
 
259
         * Commit the transaction
277
260
         */
278
261
        void commit()
279
262
        {
284
267
        }
285
268
 
286
269
        /**
287
 
         * Rollback the transaction. Note that this is done automatically in the
288
 
         * destructor if the transaction hasn't otherwise been completed.
 
270
         * Rollback the transaction early
289
271
         */
290
272
        void rollback()
291
273
        {