You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

constant.go 5.4 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package tm
  18. import "github.com/seata/seata-go/pkg/protocol/message"
  19. const (
  20. LAUNCHER GlobalTransactionRole = 0
  21. PARTICIPANT GlobalTransactionRole = 1
  22. )
  23. type (
  24. Propagation int8
  25. GlobalTransactionRole int8
  26. )
  27. type TransactionManager interface {
  28. // GlobalStatusBegin a new global transaction.
  29. Begin(applicationId, transactionServiceGroup, name string, timeout int64) (string, error)
  30. // Global commit.
  31. Commit(xid string) (message.GlobalStatus, error)
  32. //Global rollback.
  33. Rollback(xid string) (message.GlobalStatus, error)
  34. // Get current status of the give transaction.
  35. GetStatus(xid string) (message.GlobalStatus, error)
  36. // Global report.
  37. GlobalReport(xid string, globalStatus message.GlobalStatus) (message.GlobalStatus, error)
  38. }
  39. const (
  40. /**
  41. * The REQUIRED.
  42. * The default propagation.
  43. *
  44. * <p>
  45. * If transaction is existing, execute with current transaction,
  46. * else execute with new transaction.
  47. * </p>
  48. *
  49. * <p>
  50. * The logic is similar to the following code:
  51. * <code><pre>
  52. * if (tx == null) {
  53. * try {
  54. * tx = beginNewTransaction(); // begin new transaction, is not existing
  55. * Object rs = business.execute(); // execute with new transaction
  56. * commitTransaction(tx);
  57. * return rs;
  58. * } catch (Exception ex) {
  59. * rollbackTransaction(tx);
  60. * throw ex;
  61. * }
  62. * } else {
  63. * return business.execute(); // execute with current transaction
  64. * }
  65. * </pre></code>
  66. * </p>
  67. */
  68. REQUIRED = Propagation(0)
  69. /**
  70. * The REQUIRES_NEW.
  71. *
  72. * <p>
  73. * If transaction is existing, suspend it, and then execute business with new transaction.
  74. * </p>
  75. *
  76. * <p>
  77. * The logic is similar to the following code:
  78. * <code><pre>
  79. * try {
  80. * if (tx != null) {
  81. * suspendedResource = suspendTransaction(tx); // suspend current transaction
  82. * }
  83. * try {
  84. * tx = beginNewTransaction(); // begin new transaction
  85. * Object rs = business.execute(); // execute with new transaction
  86. * commitTransaction(tx);
  87. * return rs;
  88. * } catch (Exception ex) {
  89. * rollbackTransaction(tx);
  90. * throw ex;
  91. * }
  92. * } finally {
  93. * if (suspendedResource != null) {
  94. * resumeTransaction(suspendedResource); // resume transaction
  95. * }
  96. * }
  97. * </pre></code>
  98. * </p>
  99. */
  100. REQUIRES_NEW = Propagation(1)
  101. /**
  102. * The NOT_SUPPORTED.
  103. *
  104. * <p>
  105. * If transaction is existing, suspend it, and then execute business without transaction.
  106. * </p>
  107. *
  108. * <p>
  109. * The logic is similar to the following code:
  110. * <code><pre>
  111. * try {
  112. * if (tx != null) {
  113. * suspendedResource = suspendTransaction(tx); // suspend current transaction
  114. * }
  115. * return business.execute(); // execute without transaction
  116. * } finally {
  117. * if (suspendedResource != null) {
  118. * resumeTransaction(suspendedResource); // resume transaction
  119. * }
  120. * }
  121. * </pre></code>
  122. * </p>
  123. */
  124. NOT_SUPPORTED = Propagation(2)
  125. /**
  126. * The SUPPORTS.
  127. *
  128. * <p>
  129. * If transaction is not existing, execute without global transaction,
  130. * else execute business with current transaction.
  131. * </p>
  132. *
  133. * <p>
  134. * The logic is similar to the following code:
  135. * <code><pre>
  136. * if (tx != null) {
  137. * return business.execute(); // execute with current transaction
  138. * } else {
  139. * return business.execute(); // execute without transaction
  140. * }
  141. * </pre></code>
  142. * </p>
  143. */
  144. SUPPORTS = Propagation(3)
  145. /**
  146. * The NEVER.
  147. *
  148. * <p>
  149. * If transaction is existing, throw exception,
  150. * else execute business without transaction.
  151. * </p>
  152. *
  153. * <p>
  154. * The logic is similar to the following code:
  155. * <code><pre>
  156. * if (tx != null) {
  157. * throw new TransactionException("existing transaction");
  158. * }
  159. * return business.execute(); // execute without transaction
  160. * </pre></code>
  161. * </p>
  162. */
  163. NEVER = Propagation(4)
  164. /**
  165. * The MANDATORY.
  166. *
  167. * <p>
  168. * If transaction is not existing, throw exception,
  169. * else execute business with current transaction.
  170. * </p>
  171. *
  172. * <p>
  173. * The logic is similar to the following code:
  174. * <code><pre>
  175. * if (tx == null) {
  176. * throw new TransactionException("not existing transaction");
  177. * }
  178. * return business.execute(); // execute with current transaction
  179. * </pre></code>
  180. * </p>
  181. */
  182. MANDATORY = Propagation(5)
  183. )