Search in sources :

Example 1 with ValidityAuditStrategy

use of org.hibernate.envers.strategy.ValidityAuditStrategy in project hibernate-orm by hibernate.

the class AuditMetadataGenerator method addEndRevision.

private void addEndRevision(Element anyMapping) {
    // Add the end-revision field, if the appropriate strategy is used.
    if (auditStrategy instanceof ValidityAuditStrategy) {
        final Element endRevMapping = (Element) revisionInfoRelationMapping.clone();
        endRevMapping.setName("many-to-one");
        endRevMapping.addAttribute("name", verEntCfg.getRevisionEndFieldName());
        MetadataTools.addOrModifyColumn(endRevMapping, verEntCfg.getRevisionEndFieldName());
        anyMapping.add(endRevMapping);
        if (verEntCfg.isRevisionEndTimestampEnabled()) {
            // add a column for the timestamp of the end revision
            final String revisionInfoTimestampSqlType = TimestampType.INSTANCE.getName();
            final Element timestampProperty = MetadataTools.addProperty(anyMapping, verEntCfg.getRevisionEndTimestampFieldName(), revisionInfoTimestampSqlType, true, true, false);
            MetadataTools.addColumn(timestampProperty, verEntCfg.getRevisionEndTimestampFieldName(), null, null, null, null, null, null);
        }
    }
}
Also used : Element(org.dom4j.Element) ValidityAuditStrategy(org.hibernate.envers.strategy.ValidityAuditStrategy)

Example 2 with ValidityAuditStrategy

use of org.hibernate.envers.strategy.ValidityAuditStrategy in project hibernate-orm by hibernate.

the class EnversServiceImpl method initializeAuditStrategy.

private static AuditStrategy initializeAuditStrategy(String auditStrategyName, Class<?> revisionInfoClass, PropertyData revisionInfoTimestampData, ServiceRegistry serviceRegistry) {
    AuditStrategy strategy;
    try {
        final Class<?> auditStrategyClass = loadClass(auditStrategyName, serviceRegistry);
        strategy = (AuditStrategy) ReflectHelper.getDefaultConstructor(auditStrategyClass).newInstance();
    } catch (Exception e) {
        throw new MappingException(String.format("Unable to create AuditStrategy [%s] instance.", auditStrategyName), e);
    }
    if (strategy instanceof ValidityAuditStrategy) {
        // further initialization required
        final Getter revisionTimestampGetter = ReflectionTools.getGetter(revisionInfoClass, revisionInfoTimestampData, serviceRegistry);
        ((ValidityAuditStrategy) strategy).setRevisionTimestampGetter(revisionTimestampGetter);
    }
    return strategy;
}
Also used : Getter(org.hibernate.property.access.spi.Getter) AuditStrategy(org.hibernate.envers.strategy.AuditStrategy) ValidityAuditStrategy(org.hibernate.envers.strategy.ValidityAuditStrategy) ValidityAuditStrategy(org.hibernate.envers.strategy.ValidityAuditStrategy) MappingException(org.hibernate.MappingException) MappingException(org.hibernate.MappingException)

Aggregations

ValidityAuditStrategy (org.hibernate.envers.strategy.ValidityAuditStrategy)2 Element (org.dom4j.Element)1 MappingException (org.hibernate.MappingException)1 AuditStrategy (org.hibernate.envers.strategy.AuditStrategy)1 Getter (org.hibernate.property.access.spi.Getter)1