Beispiel #1
0
 private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (saveOnClose && mapping != null)
     {
         mapping.Save();
     }
     else if (mapping != null && mapping.HasChanges)
     {
         if (MessageBox.Show("Save changes?", "NDO Mapping Tool", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             mapping.Save();
         }
     }
 }
Beispiel #2
0
        public void MergeNewConnStringFromDummy2()
        {
            string file1 = "File1.Xml";
            string file2 = "File2.Xml";

            NDOMapping map1 = NDOMapping.Create(file1);

            map1.AddStandardClass(classMitarbeiter, assName, null);
            map1.Save();

            NDOMapping map2 = NDOMapping.Create(file2);

            map2.AddStandardClass(classMitarbeiter, assName, null);
            map2.Save();

            map1 = new NDOMapping(file1);
            map2 = new NDOMapping(file2);

            Assert.AreEqual(Connection.DummyConnectionString, ((Connection)map1.Connections[0]).Name, "Must be dummy connection");
            Assert.AreEqual(Connection.DummyConnectionString, ((Connection)map2.Connections[0]).Name, "Must be dummy connection");
            ((Connection)map1.Connections[0]).Name = "Some new string";

            map1.MergeMapping(map2);
            Assert.AreEqual(1, map1.Connections.Count, "Falsche Anzahl Connections");
            Class c = map1.FindClass(classMitarbeiter);

            Assert.NotNull(c, "Mitarbeiter nicht gefunden");
            Assert.AreEqual("C0", c.ConnectionId, "Connection falsch");

            File.Delete(file1);
            File.Delete(file2);
        }
Beispiel #3
0
        public void MergeNewConnStringClassChanged()
        {
            string file1 = "File1.Xml";
            string file2 = "File2.Xml";

            NDOMapping map1 = NDOMapping.Create(file1);

            map1.AddStandardClass(classMitarbeiter, assName, null);
            ((Connection)map1.Connections[0]).Name = "Alter ConnectionString";
            map1.Save();

            NDOMapping map2 = NDOMapping.Create(file2);

            map2.AddStandardClass(classMitarbeiter, assName, null);
            ((Connection)map2.Connections[0]).Name = "Neuer ConnectionString";
            ((Class)map2.Classes[0]).AssemblyName  = "New Assembly-Name";
            map2.Save();

            map1 = new NDOMapping(file1);
            map2 = new NDOMapping(file2);

            map1.MergeMapping(map2);
            Assert.AreEqual(2, map1.Connections.Count, "Falsche Anzahl Connections");
            Assert.AreEqual(1, map1.Classes.Count, "Falsche Anzahl Klassen");
            Class c = map1.FindClass(classMitarbeiter);

            Assert.NotNull(c, "Mitarbeiter nicht gefunden");
            Assert.AreEqual("C1", c.ConnectionId, "Connection falsch");

            File.Delete(file1);
            File.Delete(file2);
        }
Beispiel #4
0
        public void MergeEqualNewConnName()
        {
            string file1 = "File1.Xml";
            string file2 = "File2.Xml";

            NDOMapping map1 = NDOMapping.Create(file1);

            map1.AddStandardClass(classMitarbeiter, assName, null);

            map1.Save();

            NDOMapping map2 = NDOMapping.Create(file2);

            map2.AddStandardClass(classMitarbeiter, assName, null);
            ((Connection)map2.Connections[0]).ID = "C1";
            map2.Save();

            map1 = new NDOMapping(file1);
            map2 = new NDOMapping(file2);

            map1.MergeMapping(map2);
            Assert.AreEqual(1, map1.Classes.Count, "Falsche Anzahl Klassen");
            Assert.AreEqual(1, map1.Connections.Count, "Falsche Anzahl Connections");

            File.Delete(file1);
            File.Delete(file2);
        }
Beispiel #5
0
        public void AnlegenNNRelation()
        {
            string     testFile = "Test.Xml";
            NDOMapping mapping  = NDOMapping.Create(testFile);
            Class      c        = mapping.AddStandardClass(classMitarbeiter, assName, null);

            c.AddStandardRelation("dieReisen", "Reisekosten.Reise", false, "", false, false);
            c = mapping.AddStandardClass("Reisekosten.Reise", assName, null);
            c.AddStandardRelation("dieMitarbeiter", classMitarbeiter, false, "", false, false);
            mapping.Save();
            mapping = new NDOMapping(testFile);
            Assert.AreEqual(1, mapping.Connections.Count, "Keine Connection");
            Assert.AreEqual(2, mapping.Classes.Count, "Keine Klasse");
            c = (Class)mapping.FindClass(classMitarbeiter);
            Assert.AreEqual("Mitarbeiter", c.TableName, "TableName falsch");
            Assert.NotNull(c.Oid, "Keine Oid");
            Assert.AreEqual(1, c.Relations.Count, "Keine Relation");
            Relation r = c.FindRelation("dieReisen");

            Assert.NotNull(r, "Relation dieReisen nicht gefunden");
            Assert.AreEqual("IDMitarbeiter", ((ForeignKeyColumn)r.ForeignKeyColumns[0]).Name, "ForeignKeyColumnName falsch");
            Assert.AreEqual("n:n", r.GetRelationType(), "Relationstyp falsch");
            Assert.AreEqual("IDReise", ((ForeignKeyColumn)r.MappingTable.ChildForeignKeyColumns[0]).Name, "ChildForeignKeyColumnName von MappingTable falsch");
            Assert.AreEqual("relMitarbeiterReise", r.MappingTable.TableName, "TableName von MappingTable falsch");
            c = mapping.FindClass("Reisekosten.Reise");
            r = c.FindRelation("dieMitarbeiter");
            Assert.NotNull(r, "Relation dieMitarbeiter nicht gefunden");
            Assert.AreEqual("relMitarbeiterReise", r.MappingTable.TableName, "TableName von MappingTable falsch");
            Assert.AreEqual("n:n", r.GetRelationType(), "Relationstyp falsch");
            Assert.AreEqual("IDReise", ((ForeignKeyColumn)r.ForeignKeyColumns[0]).Name, "ForeignKeyColumnName falsch");
            Assert.AreEqual("IDMitarbeiter", ((ForeignKeyColumn)r.MappingTable.ChildForeignKeyColumns[0]).Name, "ChildForeignKeyColumnName von MappingTable falsch");
        }
Beispiel #6
0
        public void Anlegen1to1Relation()
        {
            string     testFile = "Test.Xml";
            NDOMapping mapping  = NDOMapping.Create(testFile);
            Class      c        = mapping.AddStandardClass(classMitarbeiter, assName, null);

            c.AddStandardRelation("dieReise", "Reise", true, "", false, false);
            mapping.Save();
            mapping = new NDOMapping(testFile);
            Assert.AreEqual(1, mapping.Connections.Count, "Keine Connection");
            Assert.AreEqual(1, mapping.Classes.Count, "Keine Klasse");
            c = (Class)mapping.Classes[0];
            Assert.AreEqual("Mitarbeiter", c.TableName, "TableName falsch");
            Assert.NotNull(c.Oid, "Keine Oid");
            Assert.AreEqual(1, c.Relations.Count, "Keine Relation");
            Relation r = (Relation)c.Relations[0];

            Assert.AreEqual("dieReise", r.FieldName, "FieldName falsch");
            Assert.AreEqual("1:1", r.GetRelationType(), "Relationstyp falsch");
            Assert.AreEqual("IDReise", ((ForeignKeyColumn)r.ForeignKeyColumns[0]).Name, "ForeignKeyColumnName falsch");
        }
Beispiel #7
0
        public void GleicherKlassenName()
        {
            string     testFile            = "Text.Xml";
            string     newclassMitarbeiter = classMitarbeiter.Replace("Personal", "Test");
            NDOMapping mapping             = NDOMapping.Create(testFile);

            mapping.AddStandardClass(classMitarbeiter, assName, null);
            mapping.AddStandardClass(newclassMitarbeiter, assName, null);
            mapping.Save();
            mapping = new NDOMapping(testFile);

            Class c = mapping.FindClass(classMitarbeiter);

            Assert.NotNull(c, classMitarbeiter + " nicht gefunden");

            Class c2 = mapping.FindClass(newclassMitarbeiter);

            Assert.NotNull(c, newclassMitarbeiter + " nicht gefunden");

            Assert.That(c.TableName != c2.TableName, "TableNames mössen ungleich sein");
        }
Beispiel #8
0
        public void AnlegenKlasse()
        {
            NDOMapping mapping = NDOMapping.Create(testFile);

            mapping.AddStandardClass(classMitarbeiter, assName, null);
            mapping.Save();
            mapping = new NDOMapping(testFile);

            Assert.AreEqual(1, mapping.Connections.Count, "Keine Connection");
            Assert.AreEqual(1, mapping.Classes.Count, "Keine Klasse");

            Class c = (Class)mapping.Classes[0];

            Assert.AreEqual("Mitarbeiter", c.TableName, "TableName falsch");
            Assert.NotNull(c.Oid, "Keine Oid");
            Assert.AreEqual("C0", mapping.FindConnection(c).ID, "Connection C0 nicht gefunden");

            c = mapping.FindClass(classMitarbeiter);

            Assert.NotNull(c, "FindClass fehlgeschlagen");

            File.Delete(testFile);
        }
Beispiel #9
0
        public void AnlegenField()
        {
            string     testFile = "Test.Xml";
            NDOMapping mapping  = NDOMapping.Create(testFile);
            Class      c        = mapping.AddStandardClass(classMitarbeiter, assName, null);

            c.AddStandardField("vorname", false);
            mapping.Save();
            mapping = new NDOMapping(testFile);

            Assert.AreEqual(1, mapping.Connections.Count, "Keine Connection");
            Assert.AreEqual(1, mapping.Classes.Count, "Keine Klasse");

            c = (Class)mapping.Classes[0];

            Assert.AreEqual("Mitarbeiter", c.TableName, "TableName falsch");
            Assert.NotNull(c.Oid, "Keine Oid");
            Assert.AreEqual(1, c.Fields.Count, "Kein Field");

            Field f = (Field)c.Fields[0];

            Assert.AreEqual("Vorname", f.Column.Name, "ColumnName falsch");
        }
Beispiel #10
0
        static int Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("ManipulateConnection: usage: ManipulateConnection mapping-file conn-type [-t]");
                return(-1);
            }

            Console.WriteLine("ManipulateConnection: args: " + args[0] + " " + args[1]);
            if (!File.Exists(args[0]))
            {
                if (args.Length == 2)  // return quiet if -t is not specified
                {
                    return(0);
                }
                Console.WriteLine("ManipulateConnection: can't find file " + args[0]);
                return(-2);
            }



            string fileName;
            string connName = null;
            string type     = null;

            switch (args[1])
            {
            case "Oracle":
                connName = @"Password=NDOTester;User ID=NDOTester;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.178.29)(PORT=1521)) (CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XE)));";
                type     = "Oracle";
                break;

            case "SqlServer":
                connName = @"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=NDOTest;Data Source=localhost";
                type     = "SqlServer";
                break;

            case "Access":
                connName = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Dokumente und Einstellungen\Mirko Matytschak\Eigene Dateien\db1.mdb;Persist Security Info=False";
                type     = "Access";
                break;

            case "MySql":
                connName = @"Database=NDOTest;Data Source=localhost;User Id=root;";
                type     = "MySql";
                break;

            case "Firebird":
                fileName = @"C:\Projekte\NDO\Firebird\TEST.FBD";
                if (!File.Exists(fileName))
                {
                    Console.WriteLine("Error: File doesn't exist: " + fileName);
                    return(-1);
                }
                connName = @"Dialect=3;User Id=SYSDBA;Database=localhost:" + fileName + @";Data Source=localhost;Password=masterkey";
                type     = "Firebird";
                break;

            case "Postgre":
                connName = "SERVER=localhost;ENCODING=UNICODE;DATABASE=prio;USER ID=postgres;PASSWORD=abundance;";
                type     = "Postgre";
                break;

            case "Sqlite":
                connName = @"Data Source=D:\Projekte\NDO\SqliteProvider\NdoUnitTests.db";
                type     = "Sqlite";
                break;

            case "SqlCe":
                connName = @"Data Source=""D:\Projekte\NDO\SqlCeProvider\NDOUnitTests.sdf"";Password='******'";
                type     = "SqlCe";
                break;

            default:
                Console.WriteLine("ManipulateConnection: can't find connection type " + args[1]);
                return(-1);
            }
            Console.WriteLine("ManipulateConnection: Setting Connection: " + Path.GetFullPath(args[0]) + " '" + connName + '\'');
            try
            {
                NDOMapping mapping = new NDOMapping(Path.GetFullPath(args[0]));
                if (mapping.Connections.Count() != 1)
                {
                    Console.WriteLine("Wrong connection count: " + mapping.Connections.Count().ToString());
                    return(-1);
                }
                ((Connection)mapping.Connections.First()).Name = connName;
                ((Connection)mapping.Connections.First()).Type = type;
                mapping.Save();
            }
            catch (Exception ex)
            {
                Console.WriteLine("ManipulateConnection: " + ex.Message);
                return(-3);
            }

            return(0);
        }
Beispiel #11
0
        static int Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("usage: ManipulateOidColumns mapping-file Guid|Auto");
                return(-1);
            }
            Console.WriteLine("ManipulateOidColums: args: " + args[0] + " " + args[1]);


            if (!File.Exists(args[0]))
            {
                Console.WriteLine("can't find file " + args[0]);
                return(-2);
            }

            try
            {
                NDOMapping mapping = new NDOMapping(args[0]);
                foreach (Class cl in mapping.Classes)
                {
                    if (cl.Oid.OidColumns.Count == 1)
                    {
                        OidColumn oidCol = (OidColumn)cl.Oid.OidColumns[0];

                        if (cl.FullName == "NDOObjectIdTestClasses.HintOwner")
                        {
                            oidCol.AutoIncremented = false;
                            oidCol.NetType         = "System.Int32,mscorlib";
                        }
                        else if (cl.FullName == "NDOObjectIdTestClasses.ClassWithHint")
                        {
                            oidCol.AutoIncremented = false;
                            oidCol.NetType         = "System.Guid,mscorlib";
                        }
                        else if (cl.FullName == "NDOObjectIdTestClasses.AbstractBaseGuid" || cl.FullName == "NDOObjectIdTestClasses.DerivedGuid")
                        {
                            oidCol.AutoIncremented = false;
                            oidCol.NetType         = "System.Guid,mscorlib";
                            oidCol.FieldName       = "guid";
                        }
                        else if (cl.FullName == "NDOObjectIdTestClasses.NDOoidAndHandler")
                        {
                            oidCol.AutoIncremented = false;
                            oidCol.NetType         = "System.Guid,mscorlib";
                            oidCol.FieldName       = "myId";
                        }
                        else if (cl.FullName == "NDOObjectIdTestClasses.ObjectOwner")
                        {
                            oidCol.AutoIncremented = false;
                            oidCol.NetType         = "System.Int32,mscorlib";
                        }
                        else
                        {
                            if (args[1] == "Guid")
                            {
                                oidCol.AutoIncremented = false;
                                oidCol.NetType         = "System.Guid,mscorlib";
                            }
                            else
                            {
                                oidCol.AutoIncremented = true;
                                oidCol.NetType         = null;
                            }
                        }
                    }
                }
                mapping.Save();
            }
            catch (Exception ex)
            {
                Console.WriteLine("ManipulateTableNames: " + ex.Message);
                return(-3);
            }
            return(0);
        }
Beispiel #12
0
        static int Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("usage: ManipulateTableNames mapping-file [TablePrefix]");
                return(-1);
            }
            Console.Write("ManipulateTableNames: args: " + args[0]);

            if (args.Length > 1)
            {
                Console.WriteLine(" " + args[1]);
            }
            else
            {
                Console.WriteLine();
            }

            if (!File.Exists(args[0]))
            {
                Console.WriteLine("can't find file " + args[0]);
                return(-2);
            }

            string prefix    = null;
            bool   hasPrefix = args.Length > 1;

            if (hasPrefix)
            {
                prefix = args[1];
            }
            try
            {
                NDOMapping mapping = new NDOMapping(args[0]);
                if (hasPrefix)
                {
                    foreach (Class cl in mapping.Classes)
                    {
                        if (!cl.TableName.StartsWith(prefix))
                        {
                            cl.TableName = prefix + "." + cl.TableName;
                        }
                        foreach (Relation r in cl.Relations)
                        {
                            if (r.MappingTable != null)
                            {
                                if (!r.MappingTable.TableName.StartsWith(prefix))
                                {
                                    r.MappingTable.TableName = prefix + "." + r.MappingTable.TableName;
                                }
                            }
                        }
                    }
                }
                else
                {
                    foreach (Class cl in mapping.Classes)
                    {
                        if (cl.TableName.IndexOf('.') > -1)
                        {
                            cl.TableName = cl.TableName.Substring(cl.TableName.IndexOf('.') + 1);
                        }
                        foreach (Relation r in cl.Relations)
                        {
                            if (r.MappingTable != null)
                            {
                                if (r.MappingTable.TableName.IndexOf('.') > -1)
                                {
                                    r.MappingTable.TableName = r.MappingTable.TableName.Substring(r.MappingTable.TableName.IndexOf('.') + 1);
                                }
                            }
                        }
                    }
                }
                mapping.Save();
            }
            catch (Exception ex)
            {
                Console.WriteLine("ManipulateTableNames: " + ex.Message);
                return(-3);
            }
            return(0);
        }