001 package org.apache.ojb.odmg;
002
003 /* Copyright 2002-2005 The Apache Software Foundation
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 import java.io.Serializable;
019
020 /**
021 *
022 * TransactionAware is an interface that can be implemented
023 * to provide hooks into the Transaction interface provided
024 * by ObJectRelationalBridge.
025 * Only objects which have a write lock acquired on them can
026 * participate in a transaction.
027 * To kill a transaction, implement beforeCommit() and throw
028 * a TransactionAbortedException. This will force the entire
029 * transaction to rollback.
030 *
031 * To rebuild an object after a rollback use the afterAbort()
032 * call. This is a good place to populate transient or other
033 * variables.
034 *
035 * beforeAbort and afterCommit are there for informational
036 * purposes.
037 *
038 * Here are some common ways you can expect this interface
039 * to be called:
040 *
041 * Sucessful commit:
042 * beforeCommit()
043 * afterCommit()
044 *
045 * Transaction Failure (1):
046 * beforeCommit()
047 * beforeAbort()
048 * afterAbort()
049 *
050 * Transaction Failure (2):
051 * beforeAbort()
052 * afterAbort()
053 *
054 * Commits and Aborts aren't directly provided to TransactionAware classes.
055 * The idea is that Transactions are difficult to handle, and most of it
056 * will be handled by ObjectSnapshot. However, you use TransactionAware
057 * to do one of two things, kill a transaction from happening, and clean
058 * up after a rollback.
059 *
060 * @version $Id: TransactionAware.java,v 1.1 2007-08-24 22:17:37 ewestfal Exp $
061 */
062 public interface TransactionAware extends Serializable
063 {
064 static final long serialVersionUID = 3690863289834166023L; /**
065 *
066 * beforeCommit will give an object a chance to kill a
067 * transaction before it is committed.
068 * To kill a transaction, throw a new TransactionAbortedException.
069 *
070 */
071 public void beforeCommit() throws org.odmg.TransactionAbortedException;
072
073 /**
074 *
075 * afterCommit is called only after a successful commit has taken
076 * place.
077 *
078 */
079 public void afterCommit();
080
081 /**
082 *
083 * beforeAbort is called before a transaction is aborted.
084 *
085 */
086 public void beforeAbort();
087
088 /**
089 *
090 * afterAbort will be called after a transaction has been aborted.
091 * The values of fields which get persisted will have changed to
092 * what they were at the begining of the transaction. This method
093 * should be overridden to reset any transient or non-persistent
094 * fields.
095 *
096 */
097 public void afterAbort();
098 }