Search in sources :

Example 1 with AuditOverride

use of org.hibernate.envers.AuditOverride in project hibernate-orm by hibernate.

the class AuditedPropertiesReader method addPropertyAuditingOverrides.

/**
	 * Add the {@link AuditOverride} annotations.
	 *
	 * @param property the property being processed
	 * @param propertyData the Envers auditing data for this property
	 */
private void addPropertyAuditingOverrides(XProperty property, PropertyAuditingData propertyData) {
    final AuditOverride annotationOverride = property.getAnnotation(AuditOverride.class);
    if (annotationOverride != null) {
        propertyData.addAuditingOverride(annotationOverride);
    }
    final AuditOverrides annotationOverrides = property.getAnnotation(AuditOverrides.class);
    if (annotationOverrides != null) {
        propertyData.addAuditingOverrides(annotationOverrides);
    }
}
Also used : AuditOverrides(org.hibernate.envers.AuditOverrides) AuditOverride(org.hibernate.envers.AuditOverride)

Example 2 with AuditOverride

use of org.hibernate.envers.AuditOverride in project hibernate-orm by hibernate.

the class AuditedPropertiesReader method readAuditOverrides.

/**
	 * Recursively constructs sets of audited and not audited properties and classes which behavior has been overridden
	 * using {@link AuditOverride} annotation.
	 *
	 * @param clazz Class that is being processed. Currently mapped entity shall be passed during first invocation.
	 */
private void readAuditOverrides(XClass clazz) {
    /* TODO: Code to remove with @Audited.auditParents - start. */
    final Audited allClassAudited = clazz.getAnnotation(Audited.class);
    if (allClassAudited != null && allClassAudited.auditParents().length > 0) {
        for (Class c : allClassAudited.auditParents()) {
            final XClass parentClass = reflectionManager.toXClass(c);
            checkSuperclass(clazz, parentClass);
            if (!overriddenNotAuditedClasses.contains(parentClass)) {
                // If the class has not been marked as not audited by the subclass.
                overriddenAuditedClasses.add(parentClass);
            }
        }
    }
    /* TODO: Code to remove with @Audited.auditParents - finish. */
    final List<AuditOverride> auditOverrides = computeAuditOverrides(clazz);
    for (AuditOverride auditOverride : auditOverrides) {
        if (auditOverride.forClass() != void.class) {
            final XClass overrideClass = reflectionManager.toXClass(auditOverride.forClass());
            checkSuperclass(clazz, overrideClass);
            final String propertyName = auditOverride.name();
            if (!StringTools.isEmpty(propertyName)) {
                // Override @Audited annotation on property level.
                final XProperty property = getProperty(overrideClass, propertyName);
                if (auditOverride.isAudited()) {
                    if (!overriddenNotAuditedProperties.contains(property)) {
                        // If the property has not been marked as not audited by the subclass.
                        overriddenAuditedProperties.add(property);
                    }
                } else {
                    if (!overriddenAuditedProperties.contains(property)) {
                        // If the property has not been marked as audited by the subclass.
                        overriddenNotAuditedProperties.add(property);
                    }
                }
            } else {
                // Override @Audited annotation on class level.
                if (auditOverride.isAudited()) {
                    if (!overriddenNotAuditedClasses.contains(overrideClass)) {
                        // If the class has not been marked as not audited by the subclass.
                        overriddenAuditedClasses.add(overrideClass);
                    }
                } else {
                    if (!overriddenAuditedClasses.contains(overrideClass)) {
                        // If the class has not been marked as audited by the subclass.
                        overriddenNotAuditedClasses.add(overrideClass);
                    }
                }
            }
        }
    }
    final XClass superclass = clazz.getSuperclass();
    if (!clazz.isInterface() && !Object.class.getName().equals(superclass.getName())) {
        readAuditOverrides(superclass);
    }
}
Also used : XProperty(org.hibernate.annotations.common.reflection.XProperty) Audited(org.hibernate.envers.Audited) NotAudited(org.hibernate.envers.NotAudited) AuditOverride(org.hibernate.envers.AuditOverride) XClass(org.hibernate.annotations.common.reflection.XClass) XClass(org.hibernate.annotations.common.reflection.XClass)

Example 3 with AuditOverride

use of org.hibernate.envers.AuditOverride in project hibernate-orm by hibernate.

the class PropertyAuditingData method addAuditingOverride.

public void addAuditingOverride(AuditOverride annotation) {
    if (annotation != null) {
        final String overrideName = annotation.name();
        boolean present = false;
        for (AuditOverride current : auditJoinTableOverrides) {
            if (current.name().equals(overrideName)) {
                present = true;
                break;
            }
        }
        if (!present) {
            auditJoinTableOverrides.add(annotation);
        }
    }
}
Also used : AuditOverride(org.hibernate.envers.AuditOverride)

Example 4 with AuditOverride

use of org.hibernate.envers.AuditOverride in project hibernate-orm by hibernate.

the class AuditedPropertiesReader method computeAuditOverrides.

/**
	 * @param clazz Source class.
	 *
	 * @return List of @AuditOverride annotations applied at class level.
	 */
private List<AuditOverride> computeAuditOverrides(XClass clazz) {
    final AuditOverrides auditOverrides = clazz.getAnnotation(AuditOverrides.class);
    final AuditOverride auditOverride = clazz.getAnnotation(AuditOverride.class);
    if (auditOverrides == null && auditOverride != null) {
        return Arrays.asList(auditOverride);
    } else if (auditOverrides != null && auditOverride == null) {
        return Arrays.asList(auditOverrides.value());
    } else if (auditOverrides != null && auditOverride != null) {
        throw new MappingException("@AuditOverrides annotation should encapsulate all @AuditOverride declarations. " + "Please revise Envers annotations applied to class " + clazz.getName() + ".");
    }
    return Collections.emptyList();
}
Also used : AuditOverrides(org.hibernate.envers.AuditOverrides) AuditOverride(org.hibernate.envers.AuditOverride) MappingException(org.hibernate.MappingException)

Aggregations

AuditOverride (org.hibernate.envers.AuditOverride)4 AuditOverrides (org.hibernate.envers.AuditOverrides)2 MappingException (org.hibernate.MappingException)1 XClass (org.hibernate.annotations.common.reflection.XClass)1 XProperty (org.hibernate.annotations.common.reflection.XProperty)1 Audited (org.hibernate.envers.Audited)1 NotAudited (org.hibernate.envers.NotAudited)1