Skip to content
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 @@ -10,6 +10,7 @@
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.event.spi.EventSource;
import org.hibernate.loader.ast.spi.MultiNaturalIdLoadOptions;
import org.hibernate.loader.ast.spi.MultiNaturalIdLoader;
import org.hibernate.metamodel.mapping.EntityMappingType;
Expand All @@ -31,7 +32,7 @@ public AbstractMultiNaturalIdLoader(EntityMappingType entityDescriptor) {
}

@Override
public <K> List<E> multiLoad(K[] naturalIds, MultiNaturalIdLoadOptions options, SharedSessionContractImplementor session) {
public <K> List<E> multiLoad(K[] naturalIds, MultiNaturalIdLoadOptions options, EventSource eventSource) {
assert naturalIds != null;

this.options = options;
Expand All @@ -41,41 +42,41 @@ public <K> List<E> multiLoad(K[] naturalIds, MultiNaturalIdLoadOptions options,
}

return options.isOrderReturnEnabled()
? performOrderedMultiLoad( naturalIds, options, session )
: performUnorderedMultiLoad( naturalIds, options, session );
? performOrderedMultiLoad( naturalIds, options, eventSource )
: performUnorderedMultiLoad( naturalIds, options, eventSource );
}

private <K> List<E> performUnorderedMultiLoad(K[] naturalIds, MultiNaturalIdLoadOptions options, SharedSessionContractImplementor session) {
private <K> List<E> performUnorderedMultiLoad(K[] naturalIds, MultiNaturalIdLoadOptions options, EventSource eventSource) {
if ( MultiKeyLoadLogging.MULTI_KEY_LOAD_LOGGER.isTraceEnabled() ) {
MultiKeyLoadLogging.MULTI_KEY_LOAD_LOGGER.tracef( "Unordered MultiLoad Starting - `%s`", getEntityDescriptor().getEntityName() );
}

return unorderedMultiLoad(
naturalIds,
session,
eventSource,
options.getLockOptions() == null ? LockOptions.NONE : options.getLockOptions()
);
}

protected abstract <K> List<E> unorderedMultiLoad(K[] naturalIds, SharedSessionContractImplementor session, LockOptions lockOptions);
protected abstract <K> List<E> unorderedMultiLoad(K[] naturalIds, EventSource eventSource, LockOptions lockOptions);

private <K> List<E> performOrderedMultiLoad(K[] naturalIds, MultiNaturalIdLoadOptions options, SharedSessionContractImplementor session) {
private <K> List<E> performOrderedMultiLoad(K[] naturalIds, MultiNaturalIdLoadOptions options, EventSource eventSource) {
if ( MultiKeyLoadLogging.MULTI_KEY_LOAD_LOGGER.isTraceEnabled() ) {
MultiKeyLoadLogging.MULTI_KEY_LOAD_LOGGER.tracef( "Ordered MultiLoad Starting - `%s`", getEntityDescriptor().getEntityName() );
}

return orderedMultiLoad(
naturalIds,
session,
eventSource,
options.getLockOptions() == null ? LockOptions.NONE : options.getLockOptions()
);
}

protected <K> List<E> orderedMultiLoad( K[] naturalIds, SharedSessionContractImplementor session, LockOptions lockOptions ) {
protected <K> List<E> orderedMultiLoad( K[] naturalIds, EventSource eventSource, LockOptions lockOptions ) {

unorderedMultiLoad( naturalIds, session, lockOptions );
unorderedMultiLoad( naturalIds, eventSource, lockOptions );

return handleResults( naturalIds, session, lockOptions );
return handleResults( naturalIds, eventSource, lockOptions );
}

protected <K> List<E> handleResults( K[] naturalIds, SharedSessionContractImplementor session, LockOptions lockOptions ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import org.hibernate.LockOptions;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.event.spi.EventSource;
import org.hibernate.loader.ast.spi.SqlArrayMultiKeyLoader;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.JdbcMapping;
Expand Down Expand Up @@ -44,11 +44,11 @@ protected BasicAttributeMapping getNaturalIdAttribute() {
}

@Override
public <K> List<E> unorderedMultiLoad( K[] naturalIds, SharedSessionContractImplementor session, LockOptions lockOptions ) {
public <K> List<E> unorderedMultiLoad(K[] naturalIds, EventSource eventSource, LockOptions lockOptions ) {

final SessionFactoryImplementor sessionFactory = session.getFactory();
final SessionFactoryImplementor sessionFactory = eventSource.getFactory();

naturalIds = LoaderHelper.normalizeKeys( naturalIds, getNaturalIdAttribute(), session, sessionFactory );
naturalIds = LoaderHelper.normalizeKeys( naturalIds, getNaturalIdAttribute(), eventSource, sessionFactory );

final JdbcMapping arrayJdbcMapping = MultiKeyLoadHelper.resolveArrayJdbcMapping(
getNaturalIdMapping().getSingleJdbcMapping(),
Expand All @@ -60,7 +60,7 @@ public <K> List<E> unorderedMultiLoad( K[] naturalIds, SharedSessionContractImpl
final SelectStatement sqlAst = LoaderSelectBuilder.createSelectBySingleArrayParameter(
getLoadable(),
getNaturalIdAttribute(),
session.getLoadQueryInfluencers(),
eventSource.getLoadQueryInfluencers(),
lockOptions,
jdbcParameter,
sessionFactory
Expand All @@ -86,8 +86,8 @@ public LockOptions getLockOptions() {
null,
null,
lockOptions,
session.isDefaultReadOnly(),
session
eventSource.isDefaultReadOnly(),
eventSource
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import org.hibernate.LockOptions;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.event.spi.EventSource;
import org.hibernate.loader.ast.spi.SqlInPredicateMultiKeyLoader;
import org.hibernate.metamodel.mapping.EntityMappingType;

Expand All @@ -22,17 +22,17 @@ public MultiNaturalIdLoaderInPredicate(EntityMappingType entityDescriptor) {
}

@Override
public <K> List<E> unorderedMultiLoad(K[] naturalIds, SharedSessionContractImplementor session, LockOptions lockOptions) {
public <K> List<E> unorderedMultiLoad(K[] naturalIds, EventSource eventSource, LockOptions lockOptions) {

final SessionFactoryImplementor sessionFactory = session.getFactory();
final SessionFactoryImplementor sessionFactory = eventSource.getFactory();

final int maxBatchSize;
if ( options.getBatchSize() != null && options.getBatchSize() > 0 ) {
maxBatchSize = options.getBatchSize();
}
else {
maxBatchSize =
session.getJdbcServices().getJdbcEnvironment().getDialect()
eventSource.getJdbcServices().getJdbcEnvironment().getDialect()
.getMultiKeyLoadSizingStrategy().determineOptimalBatchLoadSize(
getEntityDescriptor().getNaturalIdMapping().getJdbcTypeCount(),
naturalIds.length,
Expand All @@ -50,12 +50,12 @@ public <K> List<E> unorderedMultiLoad(K[] naturalIds, SharedSessionContractImple
// `naturalId` here is the one passed in by the API as part of the values array
return getEntityDescriptor().getNaturalIdMapping().normalizeInput( naturalId );
},
session.getLoadQueryInfluencers(),
eventSource.getLoadQueryInfluencers(),
lockOptions,
sessionFactory
);

return batcher.multiLoad( naturalIds, session );
return batcher.multiLoad( naturalIds, eventSource );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import java.util.List;

import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.event.spi.EventSource;

/**
* Loader for entities by multiple natural-ids
Expand All @@ -24,5 +24,5 @@ public interface MultiNaturalIdLoader<E> extends EntityMultiLoader<E> {
* values positioned according to "attribute ordering". Simple natural-ids can also be expressed
* by their simple (basic/embedded) type.
*/
<K> List<E> multiLoad(K[] naturalIds, MultiNaturalIdLoadOptions options, SharedSessionContractImplementor session);
<K> List<E> multiLoad(K[] naturalIds, MultiNaturalIdLoadOptions options, EventSource eventSource);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I still allowed to do this at this point in time @gavinking @sebersole @yrodiere ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would prevent that method being called from a StatelessSession.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would prevent that method being called from a StatelessSession.

fair point i guess?
This doesn't seem to be a concern for the normal multiple id loading though?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrenaat if you look in StatelessSessionImpl, you'll see how I had to hack in multiple id loading with a criteria query, I guess precisely because MultiIdEntityLoader.load() requires an EventSource. We should fix that!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrenaat if you look in StatelessSessionImpl, you'll see how I had to hack in multiple id loading with a criteria query, I guess precisely because MultiIdEntityLoader.load() requires an EventSource. We should fix that!

Well, we certainly can if, as I asked, we can still modify the signature of the implied methods at this late point in the release path of v7 ... ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #9959.

}