Exemple #1
0
        private void ProcessEntity(IEntity entity)
        {
            updater.WriteLine(creator.WriteCommentLine("Table of {0}", entity.FullName));

            ICodeWriterPlSql sql = Model.Lamp.CodeWritersFactory.CreateCodeWriterPlSql();

            sql.WriteCreateTable(entity, environment);
            ISpellHint hint = genie.FindHint(entity);

            if (hint != null)
            {
                sql.WriteText(hint.GetText(entity));
            }
            creator.WriteFrom(sql);
            creator.WriteSeparator();

            WriteExecImmediatWhenNotExists(
                "ALL_TABLES",
                String.Format("OWNER='{0}' AND TABLE_NAME='{1}'", entity.Persistence.Schema, entity.Persistence.Name),
                sql);
            updater.WriteLine();

            genie.Config.NotifyAssistants("Create", entity, sql.ToString(true));

            IAttributes attributes;

            switch (Model.Lamp.Config.Layers.DomainConfig.MappingStrategy)
            {
            case GenieLamp.Core.Layers.MappingStrategy.TablePerSubclass:
                attributes = entity.GetAttributes(false);
                break;

            case GenieLamp.Core.Layers.MappingStrategy.TablePerClass:
                attributes = entity.GetAttributes(true);
                break;

            default:
                throw new GenieLamp.Core.Exceptions.GlException("Mapping strategy is not supported: '{0}'",
                                                                Model.Lamp.Config.Layers.DomainConfig.MappingStrategy);
            }

            ProcessUpdateAttributes(entity, attributes);

            ProcessPrimaryKey(entity);

            ProcessUniqueIds(entity);

            creator.WriteLine();
            updater.WriteLine();
            WriteComment(CommentTarget.Table, entity.Persistence.FullName, entity.Doc);

            foreach (IAttribute a in attributes)
            {
                if (a.Persistence.Persisted)
                {
                    WriteComment(CommentTarget.Column,
                                 String.Format("{0}.{1}", entity.Persistence.FullName, a.Persistence.Name),
                                 a.Doc);
                }
            }
        }