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.6.2.1 2005/12/21 22:29:21 tomdz Exp $
061: */
062: public interface TransactionAware extends Serializable {
063: static final long serialVersionUID = 3690863289834166023L;
064:
065: /**
066: *
067: * beforeCommit will give an object a chance to kill a
068: * transaction before it is committed.
069: * To kill a transaction, throw a new TransactionAbortedException.
070: *
071: */
072: public void beforeCommit()
073: throws org.odmg.TransactionAbortedException;
074:
075: /**
076: *
077: * afterCommit is called only after a successful commit has taken
078: * place.
079: *
080: */
081: public void afterCommit();
082:
083: /**
084: *
085: * beforeAbort is called before a transaction is aborted.
086: *
087: */
088: public void beforeAbort();
089:
090: /**
091: *
092: * afterAbort will be called after a transaction has been aborted.
093: * The values of fields which get persisted will have changed to
094: * what they were at the begining of the transaction. This method
095: * should be overridden to reset any transient or non-persistent
096: * fields.
097: *
098: */
099: public void afterAbort();
100: }
|