private static void AddPersistableProps(IBOPropCol propsToInclude, IBOPropCol propsToIncludeTemp)
 {
     foreach (BOProp prop in propsToIncludeTemp)
     {
         if (prop.PropDef.Persistable && prop.PropDef.ReadWriteRule != PropReadWriteRule.ReadOnly)
         {
             propsToInclude.Add(prop);
         }
     }
 }
 private static void AddPersistableProps(IBOPropCol propsToInclude, IBOPropCol propsToIncludeTemp)
 {
     foreach (BOProp prop in propsToIncludeTemp)
     {
         if (prop.PropDef.Persistable && prop.PropDef.ReadWriteRule != PropReadWriteRule.ReadOnly)
         {
             propsToInclude.Add(prop);
         }
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Determines which parent ID field to add to the insertion list, depending on which
        /// ID attribute was specified in the class definition.  There are four possibilities:
        ///    1) The child contains a foreign key to the parent, with the parent ID's name
        ///    2) No attribute was given, assumes the above.
        ///    3) The child's ID has a copy of the parent's ID value
        ///    4) The child has no ID and just inherits the parent's ID (still has the parent's
        ///        ID as a field in its own table)
        /// </summary>
        private void AddParentID(IBOPropCol propsToInclude)
        {
            IClassDef currentClassDef = _currentClassDef;

            while (currentClassDef.SuperClassClassDef != null &&
                   currentClassDef.SuperClassClassDef.PrimaryKeyDef == null)
            {
                currentClassDef = currentClassDef.SuperClassClassDef;
            }
            if (currentClassDef.SuperClassClassDef == null || currentClassDef.SuperClassClassDef.PrimaryKeyDef == null)
            {
                return;
            }

            var superClassDef           = (SuperClassDef)currentClassDef.SuperClassDef;
            var parentIDCopyFieldName   = superClassDef.ID;
            var superClassPrimaryKeyDef = (PrimaryKeyDef)currentClassDef.SuperClassClassDef.PrimaryKeyDef;

            if (string.IsNullOrEmpty(parentIDCopyFieldName) ||
                superClassPrimaryKeyDef.KeyName == parentIDCopyFieldName)
            {
                propsToInclude.Add(
                    superClassPrimaryKeyDef.CreateBOKey(_bo.Props).GetBOPropCol());
            }
            else if (parentIDCopyFieldName != currentClassDef.PrimaryKeyDef.KeyName)
            {
                if (superClassPrimaryKeyDef.Count > 1)
                {
                    throw new InvalidXmlDefinitionException("For a super class definition " +
                                                            "using class table inheritance, the ID attribute can only refer to a " +
                                                            "parent with a single primary key.  Leaving out the attribute will " +
                                                            "allow composite primary keys where the child's copies have the same " +
                                                            "field name as the parent.");
                }
                var parentProp = superClassPrimaryKeyDef.CreateBOKey(_bo.Props).GetBOPropCol()[superClassPrimaryKeyDef.KeyName];
                var profDef    = new PropDef(parentIDCopyFieldName, parentProp.PropertyType, PropReadWriteRule.ReadWrite, null);
                var newProp    = new BOProp(profDef)
                {
                    Value = parentProp.Value
                };
                propsToInclude.Add(newProp);
            }
        }
Esempio n. 4
0
        private void AddDiscriminatorProperties(ClassDef classDef, IBOPropCol propsToInclude, IBOPropCol discriminatorProps)
        {
            ClassDef classDefWithSTI = null;

            if (classDef.IsUsingSingleTableInheritance() || classDefWithSTI != null)
            {
                string discriminator = null;
                if (classDef.SuperClassDef != null)
                {
                    discriminator = classDef.SuperClassDef.Discriminator;
                }
                else if (classDefWithSTI != null)
                {
                    discriminator = classDefWithSTI.SuperClassDef.Discriminator;
                }
                if (discriminator == null)
                {
                    throw new InvalidXmlDefinitionException("A super class has been defined " +
                                                            "using Single Table Inheritance, but no discriminator column has been set.");
                }
                if (propsToInclude.Contains(discriminator) && _bo.Props.Contains(discriminator))
                {
                    var boProp = _bo.Props[discriminator];
                    boProp.Value = _bo.ClassDef.ClassName;
                }
                else if (!discriminatorProps.Contains(discriminator))
                {
                    var propDef           = new PropDef(discriminator, typeof(string), PropReadWriteRule.ReadWrite, null);
                    var discriminatorProp = new BOProp(propDef, _bo.ClassDef.ClassName);
                    discriminatorProps.Add(discriminatorProp);
                }
            }

            if (classDef.IsUsingSingleTableInheritance())
            {
                IClassDef superClassClassDef = classDef.SuperClassClassDef;
                AddDiscriminatorProperties((ClassDef)superClassClassDef, propsToInclude, discriminatorProps);
            }
        }
        /// <summary>
        /// Determines which parent ID field to add to the insertion list, depending on which
        /// ID attribute was specified in the class definition.  There are four possibilities:
        ///    1) The child contains a foreign key to the parent, with the parent ID's name
        ///    2) No attribute was given, assumes the above.
        ///    3) The child's ID has a copy of the parent's ID value
        ///    4) The child has no ID and just inherits the parent's ID (still has the parent's
        ///        ID as a field in its own table)
        /// </summary>
        private void AddParentID(IBOPropCol propsToInclude)
        {
            IClassDef currentClassDef = _currentClassDef;
            while (currentClassDef.SuperClassClassDef != null &&
                   currentClassDef.SuperClassClassDef.PrimaryKeyDef == null)
            {
                currentClassDef = currentClassDef.SuperClassClassDef;
            }
            if (currentClassDef.SuperClassClassDef ==  null ||currentClassDef.SuperClassClassDef.PrimaryKeyDef == null) return;

            var superClassDef = (SuperClassDef) currentClassDef.SuperClassDef;
            var parentIDCopyFieldName = superClassDef.ID;
            var superClassPrimaryKeyDef = (PrimaryKeyDef) currentClassDef.SuperClassClassDef.PrimaryKeyDef;
            if (string.IsNullOrEmpty(parentIDCopyFieldName) ||
                superClassPrimaryKeyDef.KeyName == parentIDCopyFieldName)
            {
                propsToInclude.Add(
                    superClassPrimaryKeyDef.CreateBOKey(_bo.Props).GetBOPropCol());
            }
            else if (parentIDCopyFieldName != currentClassDef.PrimaryKeyDef.KeyName)
            {
                if (superClassPrimaryKeyDef.Count > 1)
                {
                    throw new InvalidXmlDefinitionException("For a super class definition " +
                                                            "using class table inheritance, the ID attribute can only refer to a " +
                                                            "parent with a single primary key.  Leaving out the attribute will " +
                                                            "allow composite primary keys where the child's copies have the same " +
                                                            "field name as the parent.");
                }
                var parentProp = superClassPrimaryKeyDef.CreateBOKey(_bo.Props).GetBOPropCol()[superClassPrimaryKeyDef.KeyName];
                var profDef = new PropDef(parentIDCopyFieldName, parentProp.PropertyType, PropReadWriteRule.ReadWrite, null);
                var newProp = new BOProp(profDef) {Value = parentProp.Value};
                propsToInclude.Add(newProp);
            }
        }
        private void AddDiscriminatorProperties(ClassDef classDef, IBOPropCol propsToInclude, IBOPropCol discriminatorProps)
        {
            ClassDef classDefWithSTI = null;
            if (classDef.IsUsingSingleTableInheritance() || classDefWithSTI != null)
            {
                string discriminator = null;
                if (classDef.SuperClassDef != null)
                {
                    discriminator = classDef.SuperClassDef.Discriminator;
                }
                else if (classDefWithSTI != null)
                {
                    discriminator = classDefWithSTI.SuperClassDef.Discriminator;
                }
                if (discriminator == null)
                {
                    throw new InvalidXmlDefinitionException("A super class has been defined " +
                                                            "using Single Table Inheritance, but no discriminator column has been set.");
                }
                if (propsToInclude.Contains(discriminator) && _bo.Props.Contains(discriminator))
                {
                    var boProp = _bo.Props[discriminator];
                    boProp.Value = _bo.ClassDef.ClassName;
                }
                else if (!discriminatorProps.Contains(discriminator))
                {
                    var propDef = new PropDef(discriminator, typeof (string), PropReadWriteRule.ReadWrite, null);
                    var discriminatorProp = new BOProp(propDef, _bo.ClassDef.ClassName);
                    discriminatorProps.Add(discriminatorProp);
                }
            }

            if (classDef.IsUsingSingleTableInheritance())
            {
                IClassDef superClassClassDef = classDef.SuperClassClassDef;
                AddDiscriminatorProperties((ClassDef) superClassClassDef, propsToInclude, discriminatorProps);
            }
        }