Esempio n. 1
0
        private void ProcessEntityTablePerSubClass(Entity entity, joinedsubclass joinedSubClassNode)
        {
            foreach (var childEntity in entity.Children)
            {
                var mappedTable = childEntity.MappedTables().First();

                var subclassNode = new joinedsubclass();
                subclassNode.table  = mappedTable.Name.BackTick();
                subclassNode.schema = mappedTable.Schema.BackTick();
                subclassNode.name   = childEntity.Name;

                key keyNode = GetKeyNode(mappedTable);
                subclassNode.key = keyNode;

                foreach (var property in childEntity.ConcreteProperties)
                {
                    IColumn column = property.MappedColumn();
                    if (column == null)
                    {
                        continue;
                    }

                    property propNode = ProcessProperty(property, column);
                    subclassNode.AddProperty(propNode);
                }
                joinedSubClassNode.AddJoinedSubclass(subclassNode);

                var referenceMapper = new ReferenceMapper();
                referenceMapper.ProcessReferences(childEntity, item => subclassNode.AddItem(item));
            }
        }
Esempio n. 2
0
        private void ProcessEntityTablePerClassHierarchy(Entity entity, @class classNode)
        {
            foreach (var childEntity in entity.Children)
            {
                var subclassNode = new subclass();

                subclassNode.name = childEntity.Name;
                subclassNode.discriminatorvalue = childEntity.DiscriminatorValue;

                foreach (var property in childEntity.ConcreteProperties)
                {
                    IColumn column = property.MappedColumn();
                    if (column == null)
                    {
                        continue;
                    }

                    property propNode = ProcessProperty(property, column);
                    subclassNode.AddProperty(propNode);
                }
                var referenceMapper = new ReferenceMapper();
                referenceMapper.ProcessReferences(childEntity, item => subclassNode.AddItem(item));

                classNode.AddItem1(subclassNode);
            }
            classNode.discriminator       = new discriminator();
            classNode.discriminator.force = entity.Discriminator.Force;
            //classNode.discriminator.length = entity.Discriminator.l.Force.ToString();
            //classNode.discriminator.notnull = entity.Discriminator..Force.ToString();

            if (!entity.Discriminator.Insert)
            {
                classNode.discriminator.insert = entity.Discriminator.Insert;
            }
            if (entity.Discriminator.DiscriminatorType == Providers.EntityModel.Model.Enums.DiscriminatorTypes.Column)
            {
                classNode.discriminator.column = entity.Discriminator.ColumnName;
            }
            else
            {
                classNode.discriminator.formula = entity.Discriminator.Formula;
            }
        }
Esempio n. 3
0
        public @class ProcessEntity(Entity entity)
        {
            Log.DebugFormat("Processing entity {0}", entity.Name);
            var newClass = new @class {
                name = entity.Name
            };
            IList <ITable> mappedTables = entity.MappedTables().ToList();
            // One Entity to one or more tables
            ITable table = GetPrimaryTable(entity);

            if (table != null && !string.IsNullOrEmpty(table.Name))
            {
                newClass.table = table.Name.BackTick();
            }

            if (table != null && !string.IsNullOrEmpty(table.Schema))
            {
                newClass.schema = table.Schema.BackTick();
            }

            var entityDefaultLazy = entity.GetEntityLazy();

            if (entity.GetEntityLazy() == Interfaces.NHibernateEnums.EntityLazyTypes.inherit_default)
            {
                newClass.lazy = ArchAngel.Interfaces.SharedData.CurrentProject.GetProjectDefaultLazy();
            }
            else
            {
                newClass.lazy = entityDefaultLazy == Interfaces.NHibernateEnums.EntityLazyTypes.@true;
            }

            newClass.lazySpecified = !newClass.lazy;

            newClass.batchsize          = entity.GetEntityBatchSize();
            newClass.batchsizeSpecified = entity.GetEntityBatchSize() != 1;

            if (entity.GetEntityDynamicInsert())
            {
                newClass.dynamicinsert = true;
            }

            if (entity.GetEntityDynamicUpdate())
            {
                newClass.dynamicupdate = true;
            }

            newClass.@abstract = entity.IsAbstract;

            if (entity.IsAbstract)
            {
                newClass.abstractSpecified = true;
            }

            newClass.mutable            = entity.GetEntityMutable();
            newClass.optimisticlock     = (optimisticLockMode)Enum.Parse(typeof(optimisticLockMode), entity.GetEntityOptimisticLock().ToString(), true);
            newClass.selectbeforeupdate = entity.GetEntitySelectBeforeUpdate();

            if (entity.Cache.Usage != Cache.UsageTypes.None)
            {
                newClass.cache = new cache()
                {
                    include = (cacheInclude)Enum.Parse(typeof(cacheInclude), entity.Cache.Include.ToString().Replace("_", ""), true),
                    region  = entity.Cache.Region
                };
                switch (entity.Cache.Usage)
                {
                case Cache.UsageTypes.NonStrict_Read_Write:
                    newClass.cache.usage = cacheUsage.nonstrictreadwrite;
                    break;

                case Cache.UsageTypes.Read_Only:
                    newClass.cache.usage = cacheUsage.@readonly;
                    break;

                case Cache.UsageTypes.Read_Write:
                    newClass.cache.usage = cacheUsage.readwrite;
                    break;

                case Cache.UsageTypes.Transactional:
                    newClass.cache.usage = cacheUsage.transactional;
                    break;

                default:
                    throw new NotImplementedException("This cache type not implemented yet: " + entity.Cache.Usage.ToString());
                }
            }

            if (entity.GetEntityBatchSize() != 1)
            {
                newClass.batchsize = entity.GetEntityBatchSize();
            }

            if (!string.IsNullOrWhiteSpace(entity.GetEntityProxy()))
            {
                newClass.proxy = entity.GetEntityProxy();
            }

            if (!string.IsNullOrWhiteSpace(entity.GetEntityPersister()))
            {
                newClass.persister = entity.GetEntityPersister();
            }

            string sqlWhere = entity.GetEntitySqlWhereClause();

            if (!string.IsNullOrEmpty(sqlWhere))
            {
                newClass.where = sqlWhere;
            }

            // bool isSingleColumnPK = false;

            if (entity.IsAbstract)
            {
                // This is an abstract class in Table Per Concrete Class inheritance. The child entities
                // should have properties of the same name.
                Entity firstChild = entity.Children.FirstOrDefault();

                while (firstChild != null && firstChild.IsAbstract)
                {
                    firstChild = firstChild.Children.FirstOrDefault();
                }

                if (firstChild != null)
                {
                    ITable childTable = GetPrimaryTable(firstChild);
                    ProcessEntityKey(firstChild, newClass, childTable);
                    // isSingleColumnPK = childTable.ColumnsInPrimaryKey.Count() == 1;

                    foreach (var property in entity.Properties.OrderBy(p => p.Name))
                    {
                        if (firstChild.PropertiesHiddenByAbstractParent.Single(p => p.Name == property.Name).IsKeyProperty)
                        {
                            continue;
                        }

                        var      mappedColumn = firstChild.PropertiesHiddenByAbstractParent.Single(p => p.Name == property.Name).MappedColumn();
                        property prop         = new property {
                            name = property.Name, column = mappedColumn.Name.BackTick()
                        };
                        //AddExtraInfoToProperty(prop, property);
                        newClass.AddProperty(prop);
                    }
                }
                foreach (Entity child in entity.Children)
                {
                    Entity theChild = child;

                    while (theChild != null && theChild.IsAbstract)
                    {
                        theChild = theChild.Children.FirstOrDefault();
                    }

                    ITable mappedTable = theChild.MappedTables().First();

                    unionsubclass union = new unionsubclass()
                    {
                        name  = theChild.Name,
                        table = mappedTable.Name.BackTick()
                    };
                    newClass.AddItem1(union);

                    List <property> unionProperties = new List <property>();

                    foreach (Property prop in theChild.ConcreteProperties)
                    {
                        if (prop.IsKeyProperty)
                        {
                            continue;
                        }

                        unionProperties.Add(
                            new property()
                        {
                            name   = prop.Name,
                            column = prop.MappedColumn().Name.BackTick()
                        });
                        //AddExtraInfoToProperty(prop, property);
                    }
                    union.Items = unionProperties.ToArray();
                }
            }
            else
            {
                ProcessEntityKey(entity, newClass, table);
                // isSingleColumnPK = table.ColumnsInPrimaryKey.Count() == 1;
            }
            var propertiesAlreadyHandled = new List <Property>();

            foreach (ITable joinedTable in mappedTables.OrderBy(t => t.Name))
            {
                if (joinedTable == table)
                {
                    continue;
                }

                join joinNode = new join();
                joinNode.table  = joinedTable.Name.BackTick();
                joinNode.schema = joinedTable.Schema.BackTick();
                int numPrimaryKeyColumns = joinedTable.ColumnsInPrimaryKey.Count();

                if (numPrimaryKeyColumns > 0)
                {
                    key keyNode = GetKeyNode(joinedTable);
                    joinNode.key = keyNode;
                }

                foreach (var property in entity.Properties.OrderBy(p => p.Name))
                {
                    var mappedColumn = property.MappedColumn();

                    if (mappedColumn == null || mappedColumn.Parent != joinedTable)
                    {
                        continue;
                    }

                    property prop = new property {
                        name = property.Name, column = mappedColumn.Name.BackTick()
                    };
                    AddExtraInfoToProperty(prop, property);
                    joinNode.AddProperty(prop);
                    propertiesAlreadyHandled.Add(property);
                }
                newClass.AddItem1(joinNode);
            }
            var versionProperty = entity.Properties.FirstOrDefault(p => p.GetPropertyIsVersion());

            if (versionProperty != null)
            {
                version versionNode = new version();
                versionNode.column1 = versionProperty.MappedColumn().Name.BackTick();
                versionNode.name    = versionProperty.Name;
                versionNode.type    = versionProperty.NHibernateType;
                // AddExtraInfoToProperty(prop, property);
                newClass.SetVersion(versionNode);
                propertiesAlreadyHandled.Add(versionProperty);
            }

            //foreach (var prop in ProcessProperties(entity.Properties.Except(propertiesAlreadyHandled).Except(entity.ForeignKeyPropertiesToExclude), isSingleColumnPK).OrderBy(p => p.name))
            foreach (var prop in ProcessProperties(entity.Properties.Except(propertiesAlreadyHandled).Except(entity.ForeignKeyPropertiesToExclude)).OrderBy(p => p.name))
            {
                newClass.AddProperty(prop);
            }

            // Process components, skip component used as Key.
            foreach (var component in ProcessComponent(entity.Components.Except(new[] { entity.Key.Component })).OrderBy(c => c.name))
            {
                newClass.AddComponent(component);
            }

            ProcessInheritance(entity, newClass);

            var referenceMapper = new ReferenceMapper();

            referenceMapper.ProcessReferences(entity, item => newClass.AddItem(item));
            return(newClass);
        }
Esempio n. 4
0
        public @class ProcessEntity(Entity entity)
        {
            Log.DebugFormat("Processing entity {0}", entity.Name);
            var newClass = new @class { name = entity.Name };
            IList<ITable> mappedTables = entity.MappedTables().ToList();
            // One Entity to one or more tables
            ITable table = GetPrimaryTable(entity);

            if (table != null && !string.IsNullOrEmpty(table.Name))
                newClass.table = table.Name.BackTick();

            if (table != null && !string.IsNullOrEmpty(table.Schema))
                newClass.schema = table.Schema.BackTick();

            var entityDefaultLazy = entity.GetEntityLazy();

            if (entity.GetEntityLazy() == Interfaces.NHibernateEnums.EntityLazyTypes.inherit_default)
                newClass.lazy = ArchAngel.Interfaces.SharedData.CurrentProject.GetProjectDefaultLazy();
            else
                newClass.lazy = entityDefaultLazy == Interfaces.NHibernateEnums.EntityLazyTypes.@true;

            newClass.lazySpecified = !newClass.lazy;

            newClass.batchsize = entity.GetEntityBatchSize();
            newClass.batchsizeSpecified = entity.GetEntityBatchSize() != 1;

            if (entity.GetEntityDynamicInsert())
                newClass.dynamicinsert = true;

            if (entity.GetEntityDynamicUpdate())
                newClass.dynamicupdate = true;

            newClass.@abstract = entity.IsAbstract;

            if (entity.IsAbstract)
                newClass.abstractSpecified = true;

            newClass.mutable = entity.GetEntityMutable();
            newClass.optimisticlock = (optimisticLockMode)Enum.Parse(typeof(optimisticLockMode), entity.GetEntityOptimisticLock().ToString(), true);
            newClass.selectbeforeupdate = entity.GetEntitySelectBeforeUpdate();

            if (entity.Cache.Usage != Cache.UsageTypes.None)
            {
                newClass.cache = new cache()
                {
                    include = (cacheInclude)Enum.Parse(typeof(cacheInclude), entity.Cache.Include.ToString().Replace("_", ""), true),
                    region = entity.Cache.Region
                };
                switch (entity.Cache.Usage)
                {
                    case Cache.UsageTypes.NonStrict_Read_Write:
                        newClass.cache.usage = cacheUsage.nonstrictreadwrite;
                        break;
                    case Cache.UsageTypes.Read_Only:
                        newClass.cache.usage = cacheUsage.@readonly;
                        break;
                    case Cache.UsageTypes.Read_Write:
                        newClass.cache.usage = cacheUsage.readwrite;
                        break;
                    case Cache.UsageTypes.Transactional:
                        newClass.cache.usage = cacheUsage.transactional;
                        break;
                    default:
                        throw new NotImplementedException("This cache type not implemented yet: " + entity.Cache.Usage.ToString());
                }
            }

            if (entity.GetEntityBatchSize() != 1)
                newClass.batchsize = entity.GetEntityBatchSize();

            if (!string.IsNullOrWhiteSpace(entity.GetEntityProxy()))
                newClass.proxy = entity.GetEntityProxy();

            if (!string.IsNullOrWhiteSpace(entity.GetEntityPersister()))
                newClass.persister = entity.GetEntityPersister();

            string sqlWhere = entity.GetEntitySqlWhereClause();

            if (!string.IsNullOrEmpty(sqlWhere))
                newClass.where = sqlWhere;

            // bool isSingleColumnPK = false;

            if (entity.IsAbstract)
            {
                // This is an abstract class in Table Per Concrete Class inheritance. The child entities
                // should have properties of the same name.
                Entity firstChild = entity.Children.FirstOrDefault();

                while (firstChild != null && firstChild.IsAbstract)
                    firstChild = firstChild.Children.FirstOrDefault();

                if (firstChild != null)
                {
                    ITable childTable = GetPrimaryTable(firstChild);
                    ProcessEntityKey(firstChild, newClass, childTable);
                    // isSingleColumnPK = childTable.ColumnsInPrimaryKey.Count() == 1;

                    foreach (var property in entity.Properties.OrderBy(p => p.Name))
                    {
                        if (firstChild.PropertiesHiddenByAbstractParent.Single(p => p.Name == property.Name).IsKeyProperty)
                            continue;

                        var mappedColumn = firstChild.PropertiesHiddenByAbstractParent.Single(p => p.Name == property.Name).MappedColumn();
                        property prop = new property { name = property.Name, column = mappedColumn.Name.BackTick() };
                        //AddExtraInfoToProperty(prop, property);
                        newClass.AddProperty(prop);
                    }
                }
                foreach (Entity child in entity.Children)
                {
                    Entity theChild = child;

                    while (theChild != null && theChild.IsAbstract)
                        theChild = theChild.Children.FirstOrDefault();

                    ITable mappedTable = theChild.MappedTables().First();

                    unionsubclass union = new unionsubclass()
                    {
                        name = theChild.Name,
                        table = mappedTable.Name.BackTick()
                    };
                    newClass.AddItem1(union);

                    List<property> unionProperties = new List<property>();

                    foreach (Property prop in theChild.ConcreteProperties)
                    {
                        if (prop.IsKeyProperty)
                            continue;

                        unionProperties.Add(
                        new property()
                        {
                            name = prop.Name,
                            column = prop.MappedColumn().Name.BackTick()
                        });
                        //AddExtraInfoToProperty(prop, property);
                    }
                    union.Items = unionProperties.ToArray();
                }
            }
            else
            {
                ProcessEntityKey(entity, newClass, table);
                // isSingleColumnPK = table.ColumnsInPrimaryKey.Count() == 1;
            }
            var propertiesAlreadyHandled = new List<Property>();

            foreach (ITable joinedTable in mappedTables.OrderBy(t => t.Name))
            {
                if (joinedTable == table)
                    continue;

                join joinNode = new join();
                joinNode.table = joinedTable.Name.BackTick();
                joinNode.schema = joinedTable.Schema.BackTick();
                int numPrimaryKeyColumns = joinedTable.ColumnsInPrimaryKey.Count();

                if (numPrimaryKeyColumns > 0)
                {
                    key keyNode = GetKeyNode(joinedTable);
                    joinNode.key = keyNode;
                }

                foreach (var property in entity.Properties.OrderBy(p => p.Name))
                {
                    var mappedColumn = property.MappedColumn();

                    if (mappedColumn == null || mappedColumn.Parent != joinedTable)
                        continue;

                    property prop = new property { name = property.Name, column = mappedColumn.Name.BackTick() };
                    AddExtraInfoToProperty(prop, property);
                    joinNode.AddProperty(prop);
                    propertiesAlreadyHandled.Add(property);
                }
                newClass.AddItem1(joinNode);
            }
            var versionProperty = entity.Properties.FirstOrDefault(p => p.GetPropertyIsVersion());

            if (versionProperty != null)
            {
                version versionNode = new version();
                versionNode.column1 = versionProperty.MappedColumn().Name.BackTick();
                versionNode.name = versionProperty.Name;
                versionNode.type = versionProperty.NHibernateType;
                // AddExtraInfoToProperty(prop, property);
                newClass.SetVersion(versionNode);
                propertiesAlreadyHandled.Add(versionProperty);
            }

            //foreach (var prop in ProcessProperties(entity.Properties.Except(propertiesAlreadyHandled).Except(entity.ForeignKeyPropertiesToExclude), isSingleColumnPK).OrderBy(p => p.name))
            foreach (var prop in ProcessProperties(entity.Properties.Except(propertiesAlreadyHandled).Except(entity.ForeignKeyPropertiesToExclude)).OrderBy(p => p.name))
                newClass.AddProperty(prop);

            // Process components, skip component used as Key.
            foreach (var component in ProcessComponent(entity.Components.Except(new[] { entity.Key.Component })).OrderBy(c => c.name))
                newClass.AddComponent(component);

            ProcessInheritance(entity, newClass);

            var referenceMapper = new ReferenceMapper();
            referenceMapper.ProcessReferences(entity, item => newClass.AddItem(item));
            return newClass;
        }
Esempio n. 5
0
        private void ProcessEntityTablePerSubClass(Entity entity, joinedsubclass joinedSubClassNode)
        {
            foreach (var childEntity in entity.Children)
            {
                var mappedTable = childEntity.MappedTables().First();

                var subclassNode = new joinedsubclass();
                subclassNode.table = mappedTable.Name.BackTick();
                subclassNode.schema = mappedTable.Schema.BackTick();
                subclassNode.name = childEntity.Name;

                key keyNode = GetKeyNode(mappedTable);
                subclassNode.key = keyNode;

                foreach (var property in childEntity.ConcreteProperties)
                {
                    IColumn column = property.MappedColumn();
                    if (column == null) continue;

                    property propNode = ProcessProperty(property, column);
                    subclassNode.AddProperty(propNode);
                }
                joinedSubClassNode.AddJoinedSubclass(subclassNode);

                var referenceMapper = new ReferenceMapper();
                referenceMapper.ProcessReferences(childEntity, item => subclassNode.AddItem(item));
            }
        }
Esempio n. 6
0
        private void ProcessEntityTablePerClassHierarchy(Entity entity, @class classNode)
        {
            foreach (var childEntity in entity.Children)
            {
                var subclassNode = new subclass();

                subclassNode.name = childEntity.Name;
                subclassNode.discriminatorvalue = childEntity.DiscriminatorValue;

                foreach (var property in childEntity.ConcreteProperties)
                {
                    IColumn column = property.MappedColumn();
                    if (column == null) continue;

                    property propNode = ProcessProperty(property, column);
                    subclassNode.AddProperty(propNode);
                }
                var referenceMapper = new ReferenceMapper();
                referenceMapper.ProcessReferences(childEntity, item => subclassNode.AddItem(item));

                classNode.AddItem1(subclassNode);
            }
            classNode.discriminator = new discriminator();
            classNode.discriminator.force = entity.Discriminator.Force;
            //classNode.discriminator.length = entity.Discriminator.l.Force.ToString();
            //classNode.discriminator.notnull = entity.Discriminator..Force.ToString();

            if (!entity.Discriminator.Insert)
            {
                classNode.discriminator.insert = entity.Discriminator.Insert;
            }
            if (entity.Discriminator.DiscriminatorType == Providers.EntityModel.Model.Enums.DiscriminatorTypes.Column)
                classNode.discriminator.column = entity.Discriminator.ColumnName;
            else
                classNode.discriminator.formula = entity.Discriminator.Formula;
        }