private XElement createMiddleEntityXml(string auditMiddleTableName, string auditMiddleEntityName, string where) { var schema = _mainGenerator.GetSchema(_propertyAuditingData.JoinTable.Schema, _propertyValue.CollectionTable); var catalog = _mainGenerator.GetCatalog(_propertyAuditingData.JoinTable.Catalog, _propertyValue.CollectionTable); var middleEntityXml = MetadataTools.CreateEntity(_xmlMappingData.NewAdditionalMapping(), new AuditTableData(auditMiddleEntityName, auditMiddleTableName, schema, catalog), null, false); var middleEntityXmlId = new XElement(MetadataTools.CreateElementName("composite-id"), new XAttribute("name", _mainGenerator.VerEntCfg.OriginalIdPropName)); middleEntityXml.Add(middleEntityXmlId); // If there is a where clause on the relation, adding it to the middle entity. if (where != null) { middleEntityXml.Add(new XAttribute("where", where)); } // Adding the revision number as a foreign key to the revision info entity to the composite id of the // middle table. _mainGenerator.AddRevisionInfoRelation(middleEntityXmlId); // Adding the revision type property to the entity xml. _mainGenerator.AddRevisionType(isEmbeddableElementType() ? middleEntityXmlId : middleEntityXml, middleEntityXml); // All other properties should also be part of the primary key of the middle entity. return(middleEntityXmlId); }
private XmlElement CreateMiddleEntityXml(String auditMiddleTableName, String auditMiddleEntityName, String where) { String schema = mainGenerator.GetSchema(propertyAuditingData.JoinTable.Schema, propertyValue.CollectionTable); String catalog = mainGenerator.GetCatalog(propertyAuditingData.JoinTable.Catalog, propertyValue.CollectionTable); XmlElement middleEntityXml = MetadataTools.CreateEntity(xmlMappingData.newAdditionalMapping(), new AuditTableData(auditMiddleEntityName, auditMiddleTableName, schema, catalog), null); XmlElement middleEntityXmlId = middleEntityXml.OwnerDocument.CreateElement("composite-id"); middleEntityXml.AppendChild(middleEntityXmlId); // If there is a where clause on the relation, adding it to the middle entity. if (where != null) { middleEntityXml.SetAttribute("where", where); } middleEntityXmlId.SetAttribute("name", mainGenerator.VerEntCfg.OriginalIdPropName); // Adding the revision number as a foreign key to the revision info entity to the composite id of the // middle table. mainGenerator.AddRevisionInfoRelation(middleEntityXmlId); // Adding the revision type property to the entity xml. mainGenerator.AddRevisionType(middleEntityXml); // All other properties should also be part of the primary key of the middle entity. return(middleEntityXmlId); }
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)); }