/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:46:27 UTC
  • Revision ID: edam@waxworlds.org-20120123134627-i6hi9aftfvwgp8vw
updated autotols stuff

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 (the default)
99
98
 */
100
 
typedef detail::basic_transaction deferred_transaction;
 
99
typedef detail::basic_transaction deferred_tranaction;
101
100
 
102
101
 
103
102
////////////////////////////////////////////////////////////////////////////////
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
 
224
220
 
225
221
/**
226
222
 * A scope guard (sentinel) for use with one of the transaction classes to
227
 
 * provide RAII-style transactions.  It defaults to using deferred transactions.
 
223
 * provide RIAA-style transactions.
228
224
 */
229
 
template< class T = deferred_transaction >
 
225
template< class T = deferred_tranaction >
230
226
class transaction_guard
231
227
        :
232
228
        private boost::noncopyable
236
232
public:
237
233
 
238
234
        /**
239
 
         * Constructor that provides a connection upon which to act.
240
 
         *
 
235
         * Constructor that provides a connection upon which to act
241
236
         * @param connection a connection
242
237
         */
243
238
        explicit transaction_guard(
244
239
                connection &connection )
245
240
                :
246
241
                _transaction( connection ),
247
 
                _released( true )
 
242
                _released( false )
248
243
        {
249
244
                _transaction.begin();
250
 
                _released = false;
251
245
        }
252
246
 
253
247
        ~transaction_guard()
261
255
public:
262
256
 
263
257
        /**
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.
 
258
         * Commit the transaction
277
259
         */
278
260
        void commit()
279
261
        {
284
266
        }
285
267
 
286
268
        /**
287
 
         * Rollback the transaction. Note that this is done automatically in the
288
 
         * destructor if the transaction hasn't otherwise been completed.
 
269
         * Rollback the transaction early
289
270
         */
290
271
        void rollback()
291
272
        {