public static IEnumerable <AstPackageNode> ProcessTableStaticSource(AstTableNode astTableNode) { var packageList = new List <AstPackageNode>(); foreach (var source in astTableNode.Sources) { var staticSource = source as AstTableStaticSourceNode; if (staticSource != null && staticSource.Rows.Count > 0) { var table = staticSource.ParentItem as AstTableNode; if (table != null && staticSource.EmitMergePackage) { if (table.PreferredKey == null) { MessageEngine.Trace(table, Severity.Error, "L0110", "Table {0} does not contain a primary key and therefore cannot use Static Source Merging. Add a primary key or set EmitMergePackage to false.", table.Name); } var package = new AstPackageNode(table.ParentItem) { Emit = table.Emit, Log = false, Name = staticSource.Name, PackageFolderSubpath = table.Name, PackageType = GetPackageType(table) }; // Staging Container var staging = new AstStagingContainerTaskNode(package) { Log = false, Name = Utility.NameCleanerAndUniqifier(source.Name + "_Stg"), }; var stagingCloneTable = new AstTableCloneNode(staging) { Name = String.Format(CultureInfo.InvariantCulture, "__{0}_Static", table.Name), Connection = table.Connection, Table = table }; staging.Tables.Add(stagingCloneTable); CloneTableLowerer.LowerCloneTable(stagingCloneTable); staging.Tasks.Add(CreateInsertExecuteSql(staticSource, staging, stagingCloneTable)); staging.Tasks.Add(CreateMergeTask(table, staging, stagingCloneTable)); package.Tasks.Add(staging); packageList.Add(package); staticSource.LoweredPackage = package; } } } return(packageList); }
public static void ProcessPrincipals(AstRootNode astRootNode) { if (astRootNode.Principals.Count > 0) { var package = new AstPackageNode(astRootNode) { Name = "PrincipalsInitializer", Emit = true, PackageType = "Principal" }; astRootNode.Packages.Add(package); foreach (AstPrincipalNode principal in astRootNode.Principals) { TemplatePlatformEmitter principalTemplate; switch (principal.PrincipalType) { case PrincipalType.ApplicationRole: principalTemplate = new TemplatePlatformEmitter("CreatePrincipalApplicationRole", principal.Name); break; case PrincipalType.DBRole: principalTemplate = new TemplatePlatformEmitter("CreatePrincipalDatabaseRole", principal.Name); break; case PrincipalType.SqlUser: principalTemplate = new TemplatePlatformEmitter("CreatePrincipalSqlUser", principal.Name); break; case PrincipalType.WindowsGroup: principalTemplate = new TemplatePlatformEmitter("CreatePrincipalWindowsUser", principal.Name); break; case PrincipalType.WindowsUser: principalTemplate = new TemplatePlatformEmitter("CreatePrincipalWindowsUser", principal.Name); break; default: MessageEngine.Trace(principal, Severity.Error, "V0139", "Unknown Principal Type {0} in principal {1}", principal.PrincipalType.ToString(), principal.Name); return; } var executeSqlTask = new AstExecuteSqlTaskNode(package) { Name = Utility.NameCleanerAndUniqifier(String.Format(CultureInfo.InvariantCulture, "PrincipalConfig_{0}", principal.Name)), Connection = principal.Connection }; executeSqlTask.Query = new AstExecuteSqlQueryNode(executeSqlTask) { Body = principalTemplate.Emit(), QueryType = QueryType.Standard }; package.Tasks.Add(executeSqlTask); } } }
public static void ProcessSchema(AstRootNode astRootNode, AstSchemaNode schemaNode) { const string PackageTypeName = "Schema"; var packageNode = new AstPackageNode(schemaNode.ParentItem); packageNode.Name = schemaNode.Name; packageNode.PackageType = PackageTypeName; var executeSqlNode = new AstExecuteSqlTaskNode(packageNode) { Name = schemaNode.Name, Connection = schemaNode.Connection, ResultSet = ExecuteSqlResultSet.None }; executeSqlNode.Query = new AstExecuteSqlQueryNode(executeSqlNode) { QueryType = QueryType.Standard, Body = new TemplatePlatformEmitter("CreateSchema", schemaNode.Name).Emit() }; packageNode.Tasks.Add(executeSqlNode); bool hasPermissions = false; var permissionBuilder = new StringBuilder(); foreach (var permission in schemaNode.Permissions) { hasPermissions = true; permissionBuilder.AppendLine(PermissionsLowerer.ProcessPermission(schemaNode, permission)); } if (hasPermissions) { var permissionsExecuteSqlTask = new AstExecuteSqlTaskNode(packageNode) { Name = "__SetPermissions", Connection = schemaNode.Connection, }; permissionsExecuteSqlTask.Query = new AstExecuteSqlQueryNode(permissionsExecuteSqlTask) { Body = permissionBuilder.ToString(), QueryType = QueryType.Standard }; packageNode.Tasks.Add(permissionsExecuteSqlTask); } if (schemaNode.CustomExtensions != null) { packageNode.Tasks.Add(schemaNode.CustomExtensions); } astRootNode.Packages.Add(packageNode); }
public static AstPackageNode ProcessTable(AstTableNode tableNode) { string packageTypeName = "Table"; if (tableNode is AstDimensionNode) { packageTypeName = "Dimension"; } else if (tableNode is AstFactNode) { packageTypeName = "FactTable"; } // TODO: Fix this null parent node var packageNode = new AstPackageNode(tableNode.ParentItem); packageNode.Name = tableNode.Name; packageNode.PackageType = packageTypeName; packageNode.Emit = tableNode.Emit; LowerTable(packageNode, tableNode, tableNode.SchemaQualifiedName, false); return(packageNode); }
private AstIR ProcessTableQuerySources(AstIR astIR) { List <AstTableNode> tables = new List <AstTableNode>(); tables.AddRange(astIR.AstRootNode.Dimensions.Cast <AstTableNode>()); tables.AddRange(astIR.AstRootNode.Facts.Cast <AstTableNode>()); tables.AddRange(astIR.AstRootNode.Tables); foreach (AstTableNode table in tables) { foreach (AstTableQuerySourceNode querySource in table.Sources.OfType <AstTableQuerySourceNode>()) { AstPackageNode package = new AstPackageNode(); package.ConstraintMode = ContainerConstraintMode.Linear; package.DefaultPlatform = PlatformType.SSIS08; package.Log = false; package.Name = querySource.Name; package.Type = "ETL"; AstStagingContainerTaskNode staging = new AstStagingContainerTaskNode(); staging.ConstraintMode = ContainerConstraintMode.Linear; staging.Log = false; staging.Name = querySource.Name; staging.CreateAs = String.Format("__Staging_{0}_{1}", table.Name, querySource.Name); staging.StagingConnection = table.Connection; staging.Table = table; AstETLRootNode etl = new AstETLRootNode(); etl.Name = String.Format("__ETL_Staging_{0}_{1}", table.Name, querySource.Name); etl.DelayValidation = true; AstQuerySourceNode source = new AstQuerySourceNode(); source.Connection = querySource.Connection; source.Name = String.Format("__ETL_Staging_Source_{0}_{1}", table.Name, querySource.Name); source.Query = querySource.Query; etl.Transformations.Add(source); AstDestinationNode destination = new AstDestinationNode(); destination.AccessMode = DestinationAccessModeFacet.TableFastLoad; destination.CheckConstraints = true; destination.TableLock = true; destination.Connection = table.Connection; destination.Name = String.Format("__ETL_Staging_Destination_{0}_{1}", table.Name, querySource.Name); destination.TableName = staging.CreateAs; destination.ValidateExternalMetadata = false; etl.Transformations.Add(destination); staging.Tasks.Add(etl); AstMergeTaskNode merge = new AstMergeTaskNode(); merge.Connection = table.Connection; merge.Name = String.Format("__Staging_Merge_{0}_{1}", table.Name, querySource.Name); merge.SourceName = staging.CreateAs; merge.TargetConstraint = table.PreferredKey; staging.Tasks.Add(merge); package.Tasks.Add(staging); astIR.AstRootNode.Packages.Add(package); } } return(astIR); }