remove the layer-breaking getLobCreator() methods from the Hibernate class

This is in principle a breaking change, but one I consider pretty innocuous,
since I can't imagine why anyone was calling Hibernate.getLobCreator(session)
instead of session.getLobHelper().
This commit is contained in:
Gavin King 2022-01-07 11:17:55 +01:00
parent e331c2870e
commit e02e1e2ffb
7 changed files with 12 additions and 60 deletions

View File

@ -28,20 +28,15 @@ import org.hibernate.collection.spi.PersistentSet;
import org.hibernate.collection.spi.PersistentSortedMap;
import org.hibernate.collection.spi.PersistentSortedSet;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.engine.jdbc.LobCreator;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
/**
* Various utility functions for working with proxies and lazy collection references,
* along with factory methods for obtaining a {@link LobCreator}.
* Various utility functions for working with proxies and lazy collection references.
* <p>
* Operations like {@link #isInitialized(Object)} and {@link #initialize(Object)} are
* of general purpose. But {@link #createDetachedProxy(SessionFactory, Class, Object)}
@ -63,11 +58,7 @@ import org.hibernate.proxy.LazyInitializer;
* the program to intervene in the process of serialization and of deserialization.
*
* @author Gavin King
* @see java.sql.Clob
* @see java.sql.Blob
* @see org.hibernate.type.Type
*/
public final class Hibernate {
/**
* Cannot be instantiated.
@ -112,7 +103,6 @@ public final class Hibernate {
* @param proxy a persistable object, proxy, persistent collection or {@code null}
* @return true if the argument is already initialized, or is not a proxy or collection
*/
@SuppressWarnings("SimplifiableIfStatement")
public static boolean isInitialized(Object proxy) {
if ( proxy instanceof HibernateProxy ) {
return !( (HibernateProxy) proxy ).getHibernateLazyInitializer().isUninitialized();
@ -150,45 +140,6 @@ public final class Hibernate {
return (Class<? extends T>) result;
}
/**
* Obtain a lob creator for the given session.
*
* @param session The session for which to obtain a lob creator
*
* @return The log creator reference
*/
public static LobCreator getLobCreator(Session session) {
return getLobCreator( (SessionImplementor) session );
}
/**
* Obtain a lob creator for the given session.
*
* @param session The session for which to obtain a lob creator
*
* @return The log creator reference
*/
public static LobCreator getLobCreator(SharedSessionContractImplementor session) {
return session.getFactory()
.getServiceRegistry()
.getService( JdbcServices.class )
.getLobCreator( session );
}
/**
* Obtain a lob creator for the given session.
*
* @param session The session for which to obtain a lob creator
*
* @return The log creator reference
*/
public static LobCreator getLobCreator(SessionImplementor session) {
return session.getFactory()
.getServiceRegistry()
.getService( JdbcServices.class )
.getLobCreator( session );
}
/**
* Check if the property is initialized. If the named property does not exist or
* is not persistent, this method always returns {@code true}.

View File

@ -24,7 +24,6 @@ import org.hibernate.CacheMode;
import org.hibernate.EmptyInterceptor;
import org.hibernate.EntityNameResolver;
import org.hibernate.FlushMode;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.Interceptor;
import org.hibernate.LockMode;
@ -57,7 +56,6 @@ import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.procedure.ProcedureCall;
import org.hibernate.procedure.internal.ProcedureCallImpl;
import org.hibernate.procedure.spi.NamedCallableQueryMemento;
import org.hibernate.query.NativeQuery;
import org.hibernate.query.Query;
import org.hibernate.query.criteria.HibernateCriteriaBuilder;
import org.hibernate.query.hql.spi.HqlQueryImplementor;
@ -570,7 +568,10 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
@Override
public LobCreator getLobCreator() {
return Hibernate.getLobCreator( this );
return ( (SharedSessionContractImplementor) this ).getFactory()
.getServiceRegistry()
.getService( JdbcServices.class )
.getLobCreator(this);
}
@Override

View File

@ -702,7 +702,7 @@ public class FetchGraphTest extends BaseNonConfigCoreFunctionalTestCase {
d.setOid( 1 );
byte[] lBytes = "agdfagdfagfgafgsfdgasfdgfgasdfgadsfgasfdgasfdgasdasfdg".getBytes();
Blob lBlob = Hibernate.getLobCreator( session ).createBlob( lBytes );
Blob lBlob = session.getLobCreator().createBlob( lBytes );
d.setBlob( lBlob );
BEntity b1 = new BEntity();

View File

@ -96,7 +96,7 @@ public class ProxyDeletionTest extends BaseNonConfigCoreFunctionalTestCase {
d.setOid( 1 );
byte[] lBytes = "agdfagdfagfgafgsfdgasfdgfgasdfgadsfgasfdgasfdgasdasfdg".getBytes();
Blob lBlob = Hibernate.getLobCreator( session ).createBlob( lBytes );
Blob lBlob = session.getLobCreator().createBlob( lBytes );
d.setBlob( lBlob );
BEntity b1 = new BEntity();

View File

@ -47,9 +47,9 @@ public class HibernateCreateBlobFailedCase extends BaseCoreFunctionalTestCase {
public void testLobCreation() throws SQLException {
Session session = sessionFactory().getCurrentSession();
session.beginTransaction();
Blob blob = Hibernate.getLobCreator( session ).createBlob( new byte[] {} );
Blob blob = session.getLobHelper().createBlob( new byte[] {} );
blob.free();
Clob clob = Hibernate.getLobCreator( session ).createClob( "Steve" );
Clob clob = session.getLobHelper().createClob( "Steve" );
clob.free();
session.getTransaction().commit();
assertFalse( session.isOpen() );

View File

@ -249,12 +249,12 @@ public class NativeQueryResultTypeAutoDiscoveryTest {
doTest(
ClobEntity.class,
Clob.class,
session -> Hibernate.getLobCreator( session ).createClob( "some text" )
session -> session.getLobHelper().createClob( "some text" )
);
doTest(
BlobEntity.class,
Blob.class,
session -> Hibernate.getLobCreator( session ).createBlob( "some text".getBytes() )
session -> session.getLobHelper().createBlob( "some text".getBytes() )
);
}

View File

@ -141,7 +141,7 @@ public class BlobLocatorTest extends BaseCoreFunctionalTestCase {
Session s = openSession();
s.beginTransaction();
LobHolder entity = new LobHolder();
entity.setBlobLocator( Hibernate.getLobCreator( s ).createBlob( original ) );
entity.setBlobLocator( s.getLobHelper().createBlob( original ) );
s.save( entity );
s.getTransaction().commit();
s.close();