예제 #1
0
        public RefBTAttribute(RefBLAttribute blAttribute, BTInterface ifa)
        {
            this.blAttribute         = blAttribute;
            this.refBLAttribute      = blAttribute;
            this.otherBlAttribute    = null;
            this.ParentInterface     = ifa;
            this.IsIdentity          = blAttribute.IsIdentity;
            this.IsPartOfUniqueKey   = blAttribute.IsPartOfUniqueKey;
            this.HasToUseVerionTable = GetHasToUseVersionTable();

            if (HasToUseVerionTable)
            {
                // Wenn das aktuelle Interface keine FactTable ist und beide eine Historie haben,
                // dann wird die Beziehung über die Historientabellen aufgelöst
                var blModel = blAttribute.ParentInterface.ParentModel;
                this.ReferencedBLInterface = blModel.Interfaces.Single(i => i.Name == blAttribute.ReferencedAttribute.ParentInterface.Name + "_VERSION");
                this.ReferencedBLAttribute = this.ReferencedBLInterface.Attributes.Single(a => a.IsPartOfUniqueKey && !a.IsTechnicalAttribute && a.Name != "Mandant_KNZ");
            }
            else
            {
                // ansonsten wird die Tabelle ohne Historie verwendet.
                this.ReferencedBLAttribute = blAttribute.ReferencedAttribute;
                this.ReferencedBLInterface = blAttribute.ReferencedAttribute.ParentInterface;
            }

            this.IdAttribute  = new IdSubAttribute(this);
            this.KnzAttribute = new KnzSubAttribute(this);
        }
예제 #2
0
        public static string GetSqlDataType(IBLAttribute attr)
        {
            switch (attr.DataType)
            {
            case CoreDataType.DATE:
                return("date");

            case CoreDataType.DATETIME:
                return("datetime");

            case CoreDataType.DECIMAL:
                return("decimal");

            case CoreDataType.INT:
                // Sonderfall: ID in Fakttabelle als bigint berücksichtigen...
                if (attr?.ParentInterface?.InterfaceType == CoreInterfaceType.FACT_TABLE && attr.IsIdentity)
                {
                    return("bigint");
                }
                else
                {
                    return("int");
                }

            case CoreDataType.VARCHAR:
                return("varchar");

            default:
                throw new InvalidDataTypeException($"Ungültiger Datentyp: Die SqlDataTypeDefinition für das Attribut {attr.FullName} konnte nicht generiert werden.");
            }
        }
        private bool ColumnHasCorrectType(IBLAttribute attr)
        {
            AssureOpenConnection();
            using (var cmd = con.CreateCommand()) {
                List <SqlParameter> openParams = new List <SqlParameter>();
                cmd.CommandText  = "select 1 from information_schema.columns where table_name = @table_name and table_schema = 'dbo' ";
                cmd.CommandText += "and column_name = @column_name and data_type = @data_type ";
                switch (attr.DataType)
                {
                case CoreDataType.VARCHAR:
                    cmd.CommandText += "and character_maximum_length = @max_len";
                    openParams.Add(new SqlParameter("max_len", attr.Length));
                    break;

                case CoreDataType.DECIMAL:
                    cmd.CommandText += "and numeric_precision = @max_len and numeric_scale = @scale";
                    openParams.Add(new SqlParameter("max_len", attr.Length));
                    openParams.Add(new SqlParameter("scale", attr.Decimals));
                    break;
                }
                cmd.Prepare();
                cmd.Parameters.Add(new SqlParameter("table_name", attr.ParentInterface.Name));
                cmd.Parameters.Add(new SqlParameter("column_name", attr.Name));
                cmd.Parameters.Add(new SqlParameter("data_type", BLDataType.GetSqlDataType(attr)));
                foreach (var param in openParams)
                {
                    cmd.Parameters.Add(param);
                }
                object result = cmd.ExecuteScalar();
                return(result != null);
            }
        }
예제 #4
0
        private string GenerateAttribute(IBLAttribute attr, IBLInterface ifa)
        {
            string code = $"{attr.Name} {attr.GetSqlDataTypeDefinition()}";

            if (ifa.Attributes.Last() != attr)
            {
                code += ", ";
            }
            return(code);
        }
        public void TestDefaultBLInterface_BySimpleFile()
        {
            // Daten einlesen...
            var fileName = @"C:\Users\wiw39784\Documents\git\CeusDL2\Test\Data\interface_demo.ceusdl";
            var data     = new ParsableData(System.IO.File.ReadAllText(fileName), fileName);
            var p        = new FileParser(data);
            var result   = p.Parse();
            var model    = new CoreModel(result);

            // Auswählen
            var coreIfa  = model.Interfaces[0];
            var coreAttr = coreIfa.Attributes[0];

            // in DefaultBLInterface konvertieren
            var blIfa = new DefaultBLInterface(coreIfa, null);

            IBLAttribute attr = blIfa.Attributes[0];

            // Inhalt des 0. Attributs überprüfen
            Assert.AreEqual("Semester_ID", attr.Name);
            Assert.AreEqual("def_Semester.Semester_ID", attr.FullName);
            Assert.AreEqual(CoreDataType.INT, attr.DataType);
            Assert.AreEqual(0, attr.Length);
            Assert.AreEqual(0, attr.Decimals);
            Assert.IsFalse(attr.IsPartOfUniqueKey);
            Assert.IsTrue(attr.IsIdentity);
            Assert.IsTrue(attr.IsPrimaryKey);

            attr = blIfa.Attributes[1];

            // Inhalt des 1. Attributs überprüfen
            Assert.AreEqual("Semester_KNZ", attr.Name);
            Assert.AreEqual("def_Semester.Semester_KNZ", attr.FullName);
            Assert.AreEqual(CoreDataType.VARCHAR, attr.DataType);
            Assert.AreEqual(50, attr.Length);
            Assert.AreEqual(0, attr.Decimals);
            Assert.IsTrue(attr.IsPartOfUniqueKey);
            Assert.IsFalse(attr.IsIdentity);
            Assert.IsFalse(attr.IsPrimaryKey);

            attr = blIfa.Attributes[2];

            // Inhalt des 2. Attributs überprüfen
            Assert.AreEqual("Semester_KURZBEZ", attr.Name);
            Assert.AreEqual("def_Semester.Semester_KURZBEZ", attr.FullName);
            Assert.AreEqual(CoreDataType.VARCHAR, attr.DataType);
            Assert.AreEqual(100, attr.Length);
            Assert.AreEqual(0, attr.Decimals);
            Assert.IsFalse(attr.IsPartOfUniqueKey);
            Assert.IsFalse(attr.IsIdentity);
            Assert.IsFalse(attr.IsPrimaryKey);
        }
예제 #6
0
        public void TestBLModel_BySimpleFile()
        {
            // Daten einlesen...
            var fileName = @"..\..\..\..\Test\Data\interface_demo.ceusdl";
            var data     = new ParsableData(System.IO.File.ReadAllText(fileName), fileName);
            var p        = new FileParser(data);
            var result   = p.Parse();
            var model    = new CoreModel(result);

            var blModel = new BLModel(model);
            var blIfa   = blModel.Interfaces[0];

            // Properties des 0. Interfaces prüfen...
            Assert.IsFalse(blIfa.IsHistorized);
            Assert.IsNull(blIfa.HistoryAttribute);

            IBLAttribute attr = blIfa.Attributes[0];

            // Inhalt des 0. Attributs überprüfen
            Assert.AreEqual("Semester_ID", attr.Name);
            Assert.AreEqual("def_Semester.Semester_ID", attr.FullName);
            Assert.AreEqual(CoreDataType.INT, attr.DataType);
            Assert.AreEqual(0, attr.Length);
            Assert.AreEqual(0, attr.Decimals);
            Assert.IsFalse(attr.IsPartOfUniqueKey);
            Assert.IsTrue(attr.IsIdentity);
            Assert.IsTrue(attr.IsPrimaryKey);

            attr = blIfa.Attributes[1];

            // Inhalt des 1. Attributs überprüfen
            Assert.AreEqual("Semester_KNZ", attr.Name);
            Assert.AreEqual("def_Semester.Semester_KNZ", attr.FullName);
            Assert.AreEqual(CoreDataType.VARCHAR, attr.DataType);
            Assert.AreEqual(50, attr.Length);
            Assert.AreEqual(0, attr.Decimals);
            Assert.IsTrue(attr.IsPartOfUniqueKey);
            Assert.IsFalse(attr.IsIdentity);
            Assert.IsFalse(attr.IsPrimaryKey);

            attr = blIfa.Attributes[2];

            // Inhalt des 2. Attributs überprüfen
            Assert.AreEqual("Semester_KURZBEZ", attr.Name);
            Assert.AreEqual("def_Semester.Semester_KURZBEZ", attr.FullName);
            Assert.AreEqual(CoreDataType.VARCHAR, attr.DataType);
            Assert.AreEqual(100, attr.Length);
            Assert.AreEqual(0, attr.Decimals);
            Assert.IsFalse(attr.IsPartOfUniqueKey);
            Assert.IsFalse(attr.IsIdentity);
            Assert.IsFalse(attr.IsPrimaryKey);
        }
        public void TestCustomBLAttribute_Mandant_Sample2()
        {
            IBLAttribute attr = CustomBLAttribute.GetNewMandantAttribute(null);

            Assert.AreEqual("varchar(10) not null", attr.GetSqlDataTypeDefinition());
            Assert.AreEqual("Mandant_KNZ", attr.Name);
            Assert.AreEqual(10, attr.Length);
            Assert.AreEqual(0, attr.Decimals);
            Assert.AreEqual(CoreDataType.VARCHAR, attr.DataType);
            Assert.IsNull(attr.ParentInterface);
            Assert.IsTrue(attr.IsPartOfUniqueKey);
            Assert.IsFalse(attr.IsIdentity);
            Assert.IsFalse(attr.IsPrimaryKey);
        }
예제 #8
0
        ///
        /// Wichtig: nur in BT zur Abbildung der History-Beziehung nutzen!
        ///
        internal RefBTAttribute(BaseBLAttribute blAttribute, IBLInterface blIfa, BTInterface ifa)
        {
            this.blAttribute         = blAttribute;
            this.refBLAttribute      = null;
            this.otherBlAttribute    = blAttribute;
            this.ParentInterface     = ifa;
            this.IsIdentity          = otherBlAttribute.IsIdentity;
            this.IsPartOfUniqueKey   = otherBlAttribute.IsPartOfUniqueKey;
            this.HasToUseVerionTable = false; // TODO: Das ist noch nicht sicher !

            var blModel = blAttribute.ParentInterface.ParentModel;

            this.ReferencedBLInterface = blIfa;
            this.ReferencedBLAttribute = blIfa.Attributes.Single(a => a.IsPartOfUniqueKey && (a is BaseBLAttribute));

            this.IdAttribute  = new IdSubAttribute(this);
            this.KnzAttribute = new KnzSubAttribute(this);
        }
        public void TestCustomBLAttribute_TableID_Sample1()
        {
            IBLInterface parent = new BLInterfaceMock()
            {
                ShortName = "Semester"
            };

            IBLAttribute attr = CustomBLAttribute.GetNewIDAttribute(parent);

            Assert.AreEqual("Semester_ID", attr.Name);
            Assert.AreEqual(0, attr.Length);
            Assert.AreEqual(0, attr.Decimals);
            Assert.AreEqual(CoreDataType.INT, attr.DataType);
            Assert.AreEqual(parent, attr.ParentInterface);
            Assert.IsTrue(attr.IsIdentity);
            Assert.IsTrue(attr.IsPrimaryKey);
            Assert.AreEqual("int primary key identity not null", attr.GetSqlDataTypeDefinition());
        }
        private string WrapWithCast(IBLAttribute attr, string name)
        {
            switch (attr.DataType)
            {
            case CoreDataType.VARCHAR:
                return($"cast ({name} as varchar({attr.Length})) as {name}");

            case CoreDataType.DECIMAL:
                return($"cast ({name} as decimal({attr.Length}, {attr.Decimals})) as {name}");

            default:
                // TODO: Prüfen ob das für die anderen Typen auch relevant ist und wie ich
                //       das dann am besten umsetze.
                // => Im Test hat es mit date, datetime und time auch ohne cast funktioniert,
                //    ich hab aber nie von date nach varchar oder umgekehrt ausprobiert!
                return(name);
            }
        }
        public void TestCustomBLAttribute_TAendDat()
        {
            IBLInterface parent = new BLInterfaceMock()
            {
                ShortName = "Semester"
            };

            IBLAttribute attr = CustomBLAttribute.GetNewTAendDatAttribute(parent);

            Assert.AreEqual("T_Aend_Dat", attr.Name);
            StringAssert.EndsWith(attr.FullName, attr.Name);
            Assert.AreEqual(0, attr.Length);
            Assert.AreEqual(0, attr.Decimals);
            Assert.AreEqual(CoreDataType.DATETIME, attr.DataType);
            Assert.AreEqual(parent, attr.ParentInterface);
            Assert.IsFalse(attr.IsIdentity);
            Assert.IsFalse(attr.IsPrimaryKey);
            Assert.AreEqual("datetime not null", attr.GetSqlDataTypeDefinition());
        }
예제 #12
0
        public static string GetMaxValueForHistoryAttribute(IBLAttribute hist)
        {
            switch (hist.DataType)
            {
            case CoreDataType.INT: return(Int32.MaxValue.ToString());

            case CoreDataType.DECIMAL: return(Decimal.MaxValue.ToString());

            case CoreDataType.VARCHAR: return("MAX_VALUE");

            case CoreDataType.DATETIME: return(DateTime.MaxValue.ToString("yyyy-MM-dd hh:mm:ss"));

            case CoreDataType.DATE: return(DateTime.MaxValue.ToString("yyyy-MM-dd"));

            case CoreDataType.TIME: return(DateTime.MaxValue.ToString("hh:mm:ss"));

            default:
                throw new InvalidDataTypeException();
            }
        }
        public void TestCustomBLAttribute_TModifikation()
        {
            IBLInterface parent = new BLInterfaceMock()
            {
                ShortName = "Semester"
            };

            IBLAttribute attr = CustomBLAttribute.GetNewTModifikationAttribute(parent);

            Assert.AreEqual("T_Modifikation", attr.Name);
            StringAssert.EndsWith(attr.FullName, attr.Name);
            Assert.AreEqual(10, attr.Length);
            Assert.AreEqual(0, attr.Decimals);
            Assert.AreEqual(CoreDataType.VARCHAR, attr.DataType);
            Assert.AreEqual(parent, attr.ParentInterface);
            Assert.IsFalse(attr.IsIdentity);
            Assert.IsFalse(attr.IsPrimaryKey);
            Assert.IsFalse(attr.IsPartOfUniqueKey);
            Assert.AreEqual("varchar(10) not null", attr.GetSqlDataTypeDefinition());
        }
        public void TestCustomBLAttribute_TLadelaufNR()
        {
            IBLInterface parent = new BLInterfaceMock()
            {
                ShortName = "Semester"
            };

            IBLAttribute attr = CustomBLAttribute.GetNewTLadelaufNRAttribute(parent);

            Assert.AreEqual("T_Ladelauf_NR", attr.Name);
            StringAssert.EndsWith(attr.FullName, attr.Name);
            Assert.AreEqual(0, attr.Length);
            Assert.AreEqual(0, attr.Decimals);
            Assert.AreEqual(CoreDataType.INT, attr.DataType);
            Assert.AreEqual(parent, attr.ParentInterface);
            Assert.IsFalse(attr.IsIdentity);
            Assert.IsFalse(attr.IsPrimaryKey);
            Assert.IsFalse(attr.IsPartOfUniqueKey);
            Assert.AreEqual("int not null", attr.GetSqlDataTypeDefinition());
        }
예제 #15
0
        public static string GenerateSqlDataTypeDefinition(IBLAttribute attr)
        {
            string code = "";

            switch (attr.DataType)
            {
            case CoreDataType.DATE:
                code = "date";
                break;

            case CoreDataType.DATETIME:
                code = "datetime";
                break;

            case CoreDataType.DECIMAL:
                code = $"decimal({attr.Length}, {attr.Decimals})";
                break;

            case CoreDataType.INT:
                // Sonderfall: ID in Fakttabelle als bigint berücksichtigen...
                if (attr?.ParentInterface?.InterfaceType == CoreInterfaceType.FACT_TABLE && attr.IsIdentity)
                {
                    code = "bigint";
                }
                else
                {
                    code = "int";
                }
                break;

            case CoreDataType.VARCHAR:
                code = $"varchar({attr.Length})";
                break;

            default:
                throw new InvalidDataTypeException($"Ungültiger Datentyp: Die SqlDataTypeDefinition für das Attribut {attr.FullName} konnte nicht generiert werden.");
            }

            return(code);
        }
        public void TestDefaultBLInterface_ILInterface()
        {
            // Daten einlesen...
            var fileName = @"C:\Users\wiw39784\Documents\git\CeusDL2\Test\Data\interface_demo2.1.ceusdl";
            var data     = new ParsableData(System.IO.File.ReadAllText(fileName), fileName);
            var p        = new FileParser(data);
            var result   = p.Parse();
            var model    = new CoreModel(result);

            // Auswählen
            var coreIfa  = model.Interfaces[0];
            var coreAttr = coreIfa.Attributes[0];

            // in DefaultBLInterface konvertieren
            var blIfa = new DefaultBLInterface(coreIfa, null);

            Assert.IsNotNull(blIfa.GetILInterface());
            Assert.AreEqual("AP_IL_StudiengangHisInOne", blIfa.GetILInterface().Name);

            IBLAttribute attr = blIfa.Attributes[0];

            // Inhalt des 0. Attributs überprüfen
            Assert.AreEqual("StudiengangHisInOne_ID", attr.Name);
            Assert.IsNull(attr.GetILAttribute());

            attr = blIfa.Attributes[1];

            // Inhalt des 1. Attributs überprüfen
            Assert.AreEqual("StudiengangHisInOne_KNZ", attr.Name);
            Assert.IsNotNull(attr.GetILAttribute());
            Assert.AreEqual("StudiengangHisInOne_KNZ", attr.GetILAttribute().Name);

            attr = blIfa.Attributes[2];

            // Inhalt des 2. Attributs überprüfen
            Assert.AreEqual("StudiengangHisInOne_KURZBEZ", attr.Name);
            Assert.IsNotNull(attr.GetILAttribute());
            Assert.AreEqual("StudiengangHisInOne_KURZBEZ", attr.GetILAttribute().Name);
        }
예제 #17
0
 private IBTAttribute ConvertAttribute(IBLAttribute attr)
 {
     if (attr is BaseBLAttribute)
     {
         return(new BaseBTAttribute((BaseBLAttribute)attr, this));
     }
     else if (attr is RefBLAttribute)
     {
         return(new RefBTAttribute((RefBLAttribute)attr, this));
     }
     else if (attr is CustomBLAttribute && attr.IsIdentity)
     {
         return(new BaseBTAttribute((CustomBLAttribute)attr, this));
     }
     else if (attr is CustomBLAttribute && attr.Name == "Mandant_KNZ")
     {
         return(new BaseBTAttribute((CustomBLAttribute)attr, this));
     }
     else
     {
         throw new InvalidAttributeTypeException($"in new BTInterface.ConvertAttribute() for {attr.Name} in {attr.ParentInterface.Name}");
     }
 }
예제 #18
0
        public KnzSubAttribute(RefBTAttribute refBTAttribute)
        {
            this.refBTAttribute = refBTAttribute;
            this.refBLAttribute = refBTAttribute.refBLAttribute;
            this.blAttribute    = refBTAttribute.blAttribute;

            if (refBTAttribute.HasToUseVerionTable)
            {
                var core = refBTAttribute.ReferencedBLInterface.GetCoreInterface();
                var knz  = core.Attributes.Where(a => a.IsPrimaryKey).First();
                this.ShortName = $"{core.Name}_VERSION_{knz.Name}";
                this.Alias     = refBLAttribute.Core.Alias;
            }
            else if (refBLAttribute == null)
            {
                this.ShortName = this.blAttribute.Name;
                this.Alias     = null;
            }
            else
            {
                this.ShortName = this.refBLAttribute.ReferencedAttribute.Name;
                this.Alias     = refBLAttribute.Core.Alias;
            }
        }
예제 #19
0
 public BaseBTAttribute(CustomBLAttribute blAttribute, BTInterface ifa)
 {
     this.blAttribute     = blAttribute;
     this.ParentInterface = ifa;
     SetName();
 }
예제 #20
0
 public BaseBTAttribute(string name, BaseBLAttribute blAttribute, BTInterface ifa)
 {
     this.blAttribute     = blAttribute;
     this.ParentInterface = ifa;
     Name = name;
 }