示例#1
0
 public virtual void WriteColumnDefinition(IAttribute attribute, IEnvironmentHelper environment)
 {
     Write("{0} {1}{2} {3}NULL",
           attribute.Persistence.Name,
           environment.ToTypeName(attribute, false),
           environment.ToDefaultValue(attribute).Length > 0 ? " DEFAULT " + environment.ToDefaultValue(attribute) : "",
           attribute.TypeDefinition.Required ? "NOT " : "");
 }
示例#2
0
        public override void WriteColumnDefinition(IAttribute attribute, IEnvironmentHelper environment)
        {
            string identitySpec = String.Empty;

            if (attribute.IsPrimaryId && attribute.Entity.PrimaryId.HasGenerator)
            {
                identitySpec = String.Format(" IDENTITY({0}, {1})",
                                             attribute.Entity.PrimaryId.Generator.StartWith,
                                             attribute.Entity.PrimaryId.Generator.Increment);
            }

            Write("{0} {1}{2} {3}NULL{4}",
                  attribute.Persistence.Name,
                  environment.ToTypeName(attribute, false),
                  environment.ToDefaultValue(attribute).Length > 0 ? " DEFAULT " + environment.ToDefaultValue(attribute) : "",
                  attribute.TypeDefinition.Required ? "NOT " : "",
                  identitySpec);
        }
示例#3
0
        void UpdateAttributes(IEntity entity, IAttributes attributes)
        {
            foreach (IAttribute a in attributes)
            {
                if (a.Persistence.Persisted)
                {
                    ICodeWriterTransactSql sql = Model.Lamp.CodeWritersFactory.CreateCodeWriterTransactSql();
                    sql.WriteLine("ALTER TABLE {0} ADD ", entity.Persistence.FullName);
                    sql.Indent++;
                    sql.WriteLine("{0} {1} NULL {2}{3}",
                                  a.Persistence.Name,
                                  environment.ToTypeName(a, false),
                                  a.TypeDefinition.HasDefault ? "DEFAULT " + environment.ToDefaultValue(a) : "",
                                  sql.Separator);
                    sql.Indent--;
                    if (a.TypeDefinition.Required && a.TypeDefinition.HasDefault)
                    {
                        sql.WriteSpExecuteSql("UPDATE {0} SET {1} = {2}{3}",
                                              entity.Persistence.FullName,
                                              a.Persistence.Name,
                                              environment.ToDefaultValue(a),
                                              sql.Separator);

                        sql.WriteLine("ALTER TABLE {0} ALTER COLUMN {1} {2} NOT NULL{3}",
                                      entity.Persistence.FullName,
                                      a.Persistence.Name,
                                      environment.ToTypeName(a, false),
                                      sql.Separator);
                    }

                    WriteUpdate(String.Format("NOT EXISTS(SELECT 1 FROM sys.columns WHERE object_id = OBJECT_ID(N'{0}') AND name = '{1}')",
                                              entity.Persistence.FullName, a.Persistence.Name),
                                sql);

                    genie.Config.NotifyAssistants("Update", a, sql.ToString(true));
                    updater.EndBatch();
                }
            }
            updater.WriteLine();
        }
示例#4
0
        private void ProcessUpdateAttributes(IEntity entity, IAttributes attributes)
        {
            foreach (IAttribute a in attributes)
            {
                if (a.Persistence.Persisted)
                {
                    ICodeWriterPlSql sql = Model.Lamp.CodeWritersFactory.CreateCodeWriterPlSql();
                    updater.WriteLine("SELECT count(*) INTO {0} FROM ALL_TAB_COLUMNS WHERE OWNER='{1}' AND TABLE_NAME='{2}' AND COLUMN_NAME='{3}' AND ROWNUM=1;",
                                      VarNameFoundCount,
                                      entity.Persistence.Schema,
                                      entity.Persistence.Name,
                                      a.Persistence.Name);
                    updater.If("{0} <> 1", VarNameFoundCount);

                    sql.WriteLine("ALTER TABLE {0} ADD ", entity.Persistence.FullName);
                    sql.Indent++;
                    sql.WriteLine("{0} {1} NULL",
                                  a.Persistence.Name,
                                  environment.ToTypeName(a, false));
                    WriteExecImmediat(sql);
                    string updateColSql = sql.ToString(true);

                    if (a.TypeDefinition.Required && a.TypeDefinition.HasDefault)
                    {
                        sql.ClearAll();
                        sql.WriteLine("UPDATE {0} SET {1}={2}",
                                      entity.Persistence.FullName,
                                      a.Persistence.Name,
                                      environment.ToDefaultValue(a));
                        WriteExecImmediat(sql);
                        updateColSql = updateColSql + Environment.NewLine + sql.ToString(true);

                        sql.ClearAll();
                        sql.WriteLine("ALTER TABLE {0} MODIFY ({1} NOT NULL)",
                                      entity.Persistence.FullName,
                                      a.Persistence.Name);
                        WriteExecImmediat(sql);
                        updateColSql = updateColSql + Environment.NewLine + sql.ToString(true);
                    }
                    updater.EndIf();

                    genie.Config.NotifyAssistants("Update", a, updateColSql);
                }
            }
            updater.WriteLine();
        }
示例#5
0
        public void WriteProperty(AccessLevel accessLevel,
                                  VirtualisationLevel virtualisationLevel,
                                  IAttribute attribute,
                                  IEnvironmentHelper environment,
                                  string propertyAttributes)
        {
            string defaultValue = null;

            if (attribute.Type is IEnumerationType)
            {
                defaultValue = String.Format("({0}){1}",
                                             environment.ToTypeName(attribute, true),
                                             (attribute.Type as IEnumerationType).Enumeration.DefaultItem.Value.ToString());
            }
            else if (attribute.TypeDefinition.HasDefault)
            {
                defaultValue = environment.ToDefaultValue(attribute);
            }

            if (defaultValue != null || IsAttributeIsStringLimitedLength(attribute))
            {
                StandardProperty(accessLevel,
                                 virtualisationLevel,
                                 attribute,
                                 environment,
                                 defaultValue,
                                 propertyAttributes);
            }
            else
            {
                if (!String.IsNullOrEmpty(propertyAttributes))
                {
                    WriteLine(propertyAttributes);
                }
                SimpleProperty(accessLevel,
                               virtualisationLevel,
                               attribute,
                               environment);
            }
        }