Fully upgraded orm.hibernate3 package to require Hibernate 3.6+ now
This commit is contained in:
parent
e11cf5f061
commit
541f3edd9e
|
|
@ -85,8 +85,7 @@ public class FilterDefinitionFactoryBean implements FactoryBean<FilterDefinition
|
|||
/**
|
||||
* Set the parameter types for the filter,
|
||||
* with parameter names as keys and type names as values.
|
||||
* See {@code org.hibernate.type.TypeFactory#heuristicType(String)} (Hibernate 3.x)
|
||||
* or {@code org.hibernate.type.TypeResolver#heuristicType(String)} (Hibernate 4.x)
|
||||
* See {@code org.hibernate.type.TypeResolver#heuristicType(String)}.
|
||||
*/
|
||||
public void setParameterTypes(Map<String, String> parameterTypes) {
|
||||
if (parameterTypes != null) {
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
|
|||
* support nested transactions! Hence, do not expect Hibernate access code to
|
||||
* semantically participate in a nested transaction.</i>
|
||||
*
|
||||
* <p>Requires Hibernate 3.2 or later, as of Spring 3.0.
|
||||
* <p>Requires Hibernate 3.6 or later, as of Spring 4.0.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 1.2
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
|
|
@ -36,9 +36,6 @@ import org.springframework.util.ReflectionUtils;
|
|||
* RegionFactory instance, determined by LocalSessionFactoryBean's
|
||||
* "cacheRegionFactory" property.
|
||||
*
|
||||
* <p>Compatible with Hibernate 3.3 as well as Hibernate 3.5's version
|
||||
* of the RegionFactory SPI.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.0
|
||||
* @see LocalSessionFactoryBean#setCacheRegionFactory
|
||||
|
|
@ -83,13 +80,7 @@ public class LocalRegionFactoryProxy implements RegionFactory {
|
|||
}
|
||||
|
||||
public AccessType getDefaultAccessType() {
|
||||
try {
|
||||
Method method = RegionFactory.class.getMethod("getDefaultAccessType");
|
||||
return (AccessType) ReflectionUtils.invokeMethod(method, this.regionFactory);
|
||||
}
|
||||
catch (NoSuchMethodException ex) {
|
||||
throw new IllegalStateException("getDefaultAccessType requires Hibernate 3.5+");
|
||||
}
|
||||
return this.regionFactory.getDefaultAccessType();
|
||||
}
|
||||
|
||||
public long nextTimestamp() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
|
|
@ -18,7 +18,6 @@ package org.springframework.orm.hibernate3;
|
|||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
|
@ -26,7 +25,6 @@ import java.util.Collection;
|
|||
import java.util.Enumeration;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import javax.transaction.TransactionManager;
|
||||
|
||||
|
|
@ -37,6 +35,7 @@ import org.hibernate.SessionFactory;
|
|||
import org.hibernate.cache.RegionFactory;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.cfg.Mappings;
|
||||
import org.hibernate.cfg.NamingStrategy;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.FilterDefinition;
|
||||
|
|
@ -44,6 +43,7 @@ import org.hibernate.engine.SessionFactoryImplementor;
|
|||
import org.hibernate.event.EventListeners;
|
||||
import org.hibernate.tool.hbm2ddl.DatabaseMetadata;
|
||||
import org.hibernate.transaction.JTATransactionFactory;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
|
@ -53,7 +53,6 @@ import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
|
|||
import org.springframework.jdbc.support.JdbcUtils;
|
||||
import org.springframework.jdbc.support.lob.LobHandler;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
|
|
@ -89,7 +88,7 @@ import org.springframework.util.StringUtils;
|
|||
* {@link org.springframework.orm.hibernate3.support.OpenSessionInViewFilter} /
|
||||
* {@link org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor}.
|
||||
*
|
||||
* <p><b>Requires Hibernate 3.2 or later; tested with 3.3, 3.5 and 3.6.</b>
|
||||
* <p><b>Requires Hibernate 3.6 or later.</b>
|
||||
* Note that this factory will use "on_close" as default Hibernate connection
|
||||
* release mode, unless in the case of a "jtaTransactionManager" specified,
|
||||
* for the reason that this is appropriate for most Spring-based applications
|
||||
|
|
@ -583,15 +582,9 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
|
|||
|
||||
if (this.typeDefinitions != null) {
|
||||
// Register specified Hibernate type definitions.
|
||||
// Use reflection for compatibility with both Hibernate 3.3 and 3.5:
|
||||
// the returned Mappings object changed from a class to an interface.
|
||||
Method createMappings = Configuration.class.getMethod("createMappings");
|
||||
Method addTypeDef = createMappings.getReturnType().getMethod(
|
||||
"addTypeDef", String.class, String.class, Properties.class);
|
||||
Object mappings = ReflectionUtils.invokeMethod(createMappings, config);
|
||||
Mappings mappings = config.createMappings();
|
||||
for (TypeDefinitionBean typeDef : this.typeDefinitions) {
|
||||
ReflectionUtils.invokeMethod(addTypeDef, mappings,
|
||||
typeDef.getTypeName(), typeDef.getTypeClass(), typeDef.getParameters());
|
||||
mappings.addTypeDef(typeDef.getTypeName(), typeDef.getTypeClass(), typeDef.getParameters());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -628,8 +621,7 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
|
|||
|
||||
if (this.cacheRegionFactory != null) {
|
||||
// Expose Spring-provided Hibernate RegionFactory.
|
||||
config.setProperty(Environment.CACHE_REGION_FACTORY,
|
||||
"org.springframework.orm.hibernate3.LocalRegionFactoryProxy");
|
||||
config.setProperty(Environment.CACHE_REGION_FACTORY, LocalRegionFactoryProxy.class.getName());
|
||||
}
|
||||
|
||||
if (this.mappingResources != null) {
|
||||
|
|
@ -685,12 +677,7 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
|
|||
String[] strategyAndRegion =
|
||||
StringUtils.commaDelimitedListToStringArray(this.entityCacheStrategies.getProperty(className));
|
||||
if (strategyAndRegion.length > 1) {
|
||||
// method signature declares return type as Configuration on Hibernate 3.6
|
||||
// but as void on Hibernate 3.3 and 3.5
|
||||
Method setCacheConcurrencyStrategy = Configuration.class.getMethod(
|
||||
"setCacheConcurrencyStrategy", String.class, String.class, String.class);
|
||||
ReflectionUtils.invokeMethod(setCacheConcurrencyStrategy, config,
|
||||
className, strategyAndRegion[0], strategyAndRegion[1]);
|
||||
config.setCacheConcurrencyStrategy(className, strategyAndRegion[0], strategyAndRegion[1]);
|
||||
}
|
||||
else if (strategyAndRegion.length > 0) {
|
||||
config.setCacheConcurrencyStrategy(className, strategyAndRegion[0]);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import javax.persistence.MappedSuperclass;
|
|||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.cfg.AnnotationConfiguration;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
import org.springframework.context.ResourceLoaderAware;
|
||||
|
|
@ -44,8 +43,8 @@ import org.springframework.util.ClassUtils;
|
|||
* Subclass of Spring's standard LocalSessionFactoryBean for Hibernate,
|
||||
* supporting JDK 1.5+ annotation metadata for mappings.
|
||||
*
|
||||
* <p>Note: This class requires Hibernate 3.2 or later, with the
|
||||
* Java Persistence API and the Hibernate Annotations add-on present.
|
||||
* <p>Note: As of Spring 4.0, this class requires Hibernate 3.6 or later,
|
||||
* with the Java Persistence API present.
|
||||
*
|
||||
* <p>Example for an AnnotationSessionFactoryBean bean definition:
|
||||
*
|
||||
|
|
@ -97,24 +96,10 @@ public class AnnotationSessionFactoryBean extends LocalSessionFactoryBean implem
|
|||
private ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
|
||||
|
||||
|
||||
public AnnotationSessionFactoryBean() {
|
||||
setConfigurationClass(AnnotationConfiguration.class);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setConfigurationClass(Class<?> configurationClass) {
|
||||
if (configurationClass == null || !AnnotationConfiguration.class.isAssignableFrom(configurationClass)) {
|
||||
throw new IllegalArgumentException(
|
||||
"AnnotationSessionFactoryBean only supports AnnotationConfiguration or subclasses");
|
||||
}
|
||||
super.setConfigurationClass(configurationClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify annotated classes, for which mappings will be read from
|
||||
* class-level JDK 1.5+ annotation metadata.
|
||||
* @see org.hibernate.cfg.AnnotationConfiguration#addAnnotatedClass(Class)
|
||||
* @see org.hibernate.cfg.Configuration#addAnnotatedClass(Class)
|
||||
*/
|
||||
public void setAnnotatedClasses(Class[] annotatedClasses) {
|
||||
this.annotatedClasses = annotatedClasses;
|
||||
|
|
@ -123,7 +108,7 @@ public class AnnotationSessionFactoryBean extends LocalSessionFactoryBean implem
|
|||
/**
|
||||
* Specify the names of annotated packages, for which package-level
|
||||
* JDK 1.5+ annotation metadata will be read.
|
||||
* @see org.hibernate.cfg.AnnotationConfiguration#addPackage(String)
|
||||
* @see org.hibernate.cfg.Configuration#addPackage(String)
|
||||
*/
|
||||
public void setAnnotatedPackages(String[] annotatedPackages) {
|
||||
this.annotatedPackages = annotatedPackages;
|
||||
|
|
@ -163,25 +148,24 @@ public class AnnotationSessionFactoryBean extends LocalSessionFactoryBean implem
|
|||
*/
|
||||
@Override
|
||||
protected void postProcessMappings(Configuration config) throws HibernateException {
|
||||
AnnotationConfiguration annConfig = (AnnotationConfiguration) config;
|
||||
if (this.annotatedClasses != null) {
|
||||
for (Class annotatedClass : this.annotatedClasses) {
|
||||
annConfig.addAnnotatedClass(annotatedClass);
|
||||
config.addAnnotatedClass(annotatedClass);
|
||||
}
|
||||
}
|
||||
if (this.annotatedPackages != null) {
|
||||
for (String annotatedPackage : this.annotatedPackages) {
|
||||
annConfig.addPackage(annotatedPackage);
|
||||
config.addPackage(annotatedPackage);
|
||||
}
|
||||
}
|
||||
scanPackages(annConfig);
|
||||
scanPackages(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform Spring-based scanning for entity classes.
|
||||
* @see #setPackagesToScan
|
||||
*/
|
||||
protected void scanPackages(AnnotationConfiguration config) {
|
||||
protected void scanPackages(Configuration config) {
|
||||
if (this.packagesToScan != null) {
|
||||
try {
|
||||
for (String pkg : this.packagesToScan) {
|
||||
|
|
@ -227,27 +211,4 @@ public class AnnotationSessionFactoryBean extends LocalSessionFactoryBean implem
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This default implementation delegates to {@link #postProcessAnnotationConfiguration}.
|
||||
*/
|
||||
@Override
|
||||
protected void postProcessConfiguration(Configuration config) throws HibernateException {
|
||||
postProcessAnnotationConfiguration((AnnotationConfiguration) config);
|
||||
}
|
||||
|
||||
/**
|
||||
* To be implemented by subclasses which want to to perform custom
|
||||
* post-processing of the AnnotationConfiguration object after this
|
||||
* FactoryBean performed its default initialization.
|
||||
* <p>Note: As of Hibernate 3.6, AnnotationConfiguration's features
|
||||
* have been rolled into Configuration itself. Simply overriding
|
||||
* {@link #postProcessConfiguration(org.hibernate.cfg.Configuration)}
|
||||
* becomes an option as well then.
|
||||
* @param config the current AnnotationConfiguration object
|
||||
* @throws HibernateException in case of Hibernate initialization errors
|
||||
*/
|
||||
protected void postProcessAnnotationConfiguration(AnnotationConfiguration config) throws HibernateException {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue