Class BatchFetchQueue

java.lang.Object
org.hibernate.engine.spi.BatchFetchQueue

public class BatchFetchQueue extends Object
Keeps track of:
  • entity and collection keys that are available for batch fetching
  • details related to queries which load entities with sub-select-fetchable collections
  • Constructor Details

    • BatchFetchQueue

      public BatchFetchQueue(PersistenceContext context)
      Constructs a queue for the given context.
      Parameters:
      context - The owning context.
  • Method Details

    • clear

      public void clear()
      Clears all entries from this fetch queue.

      Called after flushing or clearing the session.

    • getSubselect

      public @Nullable SubselectFetch getSubselect(EntityKey key)
      Retrieve the fetch descriptor associated with the given entity key.
      Parameters:
      key - The entity key for which to locate any defined subselect fetch.
      Returns:
      The fetch descriptor; may return null if no subselect fetch queued for this entity key.
    • addSubselect

      public void addSubselect(EntityKey key, SubselectFetch subquery)
      Adds a subselect fetch descriptor for the given entity key.
      Parameters:
      key - The entity for which to register the subselect fetch.
      subquery - The fetch descriptor.
    • removeSubselect

      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)
    • addBatchLoadableEntityKey

      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.

    • removeBatchLoadableEntityKey

      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
    • containsEntityKey

      public boolean containsEntityKey(EntityKey key)
      Intended for test usage. Really has no use-case in Hibernate proper.
    • collectBatchLoadableEntityIds

      public <T> void collectBatchLoadableEntityIds(int domainBatchSize, IndexedConsumer<T> collector, @NonNull T loadingId, EntityMappingType entityDescriptor)
      A "collector" form of getBatchLoadableEntityIds(org.hibernate.metamodel.mapping.EntityMappingType, java.lang.Object, int). 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.
    • getBatchLoadableEntityIds

      public Object[] getBatchLoadableEntityIds(EntityMappingType entityDescriptor, Object loadingId, 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.
    • addBatchLoadableCollection

      public void addBatchLoadableCollection(PersistentCollection<?> collection, CollectionEntry ce)
      If a CollectionEntry represents a batch loadable collection, add it to the queue.
    • removeBatchLoadableCollection

      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
    • collectBatchLoadableCollectionKeys

      public <T> void collectBatchLoadableCollectionKeys(int batchSize, IndexedConsumer<T> collector, @NonNull T keyBeingLoaded, PluralAttributeMapping pluralAttributeMapping)
      A "collector" form of getCollectionBatch(org.hibernate.persister.collection.CollectionPersister, java.lang.Object, int). 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.
    • getCollectionBatch

      public Object[] getCollectionBatch(CollectionPersister collectionPersister, Object id, int batchSize)
      Get a batch of uninitialized collection keys for a given role
      Parameters:
      collectionPersister - The persister for the collection role.
      id - A key that must be included in the batch fetch
      batchSize - the maximum number of keys to return
      Returns:
      an array of collection keys, of length batchSize (padded with nulls)
    • getSession

      public SharedSessionContractImplementor getSession()