Disable all code related to libXp
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / api / transaction.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /*
24  * $XConsortium: transaction.C /main/5 1996/08/21 15:51:19 drk $
25  *
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
30  * OR DISCLOSURE.
31  * 
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
36  * INTERNATIONAL, LTD.
37  * 
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.
43  *
44  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
45  *                  1315 Dell Avenue
46  *                  Campbell, CA  95008
47  * 
48  */
49
50
51 #include "api/transaction.h"
52 #include "dstr/bset.h"
53 #include "mgrs/misc.h"
54
55 transaction* g_transac = 0;
56
57 //////////////////////////////////////
58 // application functions
59 //////////////////////////////////////
60 inline void begin_trans(const void* x) 
61 {
62    ((page_storage*)x) -> begin_trans();
63 }
64
65 inline void end_trans(const void* x) 
66 {
67    ((page_storage*)x) -> commit_trans();
68 }
69
70 inline void roll_back(const void* x) 
71 {
72    ((page_storage*)x) -> roll_back();
73 }
74
75 inline void psync(const void* x) 
76 {
77    ((page_storage*)x) -> sync();
78 }
79
80 inline void commit_object(const void* x)
81 {
82    name_oid_t *y = (name_oid_t*)x;
83
84    if (y==0)
85       throw(stringException("null pointer"));
86
87    handler z(y->v_oid, y->v_store);
88    z.commit();
89 }
90
91 inline void set_updated_false_f(const void* x)
92 {
93    name_oid_t *y = (name_oid_t*)x;
94    if (y==0)
95       throw(stringException("null pointer"));
96    handler z(y->v_oid, y->v_store);
97    z -> set_mode(UPDATE, false);
98 }
99
100 //////////////////////////////////
101 //
102 //
103 //////////////////////////////////
104 transaction::transaction() :
105    v_store_array(), v_updated_objects(oid_storage_eq, oid_storage_ls)
106 {
107 }
108
109 transaction::~transaction() 
110 {
111 }
112
113 void transaction::book(abs_storage* x)
114 {
115    if ( v_store_array.member(x) == 0 ) {
116       ((page_storage*)x) -> begin_trans();
117       v_store_array.insert(x);
118    }
119 }
120
121 void transaction::book(oid_t& id, abs_storage* x)
122 {
123    char _dummy[1]; _dummy[0] = 0;
124    name_oid_t* y = new name_oid_t(_dummy, id, x);
125
126    if ( v_updated_objects.insert(y) == false )
127       delete y;
128
129    if ( v_store_array.member(x) == 0 ) {
130       debug(cerr, id);
131       debug(cerr, x -> my_path());
132       debug(cerr, x -> my_name());
133       throw(stringException("store is not in transaction mode"));
134    }
135 }
136
137 void transaction::begin()
138 {
139    v_store_array.apply(begin_trans);
140    g_transac = this;
141 //MESSAGE(cerr, "g_tr in transaction.C");
142 //debug(cerr, int(g_transac));
143 }
144
145 void transaction::end()
146 {
147 //MESSAGE(cerr, "transaction::end()");
148
149    v_updated_objects.apply(commit_object);
150    v_store_array.apply(end_trans);
151
152    v_updated_objects.del_elements(delete_name_oid_rec_f);
153
154    g_transac = 0;
155 //MESSAGE(cerr, "transaction::end() done");
156 }
157
158 void transaction::abort()
159 {
160    v_updated_objects.del_elements(delete_name_oid_rec_f);
161    g_transac = 0;
162 }
163
164 void transaction::rollback()
165 {
166    v_updated_objects.apply(set_updated_false_f);
167    v_store_array.apply(roll_back);
168 }
169
170 void transaction::sync()
171 {
172    v_updated_objects.apply(commit_object);
173    v_store_array.apply(psync);
174
175    g_transac = 0;
176 }
177