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
|
* @see SessionFactory
|
||||||
* @author Gavin King
|
* @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.
|
* 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
|
* not strictly necessary to close the session but you must at least
|
||||||
* {@link #disconnect()} it.
|
* {@link #disconnect()} it.
|
||||||
*
|
*
|
||||||
* @return the connection provided by the application or null.
|
|
||||||
* @throws HibernateException Indicates problems cleaning up.
|
* @throws HibernateException Indicates problems cleaning up.
|
||||||
*/
|
*/
|
||||||
public Connection close() throws HibernateException;
|
public void close() throws HibernateException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel the execution of the current query.
|
* Cancel the execution of the current query.
|
||||||
|
|
|
@ -473,8 +473,8 @@ public class SessionDelegatorBaseImpl implements SessionImplementor, Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Connection close() throws HibernateException {
|
public void close() throws HibernateException {
|
||||||
return session.close();
|
session.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -389,7 +389,7 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Connection close() throws HibernateException {
|
public void close() throws HibernateException {
|
||||||
LOG.trace( "Closing session" );
|
LOG.trace( "Closing session" );
|
||||||
if ( isClosed() ) {
|
if ( isClosed() ) {
|
||||||
throw new SessionException( "Session was already closed" );
|
throw new SessionException( "Session was already closed" );
|
||||||
|
@ -402,7 +402,8 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ( !isTransactionCoordinatorShared ) {
|
if ( !isTransactionCoordinatorShared ) {
|
||||||
return jdbcCoordinator.close();
|
jdbcCoordinator.close();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ( getActionQueue().hasBeforeTransactionActions() || getActionQueue().hasAfterTransactionActions() ) {
|
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"
|
"On close, shared Session had before / after transaction actions that have not yet been processed"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return null;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
|
|
@ -4075,7 +4075,7 @@ public class FooBarTest extends LegacyTestCase {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
assertTrue( s.close()==null );
|
s.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4489,7 +4489,6 @@ public class FooBarTest extends LegacyTestCase {
|
||||||
tx = s.beginTransaction();
|
tx = s.beginTransaction();
|
||||||
s.createQuery( "from Fo" ).list();
|
s.createQuery( "from Fo" ).list();
|
||||||
tx.commit();
|
tx.commit();
|
||||||
assertTrue( s.close() == c );
|
|
||||||
c.close();
|
c.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue