コード例 #1
0
 protected StorageOperation(bool atomic, ConnectionSource source = null, IsolationLevel? isolationLevel = null)
 {
     _atomic = atomic;
     if(atomic && isolationLevel.HasValue)
         Context = ConnectionStateManager.AcquireContext(isolationLevel, source);
     else
         Context = ConnectionStateManager.AcquireContext(atomic, source);
     if(Context.OperationCount == 1)
         IsInitiatingOperation = true;
     Depth = Context.OperationCount;
 }
コード例 #2
0
 public AtomicStorageOperation(IsolationLevel? isolationLevel = null, ConnectionSource source = null)
     : base(true, source, isolationLevel)
 {
 }
コード例 #3
0
 /// <summary>
 /// Acquires a OperationContext object for the current thread using the default connection source, optionally
 /// in an atomic context. If an operation using the default connection source is in progress, it will be
 /// subscribed to, otherwise a new one will be created. If the isolation level is specified, it will be used
 /// to start a new transaction, if none exists. If an existing transaction is already active in the current
 /// context, the specified isolation level will be ignored.
 /// </summary>
 /// <param name="atomic">Specifies that a new transaction should be started if no transaction is already active
 /// in the current context. If false, no new transaction will be started.</param>
 /// <param name="source">The connection source to use. If null, the default connection source will be used</param>
 /// <returns>The current operation context</returns>
 internal static OperationContext AcquireContext(bool atomic, ConnectionSource source = null)
 {
     return AcquireContext(DefaultConnectionSource, atomic);
 }
コード例 #4
0
 /// <summary>
 /// Acquires a OperationContext object for the current thread using the default connection source, optionally
 /// in an atomic context. If an operation using the default connection source is in progress, it will be
 /// subscribed to, otherwise a new one will be created. If the isolation level is specified, it will be used
 /// to start a new transaction, if none exists. If an existing transaction is already active in the current
 /// context, the specified isolation level will be ignored.
 /// </summary>
 /// <param name="isolationLevel">The isolationLevel that will be used to create a new transaction, if no
 /// transaction is already active in the current context. If null, no new transaction will be started.</param>
 /// <param name="source">The connection source to use, or null to use the default connection source</param>
 /// <returns>The current operation context</returns>
 internal static OperationContext AcquireContext(IsolationLevel? isolationLevel = null, ConnectionSource source = null)
 {
     return AcquireContext(source ?? DefaultConnectionSource, isolationLevel.HasValue, isolationLevel);
 }
コード例 #5
0
 private static OperationContext AcquireContext(ConnectionSource source, bool atomic, IsolationLevel? isolationLevel = null)
 {
     OperationContext context;
     var hash = source.GetHashForThread();
     // get the existing context for the current thread
     if(!_connections.TryGetValue(Thread.CurrentThread.ManagedThreadId, out context))
     {
         // start a new context
         context = new OperationContext
         {
             Source = source,
             Hash = hash,
         };
         // try and add the new context (should work every time unless there is some kind of unpredictable race condition in play)
         if(!_connections.TryAdd(hash, context))
             context = _connections[hash]; // this line should never be reached, but if it is and it fails, some rethinking of this code is probably in order...
     }
     context.OperationCount++;
     if(atomic)
     {
         if(context.AtomicOperationCount == 0)
             context.Transaction = isolationLevel.HasValue ? context.Connection.BeginTransaction(isolationLevel.Value) : context.Connection.BeginTransaction();
         context.AtomicOperationCount++;
     }
     return context;
 }
コード例 #6
0
 public StorageOperation(ConnectionSource source = null)
     : this(false, source)
 {
 }