예제 #1
0
        private static void EnsureAllStagingTablesExist(string connectionString, int timeoutSecs, string schemaName)
        {
            _log.DebugFormat("Checking existence of staging tables in schema: {0}", schemaName);

            if (!DatabaseUtils.SchemaExists(connectionString, timeoutSecs, schemaName))
            {
                DatabaseUtils.CreateSchema(connectionString, timeoutSecs, schemaName);
            }

            var b      = StagingTablesBuilder.Get(schemaName);
            var tables = b.GetTables();

            var tablesInPrimaryStage = DatabaseUtils.GetTablesInSchema(
                connectionString, timeoutSecs, false, StagingSchema.PrimaryStagingSchemaName);

            var builder = new Builder();

            foreach (var t in tables)
            {
                if (!tablesInPrimaryStage.Contains(t.Name))
                {
                    builder.AddTable(t);
                }
            }

            if (builder.HasTables)
            {
                _log.WarnFormat("Recreating missing staging tables in schema: {0}", schemaName);
                builder.Execute(connectionString, timeoutSecs);
            }
        }
예제 #2
0
        public static StagingTablesBuilder Get(string schemaName)
        {
            StagingTablesBuilder result;

            var o = _memoryCache.Get(schemaName);

            if (o == null)
            {
                result = new StagingTablesBuilder(schemaName);
                _memoryCache.Set(schemaName, result, DateTimeOffset.UtcNow.AddMinutes(CacheLifetimeMins));
            }
            else
            {
                result = (StagingTablesBuilder)o;
            }

            return(result);
        }