Пример #1
0
        /// <summary>
        ///   Makes operations in the context use the underlying transaction
        /// </summary>
        /// <param name="transaction"> The transaction. </param>
        public void UseTransaction(CqlBatchTransaction transaction)
        {
            if (transaction == null)
            {
                _currentTransaction = null;
                _disposeTransaction = false;
                return;
            }

            if (_currentTransaction != null)
                throw new InvalidOperationException("Context is already bound to a transaction.");

            if (transaction.Connection == null || transaction.Connection != Connection)
                throw new ArgumentException("Transaction is not using the same connection as this context",
                                            "transaction");

            _currentTransaction = transaction;
            _disposeTransaction = false;
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CqlDatabaseTransaction"/> class.
 /// </summary>
 /// <param name="transaction">The transaction.</param>
 /// <param name="connector">The database connector.</param>
 /// <exception cref="System.ArgumentNullException">transaction can not be null.</exception>
 internal CqlDatabaseTransaction(CqlBatchTransaction transaction, CqlDatabaseConnector connector)
 {
     this.Transaction = transaction ?? throw new ArgumentNullException(nameof(transaction), $"{nameof(transaction)} can not be null.");
     this.Connector   = connector;
 }
Пример #3
0
        /// <summary>
        ///   Begins a transaction on which all operations in this context are executed.
        /// </summary>
        /// <returns> </returns>
        /// <exception cref="System.InvalidOperationException">This context is already bound to an transaction</exception>
        public CqlBatchTransaction BeginTransaction()
        {
            if (_currentTransaction != null)
                throw new InvalidOperationException("This context is already bound to a transaction");

            var connection = Connection;
            if (connection.State == ConnectionState.Closed)
                connection.Open();

            _currentTransaction = new CqlContextBatchTransaction(this, connection);
            _disposeTransaction = true;

            return _currentTransaction;
        }