Example #1
0
        private static void GenerateBuildDeltaProcedures(string schema, string tableName, TrackingTable trackingTable, List <SchemaDataSet.ColumnsRow> targetTableColumns, StringBuilder sqlBuilder, AuditUpdateParameters updateParameters)
        {
            CreateUpdateDeltaTableProcedure createUpdateDeltaTableProcedureTemplate = new CreateUpdateDeltaTableProcedure(schema, tableName, trackingTable, targetTableColumns, updateParameters);
            string sql = createUpdateDeltaTableProcedureTemplate.TransformText();

            sqlBuilder.AppendLine(sql);

            SchemaDataSet schemaDataSet = updateParameters.SchemaDataSet;

            if (schemaDataSet.SchemaTables.TableExists(updateParameters.AuditingSchema, "Catalog"))
            {
                EntityConnectionStringBuilder connectionStringBuilder = Generator.GetEntityConnectionStringBuilder(updateParameters);
                AuditFrameworkEntities        context = new AuditFrameworkEntities(connectionStringBuilder.ToString());
                IOrderedQueryable <Catalog>   priorVersionTrackingTableQuery = from catalog in context.Catalogs
                                                                               where catalog.AuditedSchema.Equals(schema, StringComparison.OrdinalIgnoreCase)
                                                                               where catalog.AuditedTableName.Equals(tableName, StringComparison.OrdinalIgnoreCase)
                                                                               where catalog.Version < trackingTable.Version
                                                                               where !catalog.Archived
                                                                               orderby catalog.Version descending
                                                                               select catalog;
                foreach (Catalog catalog in priorVersionTrackingTableQuery)
                {
                    TrackingTable priorTrackingTable = TrackingTable.Parse(catalog.AuditingTableName);
                    CreateUpdateDeltaPriorTableProcedure createUpdateDeltaPriorTableProcedureTemplate = new CreateUpdateDeltaPriorTableProcedure(schema, tableName, trackingTable, priorTrackingTable, targetTableColumns, updateParameters);
                    sql = createUpdateDeltaPriorTableProcedureTemplate.TransformText();
                    sqlBuilder.AppendLine(sql);
                }
            }
        }
        internal static TrackingTable GetCurrentTrackingTable(string schema, string tableName, AuditUpdateParameters updateParameters)
        {
            SchemaDataSet schemaDataSet = updateParameters.SchemaDataSet;

            if (schemaDataSet.SchemaTables.TableExists(updateParameters.AuditingSchema, "Catalog"))
            {
                EntityConnectionStringBuilder connectionStringBuilder = Generator.GetEntityConnectionStringBuilder(updateParameters);
                AuditFrameworkEntities        context = new AuditFrameworkEntities(connectionStringBuilder.ToString());
                var catalogQuery = from catalog in context.Catalogs
                                   where catalog.AuditedSchema.Equals(schema, StringComparison.OrdinalIgnoreCase) &&
                                   catalog.AuditedTableName.Equals(tableName, StringComparison.OrdinalIgnoreCase)
                                   orderby catalog.Version descending
                                   select catalog;
                Catalog catalogRow = catalogQuery.FirstOrDefault();
                if (null == catalogRow)
                {
                    return(null);
                }
                TrackingTable trackingTable = TrackingTable.Parse(catalogRow.AuditingTableName);
                return(trackingTable);
            }
            return(null);
        }