Пример #1
0
        public void CommitResults(CacheCommitArguments arguments)
        {
            var configuration = arguments.Configuration;
            var operation     = arguments.Operation;

            DeleteCacheEntryIfAny(configuration, operation);

            //Do not change Types of source columns unless there is an explicit override
            arguments.Results.SetDoNotReType(true);

            using (var con = _server.GetConnection())
            {
                con.Open();

                string nameWeWillGiveTableInCache = operation + "_AggregateConfiguration" + configuration.ID;

                //either it has no name or it already has name we want so its ok
                arguments.Results.TableName = nameWeWillGiveTableInCache;

                //add explicit types
                var tbl = _database.ExpectTable(nameWeWillGiveTableInCache);
                if (tbl.Exists())
                {
                    tbl.Drop();
                }

                tbl = _database.CreateTable(nameWeWillGiveTableInCache, arguments.Results, arguments.ExplicitColumns);

                if (!tbl.Exists())
                {
                    throw new Exception("Cache table did not exist even after CreateTable completed without error!");
                }

                var cmdCreateNew =
                    DatabaseCommandHelper.GetCommand(
                        "INSERT INTO CachedAggregateConfigurationResults (Committer,AggregateConfiguration_ID,SqlExecuted,Operation,TableName) Values (@Committer,@AggregateConfiguration_ID,@SqlExecuted,@Operation,@TableName)", con);

                cmdCreateNew.Parameters.Add(DatabaseCommandHelper.GetParameter("@Committer", cmdCreateNew));
                cmdCreateNew.Parameters["@Committer"].Value = Environment.UserName;

                cmdCreateNew.Parameters.Add(DatabaseCommandHelper.GetParameter("@AggregateConfiguration_ID", cmdCreateNew));
                cmdCreateNew.Parameters["@AggregateConfiguration_ID"].Value = configuration.ID;

                cmdCreateNew.Parameters.Add(DatabaseCommandHelper.GetParameter("@SqlExecuted", cmdCreateNew));
                cmdCreateNew.Parameters["@SqlExecuted"].Value = arguments.SQL.Trim();

                cmdCreateNew.Parameters.Add(DatabaseCommandHelper.GetParameter("@Operation", cmdCreateNew));
                cmdCreateNew.Parameters["@Operation"].Value = operation.ToString();

                cmdCreateNew.Parameters.Add(DatabaseCommandHelper.GetParameter("@TableName", cmdCreateNew));
                cmdCreateNew.Parameters["@TableName"].Value = tbl.GetRuntimeName();

                cmdCreateNew.ExecuteNonQuery();

                arguments.CommitTableDataCompleted(tbl);
            }
        }
Пример #2
0
        public void CommitResults(CacheCommitArguments arguments)
        {
            var configuration = arguments.Configuration;
            var operation     = arguments.Operation;

            DeleteCacheEntryIfAny(configuration, operation);

            //Do not change Types of source columns unless there is an explicit override
            arguments.Results.SetDoNotReType(true);

            using (var con = _server.GetConnection())
            {
                con.Open();

                string nameWeWillGiveTableInCache = operation + "_AggregateConfiguration" + configuration.ID;

                //either it has no name or it already has name we want so its ok
                arguments.Results.TableName = nameWeWillGiveTableInCache;

                //add explicit types
                var tbl = _database.ExpectTable(nameWeWillGiveTableInCache);
                if (tbl.Exists())
                {
                    tbl.Drop();
                }

                tbl = _database.CreateTable(nameWeWillGiveTableInCache, arguments.Results, arguments.ExplicitColumns);

                if (!tbl.Exists())
                {
                    throw new Exception("Cache table did not exist even after CreateTable completed without error!");
                }

                var mgrTable = _database.ExpectTable(ResultsManagerTable);

                mgrTable.Insert(new Dictionary <string, object>()
                {
                    { "Committer", Environment.UserName },
                    { "AggregateConfiguration_ID", configuration.ID },
                    { "SqlExecuted", arguments.SQL.Trim() },
                    { "Operation", operation.ToString() },
                    { "TableName", tbl.GetRuntimeName() },
                });

                arguments.CommitTableDataCompleted(tbl);
            }
        }