HHH-5520 - Per org.hibernate.cache.RegionFactory javadocs, implementors should be allowed to use no-arg constructor

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@20295 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2010-08-31 18:57:54 +00:00
parent 487ccb38d0
commit 21c49fff68
1 changed files with 19 additions and 8 deletions

View File

@ -24,6 +24,7 @@
package org.hibernate.cfg; package org.hibernate.cfg;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DatabaseMetaData; import java.sql.DatabaseMetaData;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -368,8 +369,8 @@ public class SettingsFactory implements Serializable {
return new org.hibernate.bytecode.cglib.BytecodeProviderImpl(); return new org.hibernate.bytecode.cglib.BytecodeProviderImpl();
} }
else { else {
log.debug( "using cglib as bytecode provider by default" ); log.debug( "using javassist as bytecode provider by default" );
return new org.hibernate.bytecode.cglib.BytecodeProviderImpl(); return new org.hibernate.bytecode.javassist.BytecodeProviderImpl();
} }
} }
@ -404,9 +405,19 @@ public class SettingsFactory implements Serializable {
} }
log.info( "Cache region factory : " + regionFactoryClassName ); log.info( "Cache region factory : " + regionFactoryClassName );
try { try {
return ( RegionFactory ) ReflectHelper.classForName( regionFactoryClassName ) try {
.getConstructor( new Class[] { Properties.class } ) return (RegionFactory) ReflectHelper.classForName( regionFactoryClassName )
.newInstance( new Object[] { properties } ); .getConstructor( Properties.class )
.newInstance( properties );
}
catch ( NoSuchMethodException nsme ) {
// no constructor accepting Properties found, try no arg constructor
log.debug(
regionFactoryClassName + " did not provide constructor accepting java.util.Properties; " +
"attempting no-arg constructor."
);
return (RegionFactory) ReflectHelper.classForName( regionFactoryClassName ).newInstance();
}
} }
catch ( Exception e ) { catch ( Exception e ) {
throw new HibernateException( "could not instantiate RegionFactory [" + regionFactoryClassName + "]", e ); throw new HibernateException( "could not instantiate RegionFactory [" + regionFactoryClassName + "]", e );
@ -429,9 +440,9 @@ public class SettingsFactory implements Serializable {
protected BatcherFactory createBatcherFactory(Properties properties, int batchSize) { protected BatcherFactory createBatcherFactory(Properties properties, int batchSize) {
String batcherClass = properties.getProperty(Environment.BATCH_STRATEGY); String batcherClass = properties.getProperty(Environment.BATCH_STRATEGY);
if (batcherClass==null) { if (batcherClass==null) {
return batchSize==0 ? return batchSize == 0
(BatcherFactory) new NonBatchingBatcherFactory() : ? new NonBatchingBatcherFactory()
(BatcherFactory) new BatchingBatcherFactory(); : new BatchingBatcherFactory();
} }
else { else {
log.info("Batcher factory: " + batcherClass); log.info("Batcher factory: " + batcherClass);