private string GenerateInterface(BTInterface ifa)
        {
            string code = $"{ifa.Name}[label=<\n";

            code += "<table border=\"0\" cellborder=\"1\" cellspacing=\"0\">\n";
            code += $"<tr><td><b>{ifa.Name}:{ifa.InterfaceType}</b></td></tr>\n";

            foreach (var attr in ifa.Attributes)
            {
                if (attr is BaseBTAttribute)
                {
                    var baseAttr = (BaseBTAttribute)attr;
                    code += $"<tr><td port=\"{baseAttr.Name}\">{baseAttr.Name}:{baseAttr.GetSqlDataTypeDefinition()}</td></tr>\n";
                }
                else if (attr is RefBTAttribute)
                {
                    var baseAttr = (RefBTAttribute)attr;
                    code += $"<tr><td port=\"{baseAttr.IdAttribute.Name}\">{baseAttr.IdAttribute.Name}:{baseAttr.IdAttribute.SqlDataType}</td></tr>\n";
                    code += $"<tr><td>{baseAttr.KnzAttribute.Name}:{baseAttr.KnzAttribute.SqlDataType}</td></tr>\n";
                }
            }

            code += "</table>>];\n\n";
            return(code);
        }
示例#2
0
        public FactALInterface(BTInterface ifa, ALModel alModel)
        {
            this.joinIdx                 = 0;
            this.BTInterface             = ifa;
            this.Model                   = alModel;
            this.HistoryAttribute        = null;
            this.FactInterfaceReferences = new List <FactInterfaceReference>();

            PrepareAttributes();
        }
        private string GenerateRelations(BTInterface ifa)
        {
            var relevantAttributes = ifa.Attributes.Where(a => a is RefBTAttribute).Select(a => (RefBTAttribute)a);

            if (relevantAttributes.Count() > 0)
            {
                string code = "# Beziehungen \n";
                foreach (var r in relevantAttributes)
                {
                    code += $"{ifa.Name}:{r.IdAttribute.Name} -- {r.ReferencedBTInterface.Name}:{((BaseBTAttribute)r.ReferencedBTAttribute).Name}\n";
                }
                return(code);
            }
            else
            {
                return("");
            }
        }
示例#4
0
 private void GenerateHistoryCondition(StringBuilder sb, RefBTAttribute attr, BTInterface ifa)
 {
     if (ifa.InterfaceType == CoreInterfaceType.FACT_TABLE &&
         attr.ReferencedBTInterface.InterfaceType == CoreInterfaceType.FACT_TABLE)
     {
         // Beziehung zwischen zwei historisierten Fakt-Tabellen
         GenerateF2FHistoryCondition(sb, attr);
     }
     else if (ifa.InterfaceType == CoreInterfaceType.FACT_TABLE && attr.ReferencedBTInterface.IsHistoryTable)
     {
         // Beziehung zwischen einer historisierten Fakt-Tabelle und eienr historisierten Dimension
         GenerateF2DHistoryCondition(sb, attr);
     }
     else if (attr.ReferencedBTInterface.IsHistoryTable && ifa.IsHistoryTable)
     {
         // Beziehung zwischen zwei historisierten Dimensionen
         GenerateF2DHistoryCondition(sb, attr); // Durch die kaskadierung der Versionen in BL sollte das jetzt gehen.
     }
 }
        private void CreateCreateTable(StringBuilder sb, BTInterface ifa)
        {
            if (ifa.IsHistoryTable)
            {
                sb.Append($"-- Historientabelle für {ifa.ShortName} anlegen\n");
            }
            else
            {
                sb.Append($"-- Tabelle für {ifa.ShortName} anlegen\n");
            }

            sb.Append($"create table {ifa.FullName} (\n");

            foreach (var attr in ifa.Attributes)
            {
                if (attr is BaseBTAttribute)
                {
                    var baseAttr = (BaseBTAttribute)attr;
                    sb.Append($"{baseAttr.Name} {baseAttr.GetSqlDataTypeDefinition()}".Indent("    "));
                }
                else if (attr is RefBTAttribute)
                {
                    var refAttr = (RefBTAttribute)attr;
                    sb.Append($"{refAttr.IdAttribute.Name} {refAttr.IdAttribute.SqlDataType},\n".Indent("    "));
                    sb.Append($"{refAttr.KnzAttribute.Name} {refAttr.KnzAttribute.SqlDataType}".Indent("    "));
                }
                if (attr != ifa.Attributes.Last())
                {
                    sb.Append(",\n");
                }
                else
                {
                    sb.Append("\n");
                }
            }

            sb.Append(")\n\n");
        }
 private void CreateDropTable(StringBuilder sb, BTInterface ifa)
 {
     sb.Append($"IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[{ifa.Name}]') AND type in (N'U'))\n");
     sb.Append($"drop table {ifa.FullName}\n");
     sb.Append("go\n\n");
 }
示例#7
0
        private void GenerateInsert(StringBuilder sb, BTInterface ifa)
        {
            var refAttributes = ifa.Attributes.Where(a => a is RefBTAttribute)
                                .Select(a => (RefBTAttribute)a)
                                .ToList <RefBTAttribute>();

            sb.Append($"insert into {ifa.FullName} (\n");
            foreach (var attr in ifa.Attributes)
            {
                if (attr is BaseBTAttribute)
                {
                    var baseAttr = (BaseBTAttribute)attr;
                    sb.Append($"{baseAttr.Name}".Indent("    "));
                }
                else
                {
                    var refAttr = (RefBTAttribute)attr;
                    sb.Append($"{refAttr.IdAttribute.Name},\n{refAttr.KnzAttribute.Name}".Indent("    "));
                }
                if (attr != ifa.Attributes.Last())
                {
                    sb.Append(",");
                }
                sb.Append("\n");
            }
            sb.Append(")\nselect\n");
            foreach (var attr in ifa.Attributes)
            {
                if (attr is BaseBTAttribute)
                {
                    var baseAttr = (BaseBTAttribute)attr;
                    sb.Append($"t.{baseAttr.blAttribute.Name} as {baseAttr.Name}".Indent("    "));
                }
                else
                {
                    var refAttr = (RefBTAttribute)attr;
                    var idAttr  = refAttr.ReferencedBLInterface.Attributes.Single(a => a.IsIdentity);
                    sb.Append($"coalesce({refAttr.JoinAlias}.{idAttr.Name}, -1) as {refAttr.IdAttribute.Name},\nt.{attr.GetBLAttribute().Name} as {refAttr.KnzAttribute.Name}".Indent("    "));
                }
                if (attr != ifa.Attributes.Last())
                {
                    sb.Append(",");
                }
                sb.Append("\n");
            }
            sb.Append($"from {ifa.blInterface.FullName} as t\n");
            foreach (var attr in refAttributes)
            {
                sb.Append($"left join {attr.ReferencedBLInterface.FullName} as {attr.JoinAlias}\n");
                sb.Append($"on t.{attr.blAttribute.Name} = {attr.JoinAlias}.{attr.ReferencedBLAttribute.Name}\n".Indent("    "));
                if (ifa.IsMandant && attr.ReferencedBLInterface.IsMandant)
                {
                    sb.Append($"and t.Mandant_KNZ = {attr.JoinAlias}.Mandant_KNZ\n".Indent("    "));
                }
                if (ifa.blInterface.IsHistorized && attr.ReferencedBLInterface.IsHistorized)
                {
                    GenerateHistoryCondition(sb, attr, ifa);
                }
            }
            sb.Append(";\n\n");
        }
示例#8
0
 private void GenerateTruncate(StringBuilder sb, BTInterface ifa)
 {
     sb.Append($"truncate table {ifa.FullName};\n\n");
 }
 private void CreateDropTable(StringBuilder sb, BTInterface ifa)
 {
     sb.Append($"drop table if exists {ifa.FullName};\n");
 }