//@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); }
//@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); }