remove Session.disconnect()/reconnect()

this stuff is so old and so bad that it's not even worth deprecating
This commit is contained in:
Gavin King 2021-12-09 16:13:01 +01:00 committed by Steve Ebersole
parent 042bd47825
commit 6177210395
10 changed files with 11 additions and 62 deletions

View File

@ -7,7 +7,6 @@
package org.hibernate;
import java.io.Closeable;
import java.sql.Connection;
import java.util.List;
import jakarta.persistence.EntityGraph;
import jakarta.persistence.EntityManager;
@ -962,31 +961,6 @@ public interface Session extends SharedSessionContract, EntityManager, AutoClose
return (List) getSessionFactory().findEntityGraphsByType( entityClass );
}
/**
* Disconnect the session from its underlying JDBC connection. This is intended for use in cases where the
* application has supplied the JDBC connection to the session and which require long-sessions (aka, conversations).
* <p/>
* It is considered an error to call this method on a session which was not opened by supplying the JDBC connection
* and an exception will be thrown.
* <p/>
* For non-user-supplied scenarios, normal transaction management already handles disconnection and reconnection
* automatically.
*
* @return the application-supplied connection or {@code null}
*
* @see #reconnect(Connection)
*/
Connection disconnect();
/**
* Reconnect to the given JDBC connection.
*
* @param connection a JDBC connection
*
* @see #disconnect()
*/
void reconnect(Connection connection);
/**
* Is a particular fetch profile enabled on this session?
*

View File

@ -335,13 +335,10 @@ public class ThreadLocalSessionContext extends AbstractCurrentSessionContext {
|| "setHibernateFlushMode".equals( methodName )
|| "getFactory".equals( methodName )
|| "getSessionFactory".equals( methodName )
|| "getJdbcCoordinator".equals( methodName )
|| "getTenantIdentifier".equals( methodName ) ) {
LOG.tracef( "Allowing invocation [%s] to proceed to real (non-transacted) session", methodName );
}
else if ( "reconnect".equals( methodName ) || "disconnect".equals( methodName ) ) {
// allow these (deprecated) methods to pass through
LOG.tracef( "Allowing invocation [%s] to proceed to real (non-transacted) session - deprecated methods", methodName );
}
else {
throw new HibernateException( "Calling method '" + methodName + "' is not valid without an active transaction (Current status: "
+ realSession.getTransaction().getStatus() + ")" );

View File

@ -987,16 +987,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
return delegate.doReturningWork( work );
}
@Override
public Connection disconnect() {
return delegate.disconnect();
}
@Override
public void reconnect(Connection connection) {
delegate.reconnect( connection );
}
@Override
public boolean isFetchProfileEnabled(String name) throws UnknownProfileException {
return delegate.isFetchProfileEnabled( name );

View File

@ -14,7 +14,6 @@ import java.io.Reader;
import java.io.Serializable;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.NClob;
import java.sql.SQLException;
import java.util.Collections;
@ -487,21 +486,6 @@ public class SessionImpl
closeWithoutOpenChecks();
}
@Override
public Connection disconnect() throws HibernateException {
checkOpen();
log.debug( "Disconnecting session" );
return getJdbcCoordinator().getLogicalConnection().manualDisconnect();
}
@Override
public void reconnect(Connection conn) throws HibernateException {
checkOpen();
log.debug( "Reconnecting session" );
checkTransactionSynchStatus();
getJdbcCoordinator().getLogicalConnection().manualReconnect( conn );
}
@Override
public void setAutoClear(boolean enabled) {
checkOpenOrWaitingForAutoClose();

View File

@ -6,7 +6,6 @@
*/
package org.hibernate.internal;
import java.sql.Connection;
import java.util.Set;
import org.hibernate.CacheMode;

View File

@ -8,6 +8,7 @@ package org.hibernate.orm.test.connections;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.internal.util.SerializationHelper;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
@ -91,7 +92,7 @@ public abstract class ConnectionManagementTestCase extends BaseNonConfigCoreFunc
}
protected void disconnect(Session session) throws Throwable {
session.disconnect();
((SessionImplementor)session).getJdbcCoordinator().getLogicalConnection().manualDisconnect();
}
/**

View File

@ -17,6 +17,7 @@ import org.hibernate.cfg.Environment;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.service.spi.Stoppable;
import org.hibernate.tool.schema.internal.SchemaCreatorImpl;
@ -68,7 +69,7 @@ public class SuppliedConnectionTest extends ConnectionManagementTestCase {
@Override
protected void reconnect(Session session) {
session.reconnect( connectionUnderTest );
((SessionImplementor)session).getJdbcCoordinator().getLogicalConnection().manualReconnect( connectionUnderTest );
}
@Override

View File

@ -17,6 +17,7 @@ import jakarta.persistence.EntityManagerFactory;
import org.hibernate.Session;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.orm.test.jpa.Cat;
import org.hibernate.orm.test.jpa.Distributor;
import org.hibernate.orm.test.jpa.Item;
@ -77,7 +78,7 @@ public class EntityManagerFactorySerializationTest {
//em.getTransaction().commit();
//fake the in container work
em.unwrap( Session.class ).disconnect();
em.unwrap( SessionImplementor.class ).getJdbcCoordinator().getLogicalConnection().manualDisconnect();
stream = new ByteArrayOutputStream();
out = new ObjectOutputStream( stream );
out.writeObject( em );

View File

@ -14,6 +14,7 @@ import java.io.ObjectOutputStream;
import java.util.Date;
import org.hibernate.Session;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.orm.test.jpa.Cat;
import org.hibernate.orm.test.jpa.Distributor;
import org.hibernate.orm.test.jpa.Item;
@ -63,7 +64,7 @@ public class EntityManagerSerializationTest {
item.setDescr( "Paris-Bruxelles" );
//fake the in container work
em.unwrap( Session.class ).disconnect();
em.unwrap( SessionImplementor.class ).getJdbcCoordinator().getLogicalConnection().manualDisconnect();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream( stream );
out.writeObject( em );

View File

@ -19,6 +19,7 @@ import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.internal.SessionImpl;
import org.hibernate.internal.util.SerializationHelper;
import org.hibernate.proxy.HibernateProxy;
@ -180,7 +181,7 @@ public class ProxyTest extends BaseCoreFunctionalTestCase {
assertFalse( Hibernate.isInitialized(none) );
t.commit();
s.disconnect();
s.unwrap( SessionImplementor.class ).getJdbcCoordinator().getLogicalConnection().manualDisconnect();
Object[] holder = new Object[] { s, dp, none };