Search in sources :

Example 6 with PropertyAuditingData

use of org.hibernate.envers.configuration.internal.metadata.reader.PropertyAuditingData in project hibernate-orm by hibernate.

the class AuditMetadataGenerator method checkPropertiesAudited.

private boolean checkPropertiesAudited(Iterator<Property> properties, ClassAuditingData auditingData) {
    while (properties.hasNext()) {
        final Property property = properties.next();
        final String propertyName = property.getName();
        final PropertyAuditingData propertyAuditingData = auditingData.getPropertyAuditingData(propertyName);
        if (propertyAuditingData == null) {
            return false;
        }
    }
    return true;
}
Also used : PropertyAuditingData(org.hibernate.envers.configuration.internal.metadata.reader.PropertyAuditingData) Property(org.hibernate.mapping.Property) SyntheticProperty(org.hibernate.mapping.SyntheticProperty)

Example 7 with PropertyAuditingData

use of org.hibernate.envers.configuration.internal.metadata.reader.PropertyAuditingData in project hibernate-orm by hibernate.

the class ClassesAuditingData method updateCalculatedProperty.

private void updateCalculatedProperty(String entityName, Property property, String propertyName, AuditedPropertiesHolder propertyHolder) {
    final PropertyAuditingData propertyAuditingData = propertyHolder.getPropertyAuditingData(propertyName);
    final boolean isAuditMappedBy = propertyAuditingData.getAuditMappedBy() != null;
    final boolean isRelationMappedBy = propertyAuditingData.getRelationMappedBy() != null;
    // handle updating the property, if applicable.
    if (isAuditMappedBy || isRelationMappedBy) {
        final String referencedEntityName = MappingTools.getReferencedEntityName(property.getValue());
        final ClassAuditingData referencedAuditData = entityNameToAuditingData.get(referencedEntityName);
        if (isAuditMappedBy) {
            // If a property had the @AuditMappedBy annotation, setting the referenced fields to be always insertable.
            setAuditMappedByInsertable(referencedEntityName, entityName, referencedAuditData, propertyAuditingData);
        } else if (isRelationMappedBy && (property.getValue() instanceof List)) {
            // If a property has mappedBy= and @Indexed and isn't @AuditMappedBy, add synthetic support.
            addSyntheticIndexProperty((List) property.getValue(), property.getPropertyAccessorName(), referencedAuditData);
        }
    }
    // This is useful for AuditMappedBy inside an Embeddable that holds a collection of entities.
    if (propertyAuditingData instanceof ComponentAuditingData) {
        final ComponentAuditingData componentAuditingData = (ComponentAuditingData) propertyAuditingData;
        final Component component = (Component) property.getValue();
        for (String componentPropertyName : componentAuditingData.getNonSyntheticPropertyNames()) {
            final Property componentProperty = component.getProperty(componentPropertyName);
            updateCalculatedProperty(entityName, componentProperty, componentPropertyName, componentAuditingData);
        }
    }
}
Also used : ClassAuditingData(org.hibernate.envers.configuration.internal.metadata.reader.ClassAuditingData) ComponentAuditingData(org.hibernate.envers.configuration.internal.metadata.reader.ComponentAuditingData) List(org.hibernate.mapping.List) PropertyAuditingData(org.hibernate.envers.configuration.internal.metadata.reader.PropertyAuditingData) Component(org.hibernate.mapping.Component) Property(org.hibernate.mapping.Property)

Aggregations

PropertyAuditingData (org.hibernate.envers.configuration.internal.metadata.reader.PropertyAuditingData)7 Property (org.hibernate.mapping.Property)5 ComponentAuditingData (org.hibernate.envers.configuration.internal.metadata.reader.ComponentAuditingData)3 Component (org.hibernate.mapping.Component)3 Iterator (java.util.Iterator)2 SyntheticProperty (org.hibernate.mapping.SyntheticProperty)2 Element (org.dom4j.Element)1 ReflectionManager (org.hibernate.annotations.common.reflection.ReflectionManager)1 AuditedPropertiesReader (org.hibernate.envers.configuration.internal.metadata.reader.AuditedPropertiesReader)1 ClassAuditingData (org.hibernate.envers.configuration.internal.metadata.reader.ClassAuditingData)1 ComponentAuditedPropertiesReader (org.hibernate.envers.configuration.internal.metadata.reader.ComponentAuditedPropertiesReader)1 IdMappingData (org.hibernate.envers.internal.entities.IdMappingData)1 CompositeMapperBuilder (org.hibernate.envers.internal.entities.mapper.CompositeMapperBuilder)1 MultiPropertyMapper (org.hibernate.envers.internal.entities.mapper.MultiPropertyMapper)1 EmbeddedIdMapper (org.hibernate.envers.internal.entities.mapper.id.EmbeddedIdMapper)1 IdMapper (org.hibernate.envers.internal.entities.mapper.id.IdMapper)1 MultipleIdMapper (org.hibernate.envers.internal.entities.mapper.id.MultipleIdMapper)1 SingleIdMapper (org.hibernate.envers.internal.entities.mapper.id.SingleIdMapper)1 MiddleComponentData (org.hibernate.envers.internal.entities.mapper.relation.MiddleComponentData)1 MiddleIdData (org.hibernate.envers.internal.entities.mapper.relation.MiddleIdData)1