Skip to content

Commit 76c7ba8

Browse files
committed
more cleanups to code in loader.ast.internal package
1 parent c5dd2c3 commit 76c7ba8

21 files changed

+393
-471
lines changed

hibernate-core/src/main/java/org/hibernate/loader/ast/internal/AbstractEntityBatchLoader.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public abstract class AbstractEntityBatchLoader<T>
2222

2323
private final SingleIdEntityLoaderStandardImpl<T> singleIdLoader;
2424

25-
public AbstractEntityBatchLoader(EntityMappingType entityDescriptor, LoadQueryInfluencers loadQueryInfluencers) {
26-
super( entityDescriptor, loadQueryInfluencers.getSessionFactory() );
27-
this.singleIdLoader = new SingleIdEntityLoaderStandardImpl<>( entityDescriptor, loadQueryInfluencers );
25+
public AbstractEntityBatchLoader(EntityMappingType entityDescriptor, LoadQueryInfluencers influencers) {
26+
super( entityDescriptor, influencers.getSessionFactory() );
27+
this.singleIdLoader = new SingleIdEntityLoaderStandardImpl<>( entityDescriptor, influencers );
2828
}
2929

3030
protected abstract void initializeEntities(
@@ -49,7 +49,6 @@ public final T load(
4949
}
5050

5151
final Object[] ids = resolveIdsToInitialize( id, session );
52-
5352
return load( id, ids, hasSingleId( ids ), entityInstance, lockOptions, readOnly, session );
5453
}
5554

@@ -65,9 +64,7 @@ public T load(
6564

6665
final Object[] ids = resolveIdsToInitialize( id, session );
6766
final boolean hasSingleId = hasSingleId( ids );
68-
6967
final T entity = load( id, ids, hasSingleId, entityInstance, lockOptions, null, session );
70-
7168
if ( hasSingleId ) {
7269
return entity;
7370
}

hibernate-core/src/main/java/org/hibernate/loader/ast/internal/AbstractMultiIdEntityLoader.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private List<T> orderedMultiLoad(
120120

121121
final int maxBatchSize = maxBatchSize( ids, loadOptions );
122122

123-
final List<Object> result = arrayList( ids.length );
123+
final List<Object> results = arrayList( ids.length );
124124

125125
final List<Object> idsInBatch = new ArrayList<>();
126126
final List<Integer> elementPositionsLoadedByBatch = new ArrayList<>();
@@ -131,7 +131,7 @@ private List<T> orderedMultiLoad(
131131
final Object id = idCoercionEnabled ? idType.coerce( ids[i], session ) : ids[i];
132132
final EntityKey entityKey = new EntityKey( id, getLoadable().getEntityPersister() );
133133

134-
if ( !loadFromEnabledCaches( loadOptions, session, id, lockOptions, entityKey, result, i ) ) {
134+
if ( !loadFromEnabledCaches( loadOptions, session, id, lockOptions, entityKey, results, i ) ) {
135135
// if we did not hit any of the continues above,
136136
// then we need to batch load the entity state.
137137
idsInBatch.add( id );
@@ -143,7 +143,7 @@ private List<T> orderedMultiLoad(
143143
}
144144

145145
// Save the EntityKey instance for use later
146-
result.add( i, entityKey );
146+
results.add( i, entityKey );
147147
elementPositionsLoadedByBatch.add( i );
148148
}
149149
}
@@ -155,10 +155,10 @@ private List<T> orderedMultiLoad(
155155
}
156156

157157
// for each result where we set the EntityKey earlier, replace them
158-
handleResults( loadOptions, session, elementPositionsLoadedByBatch, result );
158+
handleResults( loadOptions, session, elementPositionsLoadedByBatch, results );
159159

160160
//noinspection unchecked
161-
return (List<T>) result;
161+
return (List<T>) results;
162162
}
163163

164164
private static LockOptions lockOptions(MultiIdLoadOptions loadOptions) {
@@ -255,12 +255,12 @@ protected List<T> unorderedMultiLoad(
255255
MultiIdLoadOptions loadOptions,
256256
SharedSessionContractImplementor session) {
257257
final LockOptions lockOptions = lockOptions( loadOptions );
258-
final List<T> result = arrayList( ids.length );
258+
final List<T> results = arrayList( ids.length );
259259
final Object[] unresolvableIds =
260260
resolveInCachesIfEnabled( ids, loadOptions, lockOptions, session,
261-
(position, entityKey, resolvedRef) -> result.add( (T) resolvedRef ) );
261+
(position, entityKey, resolvedRef) -> results.add( (T) resolvedRef ) );
262262
if ( !isEmpty( unresolvableIds ) ) {
263-
loadEntitiesWithUnresolvedIds( unresolvableIds, loadOptions, lockOptions, result, session );
263+
loadEntitiesWithUnresolvedIds( unresolvableIds, loadOptions, lockOptions, results, session );
264264
final BatchFetchQueue batchFetchQueue = session.getPersistenceContextInternal().getBatchFetchQueue();
265265
final EntityPersister persister = getLoadable().getEntityPersister();
266266
for ( Object id : unresolvableIds ) {
@@ -272,7 +272,7 @@ protected List<T> unorderedMultiLoad(
272272
}
273273
}
274274
}
275-
return result;
275+
return results;
276276
}
277277

278278
protected abstract void loadEntitiesWithUnresolvedIds(

hibernate-core/src/main/java/org/hibernate/loader/ast/internal/AbstractMultiNaturalIdLoader.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.hibernate.metamodel.mapping.NaturalIdMapping;
1717

1818
import java.util.List;
19+
import java.util.function.Consumer;
1920

2021
import static java.util.Collections.emptyList;
2122
import static org.hibernate.internal.util.collections.CollectionHelper.arrayList;
@@ -69,7 +70,7 @@ private <K> List<E> unorderedMultiLoad(
6970
final List<E> results = arrayList( naturalIds.length );
7071
final LockOptions lockOptions = lockOptions( loadOptions );
7172
final Object[] unresolvedIds =
72-
checkPersistenceContextForCachedResults( naturalIds, loadOptions, session, lockOptions, results );
73+
checkPersistenceContextForCachedResults( naturalIds, loadOptions, session, lockOptions, results::add );
7374
if ( !isEmpty( unresolvedIds ) ) {
7475
results.addAll( loadEntitiesWithUnresolvedIds( unresolvedIds, loadOptions, lockOptions, session ) );
7576
}
@@ -82,7 +83,10 @@ protected abstract List<E> loadEntitiesWithUnresolvedIds(
8283
LockOptions lockOptions,
8384
SharedSessionContractImplementor session);
8485

85-
private <K> List<E> performOrderedMultiLoad(K[] naturalIds, MultiNaturalIdLoadOptions options, SharedSessionContractImplementor session) {
86+
private <K> List<E> performOrderedMultiLoad(
87+
K[] naturalIds,
88+
MultiNaturalIdLoadOptions options,
89+
SharedSessionContractImplementor session) {
8690
if ( MULTI_KEY_LOAD_LOGGER.isTraceEnabled() ) {
8791
MULTI_KEY_LOAD_LOGGER.trace( "Ordered MultiLoad starting: "
8892
+ getEntityDescriptor().getEntityName() );
@@ -94,7 +98,12 @@ private <K> List<E> orderedMultiLoad(
9498
K[] naturalIds,
9599
MultiNaturalIdLoadOptions loadOptions,
96100
SharedSessionContractImplementor session) {
97-
unorderedMultiLoad( naturalIds, loadOptions, session );
101+
final LockOptions lockOptions = lockOptions( loadOptions );
102+
final Object[] unresolvedIds =
103+
checkPersistenceContextForCachedResults( naturalIds, loadOptions, session, lockOptions, result -> {} );
104+
if ( !isEmpty( unresolvedIds ) ) {
105+
loadEntitiesWithUnresolvedIds( unresolvedIds, loadOptions, lockOptions, session );
106+
}
98107
return sortResults( naturalIds, loadOptions, session );
99108
}
100109

@@ -133,7 +142,7 @@ private <K> Object[] checkPersistenceContextForCachedResults(
133142
MultiNaturalIdLoadOptions loadOptions,
134143
SharedSessionContractImplementor session,
135144
LockOptions lockOptions,
136-
List<E> results ) {
145+
Consumer<E> results ) {
137146
final List<K> unresolvedIds = arrayList( naturalIds.length );
138147
final PersistenceContext context = session.getPersistenceContextInternal();
139148
final NaturalIdMapping naturalIdMapping = getEntityDescriptor().getNaturalIdMapping();
@@ -147,7 +156,7 @@ private <K> Object[] checkPersistenceContextForCachedResults(
147156
// either a managed entry, or a deleted one with returnDeleted enabled
148157
upgradeLock( entity, entry, lockOptions, session );
149158
final Object result = context.proxyFor( entity );
150-
results.add( (E) result );
159+
results.accept( (E) result );
151160
}
152161
}
153162
else {
@@ -166,7 +175,7 @@ public EntityMappingType getLoadable() {
166175
return getEntityDescriptor();
167176
}
168177

169-
protected EntityMappingType getEntityDescriptor() {
178+
protected final EntityMappingType getEntityDescriptor() {
170179
return entityDescriptor;
171180
}
172181
}

0 commit comments

Comments
 (0)