Exemplo n.º 1
0
        public override int Run(string[] args)
        {
            string schemaFileName = args[0];

            XmlTextReader xr         = new XmlTextReader(schemaFileName);
            SchemaInfo    schemaInfo = SchemaManager.ReadAndValidateSchema(xr, Path.GetDirectoryName(schemaFileName));

            SqlDataSource sds = new SqlDataSource(schemaInfo.GetDataSourceInfo("default"));

            //sds.SqlBuilder = new SqlServerBuilder();
            sds.GenerateDdlForSchema(schemaInfo, Console.Out);
            return(0);
        }
Exemplo n.º 2
0
        public virtual void GenerateDdlForSchema(SchemaInfo schema, TextWriter tw)
        {
            Dictionary <string, TableInfo> tables    = new Dictionary <string, TableInfo>();
            Dictionary <string, string>    processed = new Dictionary <string, string>();

            while (processed.Count < schema.Classes.Count)
            {
                foreach (ClassInfo ci in schema.Classes)
                {
                    if (!processed.ContainsKey(ci.Name))
                    {
                        bool isInherited = ci.InheritsFromClass != null;
                        if (!isInherited || processed.ContainsKey(ci.InheritsFromClass.Name))
                        {
                            foreach (TableInfo ti in ci.UnifiedTables)
                            {
                                UnifyTable(tables, ti, isInherited);
                            }
                            processed.Add(ci.Name, ci.Name);
                        }
                    }
                }
            }

            foreach (RelationInfo ri in schema.Relations)
            {
                UnifyTable(tables, ri.Table, false);
            }

            List <string> names = new List <string>();

            foreach (TableInfo ti in tables.Values)
            {
                names.Add(ti.DBTableName);
            }

            names.Sort();

            foreach (string s in names)
            {
                tw.WriteLine("--- table {0}", s);
                SqlBuilder.GenerateCreateTable(tw, tables[s], this.CreateTable, null);
            }

            foreach (string s in names)
            {
                SqlBuilder.GeneratePrimaryKey(tw, tables[s], this.CreateIndex, null);
            }

            foreach (string s in names)
            {
                SqlBuilder.GenerateForeignKeys(tw, tables[s], null);
            }

            foreach (string s in names)
            {
                SqlBuilder.GenerateIndices(tw, tables[s], this.CreateIndex, null);
            }

            if (schema.GetDataSourceInfo(Name).EnableDynamicFields)
            {
                SqlBuilder.GenerateSoodaDynamicField(tw, null);
            }
        }