Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Data/Transaction/Support
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv19252
Modified Files:
TransactionSynchronizationManager.cs
Log Message:
SPRNET-486 - Provide better logging information in TransactionSynchronizationManager to identify ConnectionHolder, DbProvider and thread name
Index: TransactionSynchronizationManager.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Data/Transaction/Support/TransactionSynchronizationManager.cs,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** TransactionSynchronizationManager.cs 16 Aug 2007 05:41:03 -0000 1.17
--- TransactionSynchronizationManager.cs 7 Sep 2007 02:47:00 -0000 1.18
***************
*** 22,25 ****
--- 22,26 ----
using System.Collections;
using System.Data;
+ using System.Globalization;
using System.Threading;
using Spring.Core;
***************
*** 74,80 ****
#endregion
! private static readonly string SyncsDataSlotName = "Spring.Transactions:syncList";
! private static readonly string ResourcesDataSlotName = "Spring.Transactions:resources";
private static readonly string currentTxReadOnlyDataSlotName = "Spring.Transactions:currentTxReadOnly";
--- 75,82 ----
#endregion
! #region Fields
! private static readonly string syncsDataSlotName = "Spring.Transactions:syncList";
! private static readonly string resourcesDataSlotName = "Spring.Transactions:resources";
private static readonly string currentTxReadOnlyDataSlotName = "Spring.Transactions:currentTxReadOnly";
***************
*** 87,91 ****
private static IComparer syncComparer = new OrderComparator();
!
#region Management of transaction-associated resource handles
--- 89,94 ----
private static IComparer syncComparer = new OrderComparator();
!
! #endregion
#region Management of transaction-associated resource handles
***************
*** 102,106 ****
get
{
! IDictionary resources = LogicalThreadContext.GetData(ResourcesDataSlotName) as IDictionary;
if (resources != null)
{
--- 105,109 ----
get
{
! IDictionary resources = LogicalThreadContext.GetData(resourcesDataSlotName) as IDictionary;
if (resources != null)
{
***************
*** 134,138 ****
{
AssertUtils.ArgumentNotNull(key, "Key must not be null");
! IDictionary resources = LogicalThreadContext.GetData(ResourcesDataSlotName) as IDictionary;
if (resources == null)
{
--- 137,141 ----
{
AssertUtils.ArgumentNotNull(key, "Key must not be null");
! IDictionary resources = LogicalThreadContext.GetData(resourcesDataSlotName) as IDictionary;
if (resources == null)
{
***************
*** 145,152 ****
}
object val = resources[key];
if (val != null && LOG.IsDebugEnabled)
{
! LOG.Debug("Retrieved value [" + val + "] for key [" + key + "] bound to thread [" +
! Thread.CurrentThread.Name + "]");
}
return val;
--- 148,156 ----
}
object val = resources[key];
+
if (val != null && LOG.IsDebugEnabled)
{
! LOG.Debug("Retrieved value [" + Describe(val) + "] for key [" + Describe(key) + "] bound to thread [" +
! SystemUtils.ThreadId + "]");
}
return val;
***************
*** 163,183 ****
AssertUtils.ArgumentNotNull(value, "Transactional resource to bind to thread local storage must not be null" );
! IDictionary resources = LogicalThreadContext.GetData(ResourcesDataSlotName) as IDictionary;
//Set thread local resource storage if not found
if (resources == null)
{
resources = new Hashtable();
! LogicalThreadContext.SetData(ResourcesDataSlotName, resources);
}
if (resources.Contains(key))
{
throw new InvalidOperationException("Already value [" + resources[key] + "] for key [" + key +
! "] bound to thread [" + Thread.CurrentThread.Name + "]");
}
resources.Add(key, value);
if (LOG.IsDebugEnabled)
{
! LOG.Debug("Bound value [" + value + "] for key [" + key + "] to thread [" +
! Thread.CurrentThread.Name + "]");
}
}
--- 167,187 ----
AssertUtils.ArgumentNotNull(value, "Transactional resource to bind to thread local storage must not be null" );
! IDictionary resources = LogicalThreadContext.GetData(resourcesDataSlotName) as IDictionary;
//Set thread local resource storage if not found
if (resources == null)
{
resources = new Hashtable();
! LogicalThreadContext.SetData(resourcesDataSlotName, resources);
}
if (resources.Contains(key))
{
throw new InvalidOperationException("Already value [" + resources[key] + "] for key [" + key +
! "] bound to thread [" + SystemUtils.ThreadId + "]");
}
resources.Add(key, value);
if (LOG.IsDebugEnabled)
{
! LOG.Debug("Bound value [" + Describe(value) + "] for key [" + Describe(key) + "] to thread [" +
! SystemUtils.ThreadId + "]");
}
}
***************
*** 194,202 ****
AssertUtils.ArgumentNotNull(key, "Key must not be null");
! IDictionary resources = LogicalThreadContext.GetData(ResourcesDataSlotName) as IDictionary;
if (resources == null || !resources.Contains(key))
{
throw new InvalidOperationException("No value for key [" + key + "] bound to thread [" +
! Thread.CurrentThread.Name + "]");
}
Object val = resources[key];
--- 198,206 ----
AssertUtils.ArgumentNotNull(key, "Key must not be null");
! IDictionary resources = LogicalThreadContext.GetData(resourcesDataSlotName) as IDictionary;
if (resources == null || !resources.Contains(key))
{
throw new InvalidOperationException("No value for key [" + key + "] bound to thread [" +
! SystemUtils.ThreadId + "]");
}
Object val = resources[key];
***************
*** 204,213 ****
if (resources.Count == 0)
{
! LogicalThreadContext.FreeNamedDataSlot(ResourcesDataSlotName);
}
if (LOG.IsDebugEnabled)
{
! LOG.Debug("Removed value [" + val + "] for key [" + key + "] from thread [" +
! Thread.CurrentThread.Name + "]");
}
return val;
--- 208,217 ----
if (resources.Count == 0)
{
! LogicalThreadContext.FreeNamedDataSlot(resourcesDataSlotName);
}
if (LOG.IsDebugEnabled)
{
! LOG.Debug("Removed value [" + Describe(val) + "] for key [" + Describe(key) + "] from thread [" +
! SystemUtils.ThreadId + "]");
}
return val;
***************
*** 216,260 ****
#endregion
! /// <summary>
! /// Return an unmodifiable list of all registered synchronizations
! /// for the current thread.
! /// </summary>
! /// <returns>
! /// A list of <see cref="Spring.Transaction.Support.ITransactionSynchronization"/>
! /// instances.
! /// </returns>
! /// <exception cref="System.InvalidOperationException">
! /// If synchronization is not active.
! /// </exception>
! public static IList Synchronizations
! {
! get
! {
! if ( ! SynchronizationActive )
! {
! throw new InvalidOperationException( "Transaction synchronization is not active" );
! }
! ArrayList syncs = LogicalThreadContext.GetData(SyncsDataSlotName) as ArrayList;
! if (syncs != null)
! {
! // Sort lazily here, not in registerSynchronization.
! object root = syncs.SyncRoot;
! lock (root)
! {
! syncs.Sort(syncComparer);
! }
! // Return unmodifiable snapshot, to avoid exceptions
! // while iterating and invoking synchronization callbacks that in turn
! // might register further synchronizations.
! return ArrayList.ReadOnly(syncs);
! }
! else
! {
! return ArrayList.ReadOnly(new ArrayList());
! }
! }
! }
!
! /// <summary>
/// Activate transaction synchronization for the current thread.
/// </summary>
--- 220,224 ----
#endregion
! /// <summary>
/// Activate transaction synchronization for the current thread.
/// </summary>
***************
*** 271,277 ****
throw new InvalidOperationException( "Cannot activate transaction synchronization - already active" );
}
! LOG.Debug("Initializing transaction synchronization");
ArrayList syncs = new ArrayList();
! LogicalThreadContext.SetData(SyncsDataSlotName, syncs);
}
--- 235,244 ----
throw new InvalidOperationException( "Cannot activate transaction synchronization - already active" );
}
! if (LOG.IsDebugEnabled)
! {
! LOG.Debug("Initializing transaction synchronization");
! }
ArrayList syncs = new ArrayList();
! LogicalThreadContext.SetData(syncsDataSlotName, syncs);
}
***************
*** 291,296 ****
throw new InvalidOperationException( "Cannot deactivate transaction synchronization - not active" );
}
! LOG.Debug("Clearing transaction synchronization");
! LogicalThreadContext.FreeNamedDataSlot(SyncsDataSlotName);
}
--- 258,266 ----
throw new InvalidOperationException( "Cannot deactivate transaction synchronization - not active" );
}
! if (LOG.IsDebugEnabled)
! {
! LOG.Debug("Clearing transaction synchronization");
! }
! LogicalThreadContext.FreeNamedDataSlot(syncsDataSlotName);
}
***************
*** 324,328 ****
throw new InvalidOperationException( "Transaction synchronization is not active" );
}
! ArrayList syncs = LogicalThreadContext.GetData(SyncsDataSlotName) as ArrayList;
if (syncs != null)
{
--- 294,298 ----
throw new InvalidOperationException( "Transaction synchronization is not active" );
}
! ArrayList syncs = LogicalThreadContext.GetData(syncsDataSlotName) as ArrayList;
if (syncs != null)
{
***************
*** 333,339 ****
}
}
! }
! /// <summary>
/// Return if transaction synchronization is active for the current thread.
/// </summary>
--- 303,356 ----
}
}
! }
! private static string Describe(object obj)
! {
! return obj == null ? "" : obj + "@" + obj.GetHashCode().ToString("X");
! }
!
! #region Properties
!
! /// <summary>
! /// Return an unmodifiable list of all registered synchronizations
! /// for the current thread.
! /// </summary>
! /// <returns>
! /// A list of <see cref="Spring.Transaction.Support.ITransactionSynchronization"/>
! /// instances.
! /// </returns>
! /// <exception cref="System.InvalidOperationException">
! /// If synchronization is not active.
! /// </exception>
! public static IList Synchronizations
! {
! get
! {
! if ( ! SynchronizationActive )
! {
! throw new InvalidOperationException( "Transaction synchronization is not active" );
! }
! ArrayList syncs = LogicalThreadContext.GetData(syncsDataSlotName) as ArrayList;
! if (syncs != null)
! {
! // Sort lazily here, not in registerSynchronization.
! object root = syncs.SyncRoot;
! lock (root)
! {
! syncs.Sort(syncComparer);
! }
! // Return unmodifiable snapshot, to avoid exceptions
! // while iterating and invoking synchronization callbacks that in turn
! // might register further synchronizations.
! return ArrayList.ReadOnly(syncs);
! }
! else
! {
! return ArrayList.ReadOnly(new ArrayList());
! }
! }
! }
!
! /// <summary>
/// Return if transaction synchronization is active for the current thread.
/// </summary>
***************
*** 347,351 ****
get
{
! IList syncs = LogicalThreadContext.GetData(SyncsDataSlotName) as IList;
return syncs != null;
}
--- 364,368 ----
get
{
! IList syncs = LogicalThreadContext.GetData(syncsDataSlotName) as IList;
return syncs != null;
}
***************
*** 460,463 ****
}
}
! }
}
--- 477,481 ----
}
}
! #endregion
! }
}
|