FilterDefinitionFactoryBean supports Hibernate 3.6.0.beta1 as well
This commit is contained in:
parent
d3cb310962
commit
72da237474
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.orm.hibernate3;
|
package org.springframework.orm.hibernate3;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -26,6 +27,7 @@ import org.hibernate.type.TypeFactory;
|
||||||
import org.springframework.beans.factory.BeanNameAware;
|
import org.springframework.beans.factory.BeanNameAware;
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenient FactoryBean for defining Hibernate FilterDefinitions.
|
* Convenient FactoryBean for defining Hibernate FilterDefinitions.
|
||||||
|
|
@ -64,6 +66,30 @@ import org.springframework.beans.factory.InitializingBean;
|
||||||
*/
|
*/
|
||||||
public class FilterDefinitionFactoryBean implements FactoryBean<FilterDefinition>, BeanNameAware, 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 String filterName;
|
||||||
|
|
||||||
private Map<String, Type> parameterTypeMap = new HashMap<String, Type>();
|
private Map<String, Type> parameterTypeMap = new HashMap<String, Type>();
|
||||||
|
|
@ -89,7 +115,8 @@ public class FilterDefinitionFactoryBean implements FactoryBean<FilterDefinition
|
||||||
if (parameterTypes != null) {
|
if (parameterTypes != null) {
|
||||||
this.parameterTypeMap = new HashMap<String, Type>(parameterTypes.size());
|
this.parameterTypeMap = new HashMap<String, Type>(parameterTypes.size());
|
||||||
for (Map.Entry<String, String> entry : parameterTypes.entrySet()) {
|
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 {
|
else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue