1. /*
  2. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  3. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. */
  5. package javax.transaction;
  6. import java.lang.IllegalArgumentException;
  7. import java.lang.IllegalStateException;
  8. import java.lang.SecurityException;
  9. /**
  10. * The TransactionManager interface defines the methods that allow an
  11. * application server to manage transaction boundaries.
  12. */
  13. public interface TransactionManager {
  14. /**
  15. * Create a new transaction and associate it with the current thread.
  16. *
  17. * @exception NotSupportedException Thrown if the thread is already
  18. * associated with a transaction and the Transaction Manager
  19. * implementation does not support nested transactions.
  20. *
  21. * @exception SystemException Thrown if the transaction manager
  22. * encounters an unexpected error condition
  23. *
  24. */
  25. public void begin() throws NotSupportedException, SystemException;
  26. /**
  27. * Complete the transaction associated with the current thread. When this
  28. * method completes, the thread becomes associated with no transaction.
  29. *
  30. * @exception RollbackException Thrown to indicate that
  31. * the transaction has been rolled back rather than committed.
  32. *
  33. * @exception HeuristicMixedException Thrown to indicate that a heuristic
  34. * decision was made and that some relevant updates have been committed
  35. * while others have been rolled back.
  36. *
  37. * @exception HeuristicRollbackException Thrown to indicate that a
  38. * heuristic decision was made and that some relevant updates have been
  39. * rolled back.
  40. *
  41. * @exception SecurityException Thrown to indicate that the thread is
  42. * not allowed to commit the transaction.
  43. *
  44. * @exception IllegalStateException Thrown if the current thread is
  45. * not associated with a transaction.
  46. *
  47. * @exception SystemException Thrown if the transaction manager
  48. * encounters an unexpected error condition
  49. *
  50. */
  51. public void commit() throws RollbackException,
  52. HeuristicMixedException, HeuristicRollbackException, SecurityException,
  53. IllegalStateException, SystemException;
  54. /**
  55. * Obtain the status of the transaction associated with the current thread.
  56. *
  57. * @return The transaction status. If no transaction is associated with
  58. * the current thread, this method returns the Status.NoTransaction
  59. * value.
  60. *
  61. * @exception SystemException Thrown if the transaction manager
  62. * encounters an unexpected error condition
  63. *
  64. */
  65. public int getStatus() throws SystemException;
  66. /**
  67. * Get the transaction object that represents the transaction
  68. * context of the calling thread
  69. *
  70. * @return the Transaction object representing the transaction
  71. * associated with the calling thread.
  72. *
  73. * @exception SystemException Thrown if the transaction manager
  74. * encounters an unexpected error condition
  75. *
  76. */
  77. public Transaction getTransaction() throws SystemException;
  78. /**
  79. * Resume the transaction context association of the calling thread
  80. * with the transaction represented by the supplied Transaction object.
  81. * When this method returns, the calling thread is associated with the
  82. * transaction context specified.
  83. *
  84. * @param tobj The <code>Transaction</code> object that represents the
  85. * transaction to be resumed.
  86. *
  87. * @exception InvalidTransactionException Thrown if the parameter
  88. * transaction object contains an invalid transaction
  89. *
  90. * @exception IllegalStateException Thrown if the thread is already
  91. * associated with another transaction.
  92. *
  93. * @exception SystemException Thrown if the transaction manager
  94. * encounters an unexpected error condition
  95. */
  96. public void resume(Transaction tobj)
  97. throws InvalidTransactionException, IllegalStateException,
  98. SystemException;
  99. /**
  100. * Roll back the transaction associated with the current thread. When this
  101. * method completes, the thread becomes associated with no transaction.
  102. *
  103. * @exception SecurityException Thrown to indicate that the thread is
  104. * not allowed to roll back the transaction.
  105. *
  106. * @exception IllegalStateException Thrown if the current thread is
  107. * not associated with a transaction.
  108. *
  109. * @exception SystemException Thrown if the transaction manager
  110. * encounters an unexpected error condition
  111. *
  112. */
  113. public void rollback() throws IllegalStateException, SecurityException,
  114. SystemException;
  115. /**
  116. * Modify the transaction associated with the current thread such that
  117. * the only possible outcome of the transaction is to roll back the
  118. * transaction.
  119. *
  120. * @exception IllegalStateException Thrown if the current thread is
  121. * not associated with a transaction.
  122. *
  123. * @exception SystemException Thrown if the transaction manager
  124. * encounters an unexpected error condition
  125. *
  126. */
  127. public void setRollbackOnly() throws IllegalStateException, SystemException;
  128. /**
  129. * Modify the value of the timeout value that is associated with the
  130. * transactions started by the current thread with the begin method.
  131. *
  132. * <p> If an application has not called this method, the transaction
  133. * service uses some default value for the transaction timeout.
  134. *
  135. * @param seconds The value of the timeout in seconds. If the value
  136. * is zero, the transaction service restores the default value.
  137. *
  138. * @exception SystemException Thrown if the transaction manager
  139. * encounters an unexpected error condition
  140. *
  141. */
  142. public void setTransactionTimeout(int seconds) throws SystemException;
  143. /**
  144. * Suspend the transaction currently associated with the calling
  145. * thread and return a Transaction object that represents the
  146. * transaction context being suspended. If the calling thread is
  147. * not associated with a transaction, the method returns a null
  148. * object reference. When this method returns, the calling thread
  149. * is associated with no transaction.
  150. *
  151. * @return Transaction object representing the suspended transaction.
  152. *
  153. * @exception SystemException Thrown if the transaction manager
  154. * encounters an unexpected error condition
  155. *
  156. * @exception SystemException Thrown if the transaction manager
  157. * encounters an unexpected error condition
  158. *
  159. */
  160. public Transaction suspend() throws SystemException;
  161. }