Beispiel #1
0
 public Snapshotted([NotNull] FdbTransaction parent)
 {
     if (parent == null)
     {
         throw new ArgumentNullException(nameof(parent));
     }
     m_parent = parent;
 }
 public Snapshotted(FdbTransaction parent)
 {
     if (parent == null)
     {
         throw new ArgumentNullException("parent");
     }
     m_parent = parent;
 }
Beispiel #3
0
        /// <summary>Add a new transaction to the list of tracked transactions</summary>
        internal void RegisterTransaction(FdbTransaction transaction)
        {
            Contract.Requires(transaction != null);

            if (!m_transactions.TryAdd(transaction.Id, transaction))
            {
                throw Fdb.Errors.FailedToRegisterTransactionOnDatabase(transaction, this);
            }
        }
Beispiel #4
0
 internal void EnsureTransactionIsValid(FdbTransaction transaction)
 {
     Contract.Requires(transaction != null);
     if (m_disposed)
     {
         ThrowIfDisposed();
     }
     //TODO?
 }
        /// <summary>Start a new transaction on this database, with an optional context</summary>
        /// <param name="context">Optional context in which the transaction will run</param>
        internal FdbTransaction CreateNewTransaction(FdbOperationContext context)
        {
            Contract.Requires(context?.Database != null);
            ThrowIfDisposed();

            // force the transaction to be read-only, if the database itself is read-only
            var mode = context.Mode;

            if (m_readOnly)
            {
                mode |= FdbTransactionMode.ReadOnly;
            }

            int id = Interlocked.Increment(ref s_transactionCounter);

            // ensure that if anything happens, either we return a valid Transaction, or we dispose it immediately
            FdbTransaction?trans = null;

            try
            {
                var transactionHandler = m_handler.CreateTransaction(context);

                trans = new FdbTransaction(this, context, id, transactionHandler, mode);
                RegisterTransaction(trans);
                context.AttachTransaction(trans);
                // set default options..
                if (m_defaultTimeout != 0)
                {
                    trans.Timeout = m_defaultTimeout;
                }
                if (m_defaultRetryLimit != 0)
                {
                    trans.RetryLimit = m_defaultRetryLimit;
                }
                if (m_defaultMaxRetryDelay != 0)
                {
                    trans.MaxRetryDelay = m_defaultMaxRetryDelay;
                }
                if (this.DefaultLogHandler != null)
                {
                    trans.SetLogHandler(this.DefaultLogHandler, this.DefaultLogOptions);
                }

                // flag as ready
                trans.State = FdbTransaction.STATE_READY;
                return(trans);
            }
            catch (Exception)
            {
                if (trans != null)
                {
                    context.ReleaseTransaction(trans);
                    trans.Dispose();
                }
                throw;
            }
        }
Beispiel #6
0
        /// <summary>Remove a transaction from the list of tracked transactions</summary>
        /// <param name="transaction"></param>
        internal void UnregisterTransaction(FdbTransaction transaction)
        {
            Contract.Requires(transaction != null);

            //do nothing is already disposed
            if (m_disposed)
            {
                return;
            }

            // Unregister the transaction. We do not care if it has already been done
            FdbTransaction _;

            m_transactions.TryRemove(transaction.Id, out _);
            //TODO: compare removed value with the specified transaction to ensure it was the correct one?
        }
        internal static void ThrowOnInvalidState(FdbTransaction trans)
        {
            switch (trans.State)
            {
            case STATE_INIT: throw new InvalidOperationException("The transaction has not been initialized properly");

            case STATE_DISPOSED: throw new ObjectDisposedException("FdbTransaction", "This transaction has already been disposed and cannot be used anymore");

            case STATE_FAILED: throw new InvalidOperationException("The transaction is in a failed state and cannot be used anymore");

            case STATE_COMMITTED: throw new InvalidOperationException("The transaction has already been committed");

            case STATE_CANCELED: throw new FdbException(FdbError.TransactionCancelled, "The transaction has already been cancelled");

            default: throw new InvalidOperationException(String.Format("The transaction is unknown state {0}", trans.State));
            }
        }
 internal static void ThrowReadOnlyTransaction(FdbTransaction trans)
 {
     throw new InvalidOperationException("Cannot write to a read-only transaction");
 }
 public Snapshotted([NotNull] FdbTransaction parent)
 {
     Contract.NotNull(parent, nameof(parent));
     m_parent = parent;
 }
Beispiel #10
0
		internal static void ThrowReadOnlyTransaction(FdbTransaction trans)
		{
			throw new InvalidOperationException("Cannot write to a read-only transaction");
		}
Beispiel #11
0
		internal static void ThrowOnInvalidState(FdbTransaction trans)
		{
			switch (trans.State)
			{
				case STATE_INIT: throw new InvalidOperationException("The transaction has not been initialized properly");
				case STATE_DISPOSED: throw new ObjectDisposedException("FdbTransaction", "This transaction has already been disposed and cannot be used anymore");
				case STATE_FAILED: throw new InvalidOperationException("The transaction is in a failed state and cannot be used anymore");
				case STATE_COMMITTED: throw new InvalidOperationException("The transaction has already been committed");
				case STATE_CANCELED: throw new FdbException(FdbError.TransactionCancelled, "The transaction has already been cancelled");
				default: throw new InvalidOperationException(String.Format("The transaction is unknown state {0}", trans.State));
			}
		}
			public Snapshotted(FdbTransaction parent)
			{
				if (parent == null) throw new ArgumentNullException("parent");
				m_parent = parent;
			}
Beispiel #13
0
 public Snapshotted(FdbTransaction parent)
 {
     Contract.NotNull(parent);
     m_parent = parent;
 }