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 @@ -392,37 +392,23 @@ public boolean elementExists(Object element) {

protected Object readElementByIndex(final Object index) {
if ( !initialized ) {
class ExtraLazyElementByIndexReader implements LazyInitializationWork<Object> {
private boolean isExtraLazy;
private Object element;

@Override
public Object doWork() {
final var entry = getCollectionEntry();
final var persister = entry.getLoadedPersister();
checkPersister( AbstractPersistentCollection.this, persister );
isExtraLazy = persister.isExtraLazy();
if ( isExtraLazy ) {
if ( hasQueuedOperations() ) {
session.flush();
}
element = persister.getElementByIndex( entry.getLoadedKey(), index, session, owner );
return withTemporarySessionIfNeeded( () -> {
final var entry = getCollectionEntry();
final var persister = entry.getLoadedPersister();
checkPersister( AbstractPersistentCollection.this, persister );
if ( persister.isExtraLazy() ) {
if ( hasQueuedOperations() ) {
session.flush();
}
else {
read();
}
return null;
return persister.getElementByIndex( entry.getLoadedKey(), index, session, owner );
}
}

final ExtraLazyElementByIndexReader reader = new ExtraLazyElementByIndexReader();
withTemporarySessionIfNeeded( reader );
if ( reader.isExtraLazy ) {
return reader.element;
}
else {
read();
return UNKNOWN;
}
} );
}
return UNKNOWN;

}

@Override
Expand Down Expand Up @@ -791,7 +777,7 @@ private String unexpectedSessionStateMessage(SharedSessionContractImplementor se
final String roleCurrent = role;
final Object keyCurrent = key;

final var message = new StringBuilder( "Collection : " );
final var message = new StringBuilder( "Collection: " );
if ( roleCurrent != null ) {
message.append( collectionInfoString( roleCurrent, keyCurrent ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import org.hibernate.mapping.IdentifierCollection;
import org.hibernate.mapping.IndexedCollection;
import org.hibernate.mapping.Table;
import org.hibernate.mapping.Value;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.CollectionPart;
Expand Down Expand Up @@ -247,6 +246,7 @@ public AbstractCollectionPersister(
RuntimeModelCreationContext creationContext)
throws MappingException, CacheException {
factory = creationContext.getSessionFactory();
final var factoryOptions = creationContext.getSessionFactoryOptions();

this.collectionBootDescriptor = collectionBootDescriptor;
this.collectionSemantics =
Expand All @@ -256,10 +256,10 @@ public AbstractCollectionPersister(


this.cacheAccessStrategy = cacheAccessStrategy;
cacheEntryStructure = cacheEntryStructure( collectionBootDescriptor, creationContext );
cacheEntryStructure =
cacheEntryStructure( collectionBootDescriptor, factoryOptions );
useShallowQueryCacheLayout =
shouldUseShallowCacheLayout( collectionBootDescriptor.getQueryCacheLayout(),
creationContext.getSessionFactoryOptions() );
shouldUseShallowCacheLayout( collectionBootDescriptor.getQueryCacheLayout(), factoryOptions );

dialect = creationContext.getDialect();
sqlExceptionHelper = creationContext.getJdbcServices().getSqlExceptionHelper();
Expand Down Expand Up @@ -292,7 +292,7 @@ public AbstractCollectionPersister(

hasOrphanDelete = collectionBootDescriptor.hasOrphanDelete();

batchSize = batchSize( collectionBootDescriptor, creationContext );
batchSize = batchSize( collectionBootDescriptor, factoryOptions );

isVersioned = collectionBootDescriptor.isOptimisticLocked();

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

private FilterHelper filterHelper(
Collection collection, EntityPersister elementPersister, RuntimeModelCreationContext context) {
if ( collection.getFilters().isEmpty() ) {
final var filters = collection.getFilters();
if ( filters.isEmpty() ) {
return null;
}
else {
Expand All @@ -522,18 +523,19 @@ private FilterHelper filterHelper(
context.getBootModel().getEntityBinding( elementPersister.getEntityName() ),
context.getSessionFactory().getSqlStringGenerationContext()
);
return new FilterHelper( collection.getFilters(), entityNameByTableNameMap, factory );
return new FilterHelper( filters, entityNameByTableNameMap, factory );
}
}

private static int batchSize(Collection collection, RuntimeModelCreationContext context) {
return collection.getBatchSize() < 0
? context.getSessionFactoryOptions().getDefaultBatchFetchSize()
: collection.getBatchSize();
private static int batchSize(Collection collection, SessionFactoryOptions options) {
int batchSize = collection.getBatchSize();
return batchSize >= 0
? batchSize
: options.getDefaultBatchFetchSize();
}

private static CacheEntryStructure cacheEntryStructure(Collection collection, RuntimeModelCreationContext context) {
if ( context.getSessionFactoryOptions().isStructuredCacheEntriesEnabled() ) {
private static CacheEntryStructure cacheEntryStructure(Collection collection, SessionFactoryOptions options) {
if ( options.isStructuredCacheEntriesEnabled() ) {
return collection.isMap()
? StructuredMapCacheEntry.INSTANCE
: StructuredCollectionCacheEntry.INSTANCE;
Expand Down