Top Description Fields Constructors Methods
org.hibernate.engine

public Class BatchFetchQueue

extends Object
Class Inheritance
Imports
java.io.Serializable, java.util.HashMap, .Iterator, .LinkedHashMap, .Map, org.hibernate.EntityMode, org.hibernate.cache.CacheKey, org.hibernate.collection.PersistentCollection, org.hibernate.persister.collection.CollectionPersister, org.hibernate.persister.entity.EntityPersister, org.hibernate.util.MarkerObject

Tracks entity and collection keys that are available for batch fetching, and the queries which were used to load entities, which can be re-used as a subquery for loading owned collections.
Author
Gavin King

Field Summary

Modifier and TypeField and Description
private final Map<K, V>
batchLoadableEntityKeys

Defines a sequence of EntityKey elements that are currently elegible for batch-fetching.

private final PersistenceContext
context

The owning persistence context.

public static final Object
private final Map<K, V>
subselectsByEntityKey

A map of subselect-fetch descriptors keyed by the {@link 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
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 decriptor for the given entity key.

public void
clear()

Clears all entries from this fetch queue.

public void
clearSubselects()

Clears all pending subselect fetches from the queue.

public Serializable[]

Returns:

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

Get a batch of uninitialized collection keys for a given role

public Serializable[]

Returns:

an array of identifiers, of length batchSize (possibly padded with nulls)
getEntityBatch
(final EntityPersister
The persister for the entities being loaded.
persister
,
final Serializable
The identifier of the entity currently demanding load.
id
,
final int
The maximum number of keys to return
batchSize
,
final EntityMode entityMode)

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 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, EntityMode entityMode)

private boolean
isCached(Serializable collectionKey, CollectionPersister persister, EntityMode entityMode)

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

batchLoadableEntityKeysback to summary
private final Map<K, V> batchLoadableEntityKeys

Defines a sequence of EntityKey elements that are currently elegible for batch-fetching.

Even though this is a map, we only use the keys. A map was chosen in order to utilize a LinkedHashMap to maintain sequencing as well as uniqueness.

TODO : this would be better as a SequencedReferenceSet, but no such beast exists!

contextback to summary
private final PersistenceContext context

The owning persistence context.

MARKERback to summary
public static final Object MARKER
subselectsByEntityKeyback to summary
private final Map<K, V> subselectsByEntityKey

A map of subselect-fetch descriptors keyed by the {@link 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

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 decriptor 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.

clearSubselectsback to summary
public void clearSubselects()

Clears all pending subselect fetches from the queue.

Called after flushing.

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

Get a batch of uninitialized collection keys for a given role

Parameters
collectionPersister:CollectionPersister

The persister for the collection role.

id:Serializable

A key that must be included in the batch fetch

batchSize:int

the maximum number of keys to return

Returns:Serializable[]

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

getEntityBatchback to summary
public Serializable[] getEntityBatch(final EntityPersister persister, final Serializable id, final int batchSize, final EntityMode entityMode)

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.

Parameters
persister:EntityPersister

The persister for the entities being loaded.

id:Serializable

The identifier of the entity currently demanding load.

batchSize:int

The maximum number of keys to return

Returns:Serializable[]

an array of identifiers, of length batchSize (possibly padded with nulls)

getSubselectback to summary
public 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: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, EntityMode entityMode)
isCachedback to summary
private boolean isCached(Serializable collectionKey, CollectionPersister persister, EntityMode entityMode)
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)