HHH-8898 Change the Session API to enable auto-closeable when running on Java7
This commit is contained in:
parent
f3399926db
commit
7c006f7fcd
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue