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);
}
}
}
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;
}
Aggregations