Skip to content
Merged
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 @@ -208,7 +208,7 @@ public Join addJoin(JoinTable joinTable, Table table, boolean noDelayInPkColumnC
* with correctly typed sub-properties for the metamodel.
*/
public static void handleGenericComponentProperty(Property property, MemberDetails memberDetails, MetadataBuildingContext context) {
if ( property.getValue() instanceof final Component component ) {
if ( property.getValue() instanceof Component component ) {
final var collector = context.getMetadataCollector();
if ( component.isGeneric() && component.getPropertySpan() > 0
&& collector.getGenericComponent( component.getComponentClass() ) == null ) {
Expand Down Expand Up @@ -312,7 +312,7 @@ public void doSecondPass(Map<String, PersistentClass> persistentClasses) {
final var element = initializedCollection.getElement().copy();
setTypeName( element, memberDetails.getElementType().getName() );
if ( initializedCollection instanceof IndexedCollection indexedCollection ) {
final Value index = indexedCollection.getIndex().copy();
final var index = indexedCollection.getIndex().copy();
if ( memberDetails.getMapKeyType() != null ) {
setTypeName( index, memberDetails.getMapKeyType().getName() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @author Steve Ebersole
*/
@MessageLogger(projectCode = "HHH")
@ValidIdRange(min = 90006001, max = 90007000)
@ValidIdRange(min = 90006001, max = 90006100)
@Internal
public interface IncubationLogger {
String CATEGORY = SubSystemLogging.BASE + ".incubating";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,15 @@
package org.hibernate.loader.ast.internal;

import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.engine.spi.CollectionEntry;
import org.hibernate.engine.spi.CollectionKey;
import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.build.AllowReflection;
import org.hibernate.loader.ast.spi.CollectionBatchLoader;
import org.hibernate.metamodel.mapping.NonAggregatedIdentifierMapping;
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
import org.hibernate.metamodel.mapping.ValuedModelPart;
import org.hibernate.metamodel.mapping.internal.IdClassEmbeddable;
import org.hibernate.sql.results.internal.ResultsHelper;

import java.lang.reflect.Array;

import static org.hibernate.loader.ast.internal.MultiKeyLoadHelper.hasSingleId;
import static org.hibernate.loader.ast.internal.MultiKeyLoadHelper.trimIdBatch;
Expand Down Expand Up @@ -78,63 +72,56 @@ public int getKeyJdbcCount() {

abstract void initializeKeys(Object key, Object[] keysToInitialize, SharedSessionContractImplementor session);

private CollectionKey collectionKey(Object key) {
return new CollectionKey( getLoadable().getCollectionDescriptor(), key );
}

@Override
public PersistentCollection<?> load(Object key, SharedSessionContractImplementor session) {
if ( MULTI_KEY_LOAD_LOGGER.isTraceEnabled() ) {
MULTI_KEY_LOAD_LOGGER.trace( "Batch fetching collection: "
+ collectionInfoString( getLoadable(), key ) );
MULTI_KEY_LOAD_LOGGER.batchFetchingCollection(
collectionInfoString( getLoadable(), key ) );
}

final Object[] keys = resolveKeysToInitialize( key, session );

final var keys = resolveKeysToInitialize( key, session );
if ( hasSingleId( keys ) ) {
return singleKeyLoader.load( key, session );
}

initializeKeys( key, keys, session );

finishInitializingKeys( keys, session );

final CollectionKey collectionKey = new CollectionKey( getLoadable().getCollectionDescriptor(), key );
return session.getPersistenceContext().getCollection( collectionKey );
return session.getPersistenceContext().getCollection( collectionKey( key ) );
}

abstract void finishInitializingKeys(Object[] key, SharedSessionContractImplementor session);

protected void finishInitializingKey(Object key, SharedSessionContractImplementor session) {
if ( key == null ) {
return;
}

if ( MULTI_KEY_LOAD_LOGGER.isTraceEnabled() ) {
MULTI_KEY_LOAD_LOGGER.trace( "Finishing initializing batch-fetched collection: "
+ collectionInfoString( attributeMapping, key ) );
}
if ( key != null ) {
if ( MULTI_KEY_LOAD_LOGGER.isTraceEnabled() ) {
MULTI_KEY_LOAD_LOGGER.finishingInitializingBatchFetchedCollection(
collectionInfoString( attributeMapping, key ) );
}

final PersistenceContext persistenceContext = session.getPersistenceContext();
final CollectionKey collectionKey = new CollectionKey( getLoadable().getCollectionDescriptor(), key );
final PersistentCollection<?> collection = persistenceContext.getCollection( collectionKey );
if ( !collection.wasInitialized() ) {
final CollectionEntry entry = persistenceContext.getCollectionEntry( collection );
collection.initializeEmptyCollection( entry.getLoadedPersister() );
ResultsHelper.finalizeCollectionLoading(
persistenceContext,
entry.getLoadedPersister(),
collection,
key,
true
);
final var persistenceContext = session.getPersistenceContext();
final var collection = persistenceContext.getCollection( collectionKey( key ) );
if ( !collection.wasInitialized() ) {
final var entry = persistenceContext.getCollectionEntry( collection );
collection.initializeEmptyCollection( entry.getLoadedPersister() );
ResultsHelper.finalizeCollectionLoading(
persistenceContext,
entry.getLoadedPersister(),
collection,
key,
true
);
}
}

}

@AllowReflection
Object[] resolveKeysToInitialize(Object keyBeingLoaded, SharedSessionContractImplementor session) {
final int length = getDomainBatchSize();
final Object[] keysToInitialize = (Object[]) Array.newInstance(
getKeyType( getLoadable().getKeyDescriptor().getKeyPart() ),
length
);
final Object[] keysToInitialize = new Object[length];
session.getPersistenceContextInternal().getBatchFetchQueue()
.collectBatchLoadableCollectionKeys(
length,
Expand All @@ -145,16 +132,4 @@ Object[] resolveKeysToInitialize(Object keyBeingLoaded, SharedSessionContractImp
// now trim down the array to the number of keys we found
return trimIdBatch( length, keysToInitialize );
}

protected Class<?> getKeyType(ValuedModelPart keyPart) {
if ( keyPart instanceof NonAggregatedIdentifierMapping nonAggregatedIdentifierMapping ) {
final IdClassEmbeddable idClassEmbeddable = nonAggregatedIdentifierMapping.getIdClassEmbeddable();
if ( idClassEmbeddable != null ) {
return idClassEmbeddable.getMappedJavaType().getJavaTypeClass();
}
}
return keyPart.getJavaType().getJavaTypeClass();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.hibernate.Hibernate;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.loader.ast.spi.EntityBatchLoader;
Expand All @@ -25,7 +24,7 @@ public abstract class AbstractEntityBatchLoader<T>

public AbstractEntityBatchLoader(EntityMappingType entityDescriptor, LoadQueryInfluencers influencers) {
super( entityDescriptor, influencers.getSessionFactory() );
this.singleIdLoader = new SingleIdEntityLoaderStandardImpl<>( entityDescriptor, influencers );
singleIdLoader = new SingleIdEntityLoaderStandardImpl<>( entityDescriptor, influencers );
}

protected abstract void initializeEntities(
Expand All @@ -38,31 +37,29 @@ protected abstract void initializeEntities(

protected abstract Object[] resolveIdsToInitialize(Object id, SharedSessionContractImplementor session);

@Override
@Override
public final T load(
Object id,
Object entityInstance,
LockOptions lockOptions,
Boolean readOnly,
SharedSessionContractImplementor session) {
if ( MULTI_KEY_LOAD_LOGGER.isTraceEnabled() ) {
MULTI_KEY_LOAD_LOGGER.trace( "Batch fetching entity: "
+ infoString( getLoadable(), id ) );
MULTI_KEY_LOAD_LOGGER.batchFetchingEntity( infoString( getLoadable(), id ) );
}

final Object[] ids = resolveIdsToInitialize( id, session );
final var ids = resolveIdsToInitialize( id, session );
return load( id, ids, hasSingleId( ids ), entityInstance, lockOptions, readOnly, session );
}

@Override
@Override
public T load(
Object id,
Object entityInstance,
LockOptions lockOptions,
SharedSessionContractImplementor session) {
if ( MULTI_KEY_LOAD_LOGGER.isTraceEnabled() ) {
MULTI_KEY_LOAD_LOGGER.trace( "Batch fetching entity: "
+ infoString( getLoadable(), id ) );
MULTI_KEY_LOAD_LOGGER.batchFetchingEntity( infoString( getLoadable(), id ) );
}

final Object[] ids = resolveIdsToInitialize( id, session );
Expand Down Expand Up @@ -91,11 +88,11 @@ private T load(
if ( hasSingleId || lockOptions.getLockMode() != LockMode.NONE ) {
return singleIdLoader.load( id, entityInstance, lockOptions, readOnly, session );
}

initializeEntities( ids, id, entityInstance, lockOptions, readOnly, session );

final EntityKey entityKey = session.generateEntityKey( id, getLoadable().getEntityPersister() );
//noinspection unchecked
return (T) session.getPersistenceContext().getEntity( entityKey );
else {
initializeEntities( ids, id, entityInstance, lockOptions, readOnly, session );
final var entityKey = session.generateEntityKey( id, getLoadable().getEntityPersister() );
//noinspection unchecked
return (T) session.getPersistenceContext().getEntity( entityKey );
}
}
}
Loading