HHH-8898 Change the Session API to enable auto-closeable when running on Java7

This commit is contained in:
Sanne Grinovero 2015-05-09 12:59:23 +01:00
parent f3399926db
commit 7c006f7fcd
4 changed files with 9 additions and 10 deletions

View File

@ -89,7 +89,7 @@ import org.hibernate.stat.SessionStatistics;
* @see SessionFactory
* @author Gavin King
*/
public interface Session extends SharedSessionContract {
public interface Session extends SharedSessionContract, java.io.Closeable {
/**
* Obtain a {@link Session} builder with the ability to grab certain information from this session.
*
@ -164,10 +164,9 @@ public interface Session extends SharedSessionContract {
* not strictly necessary to close the session but you must at least
* {@link #disconnect()} it.
*
* @return the connection provided by the application or null.
* @throws HibernateException Indicates problems cleaning up.
*/
public Connection close() throws HibernateException;
public void close() throws HibernateException;
/**
* Cancel the execution of the current query.

View File

@ -473,8 +473,8 @@ public class SessionDelegatorBaseImpl implements SessionImplementor, Session {
}
@Override
public Connection close() throws HibernateException {
return session.close();
public void close() throws HibernateException {
session.close();
}
@Override

View File

@ -389,7 +389,7 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
}
@Override
public Connection close() throws HibernateException {
public void close() throws HibernateException {
LOG.trace( "Closing session" );
if ( isClosed() ) {
throw new SessionException( "Session was already closed" );
@ -402,7 +402,8 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
try {
if ( !isTransactionCoordinatorShared ) {
return jdbcCoordinator.close();
jdbcCoordinator.close();
return;
}
else {
if ( getActionQueue().hasBeforeTransactionActions() || getActionQueue().hasAfterTransactionActions() ) {
@ -410,7 +411,7 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
"On close, shared Session had before / after transaction actions that have not yet been processed"
);
}
return null;
return;
}
}
finally {

View File

@ -4075,7 +4075,7 @@ public class FooBarTest extends LegacyTestCase {
throw e;
}
finally {
assertTrue( s.close()==null );
s.close();
}
}
@ -4489,7 +4489,6 @@ public class FooBarTest extends LegacyTestCase {
tx = s.beginTransaction();
s.createQuery( "from Fo" ).list();
tx.commit();
assertTrue( s.close() == c );
c.close();
}