コード例 #1
0
            public override object GetStagingValue(Row stagingRow, FixupCaches caches, DataStoreConfiguration config)
            {
                Ct7Entity resType    = (Ct7Entity)stagingRow[StagingTypeColumn];
                Entity    entityType = EntityUtils.FromCt7Entity(resType);

                object id = config.Consolidation.Get(entityType).None
                   ? stagingRow[FederatedStagingIdColumn]
                   : stagingRow[ConsolidatedStagingIdColumn];

                if (id == null || id == DBNull.Value)
                {
                    return(DBNull.Value);
                }

                long idVal = (long)id;
                var  name  = caches.NameCache.Get(entityType, idVal, config);

                if (name != null)
                {
                    if (PublicColumn.Contains("unique"))
                    {
                        return(name.UniqueName);
                    }

                    if (string.IsNullOrEmpty(name.Name))
                    {
                        return(DBNull.Value);
                    }

                    return(name.Name);
                }

                return(DBNull.Value);
            }
コード例 #2
0
        public override object GetStagingValue(Row stagingRow, FixupCaches caches, DataStoreConfiguration config)
        {
            object id = stagingRow[StagingIdColumn];

            if (id == null || id == DBNull.Value)
            {
                return(DBNull.Value);
            }

            long idVal = (long)id;
            var  name  = caches.NameCache.Get(_entityType, idVal, config);

            if (name != null)
            {
                if (PublicColumn.Contains("unique"))
                {
                    if (string.IsNullOrEmpty(name.UniqueName))
                    {
                        throw new ApplicationException("Unique name is empty!");
                    }

                    return(name.UniqueName);
                }

                if (string.IsNullOrEmpty(name.Name))
                {
                    return(DBNull.Value);
                }

                return(name.Name);
            }

            return(DBNull.Value);
        }
コード例 #3
0
ファイル: PublicTable.cs プロジェクト: CELCAT/CTDataStore
        private void PopulateTempUpsertTableUsingBulkCopy(
            SqlConnection c,
            int timeoutSecs,
            IEnumerable <Row> stagingRows,
            TableColumnMappings colMappings,
            FixupCaches caches,
            DataStoreConfiguration configuration,
            Table tableName,
            bool modifyWeekNumbers)
        {
            var etl = new TempUpsertEtlProcess(c, timeoutSecs, stagingRows, colMappings, caches, configuration, tableName, modifyWeekNumbers);

            etl.Execute();

            var errors = etl.GetAllErrors().ToArray();

            if (errors.Any())
            {
                string msg = $"Errors occurred during population of temporary upsert table: {tableName.Name}";
                _log.Error(msg);

                // throw the first exception
                throw new ApplicationException(msg, errors[0]);
            }
        }
コード例 #4
0
ファイル: PublicTable.cs プロジェクト: CELCAT/CTDataStore
        public virtual void Delete(
            string sqlConnectionString,
            int timeoutSecs,
            Row stagingRow,
            TableColumnMappings colMappings,
            FixupCaches caches,
            DataStoreConfiguration configuration)
        {
            var b = new SqlBuilder();

            b.AppendFormat("delete from {0}", QualifiedName);
            b.Append("where");

            for (int n = 0; n < PrimaryKey.KeyPartsCount; ++n)
            {
                if (n > 0)
                {
                    b.Append("and");
                }

                var keyPart = PrimaryKey[n];
                b.AppendFormat("{0}={1}", keyPart.ColumnName, GetParamName(colMappings, keyPart.ColumnName));
            }

            var parameters = new List <SqlParameter>();

            for (int n = 0; n < colMappings.Count; ++n)
            {
                string paramName = GetParamName(n);
                colMappings[n].AddParamValue(parameters, paramName, stagingRow, caches, configuration);
            }

            DatabaseUtils.ExecuteSql(sqlConnectionString, b.ToString(), timeoutSecs, parameters.ToArray());
        }
コード例 #5
0
            public override void AddParamValue(
                List <SqlParameter> parameters, string paramName, Row stagingRow, FixupCaches caches, DataStoreConfiguration config)
            {
                var val = GetStagingValue(stagingRow, caches, config);

                parameters.Add(new SqlParameter(paramName, val));
            }
コード例 #6
0
 public TransformationEventExpansionOperation(PublicTable targetTable, FixupCaches caches, DataStoreConfiguration configuration)
 {
     _colMappings   = targetTable.GetColumnMappingsFromStage(configuration);
     _expandEvents  = _colMappings != null && _colMappings.EventExpansionRequired;
     _caches        = caches;
     _configuration = configuration;
 }
コード例 #7
0
            public override object GetStagingValue(Row stagingRow, FixupCaches caches, DataStoreConfiguration config)
            {
                long eventId = (long)stagingRow[StagingEventIdColumn];
                int  week    = (int)stagingRow[StagingEventWeekColumn];

                return(FabricateEventInstanceId(eventId, week));
            }
コード例 #8
0
        public override object GetStagingValue(Row stagingRow, FixupCaches caches, DataStoreConfiguration config)
        {
            Ct7Entity resType    = (Ct7Entity)stagingRow[PublicStagingTypeColumn];
            Entity    entityType = EntityUtils.FromCt7Entity(resType);

            return(config.Consolidation.Get(entityType).None
               ? stagingRow[FederatedStagingColumn]
               : stagingRow[ConsolidatedStagingColumn]);
        }
コード例 #9
0
 public override void Delete(
     string sqlConnectionString,
     int timeoutSecs,
     Row stagingRow,
     TableColumnMappings colMappings,
     FixupCaches caches,
     DataStoreConfiguration configuration)
 {
     DeleteEventAssignment(sqlConnectionString, timeoutSecs, stagingRow);
 }
コード例 #10
0
            public override object GetStagingValue(Row stagingRow, FixupCaches caches, DataStoreConfiguration config)
            {
                var val = stagingRow[StagingColumn];

                if (val != null && val != DBNull.Value)
                {
                    return(GetHardCodedValue((string)val));
                }

                return(DBNull.Value);
            }
コード例 #11
0
ファイル: PublicTable.cs プロジェクト: CELCAT/CTDataStore
        public void Upsert(
            string sqlConnectionString,
            int timeoutSecs,
            IEnumerable <Row> stagingRows,
            TableColumnMappings colMappings,
            FixupCaches caches,
            DataStoreConfiguration configuration,
            bool modifyWeekNumbers = false)
        {
            using (var c = DatabaseUtils.CreateConnection(sqlConnectionString))
            {
                var tmpTableName = GenerateTempUpsertTable(c, timeoutSecs, stagingRows, colMappings, caches, configuration, modifyWeekNumbers);

                var b = new SqlBuilder();

                b.AppendFormat("MERGE {0} target", QualifiedName);
                b.AppendFormat("using (select {0} from {1}) source", colMappings.GetPublicColNamesAsCsv(), tmpTableName);
                b.Append("on (");

                for (int n = 0; n < PrimaryKey.KeyPartsCount; ++n)
                {
                    if (n > 0)
                    {
                        b.Append("and");
                    }

                    var keyPart = PrimaryKey[n];
                    b.AppendFormat("target.{0} = source.{0}", keyPart.ColumnName);
                }

                b.Append(")");

                b.Append("when MATCHED then");
                b.Append("UPDATE SET");

                for (int n = 0; n < Columns.Count; ++n)
                {
                    if (n > 0)
                    {
                        b.AppendNoSpace(", ");
                    }

                    var col = Columns[n];
                    b.AppendFormat("target.{0} = source.{0}", col.Name);
                }

                b.Append("when NOT MATCHED then");
                b.AppendFormat("INSERT ({0}) values({1})", colMappings.GetPublicColNamesAsCsv(), GetSourceColsNamesAsCsv(colMappings));
                b.Append(";");

                DatabaseUtils.ExecuteSql(c, null, b.ToString(), timeoutSecs);
            }
        }
コード例 #12
0
            public override object GetStagingValue(Row stagingRow, FixupCaches caches, DataStoreConfiguration config)
            {
                object val = stagingRow[StagingColumn];

                if (val == null || val == DBNull.Value)
                {
                    return(DBNull.Value);
                }

                return(((string)val).Equals("Y", StringComparison.OrdinalIgnoreCase)
                   ? 1 : 0);
            }
コード例 #13
0
 public TempUpsertGetRowsOperation(
     IEnumerable <Row> stagingRows,
     TableColumnMappings colMappings,
     FixupCaches caches,
     DataStoreConfiguration configuration,
     bool modifyWeekNumbers)
 {
     _stagingRows       = stagingRows;
     _colMappings       = colMappings;
     _caches            = caches;
     _configuration     = configuration;
     _modifyWeekNumbers = modifyWeekNumbers;
 }
コード例 #14
0
        public override void AddParamValue(
            List <SqlParameter> parameters, string paramName, Row stagingRow, FixupCaches caches, DataStoreConfiguration config)
        {
            object id = GetStagingValue(stagingRow, caches, config);

            if (id == null || id == DBNull.Value)
            {
                parameters.Add(new SqlParameter(paramName, DBNull.Value));
            }
            else
            {
                parameters.Add(new SqlParameter(paramName, id));
            }
        }
コード例 #15
0
 public TransformationUpdateTargetOperation(
     string connectionString,
     int timeoutSecs,
     PublicTable targetTable,
     FixupCaches caches,
     DataStoreConfiguration configuration,
     TransformationType transformationType)
 {
     _connectionString   = connectionString;
     _timeoutSecs        = timeoutSecs;
     _targetTable        = targetTable;
     _caches             = caches;
     _configuration      = configuration;
     _transformationType = transformationType;
 }
コード例 #16
0
 public TransformationGetDataForBulkInsertOperation(
     string adminConnectionString,
     Table srcTable,
     PublicTable targetTable,
     FixupCaches caches,
     DataStoreConfiguration configuration,
     int srcTimetableId)
     : base(DatabaseUtils.CreateConnectionStringSettings(adminConnectionString))
 {
     _srcTable       = srcTable;
     _targetTable    = targetTable;
     _caches         = caches;
     _configuration  = configuration;
     _colMappings    = targetTable.GetColumnMappingsFromStage(_configuration);
     _srcTimetableId = srcTimetableId;
 }
コード例 #17
0
        private void DoParallelProcessing(TableMappings.TableMappings tableMappings)
        {
            _caches = new FixupCaches(_connectionString, _timeoutSecs, tableMappings);

            var pOptions = new ParallelOptions {
                MaxDegreeOfParallelism = _maxDegreeOfParallelism
            };

            Parallel.ForEach(tableMappings, pOptions, (tableMapping, loopState) =>
            {
                if (!loopState.IsExceptional)
                {
                    TransformStagingTable(tableMapping, loopState);
                }
            });
        }
コード例 #18
0
ファイル: PublicTable.cs プロジェクト: CELCAT/CTDataStore
        private string GenerateTempUpsertTable(
            SqlConnection c,
            int timeoutSecs,
            IEnumerable <Row> stagingRows,
            TableColumnMappings colMappings,
            FixupCaches caches,
            DataStoreConfiguration configuration,
            bool modifyWeekNumbers)
        {
            var tableName = string.Concat("#TmpUpsert", Name);

            var b = new TempUpsertTableBuilder(tableName, this);

            b.Execute(c, null, timeoutSecs);
            var tmpTable = b.GetTables()[0];

            PopulateTempUpsertTableUsingBulkCopy(c, timeoutSecs, stagingRows, colMappings, caches, configuration, tmpTable, modifyWeekNumbers);

            return(tableName);
        }
コード例 #19
0
        public override void Delete(
            string sqlConnectionString,
            int timeoutSecs,
            Row stagingRow,
            TableColumnMappings colMappings,
            FixupCaches caches,
            DataStoreConfiguration configuration)
        {
            var b = new SqlBuilder();

            long eventId = (long)stagingRow["event_id"];

            b.AppendFormat("delete from {0}", QualifiedName);
            b.Append("where event_instance_id like @P1");

            var parameters = new List <SqlParameter> {
                new SqlParameter("@P1", $"{eventId}-%")
            };

            DatabaseUtils.ExecuteSql(sqlConnectionString, b.ToString(), timeoutSecs, parameters.ToArray());
        }
コード例 #20
0
        public TempUpsertEtlProcess(
            SqlConnection c,
            int timeoutSecs,
            IEnumerable <Row> stagingRows,
            TableColumnMappings colMappings,
            FixupCaches caches,
            DataStoreConfiguration configuration,
            Table tmpTable,
            bool modifyWeekNumbers)
        {
            if (configuration.Pipelines.PublicTempUpsert.SingleThreaded)
            {
                PipelineExecuter = new SingleThreadedPipelineExecuter();
            }

            _sqlConnection     = c;
            _timeoutSecs       = timeoutSecs;
            _stagingRows       = stagingRows;
            _colMappings       = colMappings;
            _caches            = caches;
            _configuration     = configuration;
            _tempTable         = tmpTable;
            _modifyWeekNumbers = modifyWeekNumbers;
        }
コード例 #21
0
        public TransformationEtlProcess(
            Table srcTable,
            PublicTable targetTable,
            FixupCaches caches,
            string connectionString,
            int timeoutSecs,
            DataStoreConfiguration configuration,
            TransformationType transformationType,
            int srcTimetableId)
        {
            if (configuration.Pipelines.PublicTransformation.SingleThreaded)
            {
                PipelineExecuter = new SingleThreadedPipelineExecuter();
            }

            _srcTable           = srcTable;
            _targetTable        = targetTable;
            _caches             = caches;
            _connectionString   = connectionString;
            _timeoutSecs        = timeoutSecs;
            _configuration      = configuration;
            _transformationType = transformationType;
            _srcTimetableId     = srcTimetableId;
        }
コード例 #22
0
        public override object GetStagingValue(Row stagingRow, FixupCaches caches, DataStoreConfiguration config)
        {
            long eventId        = (long)stagingRow["federated_event_id"];
            int  srcTimetableId = (int)stagingRow["src_timetable_id"];
            int  timetableWeek  = (int)stagingRow["timetable_week"]; // this column will have been added by event expansion

            var eventTimes = caches.EventTimeCache.Get(eventId);
            var weekDates  = caches.WeekDatesCache.Get(srcTimetableId);

            DateTime dateOfEvent = weekDates.StartingDates[timetableWeek - 1];

            while (dateOfEvent.DayOfWeek != eventTimes.DayOfWeek)
            {
                dateOfEvent = dateOfEvent.AddDays(1);
            }

            DateTime eventInstanceDate = dateOfEvent.Date;

            DateTime dt = PublicColumn.IndexOf("start", StringComparison.OrdinalIgnoreCase) >= 0
               ? eventInstanceDate.AddHours(eventTimes.Start.Hour).AddMinutes(eventTimes.Start.Minute)
               : eventInstanceDate.AddHours(eventTimes.End.Hour).AddMinutes(eventTimes.End.Minute);

            return(dt);
        }
コード例 #23
0
ファイル: PublicTable.cs プロジェクト: CELCAT/CTDataStore
        public void Upsert(
            string sqlConnectionString,
            int timeoutSecs,
            Row stagingRow,
            TableColumnMappings colMappings,
            FixupCaches caches,
            DataStoreConfiguration configuration)
        {
            var b = new SqlBuilder();

            b.AppendFormat("MERGE {0} a", QualifiedName);
            b.AppendFormat("using (select {0}) b", GetMergeSelectCols(colMappings));
            b.Append("on (");

            for (int n = 0; n < PrimaryKey.KeyPartsCount; ++n)
            {
                if (n > 0)
                {
                    b.Append("and");
                }

                var keyPart = PrimaryKey[n];
                b.AppendFormat("a.{0}={1}", keyPart.ColumnName, GetParamName(colMappings, keyPart.ColumnName));
            }

            b.Append(")");

            b.Append("when MATCHED then");
            b.Append("UPDATE SET");

            for (int n = 0; n < Columns.Count; ++n)
            {
                if (n > 0)
                {
                    b.AppendNoSpace(", ");
                }

                var col = Columns[n];
                b.AppendFormat("{0}={1}", col.Name, GetParamName(colMappings, col.Name));
            }

            b.Append("when NOT MATCHED then");
            b.AppendFormat("INSERT ({0}) values({1})", colMappings.GetPublicColNamesAsCsv(), GetParamNamesAsCsv(colMappings));

            b.Append(";");

            int wkParamIndex = -1;

            var parameters = new List <SqlParameter>();

            for (int n = 0; n < colMappings.Count; ++n)
            {
                string paramName = GetParamName(n);
                colMappings[n].AddParamValue(parameters, paramName, stagingRow, caches, configuration);

                if (colMappings[n].PublicColumn.Equals("timetable_week"))
                {
                    wkParamIndex = n;
                }
            }

            if (wkParamIndex > -1)
            {
                // make the "timetable_week" 1-based...
                parameters[wkParamIndex].Value = (int)parameters[wkParamIndex].Value + 1;
            }

            if (colMappings.EventExpansionRequired)
            {
                string paramName1 = GetParamName(EventInstanceParamNum);
                parameters.Add(new SqlParameter(paramName1, stagingRow[colMappings.EventExpansion.PublicEventInstanceColumn]));

                string paramName2 = GetParamName(EventWeekParamNum);
                parameters.Add(new SqlParameter(paramName2, stagingRow[colMappings.EventExpansion.PublicWeekColumn]));

                string paramName3 = GetParamName(EventWeekOccurrenceParamNum);
                parameters.Add(new SqlParameter(paramName3, stagingRow[colMappings.EventExpansion.PublicWeekOccurrenceColumn]));
            }

            DatabaseUtils.ExecuteSql(sqlConnectionString, b.ToString(), timeoutSecs, parameters.ToArray());
        }
コード例 #24
0
 public abstract void AddParamValue(
     List <SqlParameter> parameters,
     string paramName,
     Row stagingRow,
     FixupCaches caches,
     DataStoreConfiguration config);
コード例 #25
0
 public abstract object GetStagingValue(Row stagingRow, FixupCaches caches, DataStoreConfiguration config);
コード例 #26
0
 public override object GetStagingValue(Row stagingRow, FixupCaches caches, DataStoreConfiguration config)
 {
     return(stagingRow[StagingColumn]);
 }