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 
60 #if defined(ASSERTION_USED)
62  if (ta_open) {
63  LocallyModify<int> keep_checked_for_error(checked_for_error, checked_for_error);
64  error = close(NULp);
65  }
66  else {
67  error = ta_err;
68  }
69 
70  if (error) {
71  fprintf(stderr, "Error while closing transaction (checked_for_error=%i): %s\n", checked_for_error, error);
72  if (!checked_for_error) {
73  gb_assert(0); // you need to manually use TA.close() or check TA.ok() after opening TA
74  }
75  }
76 #else // !ASSERTION_USED
77  if (ta_open) {
78  close(NULp);
79  }
80 #endif
81 }
82 
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:203
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:116
GBDATA * gb_main
Definition: adname.cxx:32