private void addPropertyJoinTables(MemberInfo property, PropertyAuditingData propertyData) { // first set the join table based on the AuditJoinTable annotation var joinTable = _metaDataStore.MemberMeta <AuditJoinTableAttribute>(property); propertyData.JoinTable = joinTable ?? DEFAULT_AUDIT_JOIN_TABLE; }
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); } } }
//@SuppressWarnings({"unchecked"}) public void AddOneToOneNotOwning(PropertyAuditingData propertyAuditingData, IValue value, ICompositeMapperBuilder mapper, String entityName) { OneToOne propertyValue = (OneToOne)value; String owningReferencePropertyName = propertyValue.ReferencedPropertyName; // mappedBy EntityConfiguration configuration = mainGenerator.EntitiesConfigurations[entityName]; if (configuration == null) { throw new MappingException("An audited relation to a non-audited entity " + entityName + "!"); } IdMappingData ownedIdMapping = configuration.IdMappingData; if (ownedIdMapping == null) { throw new MappingException("An audited relation to a non-audited entity " + entityName + "!"); } String lastPropertyPrefix = MappingTools.createToOneRelationPrefix(owningReferencePropertyName); String referencedEntityName = propertyValue.ReferencedEntityName; // Generating the id mapper for the relation IIdMapper ownedIdMapper = ownedIdMapping.IdMapper.PrefixMappedProperties(lastPropertyPrefix); // Storing information about this relation mainGenerator.EntitiesConfigurations[entityName].AddToOneNotOwningRelation( propertyAuditingData.Name, owningReferencePropertyName, referencedEntityName, ownedIdMapper); // Adding mapper for the id PropertyData propertyData = propertyAuditingData.getPropertyData(); mapper.AddComposite(propertyData, new OneToOneNotOwningMapper(owningReferencePropertyName, referencedEntityName, propertyData)); }
//@SuppressWarnings({"unchecked"}) public void AddComponent(XmlElement parent, PropertyAuditingData propertyAuditingData, IValue value, ICompositeMapperBuilder mapper, String entityName, EntityXmlMappingData xmlMappingData, bool firstPass) { Component prop_component = (Component) value; ICompositeMapperBuilder componentMapper = mapper.AddComponent(propertyAuditingData.getPropertyData(), prop_component.ComponentClassName); // The property auditing data must be for a component. ComponentAuditingData componentAuditingData = (ComponentAuditingData) propertyAuditingData; // Adding all properties of the component IEnumerator<Property> properties = (IEnumerator<Property>) prop_component.PropertyIterator.GetEnumerator(); while (properties.MoveNext()) { Property property = properties.Current; PropertyAuditingData 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, firstPass); } } }
/** * Process the {@link org.hibernate.envers.AuditOverride} annotations for this property. * * @param property * the property for which the {@link org.hibernate.envers.AuditOverride} * annotations are being processed * @param propertyData * the Envers auditing data for this property * @return {@code false} if isAudited() of the override annotation was set to */ private bool ProcessPropertyAuditingOverrides(PropertyInfo property, PropertyAuditingData propertyData) { // if this property is part of a component, process all override annotations if (this._auditedPropertiesHolder is ComponentAuditingData) { IList <AuditOverrideAttribute> overrides = ((ComponentAuditingData)this._auditedPropertiesHolder).AuditingOverrides; foreach (AuditOverrideAttribute ovr in overrides) { if (property.Name.Equals(ovr.Name)) { // the override applies to this property if (!ovr.IsAudited) { return(false); } else { if (ovr.AuditJoinTable != null) { propertyData.JoinTable = ovr.AuditJoinTable; } } } } } return(true); }
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()); } }
private void AddCustomValue(XmlElement parent, PropertyAuditingData propertyAuditingData, IValue value, ISimpleMapperBuilder mapper, bool insertable, bool key) { if (parent != null) { XmlElement prop_mapping = MetadataTools.AddProperty(parent, propertyAuditingData.Name, null, insertable, key); //CustomType propertyType = (CustomType) value.getType(); XmlElement type_mapping = parent.OwnerDocument.CreateElement("type"); prop_mapping.AppendChild(type_mapping); type_mapping.SetAttribute("name", value.GetType().Name); if (value is SimpleValue) { IDictionary<string, string> typeParameters = ((SimpleValue)value).TypeParameters; if (typeParameters != null) { foreach (KeyValuePair<string,string> paramKeyValue in typeParameters) { XmlElement type_param = parent.OwnerDocument.CreateElement("param"); type_param.SetAttribute("name", (String) paramKeyValue.Key); type_param["name"].Value = paramKeyValue.Value; } } } MetadataTools.AddColumns(prop_mapping, (IEnumerator<ISelectable>)value.ColumnIterator); } if (mapper != null) { mapper.Add(propertyAuditingData.getPropertyData()); } }
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 bool AddBasic(XmlElement parent, PropertyAuditingData propertyAuditingData, IValue value, ISimpleMapperBuilder mapper, bool insertable, bool key) { var type = value.Type; var custType = type as CustomType; var compType = type as CompositeCustomType; if (type is ImmutableType || type is MutableType) { AddSimpleValue(parent, propertyAuditingData, value, mapper, insertable, key); } else if (custType != null) { AddCustomValue(parent, propertyAuditingData, value, mapper, insertable, key, custType.UserType.GetType()); } else if (compType != null) { AddCustomValue(parent, propertyAuditingData, value, mapper, insertable, key, compType.UserType.GetType()); } else { return false; } return true; }
private void setCustomMapper(MemberInfo property, PropertyAuditingData propertyData) { var customMapper = _metaDataStore.MemberMeta <CustomCollectionMapperAttribute>(property); if (customMapper != null) { propertyData.CustomCollectionMapperFactory = (ICustomCollectionMapperFactory)Activator.CreateInstance(customMapper.CustomCollectionFactory); } }
/*** * Add the {@link org.hibernate.envers.AuditOverride} annotations. * * @param property the property being processed * @param propertyData the Envers auditing data for this property */ private void addPropertyAuditingOverrides(MemberInfo property, PropertyAuditingData propertyData) { var annotationOverride = _metaDataStore.MemberMeta <AuditOverrideAttribute>(property); if (annotationOverride != null) { propertyData.AddAuditingOverride(annotationOverride); } }
private void AddPropertyMapKey(PropertyInfo property, PropertyAuditingData propertyData) { MapKeyAttribute mapKey = (MapKeyAttribute)Attribute.GetCustomAttribute(property, typeof(MapKeyAttribute)); if (mapKey != null) { propertyData.MapKey = mapKey.Name; } }
private void setPropertyAuditMappedBy(MemberInfo property, PropertyAuditingData propertyData) { var auditMappedBy = _metaDataStore.MemberMeta <AuditMappedByAttribute>(property); if (auditMappedBy != null) { propertyData.MappedBy = auditMappedBy.MappedBy; propertyData.ForceInsertable = auditMappedBy.ForceInsertOverride; propertyData.PositionMappedBy = auditMappedBy.PositionMappedBy; } }
private void SetPropertyAuditMappedBy(PropertyInfo property, PropertyAuditingData propertyData) { AuditMappedByAttribute auditMappedBy = (AuditMappedByAttribute)Attribute.GetCustomAttribute(property, typeof(AuditMappedByAttribute)); if (auditMappedBy != null) { propertyData.AuditMappedBy = auditMappedBy.MappedBy; if (!"".Equals(auditMappedBy.PositionMappedBy)) { propertyData.PositionMappedBy = auditMappedBy.PositionMappedBy; } } }
private void AddSimpleValue(XmlElement parent, PropertyAuditingData propertyAuditingData, IValue value, ISimpleMapperBuilder mapper, bool insertable, bool key) { if (parent != null) { XmlElement prop_mapping = MetadataTools.AddProperty(parent, propertyAuditingData.Name, value.Type.Name, propertyAuditingData.ForceInsertable || insertable, key); MetadataTools.AddColumns(prop_mapping, (IEnumerator<ISelectable>)value.ColumnIterator.GetEnumerator()); } // A null mapper means that we only want to add xml mappings if (mapper != null) { mapper.Add(propertyAuditingData.getPropertyData()); } }
private void AddPropertyJoinTables(PropertyInfo property, PropertyAuditingData propertyData) { // first set the join table based on the AuditJoinTable annotation AuditJoinTableAttribute joinTable = (AuditJoinTableAttribute)Attribute.GetCustomAttribute(property, typeof(AuditJoinTableAttribute));; if (joinTable != null) { propertyData.JoinTable = joinTable; } else { propertyData.JoinTable = DEFAULT_AUDIT_JOIN_TABLE; } }
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)); }
/*** * Add the {@link org.hibernate.envers.AuditOverride} annotations. * * @param property the property being processed * @param propertyData the Envers auditing data for this property */ private void AddPropertyAuditingOverrides(PropertyInfo property, PropertyAuditingData propertyData) { AuditOverrideAttribute annotationOverride = (AuditOverrideAttribute)Attribute.GetCustomAttribute(property, typeof(AuditOverrideAttribute));; if (annotationOverride != null) { propertyData.addAuditingOverride(annotationOverride); } AuditOverridesAttribute annotationOverrides = (AuditOverridesAttribute)Attribute.GetCustomAttribute(property, typeof(AuditOverridesAttribute));; if (annotationOverrides != null) { propertyData.addAuditingOverrides(annotationOverrides); } }
private void addFromNotComponentProperty(DeclaredPersistentProperty property, AuditedAttribute allClassAudited) { var propertyData = new PropertyAuditingData(); var isAudited = fillPropertyData(property.Member, property.Property.Name, propertyData, property.Property.PropertyAccessorName, allClassAudited); if (isAudited) { // Now we know that the property is audited _auditedPropertiesHolder.AddPropertyAuditingData(property.Property.Name, propertyData); } }
/// <summary> /// Checks if a property is audited and if yes, fills all of its data. /// </summary> /// <param name="property">Property to check.</param> /// <param name="mappedPropertyName">NH Property name</param> /// <param name="propertyData">Property data, on which to set this property's modification store.</param> /// <param name="accessType">Access type for the property.</param> /// <param name="allClassAudited">Is class fully audited</param> /// <returns>False if this property is not audited.</returns> private bool fillPropertyData(MemberInfo property, string mappedPropertyName, PropertyAuditingData propertyData, string accessType, AuditedAttribute allClassAudited) { // check if a property is declared as not audited to exclude it // useful if a class is audited but some properties should be excluded if ((_metaDataStore.MemberMeta <NotAuditedAttribute>(property) != null && !_overriddenAuditedProperties.Contains(mappedPropertyName)) || _overriddenNotAuditedProperties.Contains(mappedPropertyName)) { return(false); } // if the optimistic locking field has to be unversioned and the current property // is the optimistic locking field, don't audit it if (_globalCfg.DoNotAuditOptimisticLockingField && _persistentPropertiesSource.VersionedProperty != null && _persistentPropertiesSource.VersionedProperty.Name.Equals(mappedPropertyName)) { return(false); } if (!CheckAudited(property, mappedPropertyName, propertyData, allClassAudited)) { return(false); } var propertyName = _propertyNamePrefix + mappedPropertyName; propertyData.Name = propertyName; propertyData.ModifiedFlagName = MetadataTools.ModifiedFlagPropertyName(propertyName, _globalCfg.ModifiedFlagSuffix); propertyData.BeanName = mappedPropertyName; propertyData.AccessType = accessType; addPropertyJoinTables(property, propertyData); addPropertyAuditingOverrides(property, propertyData); if (!processPropertyAuditingOverrides(property, propertyData)) { return(false); // not audited due to AuditOverride annotation } setPropertyAuditMappedBy(property, propertyData); setCustomMapper(property, propertyData); return(true); }
/** * @param mainGenerator Main generator, giving access to configuration and the basic mapper. * @param propertyValue Value of the collection, as mapped by Hibernate. * @param currentMapper Mapper, to which the appropriate {@link org.hibernate.envers.entities.mapper.PropertyMapper} * will be added. * @param referencingEntityName Name of the entity that owns this collection. * @param xmlMappingData In case this collection requires a middle table, additional mapping documents will * be created using this object. * @param propertyAuditingData Property auditing (meta-)data. Among other things, holds the name of the * property that references the collection in the referencing entity, the user data for middle (join) * table and the value of the <code>@MapKey</code> annotation, if there was one. */ public CollectionMetadataGenerator(AuditMetadataGenerator mainGenerator, Mapping.Collection propertyValue, ICompositeMapperBuilder currentMapper, String referencingEntityName, EntityXmlMappingData xmlMappingData, PropertyAuditingData propertyAuditingData) { this.mainGenerator = mainGenerator; this.propertyValue = propertyValue; this.currentMapper = currentMapper; this.referencingEntityName = referencingEntityName; this.xmlMappingData = xmlMappingData; this.propertyAuditingData = propertyAuditingData; this.propertyName = propertyAuditingData.Name; referencingEntityConfiguration = mainGenerator.EntitiesConfigurations[referencingEntityName]; if (referencingEntityConfiguration == null) { throw new MappingException("Unable to read auditing configuration for " + referencingEntityName + "!"); } referencedEntityName = MappingTools.getReferencedEntityName(propertyValue.Element); }
private void AddFromProperties(IEnumerable <PropertyInfo> properties, String accessType, ISet <String> persistentProperties) { //ORIG: foreach (XProperty property in properties) { foreach (PropertyInfo property in properties) { // If this is not a persistent property, with the same access type as currently checked, // it's not audited as well. if (persistentProperties.Contains(property.Name)) { IValue propertyValue = _persistentPropertiesSource.GetProperty(property.Name).Value; PropertyAuditingData propertyData; bool isAudited; if (propertyValue is Component) { ComponentAuditingData componentData = new ComponentAuditingData(); isAudited = FillPropertyData(property, componentData, accessType); IPersistentPropertiesSource componentPropertiesSource = new ComponentPropertiesSource( (Component)propertyValue); new AuditedPropertiesReader(ModificationStore.FULL, componentPropertiesSource, componentData, _globalCfg, _propertyNamePrefix + MappingTools.createComponentPrefix(property.Name)) .read(); propertyData = componentData; } else { propertyData = new PropertyAuditingData(); isAudited = FillPropertyData(property, propertyData, accessType); } if (isAudited) { // Now we know that the property is audited _auditedPropertiesHolder.addPropertyAuditingData(property.Name, propertyData); } } } }
/** * Process the {@link org.hibernate.envers.AuditOverride} annotations for this property. * * @param property * the property for which the {@link org.hibernate.envers.AuditOverride} * annotations are being processed * @param propertyData * the Envers auditing data for this property * @return {@code false} if isAudited() of the override annotation was set to */ private bool processPropertyAuditingOverrides(MemberInfo property, PropertyAuditingData propertyData) { // if this property is part of a component, process all override annotations if (_auditedPropertiesHolder is ComponentAuditingData audPropHolderAsComponentAudData) { var overrides = audPropHolderAsComponentAudData.AuditingOverrides; foreach (var ovr in overrides) { if (property.Name.Equals(ovr.PropertyName)) { // the override applies to this property if (!ovr.IsAudited) { return(false); } propertyData.JoinTable = ovr; } } } return(true); }
public bool AddBasic(XmlElement parent, PropertyAuditingData propertyAuditingData, IValue value, ISimpleMapperBuilder mapper, bool insertable, bool key) { NHibernate.Type.IType type = value.Type; if (type is ImmutableType || type is MutableType) { AddSimpleValue(parent, propertyAuditingData, value, mapper, insertable, key); } else if (type is CustomType || type is CompositeCustomType) { AddCustomValue(parent, propertyAuditingData, value, mapper, insertable, key); } // TODO Simon: There is no equivalent of PrimitiveByteArrayBlobType in NHibernate, will see later if needed // ORIG: //else if ("org.hibernate.type.PrimitiveByteArrayBlobType".equals(type.getClass().getName())) //{ // AddSimpleValue(parent, propertyAuditingData, value, mapper, insertable, key); //} else { return false; } return true; }
private void AddFromProperties(IEnumerable<PropertyInfo> properties, String accessType, ISet<String> persistentProperties) { //ORIG: foreach (XProperty property in properties) { foreach (PropertyInfo property in properties) { // If this is not a persistent property, with the same access type as currently checked, // it's not audited as well. if (persistentProperties.Contains(property.Name)) { IValue propertyValue = _persistentPropertiesSource.GetProperty(property.Name).Value; PropertyAuditingData propertyData; bool isAudited; if (propertyValue is Component) { ComponentAuditingData componentData = new ComponentAuditingData(); isAudited = FillPropertyData(property, componentData, accessType); IPersistentPropertiesSource componentPropertiesSource = new ComponentPropertiesSource( (Component) propertyValue); new AuditedPropertiesReader(ModificationStore.FULL, componentPropertiesSource, componentData, _globalCfg, _propertyNamePrefix + MappingTools.createComponentPrefix(property.Name)) .read(); propertyData = componentData; } else { propertyData = new PropertyAuditingData(); isAudited = FillPropertyData(property, propertyData, accessType); } if (isAudited) { // Now we know that the property is audited _auditedPropertiesHolder.addPropertyAuditingData(property.Name, propertyData); } } } }
/** * Process the {@link org.hibernate.envers.AuditOverride} annotations for this property. * * @param property * the property for which the {@link org.hibernate.envers.AuditOverride} * annotations are being processed * @param propertyData * the Envers auditing data for this property * @return {@code false} if isAudited() of the override annotation was set to */ private bool ProcessPropertyAuditingOverrides(PropertyInfo property, PropertyAuditingData propertyData) { // if this property is part of a component, process all override annotations if (this._auditedPropertiesHolder is ComponentAuditingData) { IList<AuditOverrideAttribute> overrides = ((ComponentAuditingData) this._auditedPropertiesHolder).AuditingOverrides; foreach (AuditOverrideAttribute ovr in overrides) { if (property.Name.Equals(ovr.Name)) { // the override applies to this property if (!ovr.IsAudited) { return false; } else { if (ovr.AuditJoinTable != null) { propertyData.JoinTable = ovr.AuditJoinTable; } } } } } return true; }
/*** * Add the {@link org.hibernate.envers.AuditOverride} annotations. * * @param property the property being processed * @param propertyData the Envers auditing data for this property */ private void AddPropertyAuditingOverrides(PropertyInfo property, PropertyAuditingData propertyData) { AuditOverrideAttribute annotationOverride = (AuditOverrideAttribute)Attribute.GetCustomAttribute(property, typeof(AuditOverrideAttribute));; if (annotationOverride != null) { propertyData.addAuditingOverride(annotationOverride); } AuditOverridesAttribute annotationOverrides = (AuditOverridesAttribute)Attribute.GetCustomAttribute(property, typeof(AuditOverridesAttribute));; if (annotationOverrides != null) { propertyData.addAuditingOverrides(annotationOverrides); } }
private void AddPropertyJoinTables(PropertyInfo property, PropertyAuditingData propertyData) { // first set the join table based on the AuditJoinTable annotation AuditJoinTableAttribute joinTable = (AuditJoinTableAttribute)Attribute.GetCustomAttribute(property, typeof(AuditJoinTableAttribute));; if (joinTable != null) { propertyData.JoinTable = joinTable; } else { propertyData.JoinTable = DEFAULT_AUDIT_JOIN_TABLE; } }
private void AddPropertyMapKey(PropertyInfo property, PropertyAuditingData propertyData) { MapKeyAttribute mapKey = (MapKeyAttribute)Attribute.GetCustomAttribute(property, typeof(MapKeyAttribute)); if (mapKey != null) { propertyData.MapKey = mapKey.Name; } }
private void SetPropertyAuditMappedBy(PropertyInfo property, PropertyAuditingData propertyData) { AuditMappedByAttribute auditMappedBy = (AuditMappedByAttribute)Attribute.GetCustomAttribute(property, typeof(AuditMappedByAttribute)); if (auditMappedBy != null) { propertyData.AuditMappedBy = auditMappedBy.MappedBy; if (!"".Equals(auditMappedBy.PositionMappedBy)) { propertyData.PositionMappedBy = auditMappedBy.PositionMappedBy; } } }
public void addPropertyAuditingData(String propertyName, PropertyAuditingData auditingData) { Properties.Add(propertyName, auditingData); }
/** * Reads the id mapping data of a referenced entity. * @param entityName Name of the entity which is the source of the relation. * @param referencedEntityName Name of the entity which is the target of the relation. * @param propertyAuditingData Auditing data of the property that is the source of the relation. * @param allowNotAuditedTarget Are not-audited target entities allowed. * @throws MappingException If a relation from an audited to a non-audited entity is detected, which is not * mapped using {@link RelationTargetAuditMode#NOT_AUDITED}. * @return The id mapping data of the related entity. */ public IdMappingData GetReferencedIdMappingData(String entityName, String referencedEntityName, PropertyAuditingData propertyAuditingData, bool allowNotAuditedTarget) { EntityConfiguration configuration; if (EntitiesConfigurations.Keys.Contains(referencedEntityName)) configuration = EntitiesConfigurations[referencedEntityName]; else { RelationTargetAuditMode relationTargetAuditMode = propertyAuditingData.getRelationTargetAuditMode(); if (!NotAuditedEntitiesConfigurations.Keys.Contains(referencedEntityName) || !allowNotAuditedTarget || !RelationTargetAuditMode.NOT_AUDITED.Equals(relationTargetAuditMode)) { throw new MappingException("An audited relation from " + entityName + "." + propertyAuditingData.Name + " to a not audited entity " + referencedEntityName + "!" + (allowNotAuditedTarget ? " Such mapping is possible, but has to be explicitly defined using [Audited(TargetAuditMode = RelationTargetAuditMode.NOT_AUDITED)]." : "")); } else configuration = NotAuditedEntitiesConfigurations[referencedEntityName]; } return configuration.IdMappingData; }
public void AddPropertyAuditingData(string propertyName, PropertyAuditingData auditingData) { properties.Add(propertyName, auditingData); }
/** * Checks if a property is audited and if yes, fills all of its data. * @param property Property to check. * @param propertyData Property data, on which to set this property's modification store. * @param accessType Access type for the property. * @return False if this property is not audited. */ private bool FillPropertyData(PropertyInfo property, PropertyAuditingData propertyData, String accessType) { // check if a property is declared as not audited to exclude it // useful if a class is audited but some properties should be excluded NotAuditedAttribute unVer = (NotAuditedAttribute)Attribute.GetCustomAttribute(property, typeof(NotAuditedAttribute)); if (unVer != null) { return(false); } else { // if the optimistic locking field has to be unversioned and the current property // is the optimistic locking field, don't audit it if (_globalCfg.isDoNotAuditOptimisticLockingField()) { //Version jpaVer = property.getAnnotation(typeof(Version)); VersionAttribute jpaVer = (VersionAttribute)Attribute.GetCustomAttribute(property, typeof(VersionAttribute)); if (jpaVer != null) { return(false); } } } // Checking if this property is explicitly audited or if all properties are. //AuditedAttribute aud = property.getAnnotation(typeof(AuditedAttribute)); AuditedAttribute aud = (AuditedAttribute)Attribute.GetCustomAttribute(property, typeof(AuditedAttribute)); if (aud != null) { propertyData.Store = aud.ModStore; propertyData.setRelationTargetAuditMode(aud.TargetAuditMode); } else { if (_defaultStore != ModificationStore._NULL) { propertyData.Store = _defaultStore; } else { return(false); } } propertyData.Name = _propertyNamePrefix + property.Name; propertyData.BeanName = property.Name; propertyData.AccessType = accessType; AddPropertyJoinTables(property, propertyData); AddPropertyAuditingOverrides(property, propertyData); if (!ProcessPropertyAuditingOverrides(property, propertyData)) { return(false); // not audited due to AuditOverride annotation } AddPropertyMapKey(property, propertyData); SetPropertyAuditMappedBy(property, propertyData); return(true); }
public void AddValue(XmlElement parent, IValue value, ICompositeMapperBuilder currentMapper, string entityName, EntityXmlMappingData xmlMappingData, PropertyAuditingData propertyAuditingData, bool insertable, bool firstPass) { var type = value.Type; // only first pass if (firstPass) { if (BasicMetadataGenerator.AddBasic(parent, propertyAuditingData, value, currentMapper, insertable, false)) { // The property was mapped by the basic generator. return; } } if (type is ComponentType) { // both passes componentMetadataGenerator.AddComponent(parent, propertyAuditingData, value, currentMapper, entityName, xmlMappingData, firstPass, insertable); } else if (type is ManyToOneType) { // only second pass if (!firstPass) { toOneRelationMetadataGenerator.AddToOne(parent, propertyAuditingData, value, currentMapper, entityName, insertable, null); } } else if (type is OneToOneType) { // only second pass if (!firstPass) { var oneToOneType = (OneToOneType)type; var oneToOneValue = (OneToOne)value; if (oneToOneType.IsReferenceToPrimaryKey && oneToOneValue.IsConstrained) { //if pk onetoone is used, "value" has no corresponding columns var pkColumns = new List<string>(); foreach (Column column in Cfg.GetClassMapping(oneToOneValue.ReferencedEntityName).Identifier.ColumnIterator) { pkColumns.Add("Ref" + column.Name); } toOneRelationMetadataGenerator.AddToOne(parent, propertyAuditingData, value, currentMapper, entityName, insertable, pkColumns); } else { toOneRelationMetadataGenerator.AddOneToOneNotOwning(propertyAuditingData, oneToOneValue, currentMapper, entityName); } } } else if (type is CollectionType) { // only second pass if (!firstPass) { var collectionMetadataGenerator = new CollectionMetadataGenerator(this, (Mapping.Collection)value, currentMapper, entityName, xmlMappingData, propertyAuditingData); collectionMetadataGenerator.AddCollection(); } } else { if (firstPass) { // If we got here in the first pass, it means the basic mapper didn't map it, and none of the // above branches either. ThrowUnsupportedTypeException(type, entityName, propertyAuditingData.Name); } } }
//@SuppressWarnings({"unchecked"}) public void AddValue(XmlElement parent, IValue value, ICompositeMapperBuilder currentMapper, String entityName, EntityXmlMappingData xmlMappingData, PropertyAuditingData propertyAuditingData, bool insertable, bool firstPass) { IType type = value.Type; // only first pass if (firstPass) { if (BasicMetadataGenerator.AddBasic(parent, propertyAuditingData, value, currentMapper, insertable, false)) { // The property was mapped by the basic generator. return; } } if (type is ComponentType) { // both passes componentMetadataGenerator.AddComponent(parent, propertyAuditingData, value, currentMapper, entityName, xmlMappingData, firstPass); } else if (type is ManyToOneType) { // only second pass if (!firstPass) { toOneRelationMetadataGenerator.AddToOne(parent, propertyAuditingData, value, currentMapper, entityName, insertable); } } else if (type is OneToOneType) { // only second pass if (!firstPass) { toOneRelationMetadataGenerator.AddOneToOneNotOwning(propertyAuditingData, value, currentMapper, entityName); } } else if (type is CollectionType) { // only second pass if (!firstPass) { CollectionMetadataGenerator collectionMetadataGenerator = new CollectionMetadataGenerator(this, (Mapping.Collection)value, currentMapper, entityName, xmlMappingData, propertyAuditingData); collectionMetadataGenerator.AddCollection(); } } else { if (firstPass) { // If we got here in the first pass, it means the basic mapper didn't map it, and none of the // above branches either. ThrowUnsupportedTypeException(type, entityName, propertyAuditingData.Name); } } }
/** * Checks if a property is audited and if yes, fills all of its data. * @param property Property to check. * @param propertyData Property data, on which to set this property's modification store. * @param accessType Access type for the property. * @return False if this property is not audited. */ private bool FillPropertyData(PropertyInfo property, PropertyAuditingData propertyData, String accessType) { // check if a property is declared as not audited to exclude it // useful if a class is audited but some properties should be excluded NotAuditedAttribute unVer = (NotAuditedAttribute)Attribute.GetCustomAttribute(property, typeof(NotAuditedAttribute)); if (unVer != null) { return false; } else { // if the optimistic locking field has to be unversioned and the current property // is the optimistic locking field, don't audit it if (_globalCfg.isDoNotAuditOptimisticLockingField()) { //Version jpaVer = property.getAnnotation(typeof(Version)); VersionAttribute jpaVer = (VersionAttribute)Attribute.GetCustomAttribute(property, typeof(VersionAttribute)); if (jpaVer != null) { return false; } } } // Checking if this property is explicitly audited or if all properties are. //AuditedAttribute aud = property.getAnnotation(typeof(AuditedAttribute)); AuditedAttribute aud = (AuditedAttribute)Attribute.GetCustomAttribute(property, typeof(AuditedAttribute)); if (aud != null) { propertyData.Store = aud.ModStore; propertyData.setRelationTargetAuditMode(aud.TargetAuditMode); } else { if (_defaultStore != ModificationStore._NULL) { propertyData.Store = _defaultStore; } else { return false; } } propertyData.Name = _propertyNamePrefix + property.Name; propertyData.BeanName = property.Name; propertyData.AccessType = accessType; AddPropertyJoinTables(property, propertyData); AddPropertyAuditingOverrides(property, propertyData); if (!ProcessPropertyAuditingOverrides(property, propertyData)) { return false; // not audited due to AuditOverride annotation } AddPropertyMapKey(property, propertyData); SetPropertyAuditMappedBy(property, propertyData); return true; }
protected override bool CheckAudited(MemberInfo property, string mappedPropertyName, PropertyAuditingData propertyData, AuditedAttribute allClassAudited) { // Checking if this property is explicitly audited or if all properties are. var aud = _metaDataStore.MemberMeta <AuditedAttribute>(property); if (aud != null) { propertyData.RelationTargetAuditMode = aud.TargetAuditMode; } return(true); }
protected virtual bool CheckAudited(MemberInfo property, string mappedPropertyName, PropertyAuditingData propertyData, AuditedAttribute allClassAudited) { // Checking if this property is explicitly audited or if all properties are. var aud = _metaDataStore.MemberMeta <AuditedAttribute>(property) ?? allClassAudited; if (aud == null && _overriddenAuditedProperties.Contains(mappedPropertyName) && !_overriddenNotAuditedProperties.Contains(mappedPropertyName)) { // Assigning AuditedAttribute defaults. If anyone needs to customize those values in the future, // appropriate fields shall be added to AuditOverrideAttribute annotation. aud = new AuditedAttribute(); } if (aud != null) { propertyData.RelationTargetAuditMode = aud.TargetAuditMode; propertyData.UsingModifiedFlag = checkUsingModifiedFlag(aud); return(true); } return(false); }