public void AddOneToOneNotOwning(PropertyAuditingData propertyAuditingData, OneToOne value, ICompositeMapperBuilder mapper, string entityName) { var owningReferencePropertyName = referencePropertyName(value, entityName); var configuration = mainGenerator.EntitiesConfigurations[entityName]; if (configuration == null) { throw new MappingException("An audited relation to a non-audited entity " + entityName + "!"); } var ownedIdMapping = configuration.IdMappingData; if (ownedIdMapping == null) { throw new MappingException("An audited relation to a non-audited entity " + entityName + "!"); } var lastPropertyPrefix = MappingTools.CreateToOneRelationPrefix(owningReferencePropertyName); var referencedEntityName = value.ReferencedEntityName; // Generating the id mapper for the relation var ownedIdMapper = ownedIdMapping.IdMapper.PrefixMappedProperties(lastPropertyPrefix); // Storing information about this relation mainGenerator.EntitiesConfigurations[entityName].AddToOneNotOwningRelation( propertyAuditingData.Name, owningReferencePropertyName, referencedEntityName, ownedIdMapper); // Adding mapper for the id var propertyData = propertyAuditingData.GetPropertyData(); mapper.AddComposite(propertyData, new OneToOneNotOwningMapper(owningReferencePropertyName, referencedEntityName, propertyData)); }
public void AddComponent(XmlElement parent, PropertyAuditingData propertyAuditingData, IValue value, ICompositeMapperBuilder mapper, string entityName, EntityXmlMappingData xmlMappingData, bool firstPass, bool insertable) { var propComponent = (Component) value; var componentMapper = mapper.AddComponent(propertyAuditingData.GetPropertyData(), propComponent.ComponentClassName); // The property auditing data must be for a component. var componentAuditingData = (ComponentAuditingData) propertyAuditingData; // Adding all properties of the component foreach (var property in propComponent.PropertyIterator) { var componentPropertyAuditingData = componentAuditingData.GetPropertyAuditingData(property.Name); // Checking if that property is audited if (componentPropertyAuditingData != null) { mainGenerator.AddValue(parent, property.Value, componentMapper, entityName, xmlMappingData, componentPropertyAuditingData, property.IsInsertable && insertable, firstPass); } } }
private static void AddCustomValue(XmlElement parent, PropertyAuditingData propertyAuditingData, IValue value, ISimpleMapperBuilder mapper, bool insertable, bool key, System.Type typeOfUserImplementation) { if (parent != null) { var prop_mapping = MetadataTools.AddProperty(parent, propertyAuditingData.Name, null, insertable, key); MetadataTools.AddColumns(prop_mapping, value.ColumnIterator.OfType<Column>()); var typeElement = parent.OwnerDocument.CreateElement("type"); typeElement.SetAttribute("name", typeOfUserImplementation.AssemblyQualifiedName); var simpleValue = value as SimpleValue; if (simpleValue != null) { var typeParameters = simpleValue.TypeParameters; if (typeParameters != null) { foreach (var paramKeyValue in typeParameters) { var type_param = typeElement.OwnerDocument.CreateElement("param"); type_param.SetAttribute("name", paramKeyValue.Key); type_param.InnerText = paramKeyValue.Value; typeElement.AppendChild(type_param); } } } prop_mapping.AppendChild(typeElement); } if (mapper != null) { mapper.Add(propertyAuditingData.GetPropertyData()); } }
public void AddToOne(XmlElement parent, PropertyAuditingData propertyAuditingData, IValue value, ICompositeMapperBuilder mapper, string entityName, bool insertable, IEnumerable<string> fixedColumnNames) { var referencedEntityName = ((ToOne)value).ReferencedEntityName; var idMapping = mainGenerator.GetReferencedIdMappingData(entityName, referencedEntityName, propertyAuditingData, true); var lastPropertyPrefix = MappingTools.CreateToOneRelationPrefix(propertyAuditingData.Name); // Generating the id mapper for the relation var relMapper = idMapping.IdMapper.PrefixMappedProperties(lastPropertyPrefix); // Storing information about this relation mainGenerator.EntitiesConfigurations[entityName].AddToOneRelation( propertyAuditingData.Name, referencedEntityName, relMapper, insertable); // If the property isn't insertable, checking if this is not a "fake" bidirectional many-to-one relationship, // that is, when the one side owns the relation (and is a collection), and the many side is non insertable. // When that's the case and the user specified to store this relation without a middle table (using // @AuditMappedBy), we have to make the property insertable for the purposes of Envers. In case of changes to // the entity that didn't involve the relation, it's value will then be stored properly. In case of changes // to the entity that did involve the relation, it's the responsibility of the collection side to store the // proper data. bool nonInsertableFake; if (!insertable && propertyAuditingData.ForceInsertable) { nonInsertableFake = true; insertable = true; } else { nonInsertableFake = false; } // Adding an element to the mapping corresponding to the references entity id's // Use OwnerDocument.ImportNode() instead of XmlNode.Clone(); var properties = (XmlElement)parent.OwnerDocument.ImportNode(idMapping.XmlRelationMapping,true); properties.SetAttribute("name",propertyAuditingData.Name); MetadataTools.PrefixNamesInPropertyElement(properties, lastPropertyPrefix, fixedColumnNames == null ? MetadataTools.GetColumnNameEnumerator(value.ColumnIterator) : fixedColumnNames.GetEnumerator(), false, insertable); parent.AppendChild(properties); // Adding mapper for the id var propertyData = propertyAuditingData.GetPropertyData(); mapper.AddComposite(propertyData, new ToOneIdMapper(relMapper,propertyData,referencedEntityName,nonInsertableFake)); }
private static void AddSimpleValue(XmlElement parent, PropertyAuditingData propertyAuditingData, IValue value, ISimpleMapperBuilder mapper, bool insertable, bool key) { if (parent != null) { var prop_mapping = MetadataTools.AddProperty(parent, propertyAuditingData.Name, value.Type.Name, propertyAuditingData.ForceInsertable || insertable, key); MetadataTools.AddColumns(prop_mapping, value.ColumnIterator.OfType<Column>()); } // A null mapper means that we only want to add xml mappings if (mapper != null) { mapper.Add(propertyAuditingData.GetPropertyData()); } }