2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * $XConsortium: transaction.C /main/5 1996/08/21 15:51:19 drk $
26 * Copyright (c) 1993 HAL Computer Systems International, Ltd.
27 * All rights reserved. Unpublished -- rights reserved under
28 * the Copyright Laws of the United States. USE OF A COPYRIGHT
29 * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
32 * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
33 * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
34 * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
35 * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
38 * RESTRICTED RIGHTS LEGEND
39 * Use, duplication, or disclosure by the Government is subject
40 * to the restrictions as set forth in subparagraph (c)(l)(ii)
41 * of the Rights in Technical Data and Computer Software clause
42 * at DFARS 252.227-7013.
44 * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
51 #include "api/transaction.h"
52 #include "dstr/bset.h"
53 #include "mgrs/misc.h"
55 transaction* g_transac = 0;
57 //////////////////////////////////////
58 // application functions
59 //////////////////////////////////////
60 inline void begin_trans(const void* x)
62 ((page_storage*)x) -> begin_trans();
65 inline void end_trans(const void* x)
67 ((page_storage*)x) -> commit_trans();
70 inline void roll_back(const void* x)
72 ((page_storage*)x) -> roll_back();
75 inline void psync(const void* x)
77 ((page_storage*)x) -> sync();
80 inline void commit_object(const void* x)
82 name_oid_t *y = (name_oid_t*)x;
85 throw(stringException("null pointer"));
87 handler z(y->v_oid, y->v_store);
91 inline void set_updated_false_f(const void* x)
93 name_oid_t *y = (name_oid_t*)x;
95 throw(stringException("null pointer"));
96 handler z(y->v_oid, y->v_store);
97 z -> set_mode(UPDATE, false);
100 //////////////////////////////////
103 //////////////////////////////////
104 transaction::transaction() :
105 v_store_array(), v_updated_objects(oid_storage_eq, oid_storage_ls)
109 transaction::~transaction()
113 void transaction::book(abs_storage* x)
115 if ( v_store_array.member(x) == 0 ) {
116 ((page_storage*)x) -> begin_trans();
117 v_store_array.insert(x);
121 void transaction::book(oid_t& id, abs_storage* x)
123 char _dummy[1]; _dummy[0] = 0;
124 name_oid_t* y = new name_oid_t(_dummy, id, x);
126 if ( v_updated_objects.insert(y) == false )
129 if ( v_store_array.member(x) == 0 ) {
131 debug(cerr, x -> my_path());
132 debug(cerr, x -> my_name());
133 throw(stringException("store is not in transaction mode"));
137 void transaction::begin()
139 v_store_array.apply(begin_trans);
141 //MESSAGE(cerr, "g_tr in transaction.C");
142 //debug(cerr, int(g_transac));
145 void transaction::end()
147 //MESSAGE(cerr, "transaction::end()");
149 v_updated_objects.apply(commit_object);
150 v_store_array.apply(end_trans);
152 v_updated_objects.del_elements(delete_name_oid_rec_f);
155 //MESSAGE(cerr, "transaction::end() done");
158 void transaction::abort()
160 v_updated_objects.del_elements(delete_name_oid_rec_f);
164 void transaction::rollback()
166 v_updated_objects.apply(set_updated_false_f);
167 v_store_array.apply(roll_back);
170 void transaction::sync()
172 v_updated_objects.apply(commit_object);
173 v_store_array.apply(psync);