Top Description Fields Constructors Methods
org.hibernate.engine.spi

public Class BatchFetchQueue

extends Object
Class Inheritance
Imports
java.util.LinkedHashMap, .LinkedHashSet, .Map, .Map.Entry, org.hibernate.cache.spi.access.CollectionDataAccess, .EntityDataAccess, org.hibernate.collection.spi.PersistentCollection, org.hibernate.engine.internal.CacheHelper, org.hibernate.internal.CoreLogging, org.hibernate.internal.util.IndexedConsumer, org.hibernate.internal.util.collections.CollectionHelper, org.hibernate.metamodel.mapping.EntityIdentifierMapping, .EntityMappingType, .PluralAttributeMapping, org.hibernate.persister.collection.CollectionPersister, org.hibernate.persister.entity.EntityPersister, org.jboss.logging.Logger, org.checkerframework.checker.nullness.qual.NonNull, .Nullable

Keeps track of:
Authors
Gavin King, Steve Ebersole, Guenther Demetz

Field Summary

Modifier and TypeField and Description
private @Nullable Map<String, LinkedHashMap<CollectionEntry, PersistentCollection<?>>>
batchLoadableCollections

Used to hold information about the collections that are currently eligible for batch-fetching.

private @Nullable Map<String, LinkedHashSet<EntityKey>>
batchLoadableEntityKeys

Used to hold information about the entities that are currently eligible for batch-fetching.

private final PersistenceContext
private static final Logger
private @Nullable Map<EntityKey, SubselectFetch>
subselectsByEntityKey

A map of subselect-fetch descriptors keyed by the EntityKey against which the descriptor is registered.

Constructor Summary

AccessConstructor and Description
public
BatchFetchQueue(PersistenceContext
The owning context.
context
)

Constructs a queue for the given context.

Method Summary

Modifier and TypeMethod and Description
public void
addBatchLoadableCollection(PersistentCollection<?> collection, CollectionEntry ce)

If a CollectionEntry represents a batch loadable collection, add it to the queue.

public void
addBatchLoadableEntityKey(EntityKey key)

If an EntityKey represents a batch loadable entity, add it to the queue.

public void
addSubselect(EntityKey
The entity for which to register the subselect fetch.
key
,
SubselectFetch
The fetch descriptor.
subquery
)

Adds a subselect fetch descriptor for the given entity key.

public void
clear()

Clears all entries from this fetch queue.

public <T> void
collectBatchLoadableCollectionKeys(int batchSize, IndexedConsumer<T> collector, @NonNull T keyBeingLoaded, PluralAttributeMapping pluralAttributeMapping)

A "collector" form of getCollectionBatch.

public <T> void
collectBatchLoadableEntityIds(final int domainBatchSize, IndexedConsumer<T> collector, final @NonNull T loadingId, final EntityMappingType entityDescriptor)

A "collector" form of getBatchLoadableEntityIds.

public boolean
containsEntityKey(EntityKey key)

Intended for test usage.

public Object[]
getBatchLoadableEntityIds(final EntityMappingType entityDescriptor, final Object loadingId, final int maxBatchSize)

Get a batch of unloaded identifiers for this class, using a slightly complex algorithm that tries to grab keys registered immediately after the given key.

public Object[]

Returns:

an array of collection keys, of length batchSize (padded with nulls)
getCollectionBatch
(final CollectionPersister
The persister for the collection role.
collectionPersister
,
final Object
A key that must be included in the batch fetch
id
,
final int
the maximum number of keys to return
batchSize
)

Get a batch of uninitialized collection keys for a given role

public SharedSessionContractImplementor
public @Nullable SubselectFetch

Returns:

The fetch descriptor; may return null if no subselect fetch queued for this entity key.
getSubselect
(EntityKey
The entity key for which to locate any defined subselect fetch.
key
)

Retrieve the fetch descriptor associated with the given entity key.

private boolean
isCached(EntityKey entityKey, EntityPersister persister)

private boolean
isCached(Object collectionKey, CollectionPersister persister)

public void
removeBatchLoadableCollection(CollectionEntry ce)

After a collection was initialized or evicted, we don't need to batch fetch it anymore, remove it from the queue if necessary

public void
removeBatchLoadableEntityKey(EntityKey key)

After evicting or deleting or loading an entity, we don't need to batch fetch it anymore, remove it from the queue if necessary

public void
removeSubselect(EntityKey key)

After evicting or deleting an entity, we don't need to know the query that was used to load it anymore (don't call this after loading the entity, since we might still need to load its collections)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

batchLoadableCollectionsback to summary
private @Nullable Map<String, LinkedHashMap<CollectionEntry, PersistentCollection<?>>> batchLoadableCollections

Used to hold information about the collections that are currently eligible for batch-fetching. Ultimately used by getCollectionBatch to build collection load batches.

batchLoadableEntityKeysback to summary
private @Nullable Map<String, LinkedHashSet<EntityKey>> batchLoadableEntityKeys

Used to hold information about the entities that are currently eligible for batch-fetching. Ultimately used by getBatchLoadableEntityIds to build entity load batches.

A Map structure is used to segment the keys by entity type since loading can only be done for a particular entity type at a time.

contextback to summary
private final PersistenceContext context
LOGback to summary
private static final Logger LOG
subselectsByEntityKeyback to summary
private @Nullable Map<EntityKey, SubselectFetch> subselectsByEntityKey

A map of subselect-fetch descriptors keyed by the EntityKey against which the descriptor is registered.

Constructor Detail

BatchFetchQueueback to summary
public BatchFetchQueue(PersistenceContext context)

Constructs a queue for the given context.

Parameters
context:PersistenceContext

The owning context.

Method Detail

addBatchLoadableCollectionback to summary
public void addBatchLoadableCollection(PersistentCollection<?> collection, CollectionEntry ce)

If a CollectionEntry represents a batch loadable collection, add it to the queue.

addBatchLoadableEntityKeyback to summary
public void addBatchLoadableEntityKey(EntityKey key)

If an EntityKey represents a batch loadable entity, add it to the queue.

Note that the contract here is such that any key passed in should previously have been been checked for existence within the PersistenceContext; failure to do so may cause the referenced entity to be included in a batch even though it is already associated with the PersistenceContext.

addSubselectback to summary
public void addSubselect(EntityKey key, SubselectFetch subquery)

Adds a subselect fetch descriptor for the given entity key.

Parameters
key:EntityKey

The entity for which to register the subselect fetch.

subquery:SubselectFetch

The fetch descriptor.

clearback to summary
public void clear()

Clears all entries from this fetch queue.

Called after flushing or clearing the session.

collectBatchLoadableCollectionKeysback to summary
public <T> void collectBatchLoadableCollectionKeys(int batchSize, IndexedConsumer<T> collector, @NonNull T keyBeingLoaded, PluralAttributeMapping pluralAttributeMapping)

A "collector" form of getCollectionBatch. Useful in cases where we want a specially created array/container - allows creation of concretely typed array for ARRAY param binding to ensure the driver does not need to cast/copy the values array.

collectBatchLoadableEntityIdsback to summary
public <T> void collectBatchLoadableEntityIds(final int domainBatchSize, IndexedConsumer<T> collector, final @NonNull T loadingId, final EntityMappingType entityDescriptor)

A "collector" form of getBatchLoadableEntityIds. Useful in cases where we want a specially created array/container - allows creation of concretely typed array for ARRAY param binding to ensure the driver does not need to cast/copy the values array.

containsEntityKeyback to summary
public boolean containsEntityKey(EntityKey key)

Intended for test usage. Really has no use-case in Hibernate proper.

getBatchLoadableEntityIdsback to summary
public Object[] getBatchLoadableEntityIds(final EntityMappingType entityDescriptor, final Object loadingId, final int maxBatchSize)

Get a batch of unloaded identifiers for this class, using a slightly complex algorithm that tries to grab keys registered immediately after the given key.

getCollectionBatchback to summary
public Object[] getCollectionBatch(final CollectionPersister collectionPersister, final Object id, final int batchSize)

Get a batch of uninitialized collection keys for a given role

Parameters
collectionPersister:CollectionPersister

The persister for the collection role.

id:Object

A key that must be included in the batch fetch

batchSize:int

the maximum number of keys to return

Returns:Object[]

an array of collection keys, of length batchSize (padded with nulls)

getSessionback to summary
public SharedSessionContractImplementor getSession()
getSubselectback to summary
public @Nullable SubselectFetch getSubselect(EntityKey key)

Retrieve the fetch descriptor associated with the given entity key.

Parameters
key:EntityKey

The entity key for which to locate any defined subselect fetch.

Returns:@Nullable SubselectFetch

The fetch descriptor; may return null if no subselect fetch queued for this entity key.

isCachedback to summary
private boolean isCached(EntityKey entityKey, EntityPersister persister)
isCachedback to summary
private boolean isCached(Object collectionKey, CollectionPersister persister)
removeBatchLoadableCollectionback to summary
public void removeBatchLoadableCollection(CollectionEntry ce)

After a collection was initialized or evicted, we don't need to batch fetch it anymore, remove it from the queue if necessary

removeBatchLoadableEntityKeyback to summary
public void removeBatchLoadableEntityKey(EntityKey key)

After evicting or deleting or loading an entity, we don't need to batch fetch it anymore, remove it from the queue if necessary

removeSubselectback to summary
public void removeSubselect(EntityKey key)

After evicting or deleting an entity, we don't need to know the query that was used to load it anymore (don't call this after loading the entity, since we might still need to load its collections)