1. /*
  2. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  3. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. */
  5. package javax.ejb;
  6. import java.rmi.RemoteException;
  7. /**
  8. * <p> The SessionSynchronization interface allows a session Bean instance
  9. * to be notified by its container of transaction boundaries.
  10. *
  11. * <p> An session Bean class is not required to implement this interface.
  12. * A session Bean class should implement this interface only if it wishes
  13. * to synchronize its state with the transactions.
  14. */
  15. public interface SessionSynchronization {
  16. /**
  17. * The afterBegin method notifies a session Bean instance that a new
  18. * transaction has started, and that the subsequent business methods on the
  19. * instance will be invoked in the context of the transaction.
  20. *
  21. * <p> The instance can use this method, for example, to read data
  22. * from a database and cache the data in the instance fields.
  23. *
  24. * <p> This method executes in the proper transaction context.
  25. *
  26. * @exception EJBException Thrown by the method to indicate a failure
  27. * caused by a system-level error.
  28. *
  29. * @exception RemoteException This exception is defined in the method
  30. * signature to provide backward compatibility for enterprise beans
  31. * written for the EJB 1.0 specification. Enterprise beans written
  32. * for the EJB 1.1 and higher specifications should throw the
  33. * javax.ejb.EJBException instead of this exception.
  34. * Enterprise beans written for the EJB 2.0 and higher specifications
  35. * must not throw the java.rmi.RemoteException.
  36. */
  37. public void afterBegin() throws EJBException, RemoteException;
  38. /**
  39. * The beforeCompletion method notifies a session Bean instance that
  40. * a transaction is about to be committed. The instance can use this
  41. * method, for example, to write any cached data to a database.
  42. *
  43. * <p> This method executes in the proper transaction context.
  44. *
  45. * <p><b>Note:</b> The instance may still cause the container to
  46. * rollback the transaction by invoking the setRollbackOnly() method
  47. * on the instance context, or by throwing an exception.
  48. *
  49. * @exception EJBException Thrown by the method to indicate a failure
  50. * caused by a system-level error.
  51. *
  52. * @exception RemoteException This exception is defined in the method
  53. * signature to provide backward compatibility for enterprise beans
  54. * written for the EJB 1.0 specification. Enterprise beans written
  55. * for the EJB 1.1 and higher specification should throw the
  56. * javax.ejb.EJBException instead of this exception.
  57. * Enterprise beans written for the EJB 2.0 and higher specifications
  58. * must not throw the java.rmi.RemoteException.
  59. */
  60. public void beforeCompletion() throws EJBException, RemoteException;
  61. /**
  62. * The afterCompletion method notifies a session Bean instance that a
  63. * transaction commit protocol has completed, and tells the instance
  64. * whether the transaction has been committed or rolled back.
  65. *
  66. * <p> This method executes with no transaction context.
  67. *
  68. * <p> This method executes with no transaction context.
  69. *
  70. * @param committed True if the transaction has been committed, false
  71. * if is has been rolled back.
  72. *
  73. * @exception EJBException Thrown by the method to indicate a failure
  74. * caused by a system-level error.
  75. *
  76. * @exception RemoteException This exception is defined in the method
  77. * signature to provide backward compatibility for enterprise beans
  78. * written for the EJB 1.0 specification. Enterprise beans written
  79. * for the EJB 1.1 and higher specification should throw the
  80. * javax.ejb.EJBException instead of this exception.
  81. * Enterprise beans written for the EJB 2.0 and higher specifications
  82. * must not throw the java.rmi.RemoteException.
  83. */
  84. public void afterCompletion(boolean committed) throws EJBException,
  85. RemoteException;
  86. }