Skip to content

Commit c8b1272

Browse files
committed
rewrite an inner class as an anonymous function
1 parent 3b07db2 commit c8b1272

File tree

2 files changed

+30
-42
lines changed

2 files changed

+30
-42
lines changed

hibernate-core/src/main/java/org/hibernate/collection/spi/AbstractPersistentCollection.java

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -392,37 +392,23 @@ public boolean elementExists(Object element) {
392392

393393
protected Object readElementByIndex(final Object index) {
394394
if ( !initialized ) {
395-
class ExtraLazyElementByIndexReader implements LazyInitializationWork<Object> {
396-
private boolean isExtraLazy;
397-
private Object element;
398-
399-
@Override
400-
public Object doWork() {
401-
final var entry = getCollectionEntry();
402-
final var persister = entry.getLoadedPersister();
403-
checkPersister( AbstractPersistentCollection.this, persister );
404-
isExtraLazy = persister.isExtraLazy();
405-
if ( isExtraLazy ) {
406-
if ( hasQueuedOperations() ) {
407-
session.flush();
408-
}
409-
element = persister.getElementByIndex( entry.getLoadedKey(), index, session, owner );
395+
return withTemporarySessionIfNeeded( () -> {
396+
final var entry = getCollectionEntry();
397+
final var persister = entry.getLoadedPersister();
398+
checkPersister( AbstractPersistentCollection.this, persister );
399+
if ( persister.isExtraLazy() ) {
400+
if ( hasQueuedOperations() ) {
401+
session.flush();
410402
}
411-
else {
412-
read();
413-
}
414-
return null;
403+
return persister.getElementByIndex( entry.getLoadedKey(), index, session, owner );
415404
}
416-
}
417-
418-
final ExtraLazyElementByIndexReader reader = new ExtraLazyElementByIndexReader();
419-
withTemporarySessionIfNeeded( reader );
420-
if ( reader.isExtraLazy ) {
421-
return reader.element;
422-
}
405+
else {
406+
read();
407+
return UNKNOWN;
408+
}
409+
} );
423410
}
424411
return UNKNOWN;
425-
426412
}
427413

428414
@Override
@@ -791,7 +777,7 @@ private String unexpectedSessionStateMessage(SharedSessionContractImplementor se
791777
final String roleCurrent = role;
792778
final Object keyCurrent = key;
793779

794-
final var message = new StringBuilder( "Collection : " );
780+
final var message = new StringBuilder( "Collection: " );
795781
if ( roleCurrent != null ) {
796782
message.append( collectionInfoString( roleCurrent, keyCurrent ) );
797783
}

hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import org.hibernate.mapping.IdentifierCollection;
5555
import org.hibernate.mapping.IndexedCollection;
5656
import org.hibernate.mapping.Table;
57-
import org.hibernate.mapping.Value;
5857
import org.hibernate.metamodel.CollectionClassification;
5958
import org.hibernate.metamodel.mapping.AttributeMapping;
6059
import org.hibernate.metamodel.mapping.CollectionPart;
@@ -247,6 +246,7 @@ public AbstractCollectionPersister(
247246
RuntimeModelCreationContext creationContext)
248247
throws MappingException, CacheException {
249248
factory = creationContext.getSessionFactory();
249+
final var factoryOptions = creationContext.getSessionFactoryOptions();
250250

251251
this.collectionBootDescriptor = collectionBootDescriptor;
252252
this.collectionSemantics =
@@ -256,10 +256,10 @@ public AbstractCollectionPersister(
256256

257257

258258
this.cacheAccessStrategy = cacheAccessStrategy;
259-
cacheEntryStructure = cacheEntryStructure( collectionBootDescriptor, creationContext );
259+
cacheEntryStructure =
260+
cacheEntryStructure( collectionBootDescriptor, factoryOptions );
260261
useShallowQueryCacheLayout =
261-
shouldUseShallowCacheLayout( collectionBootDescriptor.getQueryCacheLayout(),
262-
creationContext.getSessionFactoryOptions() );
262+
shouldUseShallowCacheLayout( collectionBootDescriptor.getQueryCacheLayout(), factoryOptions );
263263

264264
dialect = creationContext.getDialect();
265265
sqlExceptionHelper = creationContext.getJdbcServices().getSqlExceptionHelper();
@@ -292,7 +292,7 @@ public AbstractCollectionPersister(
292292

293293
hasOrphanDelete = collectionBootDescriptor.hasOrphanDelete();
294294

295-
batchSize = batchSize( collectionBootDescriptor, creationContext );
295+
batchSize = batchSize( collectionBootDescriptor, factoryOptions );
296296

297297
isVersioned = collectionBootDescriptor.isOptimisticLocked();
298298

@@ -384,7 +384,7 @@ else if ( selectable instanceof Column column ) {
384384
if ( collectionBootDescriptor instanceof IndexedCollection indexedCollection ) {
385385
assert collectionBootDescriptor.isIndexed();
386386
// NativeSQL: collect index column and auto-aliases
387-
final Value index = indexedCollection.getIndex();
387+
final var index = indexedCollection.getIndex();
388388
indexType = index.getType();
389389
final int indexSpan = index.getColumnSpan();
390390
final boolean[] indexColumnInsertability = index.getColumnInsertability();
@@ -511,7 +511,8 @@ private FilterHelper manyToManyFilterHelper(Collection collection, RuntimeModelC
511511

512512
private FilterHelper filterHelper(
513513
Collection collection, EntityPersister elementPersister, RuntimeModelCreationContext context) {
514-
if ( collection.getFilters().isEmpty() ) {
514+
final var filters = collection.getFilters();
515+
if ( filters.isEmpty() ) {
515516
return null;
516517
}
517518
else {
@@ -522,18 +523,19 @@ private FilterHelper filterHelper(
522523
context.getBootModel().getEntityBinding( elementPersister.getEntityName() ),
523524
context.getSessionFactory().getSqlStringGenerationContext()
524525
);
525-
return new FilterHelper( collection.getFilters(), entityNameByTableNameMap, factory );
526+
return new FilterHelper( filters, entityNameByTableNameMap, factory );
526527
}
527528
}
528529

529-
private static int batchSize(Collection collection, RuntimeModelCreationContext context) {
530-
return collection.getBatchSize() < 0
531-
? context.getSessionFactoryOptions().getDefaultBatchFetchSize()
532-
: collection.getBatchSize();
530+
private static int batchSize(Collection collection, SessionFactoryOptions options) {
531+
int batchSize = collection.getBatchSize();
532+
return batchSize >= 0
533+
? batchSize
534+
: options.getDefaultBatchFetchSize();
533535
}
534536

535-
private static CacheEntryStructure cacheEntryStructure(Collection collection, RuntimeModelCreationContext context) {
536-
if ( context.getSessionFactoryOptions().isStructuredCacheEntriesEnabled() ) {
537+
private static CacheEntryStructure cacheEntryStructure(Collection collection, SessionFactoryOptions options) {
538+
if ( options.isStructuredCacheEntriesEnabled() ) {
537539
return collection.isMap()
538540
? StructuredMapCacheEntry.INSTANCE
539541
: StructuredCollectionCacheEntry.INSTANCE;

0 commit comments

Comments
 (0)