@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2008 the original author or authors .
* Copyright 2002 - 201 0 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -16,6 +16,7 @@
@@ -16,6 +16,7 @@
package org.springframework.orm.hibernate3 ;
import java.lang.reflect.Method ;
import java.util.HashMap ;
import java.util.Map ;
@ -26,6 +27,7 @@ import org.hibernate.type.TypeFactory;
@@ -26,6 +27,7 @@ import org.hibernate.type.TypeFactory;
import org.springframework.beans.factory.BeanNameAware ;
import org.springframework.beans.factory.FactoryBean ;
import org.springframework.beans.factory.InitializingBean ;
import org.springframework.util.ReflectionUtils ;
/ * *
* Convenient FactoryBean for defining Hibernate FilterDefinitions .
@ -64,6 +66,30 @@ import org.springframework.beans.factory.InitializingBean;
@@ -64,6 +66,30 @@ import org.springframework.beans.factory.InitializingBean;
* /
public class FilterDefinitionFactoryBean implements FactoryBean < FilterDefinition > , BeanNameAware , InitializingBean {
private static Method heuristicTypeMethod ;
private static Object typeResolver ;
static {
// Hibernate 3.6 TypeResolver class available?
try {
Class trClass = FilterDefinitionFactoryBean . class . getClassLoader ( ) . loadClass (
"org.hibernate.type.TypeResolver" ) ;
heuristicTypeMethod = trClass . getMethod ( "heuristicType" , String . class ) ;
typeResolver = trClass . newInstance ( ) ;
}
catch ( Exception ex ) {
try {
heuristicTypeMethod = TypeFactory . class . getMethod ( "heuristicType" , String . class ) ;
typeResolver = null ;
}
catch ( Exception ex2 ) {
throw new IllegalStateException ( "Cannot find Hibernate's heuristicType method" , ex2 ) ;
}
}
}
private String filterName ;
private Map < String , Type > parameterTypeMap = new HashMap < String , Type > ( ) ;
@ -89,7 +115,8 @@ public class FilterDefinitionFactoryBean implements FactoryBean<FilterDefinition
@@ -89,7 +115,8 @@ public class FilterDefinitionFactoryBean implements FactoryBean<FilterDefinition
if ( parameterTypes ! = null ) {
this . parameterTypeMap = new HashMap < String , Type > ( parameterTypes . size ( ) ) ;
for ( Map . Entry < String , String > entry : parameterTypes . entrySet ( ) ) {
this . parameterTypeMap . put ( entry . getKey ( ) , TypeFactory . heuristicType ( entry . getValue ( ) ) ) ;
this . parameterTypeMap . put ( entry . getKey ( ) ,
( Type ) ReflectionUtils . invokeMethod ( heuristicTypeMethod , typeResolver , entry . getValue ( ) ) ) ;
}
}
else {