Polishing
Issue: SPR-11291
This commit is contained in:
@@ -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");
|
* 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.
|
||||||
@@ -22,6 +22,7 @@ import org.hibernate.FlushMode;
|
|||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
|
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.dao.DataAccessResourceFailureException;
|
import org.springframework.dao.DataAccessResourceFailureException;
|
||||||
import org.springframework.orm.hibernate4.SessionFactoryUtils;
|
import org.springframework.orm.hibernate4.SessionFactoryUtils;
|
||||||
@@ -77,23 +78,29 @@ public class OpenSessionInViewInterceptor implements AsyncWebRequestInterceptor
|
|||||||
private SessionFactory sessionFactory;
|
private SessionFactory sessionFactory;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Hibernate SessionFactory that should be used to create
|
||||||
|
* Hibernate Sessions.
|
||||||
|
*/
|
||||||
public void setSessionFactory(SessionFactory sessionFactory) {
|
public void setSessionFactory(SessionFactory sessionFactory) {
|
||||||
this.sessionFactory = sessionFactory;
|
this.sessionFactory = sessionFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the Hibernate SessionFactory that should be used to create
|
||||||
|
* Hibernate Sessions.
|
||||||
|
*/
|
||||||
public SessionFactory getSessionFactory() {
|
public SessionFactory getSessionFactory() {
|
||||||
return this.sessionFactory;
|
return this.sessionFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a new Hibernate {@code Session} according to the settings of this
|
* Open a new Hibernate {@code Session} according and bind it to the thread via the
|
||||||
* {@code HibernateAccessor} and bind it to the thread via the
|
|
||||||
* {@link org.springframework.transaction.support.TransactionSynchronizationManager}.
|
* {@link org.springframework.transaction.support.TransactionSynchronizationManager}.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void preHandle(WebRequest request) throws DataAccessException {
|
public void preHandle(WebRequest request) throws DataAccessException {
|
||||||
|
|
||||||
String participateAttributeName = getParticipateAttributeName();
|
String participateAttributeName = getParticipateAttributeName();
|
||||||
|
|
||||||
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
|
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package org.springframework.orm.hibernate3;
|
package org.springframework.orm.hibernate3;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.hibernate.ConnectionReleaseMode;
|
import org.hibernate.ConnectionReleaseMode;
|
||||||
@@ -30,6 +29,7 @@ import org.hibernate.SessionFactory;
|
|||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.exception.GenericJDBCException;
|
import org.hibernate.exception.GenericJDBCException;
|
||||||
import org.hibernate.impl.SessionImpl;
|
import org.hibernate.impl.SessionImpl;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.beans.factory.BeanFactoryAware;
|
import org.springframework.beans.factory.BeanFactoryAware;
|
||||||
@@ -110,7 +110,7 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
|
|||||||
* support nested transactions! Hence, do not expect Hibernate access code to
|
* support nested transactions! Hence, do not expect Hibernate access code to
|
||||||
* semantically participate in a nested transaction.</i>
|
* semantically participate in a nested transaction.</i>
|
||||||
*
|
*
|
||||||
* <p>Requires Hibernate 3.6 or later, as of Spring 4.0.
|
* <p>Requires Hibernate 3.6.x, as of Spring 4.0.
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @since 1.2
|
* @since 1.2
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ import org.springframework.util.StringUtils;
|
|||||||
* {@link org.springframework.orm.hibernate3.support.OpenSessionInViewFilter} /
|
* {@link org.springframework.orm.hibernate3.support.OpenSessionInViewFilter} /
|
||||||
* {@link org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor}.
|
* {@link org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor}.
|
||||||
*
|
*
|
||||||
* <p>Requires Hibernate 3.6 or later, as of Spring 4.0.
|
* <p>Requires Hibernate 3.6.x, as of Spring 4.0.
|
||||||
* Note that this factory will use "on_close" as default Hibernate connection
|
* Note that this factory will use "on_close" as default Hibernate connection
|
||||||
* release mode, unless in the case of a "jtaTransactionManager" specified,
|
* release mode, unless in the case of a "jtaTransactionManager" specified,
|
||||||
* for the reason that this is appropriate for most Spring-based applications
|
* for the reason that this is appropriate for most Spring-based applications
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import java.util.HashMap;
|
|||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import javax.transaction.Status;
|
import javax.transaction.Status;
|
||||||
import javax.transaction.Transaction;
|
import javax.transaction.Transaction;
|
||||||
@@ -57,6 +56,7 @@ import org.hibernate.exception.DataException;
|
|||||||
import org.hibernate.exception.JDBCConnectionException;
|
import org.hibernate.exception.JDBCConnectionException;
|
||||||
import org.hibernate.exception.LockAcquisitionException;
|
import org.hibernate.exception.LockAcquisitionException;
|
||||||
import org.hibernate.exception.SQLGrammarException;
|
import org.hibernate.exception.SQLGrammarException;
|
||||||
|
|
||||||
import org.springframework.core.NamedThreadLocal;
|
import org.springframework.core.NamedThreadLocal;
|
||||||
import org.springframework.dao.CannotAcquireLockException;
|
import org.springframework.dao.CannotAcquireLockException;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
@@ -91,7 +91,7 @@ import org.springframework.util.Assert;
|
|||||||
* and {@link HibernateTransactionManager}. Can also be used directly in
|
* and {@link HibernateTransactionManager}. Can also be used directly in
|
||||||
* application code.
|
* application code.
|
||||||
*
|
*
|
||||||
* <p>Requires Hibernate 3.6 or later, as of Spring 4.0.
|
* <p>Requires Hibernate 3.6.x, as of Spring 4.0.
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @since 1.2
|
* @since 1.2
|
||||||
@@ -618,10 +618,12 @@ public abstract class SessionFactoryUtils {
|
|||||||
*/
|
*/
|
||||||
public static void applyTransactionTimeout(Criteria criteria, SessionFactory sessionFactory) {
|
public static void applyTransactionTimeout(Criteria criteria, SessionFactory sessionFactory) {
|
||||||
Assert.notNull(criteria, "No Criteria object specified");
|
Assert.notNull(criteria, "No Criteria object specified");
|
||||||
SessionHolder sessionHolder =
|
if (sessionFactory != null) {
|
||||||
(SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
|
SessionHolder sessionHolder =
|
||||||
if (sessionHolder != null && sessionHolder.hasTimeout()) {
|
(SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
|
||||||
criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds());
|
if (sessionHolder != null && sessionHolder.hasTimeout()) {
|
||||||
|
criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,10 +43,7 @@ import org.springframework.util.ClassUtils;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Subclass of Spring's standard LocalSessionFactoryBean for Hibernate,
|
* Subclass of Spring's standard LocalSessionFactoryBean for Hibernate,
|
||||||
* supporting JDK 1.5+ annotation metadata for mappings.
|
* supporting annotation metadata for mappings.
|
||||||
*
|
|
||||||
* <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:
|
* <p>Example for an AnnotationSessionFactoryBean bean definition:
|
||||||
*
|
*
|
||||||
@@ -69,7 +66,7 @@ import org.springframework.util.ClassUtils;
|
|||||||
* <property name="packagesToScan" value="test.package"/>
|
* <property name="packagesToScan" value="test.package"/>
|
||||||
* </bean></pre>
|
* </bean></pre>
|
||||||
*
|
*
|
||||||
* <p>Requires Hibernate 3.6 or later, as of Spring 4.0.
|
* <p>Requires Hibernate 3.6.x, as of Spring 4.0.
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @since 1.2.2
|
* @since 1.2.2
|
||||||
|
|||||||
Reference in New Issue
Block a user