mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-17 08:35:13 +00:00
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 @@
|
||||
* @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 SessionFactory getSessionFactory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection close() throws HibernateException {
|
||||
return session.close();
|
||||
public void close() throws HibernateException {
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -389,7 +389,7 @@ public long getTimestamp() {
|
||||
}
|
||||
|
||||
@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 Connection close() throws HibernateException {
|
||||
|
||||
try {
|
||||
if ( !isTransactionCoordinatorShared ) {
|
||||
return jdbcCoordinator.close();
|
||||
jdbcCoordinator.close();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if ( getActionQueue().hasBeforeTransactionActions() || getActionQueue().hasAfterTransactionActions() ) {
|
||||
@ -410,7 +411,7 @@ public Connection close() throws HibernateException {
|
||||
"On close, shared Session had before / after transaction actions that have not yet been processed"
|
||||
);
|
||||
}
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
|
@ -4075,7 +4075,7 @@ public void testNewSessionLifecycle() throws Exception {
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
assertTrue( s.close()==null );
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@ -4489,7 +4489,6 @@ public void testUserProvidedConnection() throws Exception {
|
||||
tx = s.beginTransaction();
|
||||
s.createQuery( "from Fo" ).list();
|
||||
tx.commit();
|
||||
assertTrue( s.close() == c );
|
||||
c.close();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user