Skip to content

adapt to changes in core to use SharedSessionContractImplementor #2180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import org.hibernate.sql.results.jdbc.spi.JdbcValuesSourceProcessingOptions;
import org.hibernate.type.descriptor.WrapperOptions;

import static org.hibernate.generator.internal.NaturalIdHelper.getNaturalIdPropertyNames;
import static org.hibernate.internal.NaturalIdHelper.getNaturalIdPropertyNames;
import static org.hibernate.generator.values.internal.GeneratedValuesHelper.noCustomSql;
import static org.hibernate.reactive.sql.results.spi.ReactiveListResultsConsumer.UniqueSemantic.NONE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.concurrent.CompletionStage;

import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.event.spi.EventSource;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.loader.ast.spi.MultiIdLoadOptions;
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
import org.hibernate.metamodel.mapping.EntityMappingType;
Expand Down Expand Up @@ -50,16 +50,16 @@ public EntityMappingType getLoadable() {
}

@Override
public final <K> CompletionStage<List<T>> reactiveLoad(K[] ids, MultiIdLoadOptions loadOptions, EventSource session) {
public final <K> CompletionStage<List<T>> reactiveLoad(K[] ids, MultiIdLoadOptions loadOptions, SharedSessionContractImplementor session) {
Objects.requireNonNull( ids );

return loadOptions.isOrderReturnEnabled()
? performOrderedMultiLoad( ids, loadOptions, session )
: performUnorderedMultiLoad( ids, loadOptions, session );
}

protected abstract <K> CompletionStage<List<T>> performOrderedMultiLoad(K[] ids, MultiIdLoadOptions loadOptions, EventSource session);
protected abstract <K> CompletionStage<List<T>> performOrderedMultiLoad(K[] ids, MultiIdLoadOptions loadOptions, SharedSessionContractImplementor session);

protected abstract <K> CompletionStage<List<T>> performUnorderedMultiLoad(K[] ids, MultiIdLoadOptions loadOptions, EventSource session);
protected abstract <K> CompletionStage<List<T>> performUnorderedMultiLoad(K[] ids, MultiIdLoadOptions loadOptions, SharedSessionContractImplementor session);

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.engine.spi.SubselectFetch;
import org.hibernate.event.spi.EventSource;
import org.hibernate.loader.ast.internal.LoaderSelectBuilder;
import org.hibernate.loader.ast.internal.MultiIdEntityLoaderArrayParam;
import org.hibernate.loader.ast.internal.MultiKeyLoadLogging;
Expand Down Expand Up @@ -82,7 +82,7 @@ public BasicEntityIdentifierMapping getIdentifierMapping() {
protected <K> CompletionStage<List<E>> performOrderedMultiLoad(
K[] ids,
MultiIdLoadOptions loadOptions,
EventSource session) {
SharedSessionContractImplementor session) {
if ( MultiKeyLoadLogging.MULTI_KEY_LOAD_LOGGER.isTraceEnabled() ) {
MultiKeyLoadLogging.MULTI_KEY_LOAD_LOGGER.tracef(
"ReactiveMultiIdEntityLoaderArrayParam#performOrderedMultiLoad - %s",
Expand Down Expand Up @@ -227,7 +227,7 @@ protected <K> CompletionStage<List<E>> performOrderedMultiLoad(
protected <K> CompletionStage<List<E>> performUnorderedMultiLoad(
K[] ids,
MultiIdLoadOptions loadOptions,
EventSource session) {
SharedSessionContractImplementor session) {
if ( MultiKeyLoadLogging.MULTI_KEY_LOAD_LOGGER.isTraceEnabled() ) {
MultiKeyLoadLogging.MULTI_KEY_LOAD_LOGGER.tracef(
"ReactiveMultiIdEntityLoaderArrayParam#performUnorderedMultiLoad - %s",
Expand Down Expand Up @@ -305,7 +305,7 @@ protected final <R, K> K[] processResolvableEntities(
MultiIdEntityLoaderArrayParam.ResolutionConsumer<R> resolutionConsumer,
MultiIdLoadOptions loadOptions,
LockOptions lockOptions,
EventSource session) {
SharedSessionContractImplementor session) {
if ( !loadOptions.isSessionCheckingEnabled()
&& !loadOptions.isSecondLevelCacheCheckingEnabled() ) {
// we'll load all of them from the database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.engine.spi.SubselectFetch;
import org.hibernate.event.spi.EventSource;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.loader.ast.internal.LoaderSelectBuilder;
import org.hibernate.loader.ast.spi.MultiIdLoadOptions;
Expand Down Expand Up @@ -75,7 +74,7 @@ public ReactiveMultiIdEntityLoaderStandard(
protected CompletionStage<List<T>> performOrderedMultiLoad(
Object[] ids,
MultiIdLoadOptions loadOptions,
EventSource session) {
SharedSessionContractImplementor session) {
if ( LOG.isTraceEnabled() ) {
LOG.tracef( "#performOrderedMultiLoad(`%s`, ..)", getEntityDescriptor().getEntityName() );
}
Expand Down Expand Up @@ -289,7 +288,7 @@ private static <T> List<T> singletonList(Object loaded) {
protected CompletionStage<List<T>> performUnorderedMultiLoad(
Object[] ids,
MultiIdLoadOptions loadOptions,
EventSource session) {
SharedSessionContractImplementor session) {
assert !loadOptions.isOrderReturnEnabled();
assert ids != null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ public CompletionStage<T> load(
LockOptions lockOptions,
Boolean readOnly,
SharedSessionContractImplementor session) {
final ReactiveSingleIdLoadPlan<T> loadPlan = (ReactiveSingleIdLoadPlan<T>) resolveLoadPlan(
lockOptions,
session.getLoadQueryInfluencers(),
session.getFactory()
);
final ReactiveSingleIdLoadPlan<T> loadPlan =
(ReactiveSingleIdLoadPlan<T>)
resolveLoadPlan( lockOptions, session.getLoadQueryInfluencers() );
return loadPlan.load( key, readOnly, true, session );
}

Expand All @@ -68,7 +66,9 @@ public CompletionStage<T> load(
LockOptions lockOptions,
Boolean readOnly,
SharedSessionContractImplementor session) {
final ReactiveSingleIdLoadPlan<T> loadPlan = (ReactiveSingleIdLoadPlan<T>) resolveLoadPlan( lockOptions, session.getLoadQueryInfluencers(), session.getFactory() );
final ReactiveSingleIdLoadPlan<T> loadPlan =
(ReactiveSingleIdLoadPlan<T>)
resolveLoadPlan( lockOptions, session.getLoadQueryInfluencers() );
return loadPlan.load( key, entityInstance, readOnly, false, session );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.List;
import java.util.concurrent.CompletionStage;

import org.hibernate.event.spi.EventSource;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.loader.ast.spi.MultiIdEntityLoader;
import org.hibernate.loader.ast.spi.MultiIdLoadOptions;
import org.hibernate.reactive.logging.impl.Log;
Expand All @@ -22,9 +22,9 @@
public interface ReactiveMultiIdEntityLoader<T> extends MultiIdEntityLoader<T> {

@Override
default <K> List<T> load(K[] ids, MultiIdLoadOptions options, EventSource session) {
default <K> List<T> load(K[] ids, MultiIdLoadOptions options, SharedSessionContractImplementor session) {
throw make( Log.class, lookup() ).nonReactiveMethodCall( "reactiveLoad" );
}

<K> CompletionStage<List<T>> reactiveLoad(K[] ids, MultiIdLoadOptions options, EventSource session);
<K> CompletionStage<List<T>> reactiveLoad(K[] ids, MultiIdLoadOptions options, SharedSessionContractImplementor session);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.event.spi.EventSource;
import org.hibernate.generator.Generator;
import org.hibernate.generator.values.GeneratedValues;
import org.hibernate.id.IdentityGenerator;
import org.hibernate.loader.ast.spi.BatchLoaderFactory;
import org.hibernate.loader.ast.spi.EntityBatchLoader;
import org.hibernate.loader.ast.spi.MultiIdLoadOptions;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
Expand Down Expand Up @@ -81,11 +81,11 @@ public class ReactiveAbstractPersisterDelegate {

private static final Log LOG = LoggerFactory.make( Log.class, MethodHandles.lookup() );

private final Supplier<ReactiveSingleIdEntityLoader<Object>> singleIdEntityLoaderSupplier;
private final Supplier<ReactiveMultiIdEntityLoader<Object>> multiIdEntityLoaderSupplier;
private final Supplier<ReactiveSingleIdEntityLoader<?>> singleIdEntityLoaderSupplier;
private final Supplier<ReactiveMultiIdEntityLoader<?>> multiIdEntityLoaderSupplier;

private ReactiveSingleIdEntityLoader<Object> singleIdEntityLoader;
private ReactiveMultiIdEntityLoader<Object> multiIdEntityLoader;
private ReactiveSingleIdEntityLoader<?> singleIdEntityLoader;
private ReactiveMultiIdEntityLoader<?> multiIdEntityLoader;

private final EntityPersister entityDescriptor;

Expand All @@ -101,12 +101,12 @@ public ReactiveAbstractPersisterDelegate(
entityDescriptor = entityPersister;
}

public ReactiveSingleIdEntityLoader<Object> buildSingleIdEntityLoader() {
public ReactiveSingleIdEntityLoader<?> buildSingleIdEntityLoader() {
singleIdEntityLoader = singleIdEntityLoaderSupplier.get();
return singleIdEntityLoader;
}

public ReactiveMultiIdEntityLoader<Object> buildMultiIdEntityLoader() {
public ReactiveMultiIdEntityLoader<?> buildMultiIdEntityLoader() {
multiIdEntityLoader = multiIdEntityLoaderSupplier.get();
return multiIdEntityLoader;
}
Expand All @@ -126,7 +126,7 @@ public <T> DomainResult<T> createDomainResult(
/**
* @see org.hibernate.persister.entity.AbstractEntityPersister#multiLoad(Object[], EventSource, MultiIdLoadOptions)`
*/
public <K> CompletionStage<? extends List<?>> multiLoad(K[] ids, EventSource session, MultiIdLoadOptions loadOptions) {
public <K> CompletionStage<? extends List<?>> multiLoad(K[] ids, SharedSessionContractImplementor session, MultiIdLoadOptions loadOptions) {
return multiIdEntityLoader.reactiveLoad( ids, loadOptions, session );
}

Expand All @@ -135,45 +135,58 @@ private static ReactiveMultiIdEntityLoader<Object> buildMultiIdEntityLoader(
PersistentClass persistentClass,
SessionFactoryImplementor factory) {
return entityDescriptor.getIdentifierType() instanceof BasicType
&& supportsSqlArrayType( factory.getJdbcServices().getDialect() )
&& supportsSqlArrayType( factory.getJdbcServices().getDialect() )
? new ReactiveMultiIdEntityLoaderArrayParam<>( entityDescriptor, factory )
: new ReactiveMultiIdEntityLoaderStandard<>( entityDescriptor, persistentClass, factory );
}

private static ReactiveSingleIdEntityLoader<Object> buildSingleIdEntityLoader(
private static ReactiveSingleIdEntityLoader<?> buildSingleIdEntityLoader(
EntityPersister entityDescriptor,
PersistentClass bootDescriptor,
RuntimeModelCreationContext creationContext,
SessionFactoryImplementor factory,
String entityName) {
if ( bootDescriptor.getLoaderName() != null ) {
// We must resolve the named query on-demand through the boot model because it isn't initialized yet
final NamedQueryMemento namedQueryMemento = factory.getQueryEngine().getNamedObjectRepository()
.resolve( factory, creationContext.getBootModel(), bootDescriptor.getLoaderName() );
if ( namedQueryMemento == null ) {
throw new IllegalArgumentException( "Could not resolve named load-query [" + entityName + "] : " + bootDescriptor.getLoaderName() );
}
final NamedQueryMemento<?> namedQueryMemento =
getNamedQueryMemento( bootDescriptor, creationContext, factory, entityName );
return new ReactiveSingleIdEntityLoaderProvidedQueryImpl<>( entityDescriptor, namedQueryMemento );
}

LoadQueryInfluencers loadQueryInfluencers = new LoadQueryInfluencers( factory );
if ( loadQueryInfluencers.effectivelyBatchLoadable( entityDescriptor ) ) {
final int batchSize = loadQueryInfluencers.effectiveBatchSize( entityDescriptor );
if ( batchSize > 1 ) {
else {
final LoadQueryInfluencers loadQueryInfluencers = new LoadQueryInfluencers( factory );
if ( loadQueryInfluencers.effectivelyBatchLoadable( entityDescriptor ) ) {
final int batchSize = loadQueryInfluencers.effectiveBatchSize( entityDescriptor );
return createBatchingIdEntityLoader( entityDescriptor, batchSize, factory );
}
else {
return new ReactiveSingleIdEntityLoaderStandardImpl<>( entityDescriptor, loadQueryInfluencers );
}
}
}

return new ReactiveSingleIdEntityLoaderStandardImpl<>( entityDescriptor, new LoadQueryInfluencers( factory ) );
private static NamedQueryMemento<?> getNamedQueryMemento(
PersistentClass bootDescriptor,
RuntimeModelCreationContext creationContext,
SessionFactoryImplementor factory,
String entityName) {
final NamedQueryMemento<?> namedQueryMemento =
factory.getQueryEngine().getNamedObjectRepository()
.resolve(factory, creationContext.getBootModel(), bootDescriptor.getLoaderName() );
if ( namedQueryMemento == null ) {
throw new IllegalArgumentException( "Could not resolve named query '" + bootDescriptor.getLoaderName()
+ "' for loading entity '" + entityName + "'" );
}
return namedQueryMemento;
}

private static ReactiveSingleIdEntityLoader<Object> createBatchingIdEntityLoader(
private static <T> ReactiveSingleIdEntityLoader<?> createBatchingIdEntityLoader(
EntityMappingType entityDescriptor,
int domainBatchSize,
SessionFactoryImplementor factory) {
return (ReactiveSingleIdEntityLoader) factory.getServiceRegistry()
.getService( BatchLoaderFactory.class )
.createEntityBatchLoader( domainBatchSize, entityDescriptor, factory );
final EntityBatchLoader<?> batchLoader =
factory.getServiceRegistry().requireService( BatchLoaderFactory.class )
.createEntityBatchLoader( domainBatchSize, entityDescriptor, factory );
return (ReactiveSingleIdEntityLoader<?>) batchLoader;
}

public CompletionStage<Void> processInsertGeneratedProperties(
Expand Down Expand Up @@ -236,7 +249,7 @@ protected ReactiveSingleUniqueKeyEntityLoader<Object> getReactiveUniqueKeyLoader
);
}

public CompletionStage<Object> load(
public CompletionStage<?> load(
EntityPersister persister,
Object id,
Object optionalObject,
Expand All @@ -255,7 +268,7 @@ public Generator reactive(Generator generator) {
return generator instanceof IdentityGenerator ? new ReactiveIdentityGenerator() : generator;
}

public CompletionStage<Object> loadEntityIdByNaturalId(
public CompletionStage<?> loadEntityIdByNaturalId(
Object[] orderedNaturalIdValues, LockOptions lockOptions, SharedSessionContractImplementor session) {
if ( LOG.isTraceEnabled() ) {
LOG.tracef( "Resolving natural-id [%s] to id : %s ",
Expand All @@ -264,7 +277,7 @@ public CompletionStage<Object> loadEntityIdByNaturalId(
);
}

return ( (ReactiveNaturalIdLoader) entityDescriptor.getNaturalIdLoader() )
return ( (ReactiveNaturalIdLoader<?>) entityDescriptor.getNaturalIdLoader() )
.resolveNaturalIdToId( orderedNaturalIdValues, session );
}

Expand Down Expand Up @@ -323,13 +336,15 @@ public AttributeMapping buildPluralAttributeMapping(
}

public EntityIdentifierMapping convertEntityIdentifierMapping(EntityIdentifierMapping entityIdentifierMapping) {
if ( entityIdentifierMapping instanceof NonAggregatedIdentifierMappingImpl ) {
return new ReactiveNonAggregatedIdentifierMappingImpl( (NonAggregatedIdentifierMappingImpl) entityIdentifierMapping );
if ( entityIdentifierMapping instanceof NonAggregatedIdentifierMappingImpl nonAggregatedIdentifierMapping ) {
return new ReactiveNonAggregatedIdentifierMappingImpl(nonAggregatedIdentifierMapping);
}
else if ( entityIdentifierMapping instanceof EmbeddedIdentifierMappingImpl embeddedIdentifierMapping ) {
return new ReactiveEmbeddedIdentifierMappingImpl(embeddedIdentifierMapping);
}
if ( entityIdentifierMapping instanceof EmbeddedIdentifierMappingImpl ) {
return new ReactiveEmbeddedIdentifierMappingImpl( (EmbeddedIdentifierMappingImpl) entityIdentifierMapping );
else {
return entityIdentifierMapping;
}
return entityIdentifierMapping;
}

private static class ReactiveNonAggregatedIdentifierMappingImpl extends NonAggregatedIdentifierMappingImpl {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.hibernate.LockOptions;
import org.hibernate.bytecode.BytecodeLogging;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.event.spi.EventSource;
import org.hibernate.generator.values.GeneratedValues;
import org.hibernate.loader.ast.spi.MultiIdLoadOptions;
import org.hibernate.persister.entity.EntityPersister;
Expand Down Expand Up @@ -92,40 +91,40 @@ CompletionStage<Void> reactiveLock(

<K> CompletionStage<? extends List<?>> reactiveMultiLoad(
K[] ids,
EventSource session,
SharedSessionContractImplementor session,
MultiIdLoadOptions loadOptions);

CompletionStage<Object> reactiveLoad(
CompletionStage<?> reactiveLoad(
Object id,
Object optionalObject,
LockMode lockMode,
SharedSessionContractImplementor session);

CompletionStage<Object> reactiveLoad(
CompletionStage<?> reactiveLoad(
Object id,
Object optionalObject,
LockOptions lockOptions,
SharedSessionContractImplementor session);

CompletionStage<Object> reactiveLoad(
CompletionStage<?> reactiveLoad(
Object id,
Object optionalObject,
LockOptions lockOptions,
SharedSessionContractImplementor session,
Boolean readOnly);

CompletionStage<Object> reactiveLoadByUniqueKey(
CompletionStage<?> reactiveLoadByUniqueKey(
String propertyName,
Object uniqueKey,
SharedSessionContractImplementor session);

CompletionStage<Object> reactiveLoadByUniqueKey(
CompletionStage<?> reactiveLoadByUniqueKey(
String propertyName,
Object uniqueKey,
Boolean readOnly,
SharedSessionContractImplementor session);

CompletionStage<Object> reactiveLoadEntityIdByNaturalId(
CompletionStage<?> reactiveLoadEntityIdByNaturalId(
Object[] naturalIdValues,
LockOptions lockOptions,
SharedSessionContractImplementor session);
Expand Down
Loading
Loading