public static void AddProperty(this component theComponent, property property)
        {
            if (theComponent.Items == null)
                theComponent.Items = new object[0];

            object[] items = theComponent.Items;
            Array.Resize(ref items, theComponent.Items.Length + 1);
            items[items.Length - 1] = property;
            theComponent.Items = items;
        }
Beispiel #2
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;
        }
Beispiel #3
0
        private property ProcessProperty(Property property, IColumn mappedColumn)
        {
            var propertyNode = new property
            {
                column = mappedColumn.Name.BackTick(),
                name = property.Name,
                type1 = property.NHibernateType
            };

            var options = property.ValidationOptions;

            if (options.MaximumLength.HasValue && options.MaximumLength > 0 && options.MaximumLength != int.MaxValue)
                propertyNode.length = options.MaximumLength.Value.ToString(CultureInfo.InvariantCulture);

            AddExtraInfoToProperty(propertyNode, property);
            return propertyNode;
        }
Beispiel #4
0
        private IEnumerable<component> ProcessComponent(IEnumerable<Component> components)
        {
            foreach (var component in components.OrderBy(c => c.Name))
            {
                var componentNode = new component();
                componentNode.@class = component.Specification.Name;
                componentNode.name = component.Name;

                foreach (var property in component.Properties.OrderBy(p => p.PropertyName))
                {
                    ComponentProperty representedProperty = property.RepresentedProperty;
                    var propertyNode = new property();
                    propertyNode.name = representedProperty.Name;
                    propertyNode.type1 = representedProperty.Type;
                    propertyNode.column = property.MappedColumn().Name.BackTick();
                    propertyNode.notnull = true; // This must be true for Component Properties.
                    componentNode.AddProperty(propertyNode);
                }
                yield return componentNode;
            }
        }
Beispiel #5
0
        private void AddExtraInfoToProperty(property xmlProp, Property originalProp)
        {
            xmlProp.insert = originalProp.GetPropertyInsert();
            xmlProp.update = originalProp.GetPropertyUpdate();

            string formula = originalProp.GetPropertyFormula();

            if (!string.IsNullOrWhiteSpace(formula))
                xmlProp.formula = formula;

            xmlProp.optimisticlock = originalProp.GetPropertyOptimisticLock();
            xmlProp.generated = (propertyGeneration)Enum.Parse(typeof(propertyGeneration), originalProp.GetPropertyGenerated().ToString());

            var access = originalProp.GetPropertyAccess();

            if (access != Interfaces.NHibernateEnums.PropertyAccessTypes.inherit_default)
                xmlProp.access = access.ToString().Replace("_", "-");

            if (!originalProp.GetPropertyInsert())
            {
                xmlProp.insertSpecified = true;
                xmlProp.insert = false;
            }
            if (!originalProp.GetPropertyUpdate())
            {
                xmlProp.updateSpecified = true;
                xmlProp.update = false;
            }
        }
Beispiel #6
0
 private Property CreateProperty(Entity newEntity, Mapping mapping, property hProperty)
 {
     if (hProperty.column != null)
         return CreateProperty(newEntity, mapping, hProperty.type1, hProperty.name, hProperty.column, hProperty.length);
     else
     {
         var columns = hProperty.Columns();
         var columnName = columns.Count > 0 ? hProperty.Columns()[0].name : hProperty.name;
         return CreateProperty(newEntity, mapping, hProperty.type1, hProperty.name, columnName, hProperty.length);
     }
 }