private void WriteObjectProperty(IAttribute attribute, IEnvironmentHelper environment)
        {
            IRelation r       = attribute.UsedInRelations[0];
            IEntity   related = r.Entity;

            if (r.Entity == attribute.Entity)
            {
                related = r.Entity2;
            }

            cw.WriteLine("private {0} {1};",
                         environment.ToTypeName(related, true),
                         environment.ToMemberName(attribute));
            cw.BeginProperty(AccessLevel.Public,
                             VirtualisationLevel.Virtual,
                             environment.ToTypeName(related, true),
                             attribute.Name);
            cw.BeginPropertyGet();
            cw.WriteLine("return this.{0}.{1};",
                         PropertyName_DomainObjectProxy,
                         attribute.Name);
            cw.EndPropertyAccessor();
            cw.BeginPropertySet();
            cw.WriteLine("this.{0}.{1} = value;",
                         PropertyName_DomainObjectProxy,
                         attribute.Name);
            cw.EndPropertyAccessor();
            cw.EndProperty();
        }
Ejemplo n.º 2
0
 public void DeclareMember(IAttribute attribute, string defaultValue, IEnvironmentHelper environment)
 {
     WriteLine("private {0} {1} = {2};",
               environment.ToTypeName(attribute, true),
               environment.ToMemberName(attribute),
               defaultValue);
 }
Ejemplo n.º 3
0
 public static string ToDomainTypeName(IEntity entity, IEnvironmentHelper environment)
 {
     if (environment == null)
     {
         return(entity.Name);
     }
     return(environment.ToTypeName(entity.Type, true));
 }
Ejemplo n.º 4
0
 public static string ToDTOAdapterTypeName(IEntity entity, IEnvironmentHelper environment)
 {
     if (environment != null)
     {
         return(ToDTOAdapterTypeName(environment.ToTypeName(entity, true)));
     }
     return(ToDTOAdapterTypeName(entity.Name));
 }
Ejemplo n.º 5
0
 public static string ToServiceResponseCollectionName(IEntity entity, IEnvironmentHelper environment)
 {
     if (environment != null)
     {
         return(ToServiceResponseCollectionName(environment.ToTypeName(entity, true)));
     }
     return(ToServiceResponseCollectionName(entity.Name));
 }
Ejemplo n.º 6
0
 public static string ToServiceName(IEntity entity, IEnvironmentHelper environment)
 {
     if (environment == null)
     {
         return(ToServiceName(entity.Name));
     }
     return(ToServiceName(environment.ToTypeName(entity, true)));
 }
Ejemplo n.º 7
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 " : "");
 }
Ejemplo n.º 8
0
 public void SimpleProperty(AccessLevel accessLevel,
                            VirtualisationLevel virtualisationLevel,
                            IAttribute attribute,
                            IEnvironmentHelper environment)
 {
     SimpleProperty(accessLevel,
                    virtualisationLevel,
                    environment.ToTypeName(attribute, true),
                    attribute.Name,
                    true,
                    !attribute.ReadOnly);
 }
Ejemplo n.º 9
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();
        }
Ejemplo n.º 10
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();
        }
Ejemplo n.º 11
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);
        }
 private void WriteSimpleProperty(IAttribute attribute, IEnvironmentHelper environment)
 {
     cw.BeginProperty(AccessLevel.Public,
                      VirtualisationLevel.Virtual,
                      environment.ToTypeName(attribute, true),
                      attribute.Name);
     cw.BeginPropertyGet();
     cw.WriteLine("return this.{0}.{1};",
                  PropertyName_DomainObjectProxy,
                  attribute.Name);
     cw.EndPropertyAccessor();
     cw.BeginPropertySet();
     cw.WriteLine("this.{0}.{1} = value;",
                  PropertyName_DomainObjectProxy,
                  attribute.Name);
     cw.EndPropertyAccessor();
     cw.EndProperty();
 }
Ejemplo n.º 13
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);
            }
        }
Ejemplo n.º 14
0
        public void StandardProperty(AccessLevel accessLevel,
                                     VirtualisationLevel virtualisationLevel,
                                     IAttribute attribute,
                                     IEnvironmentHelper environment,
                                     string defaultValue,
                                     string propertyAttributes)
        {
            if (defaultValue == null || (defaultValue != null && defaultValue.Length == 0))
            {
                DeclareMember(attribute, environment);
            }
            else
            {
                DeclareMember(attribute, defaultValue, environment);
            }

            if (!String.IsNullOrEmpty(propertyAttributes))
            {
                WriteLine(propertyAttributes);
            }
            BeginProperty(accessLevel, virtualisationLevel, environment.ToTypeName(attribute, true), attribute.Name);
            WritePropertyGet(String.Format("return {0};", environment.ToMemberName(attribute)));
            if (!attribute.ReadOnly)
            {
                if (IsAttributeIsStringLimitedLength(attribute))
                {
                    WritePropertySet(String.Format("{0} = value != null && value.Length > {1} ? value.Substring(0, {1}) : value;",
                                                   environment.ToMemberName(attribute),
                                                   attribute.TypeDefinition.Length));
                }
                else
                {
                    WritePropertySet(String.Format("{0} = value;", environment.ToMemberName(attribute)));
                }
            }
            EndProperty();
        }
Ejemplo n.º 15
0
 public void DeclareMember(IAttribute attribute, IEnvironmentHelper environment)
 {
     WriteLine("private {0} {1};", environment.ToTypeName(attribute, true), environment.ToMemberName(attribute));
 }