KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > transaction > support > TransactionSynchronization


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.transaction.support;
18
19 /**
20  * Interface for transaction synchronization callbacks.
21  * Supported by AbstractPlatformTransactionManager.
22  *
23  * <p>TransactionSynchronization implementations can implement the Ordered interface
24  * to influence their execution order. A synchronization that does not implement the
25  * Ordered interface is appended to the end of the synchronization chain.
26  *
27  * <p>System synchronizations performed by Spring itself use specific order values,
28  * allowing for fine-grained interaction with their execution order (if necessary).
29  *
30  * @author Juergen Hoeller
31  * @since 02.06.2003
32  * @see TransactionSynchronizationManager
33  * @see AbstractPlatformTransactionManager
34  * @see org.springframework.jdbc.datasource.DataSourceUtils#CONNECTION_SYNCHRONIZATION_ORDER
35  * @see org.springframework.orm.hibernate.SessionFactoryUtils#SESSION_SYNCHRONIZATION_ORDER
36  */

37 public interface TransactionSynchronization {
38
39     /** Completion status in case of proper commit */
40     int STATUS_COMMITTED = 0;
41
42     /** Completion status in case of proper rollback */
43     int STATUS_ROLLED_BACK = 1;
44
45     /** Completion status in case of heuristic mixed completion or system errors */
46     int STATUS_UNKNOWN = 2;
47     
48
49     /**
50      * Suspend this synchronization.
51      * Supposed to unbind resources from TransactionSynchronizationManager if managing any.
52      * @see TransactionSynchronizationManager#unbindResource
53      */

54     void suspend();
55
56     /**
57      * Resume this synchronization.
58      * Supposed to rebind resources to TransactionSynchronizationManager if managing any.
59      * @see TransactionSynchronizationManager#bindResource
60      */

61     void resume();
62
63     /**
64      * Invoked before transaction commit (before "beforeCompletion").
65      * Can e.g. flush transactional O/R Mapping sessions to the database.
66      * <p>This callback does <i>not</i> mean that the transaction will actually be committed.
67      * A rollback decision can still occur after this method has been called. This callback
68      * is rather meant to perform work that's only relevant if a commit still has a chance
69      * to happen, such as flushing SQL statements to the database.
70      * <p>Note that exceptions will get propagated to the commit caller and cause a
71      * rollback of the transaction.
72      * @param readOnly whether the transaction is defined as read-only transaction
73      * @throws RuntimeException in case of errors; will be <b>propagated to the caller</b>
74      * (note: do not throw TransactionException subclasses here!)
75      * @see #beforeCompletion
76      */

77     void beforeCommit(boolean readOnly);
78
79     /**
80      * Invoked before transaction commit/rollback.
81      * Can perform resource cleanup <i>before</i> transaction completion.
82      * <p>This method will be invoked after <code>beforeCommit</code>, even when
83      * <code>beforeCommit</code> threw an exception. This callback allows for
84      * closing resources before transaction completion, for any outcome.
85      * @throws RuntimeException in case of errors; will be <b>logged but not propagated</b>
86      * (note: do not throw TransactionException subclasses here!)
87      * @see #beforeCommit
88      * @see #afterCompletion
89      */

90     void beforeCompletion();
91
92     /**
93      * Invoked after transaction commit. Can perform further operations right
94      * <i>after</i> the main transaction has <i>successfully</i> committed.
95      * <p>Can e.g. commit further operations that are supposed to follow on a successful
96      * commit of the main transaction, like confirmation messages or emails.
97      * <p><b>NOTE:</b> The transaction will have been committed already, but the
98      * transactional resources might still be active and accessible. As a consequence,
99      * any data access code triggered at this point will still "participate" in the
100      * original transaction, allowing to perform some cleanup (with no commit following
101      * anymore!), unless it explicitly declares that it needs to run in a separate
102      * transaction. Hence: <b>Use <code>PROPAGATION_REQUIRES_NEW</code> for any
103      * transactional operation that is called from here.</b>
104      * @throws RuntimeException in case of errors; will be <b>propagated to the caller</b>
105      * (note: do not throw TransactionException subclasses here!)
106      */

107     void afterCommit();
108
109     /**
110      * Invoked after transaction commit/rollback.
111      * Can perform resource cleanup <i>after</i> transaction completion.
112      * <p><b>NOTE:</b> The transaction will have been committed or rolled back already,
113      * but the transactional resources might still be active and accessible. As a
114      * consequence, any data access code triggered at this point will still "participate"
115      * in the original transaction, allowing to perform some cleanup (with no commit
116      * following anymore!), unless it explicitly declares that it needs to run in a
117      * separate transaction. Hence: <b>Use <code>PROPAGATION_REQUIRES_NEW</code>
118      * for any transactional operation that is called from here.</b>
119      * @param status completion status according to the <code>STATUS_*</code> constants
120      * @throws RuntimeException in case of errors; will be <b>logged but not propagated</b>
121      * (note: do not throw TransactionException subclasses here!)
122      * @see #STATUS_COMMITTED
123      * @see #STATUS_ROLLED_BACK
124      * @see #STATUS_UNKNOWN
125      * @see #beforeCompletion
126      */

127     void afterCompletion(int status);
128
129 }
130
Popular Tags