Exemplo n.º 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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
 TransactionConnection GetTransactionConnection()
 {
     if (_trconnection == null)
     {
         _trconnection = CreateTransactionConnection(SafeLevel.None);
         _trconnection.Open();
     }
     return(_trconnection);
 }
Exemplo n.º 4
0
        internal virtual IEnumerable QueryDataReader(IDataDefine source, IDbCommand dbcommand, Region region, SafeLevel level)
        {
            int start;
            int size;

            if (region != null)
            {
                start = region.Start;
                size  = region.Size;
            }
            else
            {
                start = 0;
                size  = int.MaxValue;
            }
            using (TransactionConnection transaction = CreateTransactionConnection(level))
            {
                transaction.Open();
                transaction.SetupCommand(dbcommand);
                using (IDataReader reader = dbcommand.ExecuteReader())
                {
                    int  index = 0;
                    int  count = 0;
                    bool over  = false;
                    while (reader.Read())
                    {
                        if (over)
                        {
                            dbcommand.Cancel();
                            break;
                        }
                        if (index >= start)
                        {
                            count++;
                            object item = source.LoadData(this, reader);
                            if (count >= size)
                            {
                                over = true;
                            }
                            yield return(item);
                        }
                        index++;
                    }
                }
                transaction.Commit();
            }
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
 /// <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();
 }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }