示例#1
0
        public override object Execute(DataTransaction dt, IDataCommand command)//funcName:tableName
        {
            if (destination == null)
            {
                return(null);
            }
            var v    = (BaseDataCommand)command;
            var cmd  = v.Sql.Split(':');
            var func = destination._GetProperty("Repository")._InvokeMethod("CreateFunction", cmd[0]);
            var obj  = func;

            if (cmd.Length > 1)
            {
                var tbl = GetTable.Invoke(func, new[] { cmd[1] }) as ICollection;
                tbl._InvokeMethod("Clear");
                tbl._InvokeMethod("Append");
                var row = tbl.GetEnumerator();
                row.MoveNext();
                obj = row.Current;
            }
            foreach (var x in v.Parameters)
            {
                SetValue.Invoke(obj, new[] { x.Key, x.Value });
            }
            func._InvokeMethod("Invoke", destination);
            return(null);
        }
示例#2
0
 public DataTransaction BeginTransaction()
 {
     return(CurrentTransaction = new DataTransaction()
     {
         Transaction = new DataConnection(connection.BeginTransaction())
     });
 }
示例#3
0
        public static void UseTransaction(this IDataProvider dp, Action <DataTransaction> action, DataTransaction dt = null)
        {
            DataTransaction _dt = null;

            try
            {
                _dt = dt ?? dp.BeginTransaction();
                action(_dt);
                if (dt == null)
                {
                    if (AppContext.Log.UseTrace)
                    {
                        AppContext.Log.Trace("Commit");
                    }
                    dp.CommitTransaction(_dt);
                }
            }
            catch (Exception ex)
            {
                if (dt == null)
                {
                    if (AppContext.Log.UseTrace)
                    {
                        AppContext.Log.Trace("Rollback: " + ex.Message);
                    }
                    if (_dt != null)
                    {
                        dp.RollbackTransaction(_dt);
                    }
                }
                throw;
            }
        }
示例#4
0
        public object Execute(DataTransaction dt, IDataCommand command)
        {
            var dc  = (dt ?? CurrentTransaction)?.Transaction as DataConnection;
            var cmd = (DataCommand)command;

            return(dc == null?DoAction(cmd.ExecuteScalar) : cmd.ExecuteScalar(dc));
        }
示例#5
0
        public override object Execute(DataTransaction dt, IDataCommand command)
        {
            var cmd = "";
            var v   = (BaseDataCommand)command;

            try
            {
                cmd = v.Sql.FormatStrEx(v.Parameters);
                if (AppContext.Log.UseTrace)
                {
                    AppContext.Log.Trace(cmd);
                }
                return(proxy.Exec(new ExecRequest()
                {
                    Body = new ExecRequestBody()
                    {
                        cmd = cmd
                    }
                }).Body.@return);
            }
            catch (Exception ex)
            {
                var info = GetExMessage(ex, cmd);
                if (info.IsEmpty())
                {
                    throw;
                }
                else
                {
                    throw new Exception(info);
                }
            }
        }
示例#6
0
        public static void Execute <T>(this IDataProvider dp, DataTransaction dt, string command, List <T> prms, Action <IDataCommand, T> prepare, Action <object, T> onResult)
        {
            var cmd = dp.CreateCommand(command);

            foreach (var p in prms)
            {
                cmd.ClearParams();
                prepare?.Invoke(cmd, p);
                var v = dp.Execute(dt, cmd);
                onResult?.Invoke(v, p);
            }
        }
示例#7
0
 public virtual void RollbackTransaction(DataTransaction dt)
 {
 }
示例#8
0
 public virtual void CommitTransaction(DataTransaction dt)
 {
 }
示例#9
0
 public static object Execute(this IDataProvider dp, DataTransaction dt, string command, params object[] prms)
 {
     return(dp.Execute(dt, dp.CreateCommand(command, prms)));
 }
示例#10
0
 public abstract object Execute(DataTransaction dt, IDataCommand command);
示例#11
0
 public void RollbackTransaction(DataTransaction dt)
 {
     (dt?.Transaction as DataConnection)?.Transaction?.Rollback(); CurrentTransaction = null;
 }
示例#12
0
 public void CommitTransaction(DataTransaction dt)
 {
     (dt?.Transaction as DataConnection)?.Transaction?.Commit(); CurrentTransaction = null;
 }