Example #1
0
        /// <summary>
        /// Create a new mapping file.
        /// </summary>
        /// <param name="mappingFile">Path of the file to create.</param>
        /// <returns>NDOMapping object, which represents the new file.</returns>
        public static NDOMapping Create(string mappingFile)
        {
            NDOMapping m = new NDOMapping();

            m.mappingFile = mappingFile;
            return(m);
        }
Example #2
0
        private void CreateTable(DataTable dt, System.IO.StreamWriter stream, NDO.Mapping.NDOMapping mappings)
        {
            IProvider provider  = new MySqlProvider();
            string    tableName = QualifiedTableName.Get(dt.TableName, provider);
            Class     cl        = FindClass(dt.TableName, mappings);

            //bool selfGeneratedOid = cl.Oid.FieldName != null;
            if (cl != null)
            {
                string conn  = mappings.FindConnection(cl).Name;
                Regex  regex = new Regex(@"Database\s*=\s*([^;]+)");
                Match  match = regex.Match(conn);
                if (match.Success)
                {
                    stream.WriteLine("USE " + match.Groups[1] + ";");
                }
            }
            else
            {
                stream.WriteLine("/* TODO: Insert correct USE statement */");
            }
            stream.WriteLine("DROP TABLE IF EXISTS " + tableName + ";");
            stream.WriteLine("CREATE TABLE " + tableName + "(");
            int vorletzterIndex = dt.Columns.Count - 1;

            DataColumn[] primaryKeyColumns    = dt.PrimaryKey;
            bool         hasPrimaryKeyColumns = primaryKeyColumns.Length > 0;

            for (int i = 0; i < dt.Columns.Count; i++)
            {
                System.Data.DataColumn dc = dt.Columns[i];
//				bool isPrimary = false;
//				if (!selfGeneratedOid)
//					isPrimary = IsPrimary(primaryKeyColumns, dc);
                CreateColumn(dc, stream, cl, provider, IsPrimary(primaryKeyColumns, dc));
                if (i < vorletzterIndex || hasPrimaryKeyColumns)
                {
                    stream.WriteLine(",");
                }
            }
            if (!hasPrimaryKeyColumns)
            {
                stream.WriteLine();
            }
            else
            {
                CreateConstraint(primaryKeyColumns, stream, dt, provider);
            }
            stream.WriteLine(");");
            stream.WriteLine();
        }
Example #3
0
 public void Generate()
 {
     this.mapping = new NDO.Mapping.NDOMapping(fileName);
     foreach (RelInfo ri in relInfos)
     {
         Test test = new Test(ri);
         CheckRelation(test, ri);
         if (ri.IsBi)
         {
             RelInfo reverseInfo = ri.GetReverse();
             Test    reverseTest = test.GetReverse();
             CheckRelation(reverseTest, reverseInfo);
         }
     }
     this.mapping.Save();
 }
Example #4
0
        private void CreateTable(DataTable dt, System.IO.StreamWriter stream, NDO.Mapping.NDOMapping mappings)
        {
            /*
             *
             * DROP TABLE DataContainer;
             * CREATE TABLE [Table6] (
             * Id COUNTER CONSTRAINT PrimaryKey PRIMARY KEY,
             * ...
             * );
             */

            IProvider provider  = new NDOOleDbProvider();
            string    tableName = QualifiedTableName.Get(dt.TableName, provider);
            Class     cl        = FindClass(dt.TableName, mappings);

            bool selfGeneratedOid = false;

            if (cl != null)
            {
                selfGeneratedOid = cl.Oid.FieldName != null;
            }

            stream.WriteLine("DROP TABLE " + tableName + ";");
            stream.WriteLine("CREATE TABLE " + tableName + "(");
            int vorletzterIndex = dt.Columns.Count - 1;

            DataColumn[] primaryKeyColumns    = dt.PrimaryKey;
            bool         hasPrimaryKeyColumns = primaryKeyColumns.Length > 0;

            for (int i = 0; i < dt.Columns.Count; i++)
            {
                System.Data.DataColumn dc = dt.Columns[i];
                bool isPrimary            = false;
                if (!selfGeneratedOid)
                {
                    isPrimary = IsPrimary(primaryKeyColumns, dc);
                }
                CreateColumn(dc, stream, cl, provider, IsPrimary(primaryKeyColumns, dc));
                if (i < vorletzterIndex)
                {
                    stream.WriteLine(",");
                }
            }
            stream.WriteLine(");");
            stream.WriteLine();
        }
Example #5
0
        /// <summary>
        /// Constructs a Class object according the information in the mapping file.
        /// </summary>
        /// <param name="classNode"></param>
        /// <param name="parent"></param>
        internal Class(XmlNode classNode, NDOMapping parent)
            : base(classNode, parent)
        {
            assemblyName  = classNode.Attributes["AssemblyName"].Value;
            fullName      = classNode.Attributes["FullName"].Value;
            tableName     = classNode.Attributes["TableName"].Value;
            connectionId  = classNode.Attributes["ConnectionId"].Value;
            this.typeCode = 0;  // undefined
            XmlAttribute attr = classNode.Attributes["TypeCode"];

            if (attr != null)
            {
                int.TryParse(attr.Value, out this.typeCode);
            }
            attr = classNode.Attributes["TimeStampColumn"];
            if (attr != null)
            {
                this.timeStampColumn = attr.Value;
            }

            XmlNodeList nl = classNode.SelectNodes(Parent.selectRelation, Parent.nsmgr);

            foreach (XmlNode relNode in nl)
            {
                Relation r = new Relation(relNode, this);
                relations.Add(r);
            }
            nl = classNode.SelectNodes(Parent.selectField, Parent.nsmgr);
            foreach (XmlNode fieldNode in nl)
            {
                fields.Add(new Field(fieldNode, this));
            }
            XmlNode oidNode = classNode.SelectSingleNode(Parent.selectOid, Parent.nsmgr);

            if (null != oidNode)
            {
                this.oid = new ClassOid(oidNode, this);
            }

            XmlNode typeColumnNode = classNode.SelectSingleNode(Parent.selectTypeNameColumn, Parent.nsmgr);

            if (null != typeColumnNode)
            {
                this.typeNameColumn = new Column(typeColumnNode, this);
            }
        }
Example #6
0
 public GenericSqlGenerator(ISqlGenerator concreteGenerator, MessageAdapter messages, NDO.Mapping.NDOMapping mappings) : base(concreteGenerator, messages, mappings)
 {
 }
Example #7
0
 public RelationCollector(Class classMapping)
 {
     this.classMapping = classMapping;
     mappings          = classMapping.Parent;
     this.provider     = classMapping.Provider;
 }
 public SchemaTransitionGenerator(ISqlGenerator concreteGenerator, NDO.Mapping.NDOMapping mappings)
 {
     provider = NDOProviderFactory.Instance[concreteGenerator.ProviderName];
     this.concreteGenerator = concreteGenerator;
     this.mappings          = mappings;
 }
Example #9
0
        private void CreateTable(DataTable dt, System.IO.StreamWriter stream, NDO.Mapping.NDOMapping mappings)
        {
            IProvider provider = NDOProviderFactory.Instance[concreteGenerator.ProviderName];

            if (provider == null)
            {
                throw new NDOException("Can't find NDO provider '" + concreteGenerator.ProviderName + "'.");
            }

            string tableName = QualifiedTableName.Get(dt.TableName, provider);

            Class cl = FindClass(dt.TableName, mappings);

            if (cl != null)
            {
                Connection conn = mappings.FindConnection(cl);
                if (conn != null)
                {
                    concreteGenerator.ConnectToDatabase(conn.Name);
                }
            }

            stream.WriteLine(concreteGenerator.DropTable(tableName));

            stream.WriteLine(concreteGenerator.BeginnTable(tableName));

            int vorletzterIndex = dt.Columns.Count - 1;

            DataColumn[] primaryKeyColumns    = dt.PrimaryKey;
            bool         hasPrimaryKeyColumns = primaryKeyColumns.Length > 0;

            for (int i = 0; i < dt.Columns.Count; i++)
            {
                System.Data.DataColumn dc = dt.Columns[i];

                bool isPrimary = false;
                foreach (DataColumn pkc in primaryKeyColumns)
                {
                    if (pkc.ColumnName == dc.ColumnName)
                    {
                        isPrimary = true;
                        break;
                    }
                }

                CreateColumn(dc, stream, cl, provider, isPrimary);
                if (i < vorletzterIndex ||
                    (concreteGenerator.PrimaryConstraintPlacement == PrimaryConstraintPlacement.InTable && hasPrimaryKeyColumns))
                {
                    stream.WriteLine(",");
                }
            }

            if (hasPrimaryKeyColumns && concreteGenerator.PrimaryConstraintPlacement == PrimaryConstraintPlacement.InTable)
            {
                CreateConstraint(primaryKeyColumns, stream, dt, provider);
            }
            else
            {
                stream.WriteLine();
            }
            stream.WriteLine(concreteGenerator.EndTable(tableName));

            //			CreateIndex(primaryKeyColumns, stream, dt, provider);

            if (hasPrimaryKeyColumns && concreteGenerator.PrimaryConstraintPlacement == PrimaryConstraintPlacement.AfterTable)
            {
                CreateConstraint(primaryKeyColumns, stream, dt, provider);
            }

            stream.WriteLine();
        }
Example #10
0
 public void Generate(System.Data.DataSet dsSchema, System.IO.StreamWriter stream, NDO.Mapping.NDOMapping mappings)
 {
     foreach (DataTable dt in dsSchema.Tables)
     {
         CreateTable(dt, stream, mappings);
     }
 }
Example #11
0
 public GenericDiffGenerator(ISqlGenerator concreteGenerator, MessageAdapter messages, NDO.Mapping.NDOMapping mappings) : base(concreteGenerator, messages, mappings)
 {
     provider = NDOProviderFactory.Instance[concreteGenerator.ProviderName];
 }
Example #12
0
 /// <summary>
 /// Constructs a new Class object.
 /// </summary>
 public Class(NDOMapping parent)
     : base(parent)
 {
 }
Example #13
0
 /// <summary>
 ///  Used to set the parent if Class objects are moved to another mapping file.
 /// </summary>
 /// <param name="parent">An object of type NDOMapping.</param>
 internal void SetParent(NDOMapping parent)
 {
     this.NodeParent = parent;
 }
Example #14
0
        /// <summary>
        /// Merge two mapping files. This is used by the enhancer to collect mapping information from several base assemblies.
        /// </summary>
        /// <param name="mergeMapping">Path to the mapping file to merge.</param>
        public void MergeMapping(NDOMapping mergeMapping)
        {
            /*
             * Für alle Conns. in mergeMapping:
             * Gibt's ne gleiche Connection in this?
             * Ja: ist ID von mergeConn. != this.Conn.ID
             *     Ja: alle Klassen zu dieser ID anpassen
             * Nein:
             *		übertrage Conn nach this, ggf. neue ID anlegen
             *		ID neu?
             *      Ja: alle Klassen anpassen.
             * alle Klassen der Conn. kopieren, markieren
             */

            if (this.connections.Count > 0 && mergeMapping.connections.Count > 0)
            {
                Connection std1 = this.connections[0] as Connection;
                Connection std2 = mergeMapping.connections[0] as Connection;
                if (std1.Name == Connection.DummyConnectionString && std2.Name != Connection.DummyConnectionString)
                {
                    std1.Name = std2.Name;
                    std1.Type = std2.Type;
                }
                else if (std2.Name == Connection.DummyConnectionString && std1.Name != Connection.DummyConnectionString)
                {
                    std2.Name = std1.Name;
                    std2.Type = std1.Type;
                }
            }
            else
            {
                if (this.connections.Count == 1 && ((Connection)this.connections[0]).Name == Connection.DummyConnectionString)
                {
                    ((Connection)this.connections[0]).Name = Connection.StandardConnection.Name;
                    ((Connection)this.connections[0]).Type = Connection.StandardConnection.Type;
                }
                if (mergeMapping.connections.Count == 1 && ((Connection)mergeMapping.connections[0]).Name == Connection.DummyConnectionString)
                {
                    ((Connection)mergeMapping.connections[0]).Name = Connection.StandardConnection.Name;
                    ((Connection)mergeMapping.connections[0]).Type = Connection.StandardConnection.Type;
                }
            }


            foreach (Connection co in mergeMapping.Connections)
            {
                if (co.Name == Connection.DummyConnectionString)
                {
                    co.Name = Connection.StandardConnection.Name;
                    co.Type = Connection.StandardConnection.Type;
                }

                List <Class> classesToCopy = mergeMapping.Classes.Where(c => c.ConnectionId == co.ID).ToList();

                // IDs werden umbenannt und könnten dann gleich einer vorhandenen
                // ID in mergeMapping.Connections werden.
                foreach (Class cl in classesToCopy)
                {
                    mergeMapping.RemoveClass(cl);
                }

                Connection thisConn = FindEquivalentConnection(co);
                // Gibt's schon eine Connection mit dem gleichen Conn.-String?
                if (null != thisConn)
                {
                    if (co.ID != thisConn.ID)
                    {
                        foreach (Class cl1 in classesToCopy)
                        {
                            cl1.ConnectionId = thisConn.ID;
                        }
                    }
                }
                else
                {
                    bool gleicheID = false;
                    int  maxId     = 0;
                    foreach (Connection co1 in this.Connections)
                    {
                        if (co1.ID == co.ID)
                        {
                            gleicheID = true;
                        }
                        if (co1.ID.StartsWith("C"))
                        {
                            maxId = System.Math.Max(maxId, int.Parse(co1.ID.Substring(1)));
                        }
                    }
                    if (gleicheID)
                    {
                        maxId++;
                        co.ID = "C" + maxId.ToString();
                        foreach (Class cl2 in classesToCopy)
                        {
                            cl2.ConnectionId = co.ID;
                        }
                    }
                    co.SetParent(this);
                    AddConnection(co);
                }

                // Alle Klassen der Connection einfügen
                foreach (NDO.Mapping.Class cl3 in classesToCopy)
                {
                    Class classToRemove = null;
                    bool  classFound    = false;
                    foreach (Class cl in Classes)
                    {
                        if (cl.FullName == cl3.FullName)
                        {
                            if (ClassesAreDifferent(cl, cl3))
                            {
                                classToRemove = cl;
                            }
                            classFound = true;
                            break;
                        }
                    }

                    if (classFound)
                    {
                        if (classToRemove != null)
                        {
                            RemoveClass(classToRemove);
                            AddClass(cl3);
                        }
                    }
                    else
                    {
                        AddClass(cl3);
                    }
                }
            }
        } // Ende von MergeMapping
Example #15
0
 public TypeManager(string filename, NDOMapping mapping)
 {
     this.filename = filename;
     this.mapping  = mapping;
 }