transaction.C 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 libraries 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. #include "api/transaction.h"
  50. #include "dstr/bset.h"
  51. #include "mgrs/misc.h"
  52. transaction* g_transac = 0;
  53. //////////////////////////////////////
  54. // application functions
  55. //////////////////////////////////////
  56. inline void begin_trans(const void* x)
  57. {
  58. ((page_storage*)x) -> begin_trans();
  59. }
  60. inline void end_trans(const void* x)
  61. {
  62. ((page_storage*)x) -> commit_trans();
  63. }
  64. inline void roll_back(const void* x)
  65. {
  66. ((page_storage*)x) -> roll_back();
  67. }
  68. inline void psync(const void* x)
  69. {
  70. ((page_storage*)x) -> sync();
  71. }
  72. inline void commit_object(const void* x)
  73. {
  74. name_oid_t *y = (name_oid_t*)x;
  75. if (y==0)
  76. throw(stringException("null pointer"));
  77. handler z(y->v_oid, y->v_store);
  78. z.commit();
  79. }
  80. inline void set_updated_false_f(const void* x)
  81. {
  82. name_oid_t *y = (name_oid_t*)x;
  83. if (y==0)
  84. throw(stringException("null pointer"));
  85. handler z(y->v_oid, y->v_store);
  86. z -> set_mode(UPDATE, false);
  87. }
  88. //////////////////////////////////
  89. //
  90. //
  91. //////////////////////////////////
  92. transaction::transaction() :
  93. v_store_array(), v_updated_objects(oid_storage_eq, oid_storage_ls)
  94. {
  95. }
  96. transaction::~transaction()
  97. {
  98. }
  99. void transaction::book(abs_storage* x)
  100. {
  101. if ( v_store_array.member(x) == 0 ) {
  102. ((page_storage*)x) -> begin_trans();
  103. v_store_array.insert(x);
  104. }
  105. }
  106. void transaction::book(oid_t& id, abs_storage* x)
  107. {
  108. char _dummy[1]; _dummy[0] = 0;
  109. name_oid_t* y = new name_oid_t(_dummy, id, x);
  110. if ( v_updated_objects.insert(y) == false )
  111. delete y;
  112. if ( v_store_array.member(x) == 0 ) {
  113. debug(cerr, id);
  114. debug(cerr, x -> my_path());
  115. debug(cerr, x -> my_name());
  116. throw(stringException("store is not in transaction mode"));
  117. }
  118. }
  119. void transaction::begin()
  120. {
  121. v_store_array.apply(begin_trans);
  122. g_transac = this;
  123. //MESSAGE(cerr, "g_tr in transaction.C");
  124. //debug(cerr, int(g_transac));
  125. }
  126. void transaction::end()
  127. {
  128. //MESSAGE(cerr, "transaction::end()");
  129. v_updated_objects.apply(commit_object);
  130. v_store_array.apply(end_trans);
  131. v_updated_objects.del_elements(delete_name_oid_rec_f);
  132. g_transac = 0;
  133. //MESSAGE(cerr, "transaction::end() done");
  134. }
  135. void transaction::abort()
  136. {
  137. v_updated_objects.del_elements(delete_name_oid_rec_f);
  138. g_transac = 0;
  139. }
  140. void transaction::rollback()
  141. {
  142. v_updated_objects.apply(set_updated_false_f);
  143. v_store_array.apply(roll_back);
  144. }
  145. void transaction::sync()
  146. {
  147. v_updated_objects.apply(commit_object);
  148. v_store_array.apply(psync);
  149. g_transac = 0;
  150. }