Search in sources :

Example 1 with CompositeMapperBuilder

use of org.hibernate.envers.internal.entities.mapper.CompositeMapperBuilder in project hibernate-orm by hibernate.

the class ComponentMetadataGenerator method addComponent.

@SuppressWarnings({ "unchecked" })
public void addComponent(Element parent, PropertyAuditingData propertyAuditingData, Value value, CompositeMapperBuilder mapper, String entityName, EntityXmlMappingData xmlMappingData, boolean firstPass) {
    final Component propComponent = (Component) value;
    final Class componentClass;
    if (propComponent.isDynamic()) {
        componentClass = ReflectionTools.loadClass(Map.class.getCanonicalName(), mainGenerator.getClassLoaderService());
    } else {
        componentClass = ReflectionTools.loadClass(propComponent.getComponentClassName(), mainGenerator.getClassLoaderService());
    }
    final CompositeMapperBuilder componentMapper = mapper.addComponent(propertyAuditingData.getPropertyData(), componentClass);
    // The property auditing data must be for a component.
    final ComponentAuditingData componentAuditingData = (ComponentAuditingData) propertyAuditingData;
    // Adding all properties of the component
    final Iterator<Property> properties = (Iterator<Property>) propComponent.getPropertyIterator();
    while (properties.hasNext()) {
        final Property property = properties.next();
        final PropertyAuditingData componentPropertyAuditingData = componentAuditingData.getPropertyAuditingData(property.getName());
        // Checking if that property is audited
        if (componentPropertyAuditingData != null) {
            mainGenerator.addValue(parent, property.getValue(), componentMapper, entityName, xmlMappingData, componentPropertyAuditingData, property.isInsertable(), firstPass, false);
        }
    }
}
Also used : CompositeMapperBuilder(org.hibernate.envers.internal.entities.mapper.CompositeMapperBuilder) ComponentAuditingData(org.hibernate.envers.configuration.internal.metadata.reader.ComponentAuditingData) Iterator(java.util.Iterator) PropertyAuditingData(org.hibernate.envers.configuration.internal.metadata.reader.PropertyAuditingData) Component(org.hibernate.mapping.Component) Property(org.hibernate.mapping.Property)

Example 2 with CompositeMapperBuilder

use of org.hibernate.envers.internal.entities.mapper.CompositeMapperBuilder in project hibernate-orm by hibernate.

the class AuditMetadataGenerator method generateSecondPass.

@SuppressWarnings({ "unchecked" })
public void generateSecondPass(PersistentClass pc, ClassAuditingData auditingData, EntityXmlMappingData xmlMappingData) {
    final String entityName = pc.getEntityName();
    LOG.debugf("Generating second-pass auditing mapping for entity %s", entityName);
    final CompositeMapperBuilder propertyMapper = entitiesConfigurations.get(entityName).getPropertyMapper();
    // Mapping unjoined properties
    final Element parent = xmlMappingData.getClassMapping();
    addProperties(parent, pc.getUnjoinedPropertyIterator(), propertyMapper, auditingData, entityName, xmlMappingData, false);
    // Mapping joins (second pass)
    addJoins(pc, propertyMapper, auditingData, entityName, xmlMappingData, false);
}
Also used : CompositeMapperBuilder(org.hibernate.envers.internal.entities.mapper.CompositeMapperBuilder) Element(org.dom4j.Element)

Example 3 with CompositeMapperBuilder

use of org.hibernate.envers.internal.entities.mapper.CompositeMapperBuilder in project hibernate-orm by hibernate.

the class MiddleEmbeddableComponentMapper method addMiddleEqualToQuery.

protected void addMiddleEqualToQuery(CompositeMapperBuilder compositeMapper, Parameters parameters, String idPrefix1, String prefix1, String idPrefix2, String prefix2) {
    for (final Map.Entry<PropertyData, PropertyMapper> entry : compositeMapper.getProperties().entrySet()) {
        final String propertyName = entry.getKey().getName();
        final PropertyMapper nestedMapper = entry.getValue();
        if (nestedMapper instanceof CompositeMapperBuilder) {
            addMiddleEqualToQuery((CompositeMapperBuilder) nestedMapper, parameters, idPrefix1, prefix1, idPrefix2, prefix2);
        } else if (nestedMapper instanceof ToOneIdMapper) {
            ((ToOneIdMapper) nestedMapper).addMiddleEqualToQuery(parameters, idPrefix1, prefix1, idPrefix2, prefix2);
        } else {
            parameters.addWhereOrNullRestriction(prefix1 + '.' + propertyName, false, "=", prefix2 + '.' + propertyName, false);
        }
    }
}
Also used : PropertyData(org.hibernate.envers.internal.entities.PropertyData) CompositeMapperBuilder(org.hibernate.envers.internal.entities.mapper.CompositeMapperBuilder) ToOneIdMapper(org.hibernate.envers.internal.entities.mapper.relation.ToOneIdMapper) PropertyMapper(org.hibernate.envers.internal.entities.mapper.PropertyMapper) MultiPropertyMapper(org.hibernate.envers.internal.entities.mapper.MultiPropertyMapper) Map(java.util.Map)

Aggregations

CompositeMapperBuilder (org.hibernate.envers.internal.entities.mapper.CompositeMapperBuilder)3 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Element (org.dom4j.Element)1 ComponentAuditingData (org.hibernate.envers.configuration.internal.metadata.reader.ComponentAuditingData)1 PropertyAuditingData (org.hibernate.envers.configuration.internal.metadata.reader.PropertyAuditingData)1 PropertyData (org.hibernate.envers.internal.entities.PropertyData)1 MultiPropertyMapper (org.hibernate.envers.internal.entities.mapper.MultiPropertyMapper)1 PropertyMapper (org.hibernate.envers.internal.entities.mapper.PropertyMapper)1 ToOneIdMapper (org.hibernate.envers.internal.entities.mapper.relation.ToOneIdMapper)1 Component (org.hibernate.mapping.Component)1 Property (org.hibernate.mapping.Property)1