Пример #1
0
 public static ResilientSqlTableTableFinalizerBuilder TruncateTargetTable(this ResilientSqlTableTableFinalizerBuilder builder, int commandTimeout = 60 * 60)
 {
     return(builder.Add(new TruncateTable(builder.Table.Scope.Context)
     {
         Name = "TruncateTargetTableFinalizer",
         ConnectionString = builder.Table.Scope.Configuration.ConnectionString,
         TableName = builder.Table.TableName,
         CommandTimeout = commandTimeout,
     }));
 }
Пример #2
0
 public static ResilientSqlTableTableFinalizerBuilder SimpleMergeInsertOnly(this ResilientSqlTableTableFinalizerBuilder builder, string[] keyColumns, int commandTimeout = 60 * 60)
 {
     return(builder.Add(new CustomMsSqlMergeStatement(builder.Table.Scope.Context)
     {
         Name = "SimpleMergeInsertOnlyFinalizer",
         ConnectionString = builder.Table.Scope.Configuration.ConnectionString,
         CommandTimeout = commandTimeout,
         SourceTableName = builder.Table.TempTableName,
         TargetTableName = builder.Table.TableName,
         SourceTableAlias = "s",
         TargetTableAlias = "t",
         OnCondition = string.Join(" and ", keyColumns.Select(x => "((s." + x + "=t." + x + ") or (s." + x + " is null and t." + x + " is null))")),
         WhenNotMatchedByTargetAction = "insert (" + string.Join(",", builder.Table.Columns) + ") values (" + string.Join(",", builder.Table.Columns.Select(c => "s." + c)) + ")",
     }));
 }
Пример #3
0
        public static ResilientSqlTableTableFinalizerBuilder SimpleMsSqlMergeUpdateOnly(this ResilientSqlTableTableFinalizerBuilder builder, string[] keyColumns, int commandTimeout = 60 * 60)
        {
            var columnsToUpdate = builder.Table.Columns.Where(c => !keyColumns.Contains(c)).ToList();

            return(builder.Add(new CustomMsSqlMergeStatement(builder.Table.Scope.Context)
            {
                Name = "SimpleMergeUpdateOnlyFinalizer",
                ConnectionString = builder.Table.Scope.Configuration.ConnectionString,
                CommandTimeout = commandTimeout,
                SourceTableName = builder.Table.TempTableName,
                TargetTableName = builder.Table.TableName,
                SourceTableAlias = "s",
                TargetTableAlias = "t",
                OnCondition = string.Join(" and ", keyColumns.Select(x => "((s." + x + "=t." + x + ") or (s." + x + " is null and t." + x + " is null))")),
                WhenMatchedAction = columnsToUpdate.Count > 0
                    ? "update set " + string.Join(",", columnsToUpdate.Select(c => "t." + c + "=s." + c))
                    : null,
            }));
        }
Пример #4
0
        public static ResilientSqlTableTableFinalizerBuilder CopyTable(this ResilientSqlTableTableFinalizerBuilder builder, int commandTimeout = 60 * 60, bool copyIdentityColumns = false)
        {
            if (copyIdentityColumns && builder.Table.Columns == null)
            {
                throw new EtlException(builder.Table.Scope, "identity columns can be copied only if the " + nameof(ResilientTable) + "." + nameof(ResilientTableBase.Columns) + " is specified");
            }

            return(builder.Add(new CopyTableIntoExistingTable(builder.Table.Scope.Context)
            {
                Name = "CopyTableFinalizer",
                ConnectionString = builder.Table.Scope.Configuration.ConnectionString,
                Configuration = new TableCopyConfiguration()
                {
                    SourceTableName = builder.Table.TempTableName,
                    TargetTableName = builder.Table.TableName,
                    Columns = builder.Table.Columns?.ToDictionary(x => x),
                },
                CommandTimeout = commandTimeout,
                CopyIdentityColumns = copyIdentityColumns,
            }));
        }
Пример #5
0
        public static ResilientSqlTableTableFinalizerBuilder SimpleMsSqlMerge(this ResilientSqlTableTableFinalizerBuilder builder, string[] keyColumns, int commandTimeout = 60 * 60)
        {
            var columnsToUpdate = builder.Table.Columns
                                  .Where(c => !keyColumns.Any(keyColumn => string.Equals(c, keyColumn, System.StringComparison.InvariantCultureIgnoreCase)))
                                  .ToList();

            return(builder.Add(new CustomMsSqlMergeStatement(builder.Table.Scope.Context)
            {
                Name = "SimpleMergeFinalizer",
                ConnectionString = builder.Table.Scope.Configuration.ConnectionString,
                CommandTimeout = commandTimeout,
                SourceTableName = builder.Table.TempTableName,
                TargetTableName = builder.Table.TableName,
                SourceTableAlias = "s",
                TargetTableAlias = "t",
                OnCondition = string.Join(" and ", keyColumns.Select(x => "((s." + x + "=t." + x + ") or (s." + x + " is null and t." + x + " is null))")),
                WhenMatchedAction = columnsToUpdate.Count > 0
                    ? "update set " + string.Join(",", columnsToUpdate.Select(c => "t." + c + "=s." + c))
                    : null,
                WhenNotMatchedByTargetAction = "insert (" + string.Join(",", builder.Table.Columns) + ") values (" + string.Join(",", builder.Table.Columns.Select(c => "s." + c)) + ")",
            }));
        }