Exemple #1
0
 /// <summary>
 /// Executes the multiple SQL batches in a single connection. The batches should be separated by the GO instruction.
 /// </summary>
 /// <param name="sql">The SQL code.</param>
 public void Go(string sql)
 {
     PublicInvoker.Call(Assembly.GetCallingAssembly(), (ca) =>
     {
         Reader.Go(ca, sql, this);
     });
 }
Exemple #2
0
        /// <summary>
        /// Executes the scalar function returning the value of a specified type.
        /// </summary>
        /// <typeparam name="T">The type of a value to return.</typeparam>
        /// <param name="client">A client assembly.</param>
        /// <param name="arguments">Are the arguments to pass.</param>
        protected T GoFunc <T>(System.Reflection.Assembly client, params ParameterArgument[] arguments)
        {
            return(PublicInvoker.Call <T>(() =>
            {
                var root = Mapper.GetRoot();

                DbMapping.CreateParams(root, this);

                var parameters = String.Join(",", root.AllParams.Select(p => p.Name).ToArray());

                // build
                string sql = Text.GenerateSql(100)
                             .NewLine(Text.Select).S()
                             .Append(Map.Name.Sql)
                             .EncloseLeft()
                             .Append(parameters)
                             .EncloseRight()
                             .Append(Text._As_)
                             .Append(Text.LeftSquareBracket)
                             .Append(Text.SingleColumnName)
                             .Append(Text.RightSquareBracket)
                             .Terminate()
                             .ToString();

                Mapper.SetSql(sql);

                var cpass = new PassChainer(Mapper, arguments);
                var connectable = Reader.GetConnectable(client, cpass);
                return Reader.LoadTable <Row <T> >(connectable, null, true).ToValue <T>();
            }));
        }
Exemple #3
0
        /// <summary>
        /// Returns a set of all rows in the data source.
        /// </summary>
        /// <param name="client">A client assembly.</param>
        protected Result <TRoot> Go(System.Reflection.Assembly client)
        {
            return(PublicInvoker.Call <Result <TRoot> >(client, (ca) =>
            {
                try
                {
                    var node = (DbNode)this;

                    // for reusability - !
                    var subject = node.RootWithBrokenChain ?? node.Root;

                    var query = ((ISemantic)subject).Translate(new SemqContext(subject), null);
                    query = ((ISelect)query).Select();
                    var proc = ((IEndProc)query).EndProcInternal();
                    var connectable = Reader.GetConnectable(ca, subject, proc);
                    var result = Reader.LoadTable <TRoot>(connectable, null, true);

                    subject.Recover();

                    return result;
                }
                catch (QueryTalkException ex)
                {
                    Loader.TryThrowInvalidSqlOperationException(ex, Name, Text.Method.Go);
                    throw;
                }
            }));
        }
Exemple #4
0
 /// <summary>
 /// Executes a stored procedure or SQL batch.
 /// </summary>
 /// <param name="procOrBatch">Is a stored procedure or SQL batch.</param>
 public Result ExecGo(ExecArgument procOrBatch)
 {
     return(PublicInvoker.Call <Result>(Assembly.GetCallingAssembly(), (ca) =>
     {
         var cpass = PassChainer.Create(_root, procOrBatch);
         var connectable = Reader.GetConnectable(ca, cpass, this);
         return Reader.LoadAll(connectable);
     }));
 }
Exemple #5
0
 /// <summary>
 /// Executes the procedure returning a strongly typed result set.
 /// </summary>
 /// <param name="client">A client assembly.</param>
 /// <param name="arguments">Are the arguments to pass.</param>
 protected Result <T> Go <T>(Assembly client, params ParameterArgument[] arguments)
 {
     return(PublicInvoker.Call <Result <T> >(() =>
     {
         BuildProc(arguments);
         var cpass = new PassChainer(Mapper, arguments);
         var connectable = Reader.GetConnectable(client, this, cpass);
         return Reader.LoadTable <T>(connectable, null);
     }));
 }
Exemple #6
0
 /// <summary>
 /// Executes a stored procedure or SQL batch asynchronously.
 /// </summary>
 /// <param name="procOrBatch">Is a stored procedure or SQL batch.</param>
 /// <param name="onCompleted">A delegate method that is called when the asynchronous operation completes.</param>
 /// <returns>The object of the asynchronous operation.</returns>
 public Async ExecGoAsync(ExecArgument procOrBatch, Action <Result> onCompleted = null)
 {
     return(PublicInvoker.Call <Async>(Assembly.GetCallingAssembly(), (ca) =>
     {
         var cpass = PassChainer.Create(_root, procOrBatch);
         var connectable = Reader.GetConnectable(ca, cpass, this);
         connectable.OnAsyncCompleted = onCompleted;
         return Reader.LoadAllAsync(connectable);
     }));
 }
Exemple #7
0
        /// <summary>
        /// Executes the table-valued function returning a strongly typed result set.
        /// </summary>
        /// <param name="client">A client assembly.</param>
        /// <param name="arguments">Are the arguments to pass.</param>
        protected Result <TNode> GoFunc(System.Reflection.Assembly client, params FunctionArgument[] arguments)
        {
            return(PublicInvoker.Call <Result <TNode> >(() =>
            {
                _arguments = arguments;
                var context = new SemqContext((DbNode)this);
                var query = ((ISelect)((ISemantic)this).Translate(context, null))
                            .Select();

                Mapper.SetSql(((IEndProc)query).EndProcInternal().Sql);

                var connectable = Reader.GetConnectable(client, Mapper);
                return Reader.LoadTable <TNode>(connectable, null, true);
            }));
        }
Exemple #8
0
        /// <summary>
        /// Executes a stored procedure or SQL batch asynchronously.
        /// </summary>
        /// <typeparam name="T">The type of the result set that is returned by the execution.</typeparam>
        /// <param name="procOrBatch">Is a stored procedure or SQL batch.</param>
        /// <param name="onCompleted">A delegate method that is called when the asynchronous operation completes.</param>
        /// <returns>The object of the asynchronous operation.</returns>
        public Async <Result <T> > ExecGoAsync <T>(ExecArgument procOrBatch, Action <Result <T> > onCompleted = null)

        {
            return(PublicInvoker.Call <Async <Result <T> > >(Assembly.GetCallingAssembly(), (ca) =>
            {
                var cpass = PassChainer.Create(_root, procOrBatch);
                var connectable = Reader.GetConnectable(ca, cpass, this);
                connectable.OnAsyncCompleted = onCompleted;

                if (typeof(T) == typeof(DataTable))
                {
                    return Reader.LoadDataTableAsync <T>(connectable);
                }
                else
                {
                    return Reader.LoadTableAsync <T>(connectable, null);
                }
            }));
        }
Exemple #9
0
        /// <summary>
        /// Executes a stored procedure or SQL batch.
        /// </summary>
        /// <typeparam name="T">The type of the result set that is returned by the execution.</typeparam>
        /// <param name="procOrBatch">Is a stored procedure or SQL batch.</param>
        public Result <T> ExecGo <T>(ExecArgument procOrBatch)

        {
            return(PublicInvoker.Call <Result <T> >(Assembly.GetCallingAssembly(), (ca) =>
            {
                var cpass = PassChainer.Create(_root, procOrBatch);
                var connectable = Reader.GetConnectable(ca, cpass, this);

                Result <T> result;

                if (typeof(T) == typeof(DataTable))
                {
                    result = Reader.LoadDataTable <T>(connectable);
                }
                else
                {
                    result = Reader.LoadTable <T>(connectable, null);
                }

                return result;
            }));
        }
Exemple #10
0
 /// <summary>
 /// Returns a set of all rows in the data source asynchronously.
 /// </summary>
 /// <param name="onCompleted">Is a delegate method that is invoked when the asynchronous operation completes.</param>
 /// <returns>The object of the asynchronous operation.</returns>
 public Async <Result <TRoot> > GoAsync(Action <Result <TRoot> > onCompleted = null)
 {
     return(PublicInvoker.Call <Async <Result <TRoot> > >(Assembly.GetCallingAssembly(), (ca) =>
     {
         try
         {
             var node = (DbNode)this;
             var subject = node.Root;
             var query = ((ISemantic)subject).Translate(new SemqContext(subject), null);
             query = ((ISelect)query).Select();
             var proc = ((IEndProc)query).EndProcInternal();
             var connectable = Reader.GetConnectable(ca, subject, proc);
             connectable.OnAsyncCompleted = onCompleted;
             return Reader.LoadTableAsync <TRoot>(connectable, null);
         }
         catch (QueryTalkException ex)
         {
             Loader.TryThrowInvalidSqlOperationException(ex, Name, Text.Method.GoAsync);
             throw;
         }
     }));
 }
Exemple #11
0
 /// <summary>
 /// Inserts the specified rows in the database.
 /// </summary>
 /// <typeparam name="T">The type of the row object.</typeparam>
 /// <param name="rows">The rows to insert.</param>
 /// <param name="identityInsert">If true, then the explicit value can be inserted into the identity column of a table.</param>
 public Result <T> InsertRowsGo <T>(IEnumerable <T> rows, bool identityInsert = false)
     where T : DbRow
 {
     return(PublicInvoker.Call <Result <T> >(Assembly.GetCallingAssembly(), (ca) =>
                                             Crud.InsertRowsGo(ca, rows, identityInsert, this)));
 }
Exemple #12
0
 /// <summary>
 /// Updates the specified row in the database.
 /// </summary>
 /// <typeparam name="T">The type of the row object.</typeparam>
 /// <param name="row">The row to update.</param>
 /// <param name="forceMirroring">If true, then the optimistic concurrency check is done which throws an exception if the check fails.</param>
 public Result <T> UpdateGo <T>(T row, bool forceMirroring = true)
     where T : DbRow
 {
     return(PublicInvoker.Call <Result <T> >(Assembly.GetCallingAssembly(), (ca) =>
                                             Crud.UpdateGo <T>(ca, row, forceMirroring, this)));
 }
Exemple #13
0
 /// <summary>
 /// Executes a bulk insert.
 /// </summary>
 /// <param name="rows">The data to be inserted.</param>
 public void BulkInsertGo <T>(IEnumerable <T> rows)
     where T : DbRow
 {
     PublicInvoker.Call(Assembly.GetCallingAssembly(), (ca) =>
                        Importer.ExecuteBulkInsert(ca, rows, this));
 }
Exemple #14
0
 /// <summary>
 /// Executes a bulk insert.
 /// </summary>
 /// <param name="data">The data to be inserted.</param>
 /// <param name="table">Is a target table where the data is inserted.</param>
 public void BulkInsertGo(Result <DataTable> data, TableArgument table)
 {
     PublicInvoker.Call(Assembly.GetCallingAssembly(), (ca) =>
                        Importer.ExecuteBulkInsert(ca, data.ToDataTable(), table, this));
 }
Exemple #15
0
 /// <summary>
 /// Inserts the row with the associated children rows.
 /// </summary>
 /// <typeparam name="T">The type of the row object.</typeparam>
 /// <param name="row">The row to insert.</param>
 public void InsertCascadeGo <T>(T row)
     where T : DbRow
 {
     PublicInvoker.Call(Assembly.GetCallingAssembly(), (ca) =>
                        Crud.InsertCascadeGo <T>(ca, row, this));
 }
Exemple #16
0
 /// <summary>
 /// Inserts the specified row in the database asynchronously.
 /// </summary>
 /// <typeparam name="T">The type of the row object.</typeparam>
 /// <param name="row">The row to insert.</param>
 /// <param name="identityInsert">If true, then the explicit value can be inserted into the identity column of a table.</param>
 /// <param name="onCompleted">A delegate method that is called when the asynchronous operation completes.</param>
 /// <returns>The object of the asynchronous operation.</returns>
 public Async <Result <T> > InsertGoAsync <T>(T row, bool identityInsert = false, Action <Result <T> > onCompleted = null)
     where T : DbRow
 {
     return(PublicInvoker.Call <Async <Result <T> > >(Assembly.GetCallingAssembly(), (ca) =>
                                                      Crud.InsertGoAsync <T>(ca, row, identityInsert, this, onCompleted)));
 }
Exemple #17
0
 /// <summary>
 /// Inserts the specified row in the database.
 /// </summary>
 /// <typeparam name="T">The type of the row object.</typeparam>
 /// <param name="row">The row to insert.</param>
 /// <param name="identityInsert">If true, then the explicit value can be inserted into the identity column of a table.</param>
 public Result <T> InsertGo <T>(T row, bool identityInsert = false)
     where T : DbRow
 {
     return(PublicInvoker.Call <Result <T> >(Assembly.GetCallingAssembly(), (ca) =>
                                             Crud.InsertGo <T>(ca, row, identityInsert, this)));
 }
Exemple #18
0
 /// <summary>
 /// Updates the specified rows in the database.
 /// </summary>
 /// <typeparam name="T">The type of the row object.</typeparam>
 /// <param name="rows">The rows to update.</param>
 /// <param name="forceMirroring">If true, then the optimistic concurrency check is done which throws an exception if the check fails.</param>
 public Result <T> UpdateRowsGo <T>(IEnumerable <T> rows, bool forceMirroring = true)
     where T : DbRow
 {
     return(PublicInvoker.Call <Result <T> >(Assembly.GetCallingAssembly(), (ca) =>
                                             Crud.UpdateRowsGo(ca, rows, forceMirroring, this)));
 }
Exemple #19
0
 /// <summary>
 /// Updates the specified row in the database asynchronously.
 /// </summary>
 /// <typeparam name="T">The type of the row object.</typeparam>
 /// <param name="row">The row to update.</param>
 /// <param name="forceMirroring">If true, then the optimistic concurrency check is done which throws an exception if the check fails.</param>
 /// <param name="onCompleted">A delegate method that is called when the asynchronous operation completes.</param>
 /// <returns>The object of the asynchronous operation.</returns>
 public Async <Result <T> > UpdateGoAsync <T>(T row, bool forceMirroring = true, Action <Result <T> > onCompleted = null)
     where T : DbRow
 {
     return(PublicInvoker.Call <Async <Result <T> > >(Assembly.GetCallingAssembly(), (ca) =>
                                                      Crud.UpdateGoAsync <T>(ca, row, forceMirroring, this, onCompleted)));
 }
Exemple #20
0
 /// <summary>
 /// Invokes the specified method.
 /// </summary>
 /// <param name="method">The method to invoke.</param>
 public static void Call(Action method)
 {
     PublicInvoker.Call(method);
 }
Exemple #21
0
 /// <summary>
 /// Deletes the row with the associated children rows.
 /// </summary>
 /// <typeparam name="T">The type of the row object.</typeparam>
 /// <param name="row">The row to delete.</param>
 /// <param name="maxLevels">Specifies the maximum number of cascading levels that can be included in the deletion. If more levels than maxLevels are needed to complete the cascade deletion, an exception is thrown.</param>
 public void DeleteCascadeGo <T>(T row, int maxLevels = 5)
     where T : DbRow
 {
     PublicInvoker.Call(Assembly.GetCallingAssembly(), (ca) =>
                        Crud.DeleteCascadeGo <T>(ca, row, maxLevels, this));
 }