juergen 01/10/16 09:58:31
Modified: src/share/org/apache/slide/transaction
SlideTransactionManager.java
Log:
If the commit end with an exception, the following rollback was not able to do a
proper clean-up. If the commit fails a rollback should be issued.
Revision Changes Path
1.6 +94 -90
jakarta-slide/src/share/org/apache/slide/transaction/SlideTransactionManager.java
Index: SlideTransactionManager.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/share/org/apache/slide/transaction/SlideTransactionManager.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SlideTransactionManager.java 2001/10/04 02:48:34 1.5
+++ SlideTransactionManager.java 2001/10/16 16:58:31 1.6
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/share/org/apache/slide/transaction/SlideTransactionManager.java,v
1.5 2001/10/04 02:48:34 remm Exp $
- * $Revision: 1.5 $
- * $Date: 2001/10/04 02:48:34 $
+ * $Header:
/home/cvs/jakarta-slide/src/share/org/apache/slide/transaction/SlideTransactionManager.java,v
1.6 2001/10/16 16:58:31 juergen Exp $
+ * $Revision: 1.6 $
+ * $Date: 2001/10/16 16:58:31 $
*
* ====================================================================
*
@@ -92,70 +92,70 @@
* </ul>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a>
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public final class SlideTransactionManager implements TransactionManager {
-
-
+
+
// -------------------------------------------------------------- Constants
-
-
- protected static final String LOG_CHANNEL =
+
+
+ protected static final String LOG_CHANNEL =
SlideTransactionManager.class.getName();
-
-
+
+
public static final int DEFAULT_TRANSACTION_TIMEOUT = 30;
-
-
+
+
// ------------------------------------------------------------ Constructor
-
-
+
+
// ----------------------------------------------------- Instance Variables
-
-
+
+
/**
* Transaction bindings thread id <-> transaction object.
*/
private Hashtable bindings = new Hashtable();
-
-
+
+
/**
* Transaction bindings thread id <-> transaction timeout.
*/
private Hashtable timeouts = new Hashtable();
-
-
+
+
/**
* Associated logger.
*/
private Logger logger = new SimpleLogger();
-
-
+
+
// ------------------------------------------------------------- Properties
-
-
+
+
// --------------------------------------------------------- Public Methods
-
-
+
+
/**
* Get the logger associated with the transaction manager.
*/
public Logger getLogger() {
return logger;
}
-
-
+
+
/**
* Set the logger of the transaction manager.
*/
public void setLogger(Logger logger) {
this.logger = logger;
}
-
-
+
+
// --------------------------------------------- TransactionManager Methods
-
-
+
+
/**
* Create a new transaction and associate it with the current thread.
*
@@ -167,27 +167,29 @@
*/
public void begin()
throws NotSupportedException, SystemException {
-
+
Transaction currentTransaction = getTransaction();
if (currentTransaction != null)
throw new NotSupportedException();
-
+
currentTransaction = new SlideTransaction(this);
bindings.put(Thread.currentThread(), currentTransaction);
-
+
if (logger.isEnabled(LOG_CHANNEL, Logger.DEBUG)) {
String logMessage = Messages.format
- (SlideTransactionManager.class.getName() + ".begin",
+ (SlideTransactionManager.class.getName() + ".begin",
currentTransaction.toString());
logger.log(logMessage, LOG_CHANNEL, Logger.DEBUG);
}
-
+
}
-
-
+
+
/**
* Complete the transaction associated with the current thread. When this
* method completes, the thread becomes associated with no transaction.
+ * If the commit is terminated with an exception, the rollback should be
+ * called, to do a proper clean-up.
*
* @exception RollbackException Thrown to indicate that the transaction
* has been rolled back rather than committed.
@@ -208,27 +210,29 @@
throws RollbackException, HeuristicMixedException,
HeuristicRollbackException, SecurityException, IllegalStateException,
SystemException {
-
+
Thread currentThread = Thread.currentThread();
- Transaction currentTransaction =
- (Transaction) bindings.remove(currentThread);
+ Transaction currentTransaction =
+ (Transaction) bindings.get(currentThread);
if (currentTransaction == null)
throw new IllegalStateException();
-
+
timeouts.remove(currentThread);
-
+
if (logger.isEnabled(LOG_CHANNEL, Logger.DEBUG)) {
String logMessage = Messages.format
- (SlideTransactionManager.class.getName() + ".commit",
+ (SlideTransactionManager.class.getName() + ".commit",
currentTransaction.toString());
logger.log(logMessage, LOG_CHANNEL, Logger.DEBUG);
}
-
+
currentTransaction.commit();
-
+ bindings.remove(currentThread);
+
+
}
-
-
+
+
/**
* Roll back the transaction associated with the current thread. When
* this method completes, the thread becomes associated with no
@@ -243,25 +247,25 @@
*/
public void rollback()
throws SecurityException, IllegalStateException, SystemException {
-
+
Thread currentThread = Thread.currentThread();
- Transaction currentTransaction =
+ Transaction currentTransaction =
(Transaction) bindings.remove(currentThread);
if (currentTransaction == null)
throw new IllegalStateException();
-
+
timeouts.remove(currentThread);
-
+
String logMessage = Messages.format
- (SlideTransactionManager.class.getName() + ".rollback",
+ (SlideTransactionManager.class.getName() + ".rollback",
currentTransaction.toString());
logger.log(logMessage, LOG_CHANNEL, Logger.INFO);
-
+
currentTransaction.rollback();
-
+
}
-
-
+
+
/**
* Modify the transaction associated with the current thread such that
* the only possible outcome of the transaction is to roll back the
@@ -274,21 +278,21 @@
*/
public void setRollbackOnly()
throws IllegalStateException, SystemException {
-
+
Transaction currentTransaction = getTransaction();
if (currentTransaction == null)
throw new IllegalStateException();
-
+
String logMessage = Messages.format
- (SlideTransactionManager.class.getName() + ".rollbackOnly",
+ (SlideTransactionManager.class.getName() + ".rollbackOnly",
currentTransaction.toString());
logger.log(logMessage, LOG_CHANNEL, Logger.INFO);
-
+
currentTransaction.setRollbackOnly();
-
+
}
-
-
+
+
/**
* Obtain the status of the transaction associated with the current thread.
*
@@ -299,16 +303,16 @@
*/
public int getStatus()
throws SystemException {
-
+
Transaction currentTransaction = getTransaction();
if (currentTransaction == null)
return Status.STATUS_NO_TRANSACTION;
-
+
return currentTransaction.getStatus();
-
+
}
-
-
+
+
/**
* Get the transaction object that represents the transaction context of
* the calling thread.
@@ -322,8 +326,8 @@
throws SystemException {
return (Transaction) bindings.get(Thread.currentThread());
}
-
-
+
+
/**
* Resume the transaction context association of the calling thread with
* the transaction represented by the supplied Transaction object. When
@@ -342,18 +346,18 @@
public void resume(Transaction tobj)
throws InvalidTransactionException, IllegalStateException,
SystemException {
-
+
if (getTransaction() != null)
throw new IllegalStateException();
-
+
if (tobj == null)
throw new InvalidTransactionException();
-
+
bindings.put(Thread.currentThread(), tobj);
-
+
}
-
-
+
+
/**
* Suspend the transaction currently associated with the calling thread
* and return a Transaction object that represents the transaction
@@ -367,20 +371,20 @@
*/
public Transaction suspend()
throws SystemException {
-
+
Transaction currentTransaction = getTransaction();
-
+
if (currentTransaction != null) {
- Thread currentThread = Thread.currentThread();
+ Thread currentThread = Thread.currentThread();
bindings.remove(currentThread);
timeouts.remove(currentThread);
}
-
+
return currentTransaction;
-
+
}
-
-
+
+
/**
* Modify the value of the timeout value that is associated with the
* transactions started by the current thread with the begin method.
@@ -395,10 +399,10 @@
*/
public void setTransactionTimeout(int seconds)
throws SystemException {
-
+
timeouts.put(Thread.currentThread(), new Integer(seconds));
-
+
}
-
-
+
+
}