Beispiel #1
0
        internal virtual object ExecuteInsertCommand(IDbCommand dbcommand, IDbCommand indentityCommand, SafeLevel level)
        {
            object result = null;

            using (TransactionConnection transaction = CreateTransactionConnection(level))
            {
                transaction.Open();
                try
                {
                    transaction.SetupCommand(dbcommand);
                    dbcommand.ExecuteNonQuery();
                    if (indentityCommand != null)
                    {
                        transaction.SetupCommand(indentityCommand);
                        object obj = indentityCommand.ExecuteScalar();
                        if (obj != null)
                        {
                            result = obj;
                        }
                    }
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }
            }
            return(result);
        }
        internal override int ExecuteMultiCommands(IDbCommand[] dbcommands, SafeLevel level)
        {
            int rInt = 0;

            if (_isTransaction)
            {
                foreach (IDbCommand dbcommand in dbcommands)
                {
                    _trconnection.SetupCommand(dbcommand);
                    rInt += dbcommand.ExecuteNonQuery();
                }
            }
            else
            {
                TransactionConnection transaction = GetTransactionConnection();
                transaction.ResetTransaction(level);
                try {
                    foreach (IDbCommand dbcommand in dbcommands)
                    {
                        transaction.SetupCommand(dbcommand);
                        rInt += dbcommand.ExecuteNonQuery();
                    }
                    transaction.Commit();
                }
                catch (Exception ex) {
                    transaction.Rollback();
                    throw ex;
                }
            }
            return(rInt);
        }
Beispiel #3
0
        internal virtual int ExecuteMultiCommands(IDbCommand[] dbcommands, SafeLevel level)
        {
            if (level == SafeLevel.None)
            {
                level = SafeLevel.Default;
            }
            int rInt = 0;

            using (TransactionConnection transaction = CreateTransactionConnection(level))
            {
                transaction.Open();
                try
                {
                    foreach (IDbCommand dbcommand in dbcommands)
                    {
                        transaction.SetupCommand(dbcommand);
                        rInt += dbcommand.ExecuteNonQuery();
                    }
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }
            }
            return(rInt);
        }
        internal override DataSet QueryDataSet(IDbCommand dbcommand, SafeLevel level)
        {
            DataSet ds = new DataSet();

            if (_isTransaction)
            {
                _trconnection.SetupCommand(dbcommand);
                IDbDataAdapter adapter = _dataBase.CreateDataAdapter(dbcommand);
                adapter.Fill(ds);
            }
            else
            {
                TransactionConnection transaction = GetTransactionConnection();
                transaction.ResetTransaction(level);
                try {
                    transaction.SetupCommand(dbcommand);
                    IDbDataAdapter adapter = _dataBase.CreateDataAdapter(dbcommand);
                    adapter.Fill(ds);
                    transaction.Commit();
                }
                catch (Exception ex) {
                    transaction.Rollback();
                    throw ex;
                }
            }
            return(ds);
        }
        internal override object ExecuteScalar(IDbCommand dbcommand, SafeLevel level)
        {
            object result = null;

            if (_isTransaction)
            {
                _trconnection.SetupCommand(dbcommand);
                result = dbcommand.ExecuteScalar();
            }
            else
            {
                TransactionConnection transaction = GetTransactionConnection();
                transaction.ResetTransaction(level);
                try {
                    transaction.SetupCommand(dbcommand);
                    result = dbcommand.ExecuteScalar();
                    transaction.Commit();
                }
                catch (Exception ex) {
                    transaction.Rollback();
                    throw ex;
                }
            }
            return(result);
        }
 /// <summary>
 /// 开始事务
 /// </summary>
 public void BeginTrans(SafeLevel level)
 {
     if (_trconnection != null)
     {
         if (_isTransaction)
         {
             _trconnection.Rollback();
         }
         _trconnection.Dispose();
     }
     _isTransaction = true;
     if (level == SafeLevel.None)
     {
         _trconnection = CreateTransactionConnection(SafeLevel.Default);
     }
     else
     {
         _trconnection = CreateTransactionConnection(level);
     }
     _trconnection.Open();
 }
        internal override object ExecuteInsertCommand(IDbCommand dbcommand, IDbCommand indentityCommand, SafeLevel level)
        {
            object result = null;

            if (_isTransaction)
            {
                _trconnection.SetupCommand(dbcommand);
                dbcommand.ExecuteNonQuery();
                if (indentityCommand != null)
                {
                    _trconnection.SetupCommand(indentityCommand);
                    object obj = indentityCommand.ExecuteScalar();
                    if (obj != null)
                    {
                        result = obj;
                    }
                }
            }
            else
            {
                TransactionConnection transaction = GetTransactionConnection();
                transaction.ResetTransaction(level);
                try {
                    transaction.SetupCommand(dbcommand);
                    dbcommand.ExecuteNonQuery();
                    if (indentityCommand != null)
                    {
                        transaction.SetupCommand(indentityCommand);
                        object obj = indentityCommand.ExecuteScalar();
                        if (obj != null)
                        {
                            result = obj;
                        }
                    }
                    transaction.Commit();
                }
                catch (Exception ex) {
                    transaction.Rollback();
                    throw ex;
                }
            }
            return(result);
        }
Beispiel #8
0
        internal virtual int ExecuteNonQuery(IDbCommand dbcommand, SafeLevel level)
        {
            int rInt = 0;

            using (TransactionConnection transaction = CreateTransactionConnection(level))
            {
                transaction.Open();
                try
                {
                    transaction.SetupCommand(dbcommand);
                    rInt = dbcommand.ExecuteNonQuery();
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }
            }
            return(rInt);
        }
Beispiel #9
0
        internal virtual DataSet QueryDataSet(IDbCommand dbcommand, SafeLevel level)
        {
            DataSet ds = new DataSet();

            using (TransactionConnection transaction = CreateTransactionConnection(level))
            {
                transaction.Open();
                try
                {
                    transaction.SetupCommand(dbcommand);
                    IDbDataAdapter adapter = _dataBase.CreateDataAdapter(dbcommand);
                    adapter.Fill(ds);
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }
            }
            return(ds);
        }
Beispiel #10
0
        internal virtual object ExecuteScalar(IDbCommand dbcommand, SafeLevel level)
        {
            object result = null;

            using (TransactionConnection transaction = CreateTransactionConnection(level))
            {
                transaction.Open();
                try
                {
                    transaction.SetupCommand(dbcommand);
                    result = dbcommand.ExecuteScalar();
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }
            }

            return(result);
        }