コード例 #1
0
        private Tuple <XElement, IExtendedPropertyMapper, string> generateMappingData(
            PersistentClass pc, EntityXmlMappingData xmlMappingData, AuditTableData auditTableData,
            IdMappingData idMapper)
        {
            var hasDiscriminator = pc.Discriminator != null;

            var classMapping = MetadataTools.CreateEntity(xmlMappingData.MainXmlMapping, auditTableData,
                                                          hasDiscriminator ? pc.DiscriminatorValue : null, pc.IsAbstract.HasValue && pc.IsAbstract.Value);
            var propertyMapper = new MultiPropertyMapper();

            // Adding the id mapping
            classMapping.Add(idMapper.XmlMapping);

            // Checking if there is a discriminator column
            if (hasDiscriminator)
            {
                var discriminatorElement = new XElement(MetadataTools.CreateElementName("discriminator"));
                classMapping.Add(discriminatorElement);
                // Database column or SQL formula allowed to distinguish entity types
                MetadataTools.AddColumnsOrFormulas(discriminatorElement, pc.Discriminator.ColumnIterator);
                discriminatorElement.Add(new XAttribute("type", pc.Discriminator.Type.Name));
            }

            // Adding the "revision type" property
            AddRevisionType(classMapping, classMapping);

            return(new Tuple <XElement, IExtendedPropertyMapper, string>(classMapping, propertyMapper, null));
        }
コード例 #2
0
        private Tuple <XElement, IExtendedPropertyMapper, string> generateInheritanceMappingData(
            PersistentClass pc, EntityXmlMappingData xmlMappingData, AuditTableData auditTableData,
            string inheritanceMappingType)
        {
            var extendsEntityName = VerEntCfg.GetAuditEntityName(pc.Superclass.EntityName);
            var hasDiscriminator  = pc.Discriminator != null;
            var classMapping      = MetadataTools.CreateSubclassEntity(xmlMappingData.MainXmlMapping,
                                                                       inheritanceMappingType, auditTableData, extendsEntityName, hasDiscriminator ? pc.DiscriminatorValue : null,
                                                                       pc.IsAbstract.HasValue && pc.IsAbstract.Value);

            // The id and revision type is already mapped in the parent

            // Getting the property mapper of the parent - when mapping properties, they need to be included
            var parentEntityName = pc.Superclass.EntityName;

            EntityConfiguration parentConfiguration;

            if (!EntitiesConfigurations.TryGetValue(parentEntityName, out parentConfiguration))
            {
                throw new MappingException("Entity '" + pc.EntityName + "' is audited, but its superclass: '" + parentEntityName + "' is not.");
            }

            var parentPropertyMapper = parentConfiguration.PropertyMapper;
            var propertyMapper       = new SubclassPropertyMapper(new MultiPropertyMapper(), parentPropertyMapper);

            return(new Tuple <XElement, IExtendedPropertyMapper, string>(classMapping, propertyMapper, parentEntityName));
        }
コード例 #3
0
        private Triple<XmlElement, IExtendedPropertyMapper, String> GenerateInheritanceMappingData(
                PersistentClass pc, EntityXmlMappingData xmlMappingData, AuditTableData auditTableData,
                String inheritanceMappingType)
        {
            String extendsEntityName = VerEntCfg.GetAuditEntityName(pc.Superclass.EntityName);
            XmlElement class_mapping = MetadataTools.CreateSubclassEntity(xmlMappingData.MainXmlMapping,
                    inheritanceMappingType, auditTableData, extendsEntityName, pc.DiscriminatorValue);

            // The id and revision type is already mapped in the parent

            // Getting the property mapper of the parent - when mapping properties, they need to be included
            String parentEntityName = pc.Superclass.EntityName;

            EntityConfiguration parentConfiguration = EntitiesConfigurations[parentEntityName];
            if (parentConfiguration == null)
            {
                throw new MappingException("Entity '" + pc.EntityName + "' is audited, but its superclass: '" +
                        parentEntityName + "' is not.");
            }

            IExtendedPropertyMapper parentPropertyMapper = parentConfiguration.PropertyMapper;
            IExtendedPropertyMapper propertyMapper = new SubclassPropertyMapper(new MultiPropertyMapper(), parentPropertyMapper);

            return Triple<XmlElement, IExtendedPropertyMapper, String>.Make<XmlElement, IExtendedPropertyMapper, String>(class_mapping, propertyMapper, parentEntityName);
        }
コード例 #4
0
        //@SuppressWarnings({"unchecked"})
        private Triple<XmlElement, IExtendedPropertyMapper, String> GenerateMappingData(
                PersistentClass pc, EntityXmlMappingData xmlMappingData, AuditTableData auditTableData,
                IdMappingData idMapper)
        {
            bool hasDiscriminator = pc.Discriminator != null;

            XmlElement class_mapping = MetadataTools.CreateEntity(xmlMappingData.MainXmlMapping, auditTableData,
                    hasDiscriminator ? pc.DiscriminatorValue : null);
            IExtendedPropertyMapper propertyMapper = new MultiPropertyMapper();

            // Checking if there is a discriminator column
            if (hasDiscriminator)
            {
                XmlElement discriminator_element = class_mapping.OwnerDocument.CreateElement("discriminator");
                class_mapping.AppendChild(discriminator_element);
                MetadataTools.AddColumns(discriminator_element, (IEnumerator<ISelectable>)pc.Discriminator.ColumnIterator.GetEnumerator());
                discriminator_element.SetAttribute("type", pc.Discriminator.Type.Name);
            }

            InheritanceType.Type parentInheritance = InheritanceType.GetForParent(pc);
            switch (parentInheritance)
            {
                case InheritanceType.Type.NONE:
                    break;

                case InheritanceType.Type.SINGLE:
                    AddSingleInheritancePersisterHack(class_mapping);
                    break;

                case InheritanceType.Type.JOINED:
                    AddJoinedInheritancePersisterHack(class_mapping);
                    break;

                case InheritanceType.Type.TABLE_PER_CLASS:
                    AddTablePerClassInheritancePersisterHack(class_mapping);
                    break;
            }

            // Adding the id mapping
            XmlNode xmlMp = class_mapping.OwnerDocument.ImportNode(idMapper.XmlMapping,true);
            class_mapping.AppendChild(xmlMp);

            // Adding the "revision type" property
            AddRevisionType(class_mapping);

            return Triple<XmlElement, IExtendedPropertyMapper, string>.Make<XmlElement, IExtendedPropertyMapper, string>(class_mapping, propertyMapper, null);
        }
コード例 #5
0
        private static XElement createEntityCommon(XDocument document,
                                                   string type,
                                                   AuditTableData auditTableData,
                                                   string discriminatorValue,
                                                   bool isAbstract)
        {
            var classMapping = new XElement(CreateElementName(type));
            var nhMapping    = new XElement(CreateElementName("hibernate-mapping"),
                                            new XAttribute("assembly", "NHibernate.Envers"),
                                            new XAttribute("auto-import", "false"),
                                            classMapping);

            document.Add(nhMapping);

            if (isAbstract)
            {
                classMapping.Add(new XAttribute("abstract", "true"));
            }

            if (auditTableData.AuditEntityName != null)
            {
                classMapping.Add(new XAttribute("entity-name", auditTableData.AuditEntityName));
            }

            if (discriminatorValue != null)
            {
                classMapping.Add(new XAttribute("discriminator-value", discriminatorValue));
            }

            if (!string.IsNullOrEmpty(auditTableData.AuditTableName))
            {
                classMapping.Add(new XAttribute("table", auditTableData.AuditTableName));
            }

            if (!string.IsNullOrEmpty(auditTableData.Schema) && !type.Equals("subclass"))
            {
                classMapping.Add(new XAttribute("schema", auditTableData.Schema));
            }

            if (!string.IsNullOrEmpty(auditTableData.Catalog) && !type.Equals("subclass"))
            {
                classMapping.Add(new XAttribute("catalog", auditTableData.Catalog));
            }

            return(classMapping);
        }
コード例 #6
0
        public void GenerateFirstPass(PersistentClass pc, ClassAuditingData auditingData,
                                      EntityXmlMappingData xmlMappingData, bool isAudited)
        {
            var schema  = GetSchema(auditingData.AuditTable.Schema, pc.Table);
            var catalog = GetCatalog(auditingData.AuditTable.Catalog, pc.Table);
            Func <System.Type, object> factory = auditingData.Factory.Factory.Instantiate;

            var entityName = pc.EntityName;

            if (!isAudited)
            {
                var _idMapper = idMetadataGenerator.AddId(pc);

                if (_idMapper == null)
                {
                    // Unsupported id mapping, e.g. key-many-to-one. If the entity is used in auditing, an exception
                    // will be thrown later on.
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("Unable to create auditing id mapping for entity {0}" +
                                        ", because of an unsupported Hibernate id mapping (e.g. key-many-to-one).", entityName);
                    }
                    return;
                }

                //ORIG:
                //IExtendedPropertyMapper propertyMapper = null;
                //String parentEntityName = null;
                var _entityCfg = new EntityConfiguration(entityName, pc.ClassName, _idMapper, null, null, factory);
                NotAuditedEntitiesConfigurations.Add(entityName, _entityCfg);
                return;
            }

            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Generating first-pass auditing mapping for entity {0}.", entityName);
            }

            var auditEntityName = VerEntCfg.GetAuditEntityName(entityName);
            var auditTableName  = VerEntCfg.AuditTableName(entityName, pc);

            // Registering the audit entity name, now that it is known
            AuditEntityNameRegister.Register(auditEntityName);

            var auditTableData = new AuditTableData(auditEntityName, auditTableName, schema, catalog);

            // Generating a mapping for the id
            var idMapper = idMetadataGenerator.AddId(pc);

            if (idMapper == null)
            {
                throw new AuditException("Id mapping for type " + pc.ClassName +
                                         " is currently not supported in Envers. If you need composite-id, use 'Components as composite identifiers'.");
            }

            var inheritanceType = pc.GetInheritanceType();

            // These properties will be read from the mapping data

            Tuple <XElement, IExtendedPropertyMapper, string> mappingData;

            // Reading the mapping data depending on inheritance type (if any)
            switch (inheritanceType)
            {
            case InheritanceType.None:
                mappingData = generateMappingData(pc, xmlMappingData, auditTableData, idMapper);
                break;

            case InheritanceType.Single:
                auditTableData = new AuditTableData(auditEntityName, null, schema, catalog);
                mappingData    = generateInheritanceMappingData(pc, xmlMappingData, auditTableData, "subclass");
                break;

            case InheritanceType.Joined:
                mappingData = generateInheritanceMappingData(pc, xmlMappingData, auditTableData, "joined-subclass");

                // Adding the "key" element with all id columns...
                var keyMapping = new XElement(MetadataTools.CreateElementName("key"));
                mappingData.Item1.Add(keyMapping);
                MetadataTools.AddColumns(keyMapping, pc.Table.PrimaryKey.ColumnIterator);

                // ... and the revision number column, read from the revision info relation mapping.
                keyMapping.Add(cloneAndSetupRevisionInfoRelationMapping().Element(MetadataTools.CreateElementName("column")));
                break;

            case InheritanceType.TablePerClass:
                mappingData = generateInheritanceMappingData(pc, xmlMappingData, auditTableData, "union-subclass");

                break;

            default:
                throw new AssertionFailure("AuditMetadataGenerator.GenerateFirstPass: Impossible enum value.");
            }

            var classMapping     = mappingData.Item1;
            var propertyMapper   = mappingData.Item2;
            var parentEntityName = mappingData.Item3;

            xmlMappingData.ClassMapping = classMapping;

            // Mapping unjoined properties
            addProperties(classMapping, pc.UnjoinedPropertyIterator, propertyMapper,
                          auditingData, pc.EntityName, xmlMappingData,
                          true);

            // Creating and mapping joins (first pass)
            createJoins(pc, classMapping, auditingData);
            addJoins(pc, propertyMapper, auditingData, pc.EntityName, xmlMappingData, true);

            // Storing the generated configuration
            var entityCfg = new EntityConfiguration(auditEntityName, pc.ClassName, idMapper,
                                                    propertyMapper, parentEntityName, factory);

            EntitiesConfigurations.Add(pc.EntityName, entityCfg);
        }
コード例 #7
0
        //@SuppressWarnings({"unchecked"})
        public void GenerateFirstPass(PersistentClass pc, ClassAuditingData auditingData,
                                      EntityXmlMappingData xmlMappingData, bool isAudited)
        {
            String schema = GetSchema(auditingData.AuditTable.schema, pc.Table);
            String catalog = GetCatalog(auditingData.AuditTable.catalog, pc.Table);

            String entityName = pc.EntityName;
            if (!isAudited)
            {
                IdMappingData _idMapper = idMetadataGenerator.AddId(pc);

                if (_idMapper == null)
                {
                    // Unsupported id mapping, e.g. key-many-to-one. If the entity is used in auditing, an exception
                    // will be thrown later on.
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Unable to create auditing id mapping for entity " + entityName +
                            ", because of an unsupported Hibernate id mapping (e.g. key-many-to-one).");
                    }
                    return;
                }

                //ORIG:
                //IExtendedPropertyMapper propertyMapper = null;
                //String parentEntityName = null;
                EntityConfiguration _entityCfg = new EntityConfiguration(entityName, _idMapper, null,
                        null);
                NotAuditedEntitiesConfigurations.Add(entityName, _entityCfg);
                return;
            }

            if (log.IsDebugEnabled)
            {
                log.Debug("Generating first-pass auditing mapping for entity " + entityName + ".");
            }

            String auditEntityName = VerEntCfg.GetAuditEntityName(entityName);
            String auditTableName = VerEntCfg.GetAuditTableName(entityName, pc.Table.Name);

            // Registering the audit entity name, now that it is known
            AuditEntityNameRegister.register(auditEntityName);

            AuditTableData auditTableData = new AuditTableData(auditEntityName, auditTableName, schema, catalog);

            // Generating a mapping for the id
            IdMappingData idMapper = idMetadataGenerator.AddId(pc);

            InheritanceType.Type inheritanceType = InheritanceType.GetForChild(pc);

            // These properties will be read from the mapping data
            XmlElement class_mapping;
            IExtendedPropertyMapper propertyMapper;
            String parentEntityName;

            Triple<XmlElement, IExtendedPropertyMapper, String> mappingData;

            // Reading the mapping data depending on inheritance type (if any)
            switch (inheritanceType)
            {
                case InheritanceType.Type.NONE:
                    mappingData = GenerateMappingData(pc, xmlMappingData, auditTableData, idMapper);
                    break;

                case InheritanceType.Type.SINGLE:
                    mappingData = GenerateInheritanceMappingData(pc, xmlMappingData, auditTableData, "subclass");
                    break;

                case InheritanceType.Type.JOINED:
                    mappingData = GenerateInheritanceMappingData(pc, xmlMappingData, auditTableData, "joined-subclass");

                    AddJoinedInheritancePersisterHack(mappingData.First);

                    // Adding the "key" element with all id columns...
                    XmlElement keyMapping = mappingData.First.OwnerDocument.CreateElement("key");
                    mappingData.First.AppendChild(keyMapping);
                    MetadataTools.AddColumns(keyMapping, (IEnumerator<ISelectable>)pc.Table.PrimaryKey.ColumnIterator.GetEnumerator());

                    // ... and the revision number column, read from the revision info relation mapping.
                    keyMapping.AppendChild((XmlElement)CloneAndSetupRevisionInfoRelationMapping(keyMapping.OwnerDocument).GetElementsByTagName("column")[0].Clone());
                    break;

                case InheritanceType.Type.TABLE_PER_CLASS:
                    mappingData = GenerateInheritanceMappingData(pc, xmlMappingData, auditTableData, "union-subclass");

                    AddTablePerClassInheritancePersisterHack(mappingData.First);

                    break;

                default:
                    throw new AssertionFailure("Envers.NET: AuditMetadataGenerator.GenerateFirstPass: Impossible enum value.");
            }

            class_mapping = mappingData.First;
            propertyMapper = mappingData.Second;
            parentEntityName = mappingData.Third;

            xmlMappingData.ClassMapping = class_mapping;

            // Mapping unjoined properties
            AddProperties(class_mapping, (IEnumerator<Property>)pc.UnjoinedPropertyIterator.GetEnumerator(), propertyMapper,
                    auditingData, pc.EntityName, xmlMappingData,
                    true);

            // Creating and mapping joins (first pass)
            CreateJoins(pc, class_mapping, auditingData);
            AddJoins(pc, propertyMapper, auditingData, pc.EntityName, xmlMappingData, true);

            // Storing the generated configuration
            EntityConfiguration entityCfg = new EntityConfiguration(auditEntityName, idMapper,
                    propertyMapper, parentEntityName);
            EntitiesConfigurations.Add(pc.EntityName, entityCfg);
        }
コード例 #8
0
        private Triple<XmlElement, IExtendedPropertyMapper, string> GenerateMappingData(
				PersistentClass pc, EntityXmlMappingData xmlMappingData, AuditTableData auditTableData,
				IdMappingData idMapper)
        {
            var hasDiscriminator = pc.Discriminator != null;

            var classMapping = MetadataTools.CreateEntity(xmlMappingData.MainXmlMapping, auditTableData,
                    hasDiscriminator ? pc.DiscriminatorValue : null);
            var propertyMapper = new MultiPropertyMapper();

            // Adding the id mapping
            var xmlMp = classMapping.OwnerDocument.ImportNode(idMapper.XmlMapping, true);
            classMapping.AppendChild(xmlMp);

            // Checking if there is a discriminator column
            if (hasDiscriminator)
            {
                var discriminatorElement = classMapping.OwnerDocument.CreateElement("discriminator");
                classMapping.AppendChild(discriminatorElement);
                // Database column or SQL formula allowed to distinguish entity types
                MetadataTools.AddColumnsOrFormulas(discriminatorElement, pc.Discriminator.ColumnIterator);
                discriminatorElement.SetAttribute("type", pc.Discriminator.Type.Name);
            }

            // Adding the "revision type" property
            AddRevisionType(classMapping);

            return new Triple<XmlElement, IExtendedPropertyMapper, string>(classMapping, propertyMapper, null);
        }
コード例 #9
0
        public static XmlElement CreateSubclassEntity(XmlDocument document, String subclassType, AuditTableData auditTableData,
                                                      String extendsEntityName, String discriminatorValue)
        {
            XmlElement class_mapping = CreateEntityCommon(document, subclassType, auditTableData, discriminatorValue);

            class_mapping.SetAttribute("extends", extendsEntityName);

            return(class_mapping);
        }
コード例 #10
0
 public static XmlElement CreateEntity(XmlDocument document, AuditTableData auditTableData, String discriminatorValue)
 {
     return(CreateEntityCommon(document, "class", auditTableData, discriminatorValue));
 }
コード例 #11
0
        private static XmlElement CreateEntityCommon(XmlDocument document, String type, AuditTableData auditTableData,
                                                     String discriminatorValue)
        {
            XmlElement hibernate_mapping = document.CreateElement("hibernate-mapping");

            hibernate_mapping.SetAttribute("assembly", "Envers.NET");
            hibernate_mapping.SetAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
            hibernate_mapping.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
            //rk: changed from Configuration.MappingSchemaXMLNS. Not available in NH3
            hibernate_mapping.SetAttribute("xmlns", "urn:nhibernate-mapping-2.2");
            hibernate_mapping.SetAttribute("auto-import", "false");
            document.AppendChild(hibernate_mapping);

            XmlElement class_mapping = document.CreateElement(type);

            hibernate_mapping.AppendChild(class_mapping);

            if (auditTableData.getAuditEntityName() != null)
            {
                class_mapping.SetAttribute("entity-name", auditTableData.getAuditEntityName());
            }

            if (discriminatorValue != null)
            {
                class_mapping.SetAttribute("discriminator-value", discriminatorValue);
            }

            if (!String.IsNullOrEmpty(auditTableData.getAuditTableName()))
            {
                class_mapping.SetAttribute("table", auditTableData.getAuditTableName());
            }

            if (!String.IsNullOrEmpty(auditTableData.getSchema()))
            {
                class_mapping.SetAttribute("schema", auditTableData.getSchema());
            }

            if (!String.IsNullOrEmpty(auditTableData.getCatalog()))
            {
                class_mapping.SetAttribute("catalog", auditTableData.getCatalog());
            }

            return(class_mapping);
        }
コード例 #12
0
ファイル: MetadataTools.cs プロジェクト: umittal/MunimJi
        private static XmlElement CreateEntityCommon(XmlDocument document, string type, AuditTableData auditTableData, string discriminatorValue)
        {
            var hibernateMapping = document.CreateElement("hibernate-mapping");
            hibernateMapping.SetAttribute("assembly", "NHibernate.Envers");
            hibernateMapping.SetAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
            hibernateMapping.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
            hibernateMapping.SetAttribute("xmlns", "urn:nhibernate-mapping-2.2");
            hibernateMapping.SetAttribute("auto-import", "false");
            document.AppendChild(hibernateMapping);

            var classMapping = document.CreateElement(type);
            hibernateMapping.AppendChild(classMapping);

            if (auditTableData.AuditEntityName != null)
            {
                classMapping.SetAttribute("entity-name", auditTableData.AuditEntityName);
            }

            if (discriminatorValue != null)
            {
                classMapping.SetAttribute("discriminator-value", discriminatorValue);
            }

            if (!string.IsNullOrEmpty(auditTableData.AuditTableName))
            {
                classMapping.SetAttribute("table", auditTableData.AuditTableName);
            }

            if (!string.IsNullOrEmpty(auditTableData.Schema))
            {
                classMapping.SetAttribute("schema", auditTableData.Schema);
            }

            if (!string.IsNullOrEmpty(auditTableData.Catalog))
            {
                classMapping.SetAttribute("catalog", auditTableData.Catalog);
            }

            return classMapping;
        }
コード例 #13
0
ファイル: MetadataTools.cs プロジェクト: umittal/MunimJi
        public static XmlElement CreateSubclassEntity(XmlDocument document, string subclassType, AuditTableData auditTableData,
												   string extendsEntityName, string discriminatorValue)
        {
            var classMapping = CreateEntityCommon(document, subclassType, auditTableData, discriminatorValue);
            classMapping.SetAttribute("extends", extendsEntityName);

            return classMapping;
        }
コード例 #14
0
ファイル: MetadataTools.cs プロジェクト: umittal/MunimJi
 public static XmlElement CreateEntity(XmlDocument document, AuditTableData auditTableData, string discriminatorValue)
 {
     return CreateEntityCommon(document, "class", auditTableData, discriminatorValue);
 }
コード例 #15
0
 public static XElement CreateEntity(XDocument document, AuditTableData auditTableData, string discriminatorValue, bool isAbstract)
 {
     return(createEntityCommon(document, "class", auditTableData, discriminatorValue, isAbstract));
 }
コード例 #16
0
        public static XElement CreateSubclassEntity(XDocument document, string subclassType, AuditTableData auditTableData,
                                                    string extendsEntityName, string discriminatorValue, bool isAbstract)
        {
            var classMapping = createEntityCommon(document, subclassType, auditTableData, discriminatorValue, isAbstract);

            classMapping.Add(new XAttribute("extends", extendsEntityName));

            return(classMapping);
        }
コード例 #17
0
        public void GenerateFirstPass(PersistentClass pc, ClassAuditingData auditingData,
									  EntityXmlMappingData xmlMappingData, bool isAudited)
        {
            var schema = GetSchema(auditingData.AuditTable.Schema, pc.Table);
            var catalog = GetCatalog(auditingData.AuditTable.Catalog, pc.Table);

            var entityName = pc.EntityName;
            if (!isAudited)
            {
                var _idMapper = idMetadataGenerator.AddId(pc);

                if (_idMapper == null)
                {
                    // Unsupported id mapping, e.g. key-many-to-one. If the entity is used in auditing, an exception
                    // will be thrown later on.
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("Unable to create auditing id mapping for entity {0}" +
                            ", because of an unsupported Hibernate id mapping (e.g. key-many-to-one).", entityName);
                    }
                    return;
                }

                //ORIG:
                //IExtendedPropertyMapper propertyMapper = null;
                //String parentEntityName = null;
                var _entityCfg = new EntityConfiguration(entityName, pc.ClassName, _idMapper, null, null);
                NotAuditedEntitiesConfigurations.Add(entityName, _entityCfg);
                return;
            }

            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Generating first-pass auditing mapping for entity {0}.", entityName);
            }

            var auditEntityName = VerEntCfg.GetAuditEntityName(entityName);
            var auditTableName = VerEntCfg.GetAuditTableName(entityName, pc.Table.Name);

            // Registering the audit entity name, now that it is known
            AuditEntityNameRegister.Register(auditEntityName);

            var auditTableData = new AuditTableData(auditEntityName, auditTableName, schema, catalog);

            // Generating a mapping for the id
            var idMapper = idMetadataGenerator.AddId(pc);

            var inheritanceType = pc.GetInheritanceType();

            // These properties will be read from the mapping data

            Triple<XmlElement, IExtendedPropertyMapper, string> mappingData;

            // Reading the mapping data depending on inheritance type (if any)
            switch (inheritanceType)
            {
                case InheritanceType.None:
                    mappingData = GenerateMappingData(pc, xmlMappingData, auditTableData, idMapper);
                    break;

                case InheritanceType.Single:
                    auditTableData = new AuditTableData(auditEntityName, null, schema, catalog);
                    mappingData = GenerateInheritanceMappingData(pc, xmlMappingData, auditTableData, "subclass");
                    break;

                case InheritanceType.Joined:
                    mappingData = GenerateInheritanceMappingData(pc, xmlMappingData, auditTableData, "joined-subclass");

                    // Adding the "key" element with all id columns...
                    var keyMapping = mappingData.First.OwnerDocument.CreateElement("key");
                    mappingData.First.AppendChild(keyMapping);
                    MetadataTools.AddColumns(keyMapping, pc.Table.PrimaryKey.ColumnIterator);

                    // ... and the revision number column, read from the revision info relation mapping.
                    keyMapping.AppendChild(CloneAndSetupRevisionInfoRelationMapping(keyMapping.OwnerDocument).GetElementsByTagName("column")[0].Clone());
                    break;

                case InheritanceType.TablePerClass:
                    mappingData = GenerateInheritanceMappingData(pc, xmlMappingData, auditTableData, "union-subclass");

                    break;

                default:
                    throw new AssertionFailure("AuditMetadataGenerator.GenerateFirstPass: Impossible enum value.");
            }

            var class_mapping = mappingData.First;
            var propertyMapper = mappingData.Second;
            var parentEntityName = mappingData.Third;

            xmlMappingData.ClassMapping = class_mapping;

            // Mapping unjoined properties
            AddProperties(class_mapping, pc.UnjoinedPropertyIterator, propertyMapper,
                    auditingData, pc.EntityName, xmlMappingData,
                    true);

            // Creating and mapping joins (first pass)
            CreateJoins(pc, class_mapping, auditingData);
            AddJoins(pc, propertyMapper, auditingData, pc.EntityName, xmlMappingData, true);

            // Storing the generated configuration
            var entityCfg = new EntityConfiguration(auditEntityName, pc.ClassName, idMapper,
                    propertyMapper, parentEntityName);
            EntitiesConfigurations.Add(pc.EntityName, entityCfg);
        }