1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5 *
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common Development
8 * and Distribution License("CDDL") (collectively, the "License"). You
9 * may not use this file except in compliance with the License. You can obtain
10 * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
11 * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
12 * language governing permissions and limitations under the License.
13 *
14 * When distributing the software, include this License Header Notice in each
15 * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
16 * Sun designates this particular file as subject to the "Classpath" exception
17 * as provided by Sun in the GPL Version 2 section of the License file that
18 * accompanied this code. If applicable, add the following below the License
19 * Header, with the fields enclosed by brackets [] replaced by your own
20 * identifying information: "Portions Copyrighted [year]
21 * [name of copyright owner]"
22 *
23 * Contributor(s):
24 *
25 * If you wish your version of this file to be governed by only the CDDL or
26 * only the GPL Version 2, indicate your decision by adding "[Contributor]
27 * elects to include this software in this distribution under the [CDDL or GPL
28 * Version 2] license." If you don't indicate a single choice of license, a
29 * recipient has the option to distribute your version of this file under
30 * either the CDDL, the GPL Version 2 or to extend the choice of license to
31 * its licensees as provided above. However, if you add GPL Version 2 code
32 * and therefore, elected the GPL Version 2 license, then the option applies
33 * only if the new code is made subject to such option by the copyright
34 * holder.
35 */
36 package javax.ejb;
37
38 import java.rmi.RemoteException;
39
40 /**
41 * <p> The SessionSynchronization interface allows a session Bean instance
42 * to be notified by its container of transaction boundaries.
43 *
44 * <p> An session Bean class is not required to implement this interface.
45 * A session Bean class should implement this interface only if it wishes
46 * to synchronize its state with the transactions.
47 */
48 public interface SessionSynchronization {
49 /**
50 * The afterBegin method notifies a session Bean instance that a new
51 * transaction has started, and that the subsequent business methods on the
52 * instance will be invoked in the context of the transaction.
53 *
54 * <p> The instance can use this method, for example, to read data
55 * from a database and cache the data in the instance fields.
56 *
57 * <p> This method executes in the proper transaction context.
58 *
59 * @exception EJBException Thrown by the method to indicate a failure
60 * caused by a system-level error.
61 *
62 * @exception RemoteException This exception is defined in the method
63 * signature to provide backward compatibility for enterprise beans
64 * written for the EJB 1.0 specification. Enterprise beans written
65 * for the EJB 1.1 and higher specifications should throw the
66 * javax.ejb.EJBException instead of this exception.
67 * Enterprise beans written for the EJB 2.0 and higher specifications
68 * must not throw the java.rmi.RemoteException.
69 */
70 public void afterBegin() throws EJBException, RemoteException;
71
72 /**
73 * The beforeCompletion method notifies a session Bean instance that
74 * a transaction is about to be committed. The instance can use this
75 * method, for example, to write any cached data to a database.
76 *
77 * <p> This method executes in the proper transaction context.
78 *
79 * <p><b>Note:</b> The instance may still cause the container to
80 * rollback the transaction by invoking the setRollbackOnly() method
81 * on the instance context, or by throwing an exception.
82 *
83 * @exception EJBException Thrown by the method to indicate a failure
84 * caused by a system-level error.
85 *
86 * @exception RemoteException This exception is defined in the method
87 * signature to provide backward compatibility for enterprise beans
88 * written for the EJB 1.0 specification. Enterprise beans written
89 * for the EJB 1.1 and higher specification should throw the
90 * javax.ejb.EJBException instead of this exception.
91 * Enterprise beans written for the EJB 2.0 and higher specifications
92 * must not throw the java.rmi.RemoteException.
93 */
94 public void beforeCompletion() throws EJBException, RemoteException;
95
96 /**
97 * The afterCompletion method notifies a session Bean instance that a
98 * transaction commit protocol has completed, and tells the instance
99 * whether the transaction has been committed or rolled back.
100 *
101 * <p> This method executes with no transaction context.
102 *
103 * <p> This method executes with no transaction context.
104 *
105 * @param committed True if the transaction has been committed, false
106 * if is has been rolled back.
107 *
108 * @exception EJBException Thrown by the method to indicate a failure
109 * caused by a system-level error.
110 *
111 * @exception RemoteException This exception is defined in the method
112 * signature to provide backward compatibility for enterprise beans
113 * written for the EJB 1.0 specification. Enterprise beans written
114 * for the EJB 1.1 and higher specification should throw the
115 * javax.ejb.EJBException instead of this exception.
116 * Enterprise beans written for the EJB 2.0 and higher specifications
117 * must not throw the java.rmi.RemoteException.
118 */
119 public void afterCompletion(boolean committed) throws EJBException,
120 RemoteException;
121 }