/// <summary> /// Load all the Entities into the EntityStore. /// </summary> protected virtual void Initialize(TableSchemaCollection tables, ViewSchemaCollection views, CommandSchemaCollection commands) { LoadTables(tables); LoadViews(views); LoadCommands(commands); foreach (IEntity entity in EntityStore.Instance.EntityCollection.Values) { List <IEntity> entities = EntityStore.Instance.EntityCollection.Values.Where(e => e.Name == entity.Name).ToList(); if (entities.Count > 1) { for (int index = 1; index < entities.Count(); index++) { entities[index].AppendNameSuffix(index); } } } // For all entities, Initialize them. foreach (IEntity entity in EntityStore.Instance.EntityCollection.Values) { entity.Initialize(); } foreach (IEntity entity in EntityStore.Instance.EntityCollection.Values) { entity.ValidateAllMembers(); } }
public override ViewSchemaCollection GetViews() { ViewSchemaCollection views = new ViewSchemaCollection(); IPooledDbConnection conn = connectionPool.Request(); IDbCommand command = conn.CreateCommand( "SELECT name, sql FROM sqlite_master WHERE type = 'views'" ); try { using (command) { using (IDataReader r = command.ExecuteReader()) { while (r.Read()) { ViewSchema view = new ViewSchema(this); view.SchemaName = "main"; view.Name = r.GetString(0); view.Definition = r.GetString(1); views.Add(view); } r.Close(); } } } catch (Exception e) { QueryService.RaiseException(e); } conn.Release(); return(views); }
/// <summary> /// 生成数据仓库代码 /// </summary> /// <param name="tables"></param> /// <returns></returns> public int GenerateBusinessRepositoryClasses(ViewSchemaCollection views) { if (views == null || views.Count <= 0) { return(0); } int tempIntTableNum = 0; CodeTemplate BusinessRepositoryTemplate = GetCodeTemplate("ViewBusinessRepository.cst"); foreach (ViewSchema view in views) { BusinessRepositoryTemplate.SetProperty("TargetView", view); BusinessRepositoryTemplate.SetProperty("CommonNamespace", CommonNamespace); BusinessRepositoryTemplate.SetProperty("BusinessRepositoryNamespace", BusinessRepositoryNamespace); BusinessRepositoryTemplate.SetProperty("EntityNamespace", EntityNamespace); BusinessRepositoryTemplate.SetProperty("DBUtilityNamespace", DBUtilityNamespace); BusinessRepositoryTemplate.SetProperty("CreatePerson", CreatePerson); BusinessRepositoryTemplate.SetProperty("CompanyName", CompanyName); BusinessRepositoryTemplate.SetProperty("BusinessRepositorySuffix", BusinessRepositorySuffix); BusinessRepositoryTemplate.SetProperty("FileDesc", "表[" + view.Name + "]的 数据仓库代码"); string tempFilePath = string.Format(@"{0}{1}\{2}", this.OutputDirectory, BusinessRepositoryNamespace, BusinessRepositoryTemplate.GetFileName()); BusinessRepositoryTemplate.RenderToFile(tempFilePath, true); WriteInfo("成功在路径[" + this.OutputDirectory + BusinessRepositoryNamespace + "] 生成 BusinessReposity 层代码文件:" + BusinessRepositoryTemplate.GetFileName() + ""); tempIntTableNum++; } WriteInfo("-----成功在路径[" + this.OutputDirectory + BusinessRepositoryNamespace + "] 生成:" + tempIntTableNum + " 个 BusinessReposity 层代码文件-----"); return(tempIntTableNum); }
// see: http://dev.mysql.com/doc/refman/5.1/en/views-table.html public override ViewSchemaCollection GetViews() { ViewSchemaCollection views = new ViewSchemaCollection(); using (IPooledDbConnection conn = connectionPool.Request()) { using (IDbCommand command = conn.CreateCommand(string.Format( @"SELECT TABLE_NAME, TABLE_SCHEMA FROM information_schema.VIEWS where TABLE_SCHEMA = '{0}' ORDER BY TABLE_NAME" , ConnectionPool.ConnectionContext.ConnectionSettings.Database))){ try { // Views are supported in mysql since version 5. if (GetMainVersion(command) >= 5) { using (IDataReader r = command.ExecuteReader()) { while (r.Read()) { ViewSchema view = new ViewSchema(this); view.Name = r.GetString(0); view.OwnerName = r.GetString(1); using (IPooledDbConnection conn2 = connectionPool.Request()) { using (IDbCommand command2 = conn2.CreateCommand(string.Concat( "SHOW CREATE TABLE `", view.Name, "`;"))) { using (IDataReader r2 = command2.ExecuteReader()) { r2.Read(); view.Definition = r2.GetString(1); } } conn2.Release(); } views.Add(view); } r.Close(); } } } catch (Exception e) { QueryService.RaiseException(e); } finally { conn.Release(); } } } return(views); }
public override ViewSchemaCollection GetViews() { ViewSchemaCollection views = new ViewSchemaCollection(); using (IPooledDbConnection conn = connectionPool.Request()) { using (IDbCommand command = conn.CreateCommand(@"SELECT su.name AS owner, so.name as table_name, so.id as table_id, so.crdate as created_date, so.xtype as table_type FROM dbo.sysobjects so, dbo.sysusers su WHERE xtype = 'V' AND su.uid = so.uid ORDER BY 1, 2" )) try { using (command) { using (IDataReader r = command.ExecuteReader()) { while (r.Read()) { ViewSchema view = new ViewSchema(this); view.Name = r.GetString(1); view.SchemaName = r.GetString(0); view.OwnerName = r.GetString(0); StringBuilder sb = new StringBuilder(); sb.AppendFormat("-- View: {0}\n", view.Name); sb.AppendFormat("-- DROP VIEW {0};\n\n", view.Name); sb.AppendFormat(" {0}\n);", GetSource("[" + view.OwnerName + "].[" + view.Name + "]")); view.Definition = sb.ToString(); views.Add(view); } r.Close(); } } } catch (Exception e) { QueryService.RaiseException(e); } finally { conn.Release(); } } return(views); }
/// <summary> /// </summary> /// <param name="database"></param> public SchemaExplorerEntityProvider(DatabaseSchema database) { _database = database; if (_database != null) { if (!_database.DeepLoad) { _database.DeepLoad = true; _database.Refresh(); } _tables = _database.Tables; _views = _database.Views; _commands = _database.Commands; } }
/// <summary> /// </summary> /// <param name="tables"></param> /// <param name="views"></param> /// <param name="commands"></param> public SchemaExplorerEntityProvider(TableSchemaCollection tables, ViewSchemaCollection views, CommandSchemaCollection commands) { _tables = tables; _views = views; _commands = commands; if (_tables != null && _tables.Count > 0) { _database = _tables[0].Database; } else if (_views != null && _views.Count > 0) { _database = _views[0].Database; } else if (_commands != null && _commands.Count > 0) { _database = _commands[0].Database; } }
protected virtual void LoadViews(ViewSchemaCollection views) { // Load the Views. if (Configuration.Instance.IncludeViews && views != null && views.Count > 0 && views[0].Database != null) { foreach (ViewSchema view in views) { if (!Configuration.Instance.IncludeRegexIsMatch(view.FullName) || Configuration.Instance.ExcludeRegexIsMatch(view.FullName) || EntityStore.Instance.GetEntity(view.FullName) != null) { Trace.WriteLine(String.Format("Skipping view: '{0}'", view.FullName)); Debug.WriteLine(String.Format("Skipping view: '{0}'", view.FullName)); EntityStore.Instance.ExcludedEntityCollection.Add(view.FullName, null); continue; } EntityStore.Instance.EntityCollection.Add(view.FullName, new ViewEntity(view)); } } }
private void BuildChildNodesThreaded(object state) { BaseNode node = state as BaseNode; ITreeBuilder builder = Context.GetTreeBuilder(state); bool showSystemObjects = (bool)builder.Options["ShowSystemObjects"]; ViewSchemaCollection views = node.ConnectionContext.SchemaProvider.GetViews(); DispatchService.GuiDispatch(delegate { foreach (ViewSchema view in views) { if (view.IsSystemView && !showSystemObjects) { continue; } builder.AddChild(new ViewNode(node.ConnectionContext, view)); } builder.Expanded = true; }); }
/// <summary> /// 生成数据实体代码 /// </summary> /// <param name="tables"></param> /// <returns></returns> public int GenerateEntityClasses(ViewSchemaCollection views) { if (views == null || views.Count <= 0) { return(0); } int tempIntTableNum = 0; CodeTemplate EntityTemplate = GetCodeTemplate("ViewEntity.cst"); foreach (ViewSchema view in views) { EntityTemplate.SetProperty("TargetView", view); EntityTemplate.SetProperty("EntityNamespace", EntityNamespace); EntityTemplate.SetProperty("CreatePerson", CreatePerson); EntityTemplate.SetProperty("CompanyName", CompanyName); EntityTemplate.SetProperty("FileDesc", "表[" + view.Name + "] 数据库实体代码"); string tempFilePath = string.Format(@"{0}{1}\{2}", this.OutputDirectory, EntityNamespace, EntityTemplate.GetFileName()); EntityTemplate.RenderToFile(tempFilePath, true); WriteInfo("成功在路径[" + this.OutputDirectory + EntityNamespace + "] 生成 Entity 层代码文件:" + EntityTemplate.GetFileName() + ""); tempIntTableNum++; } WriteInfo("-----成功在路径[" + this.OutputDirectory + EntityNamespace + "] 生成 " + tempIntTableNum + " 个 Entity 层代码文件-----"); return(tempIntTableNum); }
// see: http://dev.mysql.com/doc/refman/5.1/en/views-table.html public override ViewSchemaCollection GetViews () { ViewSchemaCollection views = new ViewSchemaCollection (); using (IPooledDbConnection conn = connectionPool.Request ()) { using (IDbCommand command = conn.CreateCommand (string.Format ( @"SELECT TABLE_NAME, TABLE_SCHEMA FROM information_schema.VIEWS where TABLE_SCHEMA = '{0}' ORDER BY TABLE_NAME", ConnectionPool.ConnectionContext.ConnectionSettings.Database))){ try { // Views are supported in mysql since version 5. if (GetMainVersion (command) >= 5) { using (IDataReader r = command.ExecuteReader()) { while (r.Read ()) { ViewSchema view = new ViewSchema (this); view.Name = r.GetString (0); view.OwnerName = r.GetString (1); using (IPooledDbConnection conn2 = connectionPool.Request ()) { using (IDbCommand command2 = conn2.CreateCommand (string.Concat( "SHOW CREATE TABLE `", view.Name, "`;"))) { using (IDataReader r2 = command2.ExecuteReader()) { r2.Read (); view.Definition = r2.GetString (1); } } conn2.Release (); } views.Add (view); } r.Close (); } } } catch (Exception e) { QueryService.RaiseException (e); } finally { conn.Release (); } } } return views; }
public override ViewSchemaCollection GetViews () { ViewSchemaCollection views = new ViewSchemaCollection (); using (IPooledDbConnection conn = connectionPool.Request ()) { using (IDbCommand command = conn.CreateCommand (string.Format ( @"SELECT v.schemaname, v.viewname, v.viewowner, v.definition, (c.oid <= {0}), (SELECT description from pg_description pd, pg_class pc WHERE pc.oid = pd.objoid AND pc.relname= v.viewname) FROM pg_views v, pg_class c WHERE v.viewname = c.relname ORDER BY viewname", LastSystemOID))) { try { using (IDataReader r = command.ExecuteReader()) { while (r.Read ()) { ViewSchema view = new ViewSchema (this); view.Name = r.GetString (1); view.OwnerName = r.GetString (2); view.SchemaName = r.GetString (0); view.IsSystemView = r.GetBoolean (4); view.Comment = r.IsDBNull (5) ? null : r.GetString (5); // TODO: Fill view.Definition views.Add (view); } r.Close (); } } catch (Exception e) { QueryService.RaiseException (e); } finally { conn.Release (); } } } return views;
public override ViewSchemaCollection GetViews () { ViewSchemaCollection views = new ViewSchemaCollection (); using (IPooledDbConnection conn = connectionPool.Request ()) { using (IDbCommand command = conn.CreateCommand (@"SELECT su.name AS owner, so.name as table_name, so.id as table_id, so.crdate as created_date, so.xtype as table_type FROM dbo.sysobjects so, dbo.sysusers su WHERE xtype = 'V' AND su.uid = so.uid ORDER BY 1, 2")) try { using (command) { using (IDataReader r = command.ExecuteReader()) { while (r.Read()) { ViewSchema view = new ViewSchema (this); view.Name = r.GetString (1); view.SchemaName = r.GetString (0); view.OwnerName = r.GetString (0); StringBuilder sb = new StringBuilder(); sb.AppendFormat ("-- View: {0}\n", view.Name); sb.AppendFormat ("-- DROP VIEW {0};\n\n", view.Name); sb.AppendFormat (" {0}\n);", GetSource ("[" + view.OwnerName + "].[" + view.Name + "]")); view.Definition = sb.ToString (); views.Add (view); } r.Close (); } } } catch (Exception e) { QueryService.RaiseException (e); } finally { conn.Release (); } } return views;
public virtual ViewSchemaCollection GetViews () { ViewSchemaCollection collection = new ViewSchemaCollection (); IPooledDbConnection conn = connectionPool.Request (); try { //restrictions: database, schema, table DataTable dt = conn.GetSchema (viewsCollectionString, null, connectionPool.ConnectionContext.ConnectionSettings.Database); for (int r = 0; r < dt.Rows.Count; r++) { DataRow row = dt.Rows[r]; collection.Add (GetView (row)); } } catch (Exception e) { QueryService.RaiseException (e); } conn.Release (); return collection; }
public override ViewSchemaCollection GetViews () { ViewSchemaCollection views = new ViewSchemaCollection (); IPooledDbConnection conn = connectionPool.Request (); IDbCommand command = conn.CreateCommand ( "SELECT name, sql FROM sqlite_master WHERE type = 'views'" ); try { using (command) { using (IDataReader r = command.ExecuteReader()) { while (r.Read ()) { ViewSchema view = new ViewSchema (this); view.SchemaName = "main"; view.Name = r.GetString (0); view.Definition = r.GetString (1); views.Add (view); } r.Close (); } } } catch (Exception e) { QueryService.RaiseException (e); } conn.Release (); return views; }
public override ViewSchemaCollection GetViews () { ViewSchemaCollection views = new ViewSchemaCollection (); IPooledDbConnection conn = connectionPool.Request (); IDbCommand command = conn.CreateCommand ( "SELECT v.schemaname, v.viewname, v.viewowner, v.definition," + " (c.oid <= " + LastSystemOID + "), " + "(SELECT description from pg_description pd, " + " pg_class pc WHERE pc.oid=pd.objoid AND pc.relname=" + " v.viewname) " + "FROM pg_views v, pg_class c " + "WHERE v.viewname = c.relname " + "ORDER BY viewname" ); try { using (command) { using (IDataReader r = command.ExecuteReader()) { while (r.Read ()) { ViewSchema view = new ViewSchema (this); view.Name = r.GetString (1); view.OwnerName = r.GetString (2); view.SchemaName = r.GetString (0); view.IsSystemView = r.GetBoolean (4); view.Comment = r.IsDBNull (5) ? null : r.GetString (5); // StringBuilder sb = new StringBuilder(); // sb.AppendFormat ("-- View: {0}\n", view.Name); // sb.AppendFormat ("-- DROP VIEW {0};\n\n", view.Name); // sb.AppendFormat ("CREATE VIEW {0} AS (\n", view.Name); // string core = r.GetString(3); // sb.AppendFormat (" {0}\n);", core.Substring (0, core.Length-1)); // view.Definition = sb.ToString (); views.Add (view); } r.Close (); } } } catch (Exception e) { QueryService.RaiseException (e); } conn.Release (); return views;