ARB
arbdbpp.cxx
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : arbdbpp.cxx //
4 // Purpose : //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // =============================================================== //
10 
11 #include "gb_local.h"
12 
13 void GB_transaction::init(GBDATA *gb_main, bool initial) {
14  ta_main = gb_main;
15  ta_open = false;
16  ta_err = NULp;
17 #if defined(ASSERTION_USED)
18  checked_for_error = 0;
19 #endif
20 
21  if (ta_main) {
22  ta_err = initial ? GB_begin_transaction(ta_main) : GB_push_transaction(ta_main);
23  if (!ta_err) {
24  ta_open = true;
25  }
26  }
27  else {
28  ta_err = "NULp-Transaction";
29  }
30 }
31 
33  return close(error.deliver());
34 }
36  // abort transaction if error is set
37 
38  if (error) {
39  if (ta_err) {
40  ta_err = GBS_global_string("%s\n(previous error: %s)", error, ta_err);
41  }
42  else {
43  ta_err = error;
44  }
45  }
46 
47  // @@@ check for exported error here (when GB_export_error gets redesigned)
48 
49  if (ta_open) {
50  ta_err = GB_end_transaction(ta_main, ta_err);
51  ta_open = false;
52  }
53 
54  CFE(2);
55 
56  return ta_err;
57 }
58 
61  if (ta_open) {
62 #if defined(ASSERTION_USED)
63  LocallyModify<int> keep_checked_for_error(checked_for_error, checked_for_error);
64 #endif
65  error = close(NULp);
66  }
67  else {
68  error = ta_err;
69  }
70 
71 #if defined(ASSERTION_USED)
72  if (error) {
73  fprintf(stderr, "Error while closing transaction (checked_for_error=%i): %s\n", checked_for_error, error);
74  if (!checked_for_error) {
75  gb_assert(0); // you need to manually use TA.close() or check TA.ok() after opening TA
76  }
77  }
78 #endif
79 }
80 
GB_ERROR GB_begin_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2528
GB_ERROR GB_end_transaction(GBDATA *gbd, GB_ERROR error)
Definition: arbdb.cxx:2561
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:202
GB_ERROR GB_push_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2494
GB_ERROR deliver() const
Definition: arb_error.h:116
static void error(const char *msg)
Definition: mkptypes.cxx:96
#define gb_assert(cond)
Definition: arbdbt.h:11
GB_ERROR close(GB_ERROR error)
Definition: arbdbpp.cxx:35
#define NULp
Definition: cxxforward.h:114
GBDATA * gb_main
Definition: adname.cxx:33