Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Data/Data/Core
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv28501
Modified Files:
TxScopeTransactionManager.cs
Log Message:
Fix use of Nested Transactions in TxScopeTransactionManager.
Index: TxScopeTransactionManager.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Data/Data/Core/TxScopeTransactionManager.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** TxScopeTransactionManager.cs 8 Aug 2007 20:59:44 -0000 1.2
--- TxScopeTransactionManager.cs 30 Nov 2007 07:55:29 -0000 1.3
***************
*** 32,35 ****
--- 32,37 ----
/// TransactionManager that uses TransactionScope provided by System.Transactions.
/// </summary>
+ /// <author>Mark Pollack (.NET)</author>
+ /// <version>$Id$</version>
public class TxScopeTransactionManager : AbstractPlatformTransactionManager, IInitializingObject
{
***************
*** 39,43 ****
public void AfterPropertiesSet()
{
! // Decide what should be requried for more advanced configurations.
}
--- 41,45 ----
public void AfterPropertiesSet()
{
! // placeholder for more advanced configurations.
}
***************
*** 64,75 ****
DoTxScopeBegin(txObject, definition);
}
- // TODO - may want to catch some exceptions here to map into DAO
- // exception hierarchy.
catch (Exception e)
{
! throw new Spring.Transaction.CannotCreateTransactionException("Promotable Transaction Scope failure on begin", e);
}
}
protected override void DoCommit(DefaultTransactionStatus status)
{
--- 66,87 ----
DoTxScopeBegin(txObject, definition);
}
catch (Exception e)
{
! throw new CannotCreateTransactionException("Transaction Scope failure on begin", e);
}
}
+ protected override object DoSuspend(object transaction)
+ {
+ // Passing the current TransactionScope as the 'suspended resource, even though DoResume has no need to operate
+ // on this object as it is handled internally inside TransactionScope.
+ PromotableTxScopeTransactionObject txMgrStateObject = (PromotableTxScopeTransactionObject) transaction;
+ return txMgrStateObject.TransactionScope;
+ }
+
+ protected override void DoResume(object transaction, object suspendedResources)
+ {
+ }
+
protected override void DoCommit(DefaultTransactionStatus status)
{
***************
*** 81,88 ****
txObject.TransactionScope.Dispose();
}
! catch (Exception e)
{
! //TODO provide more accurate exception mappings.
! throw new Spring.Transaction.TransactionSystemException("Failure on Promotable Transaction Scope Commit", e);
}
}
--- 93,107 ----
txObject.TransactionScope.Dispose();
}
! catch (TransactionAbortedException ex)
{
! throw new UnexpectedRollbackException("Transaction unexpectedly rolled back (maybe due to a timeout)", ex);
! }
! catch (TransactionInDoubtException ex)
! {
! throw new HeuristicCompletionException(TransactionOutcomeState.Unknown, ex);
! }
! catch (Exception ex)
! {
! throw new TransactionSystemException("Failure on Transaction Scope Commit", ex);
}
}
***************
*** 99,107 ****
catch (Exception e)
{
! throw new Spring.Transaction.TransactionSystemException("Failure on Promotable Transaction Scope rollback.", e);
}
}
private void DoTxScopeBegin(PromotableTxScopeTransactionObject transaction,
Spring.Transaction.ITransactionDefinition definition)
--- 118,143 ----
catch (Exception e)
{
! throw new Spring.Transaction.TransactionSystemException("Failure on Transaction Scope rollback.", e);
}
}
+ protected override void DoSetRollbackOnly(DefaultTransactionStatus status)
+ {
+ if (status.Debug)
+ {
+ log.Debug("Setting transaction rollback-only");
+ }
+ try
+ {
+ System.Transactions.Transaction.Current.Rollback();
+ } catch (Exception ex)
+ {
+ throw new TransactionSystemException("Failure on System.Transactions.Transaction.Current.Rollback", ex);
+ }
+ }
+
+
+
private void DoTxScopeBegin(PromotableTxScopeTransactionObject transaction,
Spring.Transaction.ITransactionDefinition definition)
***************
*** 169,173 ****
}
! public class PromotableTxScopeTransactionObject
{
private TransactionScope txScope;
--- 205,209 ----
}
! public class PromotableTxScopeTransactionObject : ISmartTransactionObject
{
private TransactionScope txScope;
***************
*** 179,182 ****
--- 215,234 ----
}
+ public bool RollbackOnly
+ {
+ get {
+ if (System.Transactions.Transaction.Current != null &&
+ System.Transactions.Transaction.Current.TransactionInformation != null &&
+ System.Transactions.Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+
/// <summary>
/// Determines whether a current transaction exists.
|