예제 #1
0
        public override void Emit(XPathNavigator patternNavigator)
        {
            string name           = patternNavigator.SelectSingleNode("@Name").Value;
            string constraintMode = patternNavigator.SelectSingleNode("@ConstraintMode").Value;

            DTS.Sequence newParentContainer = VulcanPackage.AddSequenceContainer(name, ParentContainer);

            DTS.Executable previousExec = null;
            Pattern        p            = null;

            foreach (XPathNavigator nav in patternNavigator.SelectChildren(XPathNodeType.Element))
            {
                p = PatternFactory.ProcessPattern(VulcanPackage, newParentContainer, nav, p);

                switch (constraintMode)
                {
                case "Linear":
                    VulcanPackage.AddPrecedenceConstraint(previousExec, p.FirstExecutableGeneratedByPattern, newParentContainer);
                    break;

                case "Parallel":
                    break;

                default:
                    Message.Trace(Severity.Error, "Unknown ConstraintMode {0}", constraintMode);
                    break;
                }
                previousExec = p.LastExecutableGeneratedByPattern;
            }
            this.FirstExecutableGeneratedByPattern = newParentContainer;
            this.LastExecutableGeneratedByPattern  = this.FirstExecutableGeneratedByPattern;
        }
예제 #2
0
        public override void Emit(XPathNavigator patternNavigator)
        {
            if (patternNavigator != null)
            {
                string taskName       = patternNavigator.SelectSingleNode("@Name").Value;
                string connectionName = patternNavigator.SelectSingleNode("@Connection").Value;
                string varPrefix      = patternNavigator.SelectSingleNode("@PreviousLogEntryVariablePrefix").Value;

                string sourceColumn        = patternNavigator.SelectSingleNode("@SourceColumn") == null ? null : patternNavigator.SelectSingleNode("@SourceColumn").Value;
                string destinationColumn   = patternNavigator.SelectSingleNode("@DestinationColumn") == null ? null : patternNavigator.SelectSingleNode("@DestinationColumn").Value;
                string table               = patternNavigator.SelectSingleNode("@Table") == null ? null : patternNavigator.SelectSingleNode("@Table").Value;
                string tableConnectionName = patternNavigator.SelectSingleNode("@TableConnection") == null ? null : patternNavigator.SelectSingleNode("@TableConnection").Value;

                if (varPrefix.ToUpperInvariant() == "varLog")
                {
                    Message.Trace(Severity.Error, "Name: {0}: Error in PreviousLogEntryVariablePrefix: varLog is a reserved variable name.", taskName);
                    return;
                }

                Connection connection =
                    Connection.GetExistingConnection(VulcanPackage, connectionName);

                LogtainerLog ll = new LogtainerLog(
                    VulcanPackage,
                    Resources.LogVariablePrefix + VulcanPackage.Name + taskName,
                    sourceColumn,
                    destinationColumn,
                    table,
                    tableConnectionName
                    );

                string  execSqlTaskName = Resources.Log + Resources.Seperator + VulcanPackage.Name + Resources.Seperator + taskName + Resources.Seperator;
                SQLTask logStartTask    = new SQLTask(VulcanPackage, execSqlTaskName + Resources.Start, execSqlTaskName + Resources.Start, ParentContainer, connection);


                TemplateEmitter te = new TemplateEmitter(VulcanPackage.TemplateManager["LogStart"]);
                te.SetNamedParameter("ETLName", VulcanPackage.Name);
                te.SetNamedParameter("TaskName", taskName);

                if (_logStack.Count > 0)
                {
                    te.SetNamedParameter("ParentLogID", "?");
                    // Yes you have to hard code the data type as there is no lookup or cross-reference source, and the intger is dependent on the connection you create... bugbug!
                    logStartTask.BindParameter(CurrentLog.LogVariable, Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Input, 3);
                }
                else
                {
                    te.SetNamedParameter("ParentLogID", "NULL");
                }
                logStartTask.BindParameter(ll.LogVariable, Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, 3);
                logStartTask.BindParameter(ll.LastRecordLogVariable, Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, 3);
                logStartTask.BindParameter(ll.IsAnotherInstanceCurrentlyRunningLogVariable, Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, 3);


                string sqlExpression;
                te.Emit(out sqlExpression);
                logStartTask.TransmuteToExpressionTask(sqlExpression);

                te = new TemplateEmitter(VulcanPackage.TemplateManager["LogGetValue"]);
                te.SetNamedParameter("LogID", ll.LastRecordLogVariable.QualifiedName);
                this.FirstExecutableGeneratedByPattern = logStartTask.SQLTaskHost;



                // Push the current log variable onto the stack!
                _logStack.Push(ll);

                //Add a new SQL Task to read the  previous log
                te = new TemplateEmitter("LogGetValue", VulcanPackage, ll.LastRecordLogVariable.QualifiedName);
                string readPreviousLogValuesQuery;
                te.Emit(out readPreviousLogValuesQuery);

                SQLTask readPreviousLogValues = new SQLTask(VulcanPackage, Resources.Log + Resources.LoadInto + varPrefix, Resources.Log + Resources.LoadInto + varPrefix, ParentContainer, connection);
                readPreviousLogValues.TransmuteToExpressionTask(readPreviousLogValuesQuery);
                VulcanPackage.AddPrecedenceConstraint(this.FirstExecutableGeneratedByPattern, readPreviousLogValues.SQLTaskHost, ParentContainer);

                //Bind and create variables for the SQL Task that reads the previous log. This is kinda hacky
                readPreviousLogValues.BindParameter(
                    VulcanPackage.AddVariable(varPrefix + "StartTime", new DateTime(1980, 1, 1)),
                    Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output,
                    (int)System.Data.OleDb.OleDbType.DBTimeStamp,
                    255);
                readPreviousLogValues.BindParameter(
                    VulcanPackage.AddVariable(varPrefix + "EndTime", new DateTime(1980, 1, 1)),
                    Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output,
                    (int)System.Data.OleDb.OleDbType.DBTimeStamp,
                    255);

                readPreviousLogValues.BindParameter(
                    VulcanPackage.AddVariable(varPrefix + "FirstSourceRecord", String.Empty),
                    Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output,
                    (int)System.Data.OleDb.OleDbType.WChar,
                    255);
                readPreviousLogValues.BindParameter(
                    VulcanPackage.AddVariable(varPrefix + "FirstDestinationRecord", String.Empty),
                    Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output,
                    (int)System.Data.OleDb.OleDbType.WChar,
                    255);
                readPreviousLogValues.BindParameter(
                    VulcanPackage.AddVariable(varPrefix + "LastSourceRecord", String.Empty),
                    Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output,
                    (int)System.Data.OleDb.OleDbType.WChar,
                    255);
                readPreviousLogValues.BindParameter(
                    VulcanPackage.AddVariable(varPrefix + "LastDestinationRecord", String.Empty),
                    Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output,
                    (int)System.Data.OleDb.OleDbType.WChar,
                    255);

                readPreviousLogValues.BindParameter(
                    VulcanPackage.AddVariable(varPrefix + "Status", String.Empty),
                    Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output,
                    (int)System.Data.OleDb.OleDbType.WChar,
                    255);

                readPreviousLogValues.BindParameter(
                    VulcanPackage.AddVariable(varPrefix + "Notes", String.Empty),
                    Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output,
                    (int)System.Data.OleDb.OleDbType.WChar,
                    255);

                // Handle the sub-tasks just like the Container pattern
                DTS.Executable previousExec = readPreviousLogValues.SQLTaskHost;
                Pattern        p            = null;
                foreach (XPathNavigator nav in patternNavigator.SelectChildren(XPathNodeType.Element))
                {
                    p = PatternFactory.ProcessPattern(VulcanPackage, ParentContainer, nav, p);
                    VulcanPackage.AddPrecedenceConstraint(previousExec, p.FirstExecutableGeneratedByPattern, ParentContainer);
                    previousExec = p.LastExecutableGeneratedByPattern;
                }

                this.LastExecutableGeneratedByPattern = previousExec;

                // Pop the current log variable off of the stack and end the log.
                ll = _logStack.Pop();

                te = new TemplateEmitter(VulcanPackage.TemplateManager["LogSetValue"]);
                te.SetNamedParameter("LogID", ll.LogVariable.QualifiedName);
                StringBuilder writeValuesToLogQuery = new StringBuilder();
                foreach (string column in ll.LogColumnDictionary.Keys)
                {
                    string temp;
                    te.SetNamedParameter("Column", column);
                    te.SetNamedParameter("Value", ll.LogColumnDictionary[column].QualifiedName);
                    te.Emit(out temp);
                    writeValuesToLogQuery.Append(temp);
                    writeValuesToLogQuery.AppendFormat(" + \n");
                }

                te = new TemplateEmitter(VulcanPackage.TemplateManager["LogEnd"]);
                te.Emit(out sqlExpression);

                writeValuesToLogQuery.Append(sqlExpression);

                SQLTask logEndTask = new SQLTask(VulcanPackage, execSqlTaskName + Resources.Stop, execSqlTaskName + Resources.Stop, ParentContainer, connection);
                logEndTask.TransmuteToExpressionTask(writeValuesToLogQuery.ToString());
                logEndTask.BindParameter(ll.LogVariable, Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Input, 3);
                if (previousExec != null)
                {
                    VulcanPackage.AddPrecedenceConstraint(previousExec, logEndTask.SQLTaskHost, ParentContainer);
                }
                this.LastExecutableGeneratedByPattern = logEndTask.SQLTaskHost;
            }
        }
예제 #3
0
        public override void Emit(XPathNavigator patternNavigator)
        {
            if (patternNavigator != null)
            {
                string createTableFile = VulcanPackage.AddFileToProject(
                    Resources.Create + Resources.Schema + Resources.Seperator +
                    VulcanPackage.Name +
                    Resources.ExtensionSQLFile
                    );

                File.Delete(createTableFile);
                string insertSPFile          = null;
                string checkAndinsertSPFile  = null;
                string insertAndUpdateSPFile = null;
                bool   hasCheckAndInsert     = false;
                bool   hasInsertAndUpdate    = false;

                foreach (XPathNavigator nav in patternNavigator.Select("rc:Dimension", VulcanPackage.VulcanConfig.NamespaceManager))
                {
                    string dimensionName = nav.SelectSingleNode("@Name", VulcanPackage.VulcanConfig.NamespaceManager).Value;

                    Message.Trace(Severity.Debug, "Emitting Create Statement for " + dimensionName);

                    TableHelper    th = new TableHelper(dimensionName, VulcanPackage.VulcanConfig, nav.SelectSingleNode("rc:Table", VulcanPackage.VulcanConfig.NamespaceManager));
                    TableEmitterEx te = new TableEmitterEx(th, VulcanPackage);
                    te.Emit(createTableFile, true);

                    if (String.IsNullOrEmpty(insertSPFile))
                    {
                        insertSPFile = VulcanPackage.AddFileToProject(
                            Resources.SPPrefix + Resources.Seperator +
                            Resources.Insert +
                            VulcanPackage.Name +
                            Resources.ExtensionSQLFile
                            );
                        File.Delete(insertSPFile);
                    }

                    InsertSPEmitter spe = new InsertSPEmitter(dimensionName, nav.SelectSingleNode("rc:Table", VulcanPackage.VulcanConfig.NamespaceManager), th, VulcanPackage);
                    spe.Emit(insertSPFile, true);

                    if (nav.Select("rc:Table/rc:CheckAndInsertUniqueColumn", VulcanPackage.VulcanConfig.NamespaceManager).Count > 0)
                    {
                        hasCheckAndInsert = true;


                        if (String.IsNullOrEmpty(checkAndinsertSPFile))
                        {
                            checkAndinsertSPFile = VulcanPackage.AddFileToProject(
                                Resources.SPPrefix + Resources.Seperator +
                                Resources.CheckAndInsert +
                                VulcanPackage.Name +
                                Resources.ExtensionSQLFile
                                );

                            File.Delete(checkAndinsertSPFile);
                        }

                        CheckAndInsertSPEmitter cispe = new CheckAndInsertSPEmitter(dimensionName, nav.SelectSingleNode("rc:Table", VulcanPackage.VulcanConfig.NamespaceManager), th, VulcanPackage);
                        cispe.Emit(checkAndinsertSPFile, true);
                    }

                    if (nav.Select("rc:Table/rc:InsertOrUpdateUniqueColumn", VulcanPackage.VulcanConfig.NamespaceManager).Count > 0)
                    {
                        hasInsertAndUpdate = true;

                        if (String.IsNullOrEmpty(insertAndUpdateSPFile))
                        {
                            insertAndUpdateSPFile = VulcanPackage.AddFileToProject(
                                Resources.SPPrefix + Resources.Seperator +
                                Resources.CheckAndInsert +
                                Resources.Update +
                                VulcanPackage.Name +
                                Resources.ExtensionSQLFile
                                );

                            File.Delete(insertAndUpdateSPFile);
                        }
                        InsertAndUpdateSPEmitter iuspe = new InsertAndUpdateSPEmitter(dimensionName, nav.SelectSingleNode("rc:Table", VulcanPackage.VulcanConfig.NamespaceManager), th, VulcanPackage);
                        iuspe.Emit(insertAndUpdateSPFile, true);
                    }
                }

                Dictionary <string, object> properties = new Dictionary <string, object>();
                properties["Name"] = Resources.Create + Resources.Schema + Resources.Seperator + VulcanPackage.Name;

                //TODO: This is a hardcoded bug, should be removed when Dimensions are rewritten!
                Connection dimensionConnection = Connection.GetExistingConnection(VulcanPackage, patternNavigator);

                SQLTask createTableTask =
                    new SQLTask(
                        VulcanPackage,
                        properties["Name"].ToString(),
                        properties["Name"].ToString(),
                        ParentContainer,
                        dimensionConnection,
                        properties
                        );

                createTableTask.TransmuteToFileTask(properties["Name"] + Resources.ExtensionSQLFile);

                properties["Name"] = Resources.SPPrefix + Resources.Seperator +
                                     Resources.Insert +
                                     VulcanPackage.Name;

                this.FirstExecutableGeneratedByPattern = createTableTask.SQLTaskHost;
                this.LastExecutableGeneratedByPattern  = this.FirstExecutableGeneratedByPattern;


                SQLTask createInsertSPTask =
                    new SQLTask(
                        VulcanPackage,
                        properties["Name"].ToString(),
                        properties["Name"].ToString(),
                        ParentContainer,
                        dimensionConnection,
                        properties
                        );
                createInsertSPTask.TransmuteToFileTask(properties["Name"] + Resources.ExtensionSQLFile);


                properties["Name"] = Resources.SPPrefix + Resources.Seperator +
                                     Resources.CheckAndInsert +
                                     VulcanPackage.Name;

                properties["Description"] = properties["Name"];

                VulcanPackage.AddPrecedenceConstraint(LastExecutableGeneratedByPattern, createInsertSPTask.SQLTaskHost, ParentContainer);
                this.LastExecutableGeneratedByPattern = createInsertSPTask.SQLTaskHost;

                if (hasCheckAndInsert)
                {
                    SQLTask createCheckInsertSPTask =
                        new SQLTask(
                            VulcanPackage,
                            properties["Name"].ToString(),
                            properties["Name"].ToString(),
                            ParentContainer,
                            dimensionConnection,
                            properties
                            );
                    createCheckInsertSPTask.TransmuteToFileTask(properties["Name"] + Resources.ExtensionSQLFile);

                    properties["Name"] = Resources.SPPrefix + Resources.Seperator +
                                         Resources.Insert + Resources.Defaults +
                                         VulcanPackage.Name;

                    properties["Description"] = properties["Name"];

                    VulcanPackage.AddPrecedenceConstraint(createInsertSPTask.SQLTaskHost, createCheckInsertSPTask.SQLTaskHost, ParentContainer);
                    this.LastExecutableGeneratedByPattern = createCheckInsertSPTask.SQLTaskHost;
                } // hasCheckAndInsert

                if (hasInsertAndUpdate)
                {
                    properties["Name"] = properties["Name"] = Resources.SPPrefix + Resources.Seperator +
                                                              Resources.CheckAndInsert + Resources.Update +
                                                              VulcanPackage.Name;
                    properties["Description"] = properties["Name"];

                    SQLTask createInsertUpdateTask =
                        new SQLTask(
                            VulcanPackage,
                            properties["Name"].ToString(),
                            properties["Name"].ToString(),
                            ParentContainer,
                            dimensionConnection,
                            properties
                            );
                    createInsertUpdateTask.TransmuteToFileTask(properties["Name"] + Resources.ExtensionSQLFile);

                    VulcanPackage.AddPrecedenceConstraint(LastExecutableGeneratedByPattern, createInsertUpdateTask.SQLTaskHost, ParentContainer);
                    this.LastExecutableGeneratedByPattern = createInsertUpdateTask.SQLTaskHost;
                } // hasInsertAndUpdate
            }
        }