HHH-6964 EnversIntegrator is always detected by default while initializing Serviceregistry using Native Hibernate API causing a MappingException even when Envers is not used

This commit is contained in:
Strong Liu 2012-01-13 04:09:01 +08:00
parent e07aff45da
commit 8f9d8b530e
1 changed files with 82 additions and 70 deletions

View File

@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.configuration;
import java.util.Map;
import java.util.Properties;
import java.util.WeakHashMap;
@ -89,25 +90,30 @@ public class AuditConfiguration {
}
public AuditConfiguration(Configuration cfg) {
this(cfg, null);
this( cfg, null );
}
public AuditConfiguration(Configuration cfg, ClassLoaderService classLoaderService) {
Properties properties = cfg.getProperties();
ReflectionManager reflectionManager = cfg.getReflectionManager();
globalCfg = new GlobalConfiguration(properties);
RevisionInfoConfiguration revInfoCfg = new RevisionInfoConfiguration(globalCfg);
RevisionInfoConfigurationResult revInfoCfgResult = revInfoCfg.configure(cfg, reflectionManager);
auditEntCfg = new AuditEntitiesConfiguration(properties, revInfoCfgResult.getRevisionInfoEntityName());
auditProcessManager = new AuditProcessManager(revInfoCfgResult.getRevisionInfoGenerator());
globalCfg = new GlobalConfiguration( properties );
RevisionInfoConfiguration revInfoCfg = new RevisionInfoConfiguration( globalCfg );
RevisionInfoConfigurationResult revInfoCfgResult = revInfoCfg.configure( cfg, reflectionManager );
auditEntCfg = new AuditEntitiesConfiguration( properties, revInfoCfgResult.getRevisionInfoEntityName() );
auditProcessManager = new AuditProcessManager( revInfoCfgResult.getRevisionInfoGenerator() );
revisionInfoQueryCreator = revInfoCfgResult.getRevisionInfoQueryCreator();
revisionInfoNumberReader = revInfoCfgResult.getRevisionInfoNumberReader();
modifiedEntityNamesReader = revInfoCfgResult.getModifiedEntityNamesReader();
this.classLoaderService = classLoaderService;
auditStrategy = initializeAuditStrategy(revInfoCfgResult.getRevisionInfoClass(),
revInfoCfgResult.getRevisionInfoTimestampData());
entCfg = new EntitiesConfigurator().configure(cfg, reflectionManager, globalCfg, auditEntCfg, auditStrategy,
revInfoCfgResult.getRevisionInfoXmlMapping(), revInfoCfgResult.getRevisionInfoRelationMapping());
auditStrategy = initializeAuditStrategy(
revInfoCfgResult.getRevisionInfoClass(),
revInfoCfgResult.getRevisionInfoTimestampData()
);
entCfg = new EntitiesConfigurator().configure(
cfg, reflectionManager, globalCfg, auditEntCfg, auditStrategy,
revInfoCfgResult.getRevisionInfoXmlMapping(), revInfoCfgResult.getRevisionInfoRelationMapping()
);
}
private AuditStrategy initializeAuditStrategy(Class<?> revisionInfoClass, PropertyData revisionInfoTimestampData) {
@ -116,23 +122,28 @@ public class AuditConfiguration {
try {
Class<?> auditStrategyClass = null;
if(classLoaderService!=null){
if ( classLoaderService != null ) {
auditStrategyClass = classLoaderService.classForName( auditEntCfg.getAuditStrategyName() );
} else {
auditStrategyClass = Thread.currentThread().getContextClassLoader().loadClass(auditEntCfg.getAuditStrategyName());
}
else {
auditStrategyClass = Thread.currentThread()
.getContextClassLoader()
.loadClass( auditEntCfg.getAuditStrategyName() );
}
strategy = (AuditStrategy) auditStrategyClass.newInstance();
} catch (Exception e) {
}
catch ( Exception e ) {
throw new MappingException(
String.format("Unable to create AuditStrategy[%s] instance." , auditEntCfg.getAuditStrategyName()),
e);
String.format( "Unable to create AuditStrategy[%s] instance.", auditEntCfg.getAuditStrategyName() ),
e
);
}
if (strategy instanceof ValidityAuditStrategy) {
if ( strategy instanceof ValidityAuditStrategy ) {
// further initialization required
Getter revisionTimestampGetter = ReflectionTools.getGetter(revisionInfoClass, revisionInfoTimestampData);
((ValidityAuditStrategy) strategy).setRevisionTimestampGetter(revisionTimestampGetter);
Getter revisionTimestampGetter = ReflectionTools.getGetter( revisionInfoClass, revisionInfoTimestampData );
( (ValidityAuditStrategy) strategy ).setRevisionTimestampGetter( revisionTimestampGetter );
}
return strategy;
@ -146,12 +157,13 @@ public class AuditConfiguration {
public synchronized static AuditConfiguration getFor(Configuration cfg) {
return getFor( cfg, null );
}
public synchronized static AuditConfiguration getFor(Configuration cfg, ClassLoaderService classLoaderService) {
AuditConfiguration verCfg = cfgs.get(cfg);
if (verCfg == null) {
verCfg = new AuditConfiguration(cfg, classLoaderService);
cfgs.put(cfg, verCfg);
public synchronized static AuditConfiguration getFor(Configuration cfg, ClassLoaderService classLoaderService) {
AuditConfiguration verCfg = cfgs.get( cfg );
if ( verCfg == null ) {
verCfg = new AuditConfiguration( cfg, classLoaderService );
cfgs.put( cfg, verCfg );
cfg.buildMappings();
}