private void GenerateContent()
        {
            try
            {
                ISQLGenerate generator = null;

                sb.AppendLine("--DO NOT MODIFY THIS FILE. IT IS ALWAYS OVERWRITTEN ON GENERATION.");
                sb.AppendLine("--Data Schema For Version " + _model.Version);
                ValidationHelper.AppendCopyrightInSQL(sb, _model);

                generator = new SQLSelectViewByAndTemplate(_model, _view);
                generator.GenerateContent(sb);

                generator = new SQLSelectViewByOrTemplate(_model, _view);
                generator.GenerateContent(sb);

                generator = new SQLSelectViewTemplate(_model, _view);
                generator.GenerateContent(sb);

                generator = new SQLPagedSelectViewTemplate(_model, _view);
                generator.GenerateContent(sb);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 2
0
 private void AppendViews()
 {
     try
     {
         foreach (CustomView customView in _model.Database.CustomViews)
         {
             sb.AppendLine("--DO NOT MODIFY THIS FILE. IT IS ALWAYS OVERWRITTEN ON GENERATION.");
             sb.AppendLine("--Data Schema For Version " + _model.Version);
             ValidationHelper.AppendCopyrightInSQL(sb, _model);
             sb.AppendLine("if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[view_" + customView.DatabaseName + "]') and OBJECTPROPERTY(id, N'IsView') = 1)");
             sb.AppendLine("drop view [dbo].[view_" + customView.DatabaseName + "]");
             sb.AppendLine("GO");
             sb.AppendLine();
             sb.AppendLine("SET QUOTED_IDENTIFIER ON ");
             sb.AppendLine("GO");
             sb.AppendLine("SET ANSI_NULLS ON ");
             sb.AppendLine("GO");
             sb.AppendLine();
             sb.AppendLine("CREATE VIEW dbo.view_" + customView.DatabaseName);
             sb.AppendLine("AS");
             sb.AppendLine(customView.SQL);
             sb.AppendLine("GO");
             sb.AppendLine("SET QUOTED_IDENTIFIER OFF ");
             sb.AppendLine("GO");
             sb.AppendLine("SET ANSI_NULLS ON ");
             sb.AppendLine("GO");
             sb.AppendLine();
         }
     }
     catch (Exception ex)
     {
         throw;
     }
 }
        private void GenerateContent()
        {
            if (_model.Database.AllowZeroTouch)
            {
                return;
            }
            try
            {
                sb.AppendLine("--DO NOT MODIFY THIS FILE. IT IS ALWAYS OVERWRITTEN ON GENERATION.");
                sb.AppendLine("--Data Schema For Version " + _model.Version);
                ValidationHelper.AppendCopyrightInSQL(sb, _model);
                sb.AppendLine("if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[" + StoredProcedureName + "]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)");
                sb.AppendLine("	drop procedure [dbo].[" + StoredProcedureName + "]");
                sb.AppendLine("GO");
                sb.AppendLine();

                sb.AppendLine();
                sb.AppendLine("SET QUOTED_IDENTIFIER ON ");
                sb.AppendLine("GO");
                sb.AppendLine("SET ANSI_NULLS ON ");
                sb.AppendLine("GO");
                sb.AppendLine();
                sb.AppendLine("CREATE PROCEDURE [dbo].[" + StoredProcedureName + "]");
                sb.AppendLine("(");
                sb.AppendLine(this.BuildParameterList());
                sb.AppendLine(")");
                sb.AppendLine("AS");
                sb.AppendLine();
                sb.Append(SQLGeneratedBodyHelper.SQLDeleteBusinessObjectBody(_currentTable, _model));
                sb.AppendLine("GO");
                sb.AppendLine("SET QUOTED_IDENTIFIER OFF");
                sb.AppendLine("GO");
                sb.AppendLine("SET ANSI_NULLS ON");
                sb.AppendLine("GO");
                sb.AppendLine();

                if (_model.Database.GrantExecUser != string.Empty)
                {
                    sb.AppendFormat("GRANT EXECUTE ON [dbo].[{0}] TO [{1}]", StoredProcedureName, _model.Database.GrantExecUser);
                    sb.AppendLine();
                    sb.AppendLine("GO");
                    sb.AppendLine();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 4
0
        public void AppendFullTemplate()
        {
            try
            {
                sb.AppendLine("--DO NOT MODIFY THIS FILE. IT IS ALWAYS OVERWRITTEN ON GENERATION.");
                sb.AppendLine("--Data Schema For Version " + _model.Version);
                ValidationHelper.AppendCopyrightInSQL(sb, _model);
                sb.AppendLine("if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[" + this.StoredProcedureName + "]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)");
                sb.AppendLine("	drop procedure [dbo].[" + this.StoredProcedureName + "]");
                sb.AppendLine("GO");
                sb.AppendLine();
                sb.AppendLine("SET QUOTED_IDENTIFIER ON ");
                sb.AppendLine("GO");
                sb.AppendLine("SET ANSI_NULLS ON ");
                sb.AppendLine("GO");
                sb.AppendLine();
                sb.AppendLine("CREATE PROCEDURE [dbo].[" + this.StoredProcedureName + "]");

                if (_currentStoredProcedure.Parameters.Count > 0)
                {
                    sb.AppendLine("(");
                    sb.Append(this.BuildParameterList());
                    sb.AppendLine(")");
                }

                sb.AppendLine("AS");
                sb.AppendLine("SET NOCOUNT ON;");
                sb.AppendLine();
                sb.Append(_currentStoredProcedure.SQL);
                sb.AppendLine();
                sb.AppendLine("GO");
                sb.AppendLine();
                sb.AppendLine("SET QUOTED_IDENTIFIER OFF ");
                sb.AppendLine("GO");
                sb.AppendLine("SET ANSI_NULLS ON ");
                sb.AppendLine("GO");
                sb.AppendLine();
                if (_model.Database.GrantExecUser != string.Empty)
                {
                    sb.AppendFormat("GRANT  EXECUTE  ON [dbo].[{0}]  TO [{1}]", this.StoredProcedureName, _model.Database.GrantExecUser).AppendLine();
                    sb.AppendLine("GO");
                    sb.AppendLine();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        private void GenerateContent()
        {
            try
            {
                ISQLGenerate generator = null;

                sb.AppendLine("--DO NOT MODIFY THIS FILE. IT IS ALWAYS OVERWRITTEN ON GENERATION.");
                sb.AppendLine("--Data Schema For Version " + _model.Version);
                ValidationHelper.AppendCopyrightInSQL(sb, _model);

                generator = new SQLDeleteBusinessObjectTemplate(_model, _table);
                generator.GenerateContent(sb);

                generator = new SQLSelectBusinessObjectByPrimaryKeyTemplate(_model, _table);
                generator.GenerateContent(sb);

                generator = new SQLInsertBusinessObjectTemplate(_model, _table);
                generator.GenerateContent(sb);

                generator = new SQLPagedSelectBusinessObjectTemplate(_model, _table);
                generator.GenerateContent(sb);

                generator = new SQLSelectBusinessObjectByAndTemplate(_model, _table);
                generator.GenerateContent(sb);

                generator = new SQLSelectBusinessObjectByFieldTemplate(_model, _table);
                generator.GenerateContent(sb);

                generator = new SQLUpdateBusinessObjectTemplate(_model, _table);
                generator.GenerateContent(sb);

                if (_table.AllowCreateAudit)
                {
                    generator = new SQLSelectBusinessObjectByCreatedDateTemplate(_model, _table);
                    generator.GenerateContent(sb);
                }

                if (_table.AllowModifiedAudit)
                {
                    generator = new SQLSelectBusinessObjectByModifiedDateTemplate(_model, _table);
                    generator.GenerateContent(sb);
                }

                generator = new SQLSelectBusinessObjectByOrTemplate(_model, _table);
                generator.GenerateContent(sb);

                generator = new SQLSelectBusinessObjectTemplate(_model, _table);
                generator.GenerateContent(sb);


                //All parent relationships
                foreach (Relation relation in _table.ParentRoleRelations.Where(x => x.IsGenerated))
                {
                    if (!relation.IsPrimaryKeyRelation())
                    {
                        generator = new SQLSelectBusinessObjectByRelationTemplate(_model, _table, relation);
                        generator.GenerateContent(sb);
                    }
                }

                foreach (Relation relation in _table.GetChildRoleRelationsFullHierarchy().Where(x => x.IsGenerated))
                {
                    generator = new SQLSelectBusinessObjectByForeignKeyTemplate(_model, relation, _table);
                    generator.GenerateContent(sb);
                }

                //All Components for this table
                foreach (TableComponent component in _table.ComponentList)
                {
                    generator = new SQLPagedSelectComponentTemplate(_model, component);
                    generator.GenerateContent(sb);

                    generator = new SQLSelectComponentByPrimaryKeyTemplate(_model, component);
                    generator.GenerateContent(sb);

                    generator = new SQLSelectComponentByFieldTemplate(_model, component);
                    generator.GenerateContent(sb);

                    if (component.Parent.AllowCreateAudit)
                    {
                        generator = new SQLSelectComponentByCreatedDateTemplate(_model, component);
                        generator.GenerateContent(sb);
                    }

                    if (component.Parent.AllowModifiedAudit)
                    {
                        generator = new SQLSelectComponentByModifiedDateTemplate(_model, component);
                        generator.GenerateContent(sb);
                    }

                    generator = new SqlSelectComponentTemplate(_model, component);
                    generator.GenerateContent(sb);

                    generator = new SQLUpdateComponentTemplate(_model, component);
                    generator.GenerateContent(sb);
                }


                foreach (CustomRetrieveRule rule in _model.Database.CustomRetrieveRules)
                {
                    Table table = (Table)rule.ParentTableRef.Object;
                    if (table == _table)
                    {
                        if (rule.Generated && table.Generated)
                        {
                            generator = new SQLSelectRetrieveRuleTemplate(_model, rule);
                            generator.GenerateContent(sb);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        private void GenerateContent()
        {
            if (_model.Database.AllowZeroTouch)
            {
                return;
            }
            try
            {
                sb.AppendLine("--DO NOT MODIFY THIS FILE. IT IS ALWAYS OVERWRITTEN ON GENERATION.");
                sb.AppendLine("--Data Schema For Version " + _model.Version);
                ValidationHelper.AppendCopyrightInSQL(sb, _model);
                sb.AppendLine("if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[" + StoredProcedureName + "]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)");
                sb.AppendLine("	drop procedure [dbo].[" + StoredProcedureName + "]");
                sb.AppendLine("GO");
                sb.AppendLine();

                sb.AppendLine();
                sb.AppendLine("SET QUOTED_IDENTIFIER ON ");
                sb.AppendLine("GO");
                sb.AppendLine("SET ANSI_NULLS ON ");
                sb.AppendLine("GO");
                sb.AppendLine();
                sb.AppendLine("CREATE PROCEDURE [dbo].[" + StoredProcedureName + "]");
                sb.AppendLine("(");
                sb.AppendLine(this.BuildParameterList());
                sb.AppendLine(")");
                sb.AppendLine("AS");
                sb.AppendLine();

                if (_currentComponent.Parent.AllowModifiedAudit)
                {
                    sb.AppendLine("IF (@" + _model.Database.ModifiedDateColumnName + " IS NULL)");
                    sb.AppendLine("SET @" + _model.Database.ModifiedDateColumnName + " = GetDate();");
                    sb.AppendLine();
                }

                sb.AppendLine("SET NOCOUNT OFF;");

                List <Table> tableList = new List <Table>();
                foreach (Reference reference in _currentComponent.Columns)
                {
                    Column column = (Column)reference.Object;
                    Table  table  = (Table)column.ParentTableRef.Object;
                    if (!tableList.Contains(table))
                    {
                        tableList.Add(table);
                    }
                }

                foreach (Table table in tableList)
                {
                    sb.AppendLine("UPDATE ");
                    sb.AppendLine("\t[" + table.DatabaseName + "] ");
                    sb.AppendLine("SET");
                    sb.AppendLine(BuildSetStatement(table));
                    sb.AppendLine("WHERE");
                    sb.AppendLine("\t" + BuildUpdateWhereStatement(table));
                    sb.AppendLine();
                }

                sb.AppendLine("SELECT");
                sb.Append(Globals.BuildSelectList(_currentComponent, _model));
                sb.AppendLine("FROM ");
                sb.AppendLine(_currentComponent.Parent.GetFullHierarchyTableJoin());
                sb.AppendLine("WHERE");
                sb.AppendLine("\t" + BuildSelectWhereStatement());
                sb.AppendLine("GO");
                sb.AppendLine("SET QUOTED_IDENTIFIER OFF");
                sb.AppendLine("GO");
                sb.AppendLine("SET ANSI_NULLS ON");
                sb.AppendLine("GO");
                sb.AppendLine();

                if (_model.Database.GrantExecUser != string.Empty)
                {
                    sb.AppendFormat("GRANT EXECUTE ON [dbo].[{0}] TO [{1}]", StoredProcedureName, _model.Database.GrantExecUser);
                    sb.AppendLine();
                    sb.AppendLine("GO");
                    sb.AppendLine();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }