HHH-16651 promote new operations from SessionBuilder to Session

setFetchBatchSize() and setSubselectFetchEnabled()
This commit is contained in:
Gavin 2023-05-23 01:12:08 +02:00 committed by Gavin King
parent 6215a8ef42
commit 3be2dc5978
11 changed files with 106 additions and 91 deletions

View File

@ -272,6 +272,59 @@ public interface Session extends SharedSessionContract, EntityManager {
*/
void setCacheRetrieveMode(CacheRetrieveMode cacheRetrieveMode);
/**
* Get the maximum batch size for batch fetching associations by
* id in this session.
*
* @since 6.3
*/
int getFetchBatchSize();
/**
* Set the maximum batch size for batch fetching associations by
* id in this session. Override the
* {@linkplain org.hibernate.boot.spi.SessionFactoryOptions#getDefaultBatchFetchSize()
* factory-level} default controlled by the configuration property
* {@value org.hibernate.cfg.AvailableSettings#DEFAULT_BATCH_FETCH_SIZE}.
* <p>
* <ul>
* <li>If {@code batchSize>1}, then batch fetching is enabled.
* <li>If {@code batchSize<0}, the batch size is inherited from
* the factory-level setting.
* <li>Otherwise, batch fetching is disabled.
* </ul>
*
* @param batchSize the maximum batch size for batch fetching
*
* @since 6.3
*
* @see org.hibernate.cfg.AvailableSettings#DEFAULT_BATCH_FETCH_SIZE
*/
void setFetchBatchSize(int batchSize);
/**
* Determine if subselect fetching is enabled in this session.
*
* @return {@code true} is subselect fetching is enabled
*
* @since 6.3
*/
boolean isSubselectFetchingEnabled();
/**
* Enable or disable subselect fetching in this session. Override the
* {@linkplain org.hibernate.boot.spi.SessionFactoryOptions#isSubselectFetchEnabled()
* factory-level} default controlled by the configuration property
* {@value org.hibernate.cfg.AvailableSettings#USE_SUBSELECT_FETCH}.
*
* @param enabled {@code true} to enable subselect fetching
*
* @since 6.3
*
* @see org.hibernate.cfg.AvailableSettings#USE_SUBSELECT_FETCH
*/
void setSubselectFetchingEnabled(boolean enabled);
/**
* Get the session factory which created this session.
*

View File

@ -145,8 +145,4 @@ public interface SessionBuilder {
* @see jakarta.persistence.PersistenceContextType
*/
SessionBuilder autoClose(boolean autoClose);
SessionBuilder defaultBatchFetchSize(int batchSize);
SessionBuilder subselectFetchEnabled(boolean enabled);
}

View File

@ -60,10 +60,6 @@ public interface SharedSessionBuilder extends SessionBuilder {
*/
SharedSessionBuilder flushMode();
SharedSessionBuilder defaultBatchFetchSize();
SharedSessionBuilder subselectFetchEnabled();
/**
* Signifies that the autoClose flag from the original session should be used to create the new session.
*
@ -88,10 +84,4 @@ public interface SharedSessionBuilder extends SessionBuilder {
@Override
SharedSessionBuilder autoClose(boolean autoClose);
@Override
SharedSessionBuilder defaultBatchFetchSize(int batchSize);
@Override
SharedSessionBuilder subselectFetchEnabled(boolean enabled);
}

View File

@ -185,15 +185,16 @@ public interface SharedSessionContract extends QueryProducer, Closeable, Seriali
Integer getJdbcBatchSize();
/**
* Set the session-level JDBC batch size. Overrides the
* {@link org.hibernate.boot.spi.SessionFactoryOptions#getJdbcBatchSize() factory-level}
* JDBC batch size defined by the configuration property
* Set the session-level JDBC batch size. Override the
* {@linkplain org.hibernate.boot.spi.SessionFactoryOptions#getJdbcBatchSize() factory-level}
* JDBC batch size controlled by the configuration property
* {@value org.hibernate.cfg.AvailableSettings#STATEMENT_BATCH_SIZE}.
*
* @param jdbcBatchSize the new session-level JDBC batch size
*
* @since 5.2
*
* @see org.hibernate.cfg.AvailableSettings#STATEMENT_BATCH_SIZE
* @see org.hibernate.boot.spi.SessionFactoryOptions#getJdbcBatchSize
* @see org.hibernate.boot.SessionFactoryBuilder#applyJdbcBatchSize
*/

View File

@ -1033,6 +1033,7 @@ public interface AvailableSettings {
* collections explicitly annotated {@code @BatchSize}.
*
* @see org.hibernate.annotations.BatchSize
* @see org.hibernate.Session#setFetchBatchSize(int)
* @see org.hibernate.boot.SessionFactoryBuilder#applyDefaultBatchFetchSize(int)
*/
String DEFAULT_BATCH_FETCH_SIZE = "hibernate.default_batch_fetch_size";
@ -1045,6 +1046,7 @@ public interface AvailableSettings {
* explicitly annotated {@code @Fetch(SUBSELECT)}.
*
* @see org.hibernate.annotations.FetchMode#SUBSELECT
* @see org.hibernate.Session#setSubselectFetchingEnabled(boolean)
* @see org.hibernate.boot.SessionFactoryBuilder#applySubselectFetchEnabled(boolean)
*/
String USE_SUBSELECT_FETCH = "hibernate.use_subselect_fetch";

View File

@ -122,16 +122,4 @@ public abstract class AbstractDelegatingSessionBuilder implements SessionBuilder
delegate.flushMode( flushMode );
return this;
}
@Override
public SessionBuilder defaultBatchFetchSize(int batchSize) {
delegate.defaultBatchFetchSize( batchSize );
return this;
}
@Override
public SessionBuilder subselectFetchEnabled(boolean enabled) {
delegate.subselectFetchEnabled( enabled );
return this;
}
}

View File

@ -164,28 +164,4 @@ public abstract class AbstractDelegatingSharedSessionBuilder implements SharedSe
delegate.jdbcTimeZone( timeZone );
return this;
}
@Override
public SharedSessionBuilder defaultBatchFetchSize(int batchSize) {
delegate.defaultBatchFetchSize( batchSize );
return this;
}
@Override
public SharedSessionBuilder subselectFetchEnabled(boolean enabled) {
delegate.subselectFetchEnabled( enabled );
return this;
}
@Override
public SharedSessionBuilder defaultBatchFetchSize() {
delegate.defaultBatchFetchSize();
return this;
}
@Override
public SharedSessionBuilder subselectFetchEnabled() {
delegate.subselectFetchEnabled();
return this;
}
}

View File

@ -1201,6 +1201,26 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
delegate.setJdbcBatchSize( jdbcBatchSize );
}
@Override
public boolean isSubselectFetchingEnabled() {
return delegate.isSubselectFetchingEnabled();
}
@Override
public void setSubselectFetchingEnabled(boolean enabled) {
delegate.setSubselectFetchingEnabled( enabled );
}
@Override
public int getFetchBatchSize() {
return delegate.getFetchBatchSize();
}
@Override
public void setFetchBatchSize(int batchSize) {
delegate.setFetchBatchSize( batchSize );
}
@Override
public TimeZone getJdbcTimeZone() {
return delegate.getJdbcTimeZone();

View File

@ -659,6 +659,26 @@ public class SessionLazyDelegator implements Session {
this.lazySession.get().setJdbcBatchSize( jdbcBatchSize );
}
@Override
public int getFetchBatchSize() {
return this.lazySession.get().getFetchBatchSize();
}
@Override
public void setFetchBatchSize(int batchSize) {
this.lazySession.get().setFetchBatchSize( batchSize );
}
@Override
public boolean isSubselectFetchingEnabled() {
return this.lazySession.get().isSubselectFetchingEnabled();
}
@Override
public void setSubselectFetchingEnabled(boolean enabled) {
this.lazySession.get().setSubselectFetchingEnabled( enabled );
}
@Override
public HibernateCriteriaBuilder getCriteriaBuilder() {
return this.lazySession.get().getCriteriaBuilder();

View File

@ -31,7 +31,6 @@ import org.hibernate.HibernateException;
import org.hibernate.Interceptor;
import org.hibernate.MappingException;
import org.hibernate.Session;
import org.hibernate.SessionBuilder;
import org.hibernate.SessionEventListener;
import org.hibernate.SessionFactory;
import org.hibernate.SessionFactoryObserver;
@ -1360,18 +1359,6 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
return this;
}
@Override
public SessionBuilder defaultBatchFetchSize(int batchSize) {
defaultBatchFetchSize = batchSize;
return this;
}
@Override
public SessionBuilder subselectFetchEnabled(boolean enabled) {
subselectFetchEnabled = enabled;
return null;
}
@Override
public SessionBuilderImpl flushMode(FlushMode flushMode) {
this.flushMode = flushMode;

View File

@ -1939,20 +1939,22 @@ public class SessionImpl
loadQueryInfluencers.disableFetchProfile( name );
}
// TODO: unused for now, should we promote to Session?
@Override
public void setSubselectFetchingEnabled(boolean enabled) {
loadQueryInfluencers.setSubselectFetchEnabled( enabled );
}
@Override
public boolean isSubselectFetchingEnabled() {
return loadQueryInfluencers.getSubselectFetchEnabled();
}
// TODO: unused for now, should we promote to Session?
@Override
public void setFetchBatchSize(int batchSize) {
loadQueryInfluencers.setBatchSize( batchSize );
}
@Override
public int getFetchBatchSize() {
return loadQueryInfluencers.getBatchSize();
}
@ -2065,7 +2067,9 @@ public class SessionImpl
}
}
private static class SharedSessionBuilderImpl extends SessionFactoryImpl.SessionBuilderImpl implements SharedSessionBuilder, SharedSessionCreationOptions {
private static class SharedSessionBuilderImpl
extends SessionFactoryImpl.SessionBuilderImpl
implements SharedSessionBuilder, SharedSessionCreationOptions {
private final SessionImpl session;
private boolean shareTransactionContext;
@ -2156,28 +2160,6 @@ public class SessionImpl
return this;
}
@Override
public SharedSessionBuilderImpl defaultBatchFetchSize(int batchSize) {
super.defaultBatchFetchSize( batchSize );
return this;
}
@Override
public SharedSessionBuilderImpl subselectFetchEnabled(boolean enabled) {
super.subselectFetchEnabled( enabled );
return this;
}
@Override
public SharedSessionBuilder defaultBatchFetchSize() {
return defaultBatchFetchSize( session.getFetchBatchSize() );
}
@Override
public SharedSessionBuilder subselectFetchEnabled() {
return subselectFetchEnabled( session.isSubselectFetchingEnabled() );
}
@Override
public SharedSessionBuilderImpl autoClose() {
autoClose( session.autoClose );