public IdMappingData AddId(PersistentClass pc) { var relIdMapping = new XElement(MetadataTools.CreateElementName("properties")); // Xml mapping which will be used for the primary key of the versions table var origIdMapping = new XElement(MetadataTools.CreateElementName("composite-id"), new XAttribute("name", _mainGenerator.VerEntCfg.OriginalIdPropName)); var idProp = pc.IdentifierProperty; var idMapper = pc.IdentifierMapper; // Checking if the id mapping is supported if (idMapper == null && idProp == null) { return(null); } ISimpleIdMapperBuilder mapper; if (idMapper != null) { // Multiple id throw new MappingException("Multi id mapping isn't (wasn't?) available in NH Core"); } if (idProp.IsComposite) { // Embedded id var idComponent = (Component)idProp.Value; mapper = new EmbeddedIdMapper(getIdPropertyData(idProp), idComponent.ComponentClass); addIdProperties(relIdMapping, idComponent.PropertyIterator, mapper, false); // null mapper - the mapping where already added the first time, now we only want to generate the xml addIdProperties(origIdMapping, idComponent.PropertyIterator, null, true); } else { // Single id mapper = new SingleIdMapper(); // Last but one parameter: ids are always insertable _mainGenerator.BasicMetadataGenerator.AddBasic(relIdMapping, getIdPersistentPropertyAuditingData(idProp), idProp.Value, mapper, true, false); // null mapper - the mapping where already added the first time, now we only want to generate the xml _mainGenerator.BasicMetadataGenerator.AddBasic(origIdMapping, getIdPersistentPropertyAuditingData(idProp), idProp.Value, null, true, true); } // Adding a relation to the revision entity (effectively: the "revision number" property) _mainGenerator.AddRevisionInfoRelation(origIdMapping); return(new IdMappingData(mapper, origIdMapping, relIdMapping)); }
//@SuppressWarnings({"unchecked"}) public IdMappingData AddId(PersistentClass pc) { // Xml mapping which will be used for relations XmlDocument id_mappingDoc = new XmlDocument(); XmlElement rel_id_mapping = id_mappingDoc.CreateElement("properties"); //= new DefaultElement("properties"); // (din DOM4J) // Xml mapping which will be used for the primary key of the versions table XmlElement orig_id_mapping = id_mappingDoc.CreateElement("composite-id"); //= new DefaultElement("composite-id"); // (din DOM4J) Property id_prop = pc.IdentifierProperty; Component id_mapper = pc.IdentifierMapper; // Checking if the id mapping is supported if (id_mapper == null && id_prop == null) { return(null); } ISimpleIdMapperBuilder mapper; if (id_mapper != null) { // Multiple id mapper = new MultipleIdMapper(((Component)pc.Identifier).ComponentClass); AddIdProperties(rel_id_mapping, (IEnumerator <Property>)id_mapper.PropertyIterator, mapper, false); // null mapper - the mapping where already added the first time, now we only want to generate the xml AddIdProperties(orig_id_mapping, (IEnumerator <Property>)id_mapper.PropertyIterator, null, true); } else if (id_prop.IsComposite) { // Embedded id Component id_component = (Component)id_prop.Value; mapper = new EmbeddedIdMapper(GetIdPropertyData(id_prop), id_component.ComponentClass); AddIdProperties(rel_id_mapping, (IEnumerator <Property>)id_component.PropertyIterator, mapper, false); // null mapper - the mapping where already added the first time, now we only want to generate the xml AddIdProperties(orig_id_mapping, (IEnumerator <Property>)id_component.PropertyIterator, null, true); } else { // Single id mapper = new SingleIdMapper(); // Last but one parameter: ids are always insertable mainGenerator.BasicMetadataGenerator.AddBasic(rel_id_mapping, GetIdPersistentPropertyAuditingData(id_prop), id_prop.Value, mapper, true, false); // null mapper - the mapping where already added the first time, now we only want to generate the xml mainGenerator.BasicMetadataGenerator.AddBasic(orig_id_mapping, GetIdPersistentPropertyAuditingData(id_prop), id_prop.Value, null, true, true); } orig_id_mapping.SetAttribute("name", mainGenerator.VerEntCfg.OriginalIdPropName); // Adding a relation to the revision entity (effectively: the "revision number" property) mainGenerator.AddRevisionInfoRelation(orig_id_mapping); return(new IdMappingData(mapper, orig_id_mapping, rel_id_mapping)); }