Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
TransactionAware |
|
| 1.0;1 |
1 | package org.apache.ojb.odmg; | |
2 | ||
3 | /* Copyright 2002-2005 The Apache Software Foundation | |
4 | * | |
5 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | * you may not use this file except in compliance with the License. | |
7 | * 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 | ||
18 | import java.io.Serializable; | |
19 | ||
20 | /** | |
21 | * | |
22 | * TransactionAware is an interface that can be implemented | |
23 | * to provide hooks into the Transaction interface provided | |
24 | * by ObJectRelationalBridge. | |
25 | * Only objects which have a write lock acquired on them can | |
26 | * participate in a transaction. | |
27 | * To kill a transaction, implement beforeCommit() and throw | |
28 | * a TransactionAbortedException. This will force the entire | |
29 | * transaction to rollback. | |
30 | * | |
31 | * To rebuild an object after a rollback use the afterAbort() | |
32 | * call. This is a good place to populate transient or other | |
33 | * variables. | |
34 | * | |
35 | * beforeAbort and afterCommit are there for informational | |
36 | * purposes. | |
37 | * | |
38 | * Here are some common ways you can expect this interface | |
39 | * to be called: | |
40 | * | |
41 | * Sucessful commit: | |
42 | * beforeCommit() | |
43 | * afterCommit() | |
44 | * | |
45 | * Transaction Failure (1): | |
46 | * beforeCommit() | |
47 | * beforeAbort() | |
48 | * afterAbort() | |
49 | * | |
50 | * Transaction Failure (2): | |
51 | * beforeAbort() | |
52 | * afterAbort() | |
53 | * | |
54 | * Commits and Aborts aren't directly provided to TransactionAware classes. | |
55 | * The idea is that Transactions are difficult to handle, and most of it | |
56 | * will be handled by ObjectSnapshot. However, you use TransactionAware | |
57 | * to do one of two things, kill a transaction from happening, and clean | |
58 | * up after a rollback. | |
59 | * | |
60 | * @version $Id: TransactionAware.java,v 1.1 2007-08-24 22:17:37 ewestfal Exp $ | |
61 | */ | |
62 | public interface TransactionAware extends Serializable | |
63 | { | |
64 | static final long serialVersionUID = 3690863289834166023L; /** | |
65 | * | |
66 | * beforeCommit will give an object a chance to kill a | |
67 | * transaction before it is committed. | |
68 | * To kill a transaction, throw a new TransactionAbortedException. | |
69 | * | |
70 | */ | |
71 | public void beforeCommit() throws org.odmg.TransactionAbortedException; | |
72 | ||
73 | /** | |
74 | * | |
75 | * afterCommit is called only after a successful commit has taken | |
76 | * place. | |
77 | * | |
78 | */ | |
79 | public void afterCommit(); | |
80 | ||
81 | /** | |
82 | * | |
83 | * beforeAbort is called before a transaction is aborted. | |
84 | * | |
85 | */ | |
86 | public void beforeAbort(); | |
87 | ||
88 | /** | |
89 | * | |
90 | * afterAbort will be called after a transaction has been aborted. | |
91 | * The values of fields which get persisted will have changed to | |
92 | * what they were at the begining of the transaction. This method | |
93 | * should be overridden to reset any transient or non-persistent | |
94 | * fields. | |
95 | * | |
96 | */ | |
97 | public void afterAbort(); | |
98 | } |