예제 #1
0
        protected virtual IEnumerable <T> ExecuteQuery <T>(Func <IContribDbStatement, IEnumerable <T> > query)
        {
            this.ThrowWhenDisposed();

            TransactionScope    scope       = this.OpenQueryScope();
            IDbConnection       connection  = null;
            IDbTransaction      transaction = null;
            IContribDbStatement statement   = null;

            try
            {
                connection         = this._connectionFactory.Open();
                transaction        = this._dialect.OpenTransaction(connection);
                statement          = this._dialect.BuildStatement(scope, connection, transaction);
                statement.PageSize = this._pageSize;

                Logger.Verbose(Messages.ExecutingQuery);
                return(query(statement));
            }
            catch (Exception e)
            {
                if (statement != null)
                {
                    statement.Dispose();
                }
                if (transaction != null)
                {
                    transaction.Dispose();
                }
                if (connection != null)
                {
                    connection.Dispose();
                }
                if (scope != null)
                {
                    scope.Dispose();
                }

                Logger.Debug(Messages.StorageThrewException, e.GetType());
                if (e is StorageUnavailableException)
                {
                    throw;
                }

                throw new StorageException(e.Message, e);
            }
        }
예제 #2
0
        protected virtual T ExecuteCommand <T>(Func <IDbConnection, IContribDbStatement, T> command)
        {
            this.ThrowWhenDisposed();

            using (TransactionScope scope = this.OpenCommandScope())
                using (IDbConnection connection = this._connectionFactory.Open())
                    using (IDbTransaction transaction = this._dialect.OpenTransaction(connection))
                        using (IContribDbStatement statement = this._dialect.BuildStatement(scope, connection, transaction))
                        {
                            try
                            {
                                Logger.Verbose(Messages.ExecutingCommand);
                                T rowsAffected = command(connection, statement);
                                Logger.Verbose(Messages.CommandExecuted, rowsAffected);

                                if (transaction != null)
                                {
                                    transaction.Commit();
                                }

                                if (scope != null)
                                {
                                    scope.Complete();
                                }

                                return(rowsAffected);
                            }
                            catch (Exception e)
                            {
                                Logger.Debug(Messages.StorageThrewException, e.GetType());
                                if (!RecoverableException(e))
                                {
                                    throw new StorageException(e.Message, e);
                                }

                                Logger.Info(Messages.RecoverableExceptionCompletesScope);
                                if (scope != null)
                                {
                                    scope.Complete();
                                }

                                throw;
                            }
                        }
        }
예제 #3
0
 public virtual void AddPayloadParamater(IConnectionFactory connectionFactory, IDbConnection connection, IContribDbStatement cmd, byte[] payload)
 {
     cmd.AddParameter(this.Payload, payload);
 }
예제 #4
0
 protected virtual void OnPersistCommit(IContribDbStatement cmd, CommitAttempt attempt)
 {
 }
예제 #5
0
 public virtual void AddPayloadParamater(IConnectionFactory connectionFactory, IDbConnection connection, IContribDbStatement cmd, byte[] payload)
 {
     cmd.AddParameter(this.Payload, payload);
 }