use of org.hibernate.engine.spi.BatchFetchQueue in project hibernate-orm by hibernate.
the class BatchFetchNotFoundIgnoreDefaultStyleTest method checkInBatchFetchQueue.
private static void checkInBatchFetchQueue(long id, Session session, boolean expected) {
final SessionImplementor sessionImplementor = (SessionImplementor) session;
final EntityPersister persister = sessionImplementor.getFactory().getMetamodel().entityPersister(Task.class);
final BatchFetchQueue batchFetchQueue = sessionImplementor.getPersistenceContext().getBatchFetchQueue();
assertEquals(expected, batchFetchQueue.containsEntityKey(new EntityKey(id, persister)));
}
use of org.hibernate.engine.spi.BatchFetchQueue in project hibernate-orm by hibernate.
the class StatefulPersistenceContext method addEntity.
@Override
public void addEntity(EntityKey key, Object entity) {
if (entitiesByKey == null) {
entitiesByKey = CollectionHelper.mapOfSize(INIT_COLL_SIZE);
}
entitiesByKey.put(key, entity);
final BatchFetchQueue fetchQueue = this.batchFetchQueue;
if (fetchQueue != null) {
fetchQueue.removeBatchLoadableEntityKey(key);
}
}
use of org.hibernate.engine.spi.BatchFetchQueue in project hibernate-orm by hibernate.
the class StatefulPersistenceContext method removeProxy.
@Override
public Object removeProxy(EntityKey key) {
final BatchFetchQueue fetchQueue = this.batchFetchQueue;
if (fetchQueue != null) {
fetchQueue.removeBatchLoadableEntityKey(key);
fetchQueue.removeSubselect(key);
}
return removeProxyByKey(key);
}
use of org.hibernate.engine.spi.BatchFetchQueue in project hibernate-orm by hibernate.
the class ResultsHelper method finalizeCollectionLoading.
public static void finalizeCollectionLoading(PersistenceContext persistenceContext, CollectionPersister collectionDescriptor, PersistentCollection<?> collectionInstance, Object key, boolean hasNoQueuedAdds) {
CollectionEntry collectionEntry = persistenceContext.getCollectionEntry(collectionInstance);
if (collectionEntry == null) {
collectionEntry = persistenceContext.addInitializedCollection(collectionDescriptor, collectionInstance, key);
} else {
collectionEntry.postInitialize(collectionInstance);
}
if (collectionDescriptor.getCollectionType().hasHolder()) {
// in case of PersistentArrayHolder we have to realign the EntityEntry loaded state with
// the entity values
final Object owner = collectionInstance.getOwner();
final EntityEntry entry = persistenceContext.getEntry(owner);
final PluralAttributeMapping mapping = collectionDescriptor.getAttributeMapping();
final int propertyIndex = mapping.getStateArrayPosition();
final Object[] loadedState = entry.getLoadedState();
loadedState[propertyIndex] = mapping.getValue(owner);
persistenceContext.addCollectionHolder(collectionInstance);
}
final BatchFetchQueue batchFetchQueue = persistenceContext.getBatchFetchQueue();
batchFetchQueue.removeBatchLoadableCollection(collectionEntry);
final SharedSessionContractImplementor session = persistenceContext.getSession();
// add to cache if:
final boolean addToCache = // there were no queued additions
hasNoQueuedAdds && // and the role has a cache
collectionDescriptor.hasCache() && // and this is not a forced initialization during flush
session.getCacheMode().isPutEnabled() && !collectionEntry.isDoremove();
if (addToCache) {
addCollectionToCache(persistenceContext, collectionDescriptor, collectionInstance, key);
}
if (LOG.isDebugEnabled()) {
LOG.debugf("Collection fully initialized: %s", MessageHelper.collectionInfoString(collectionDescriptor, collectionInstance, key, session));
}
final StatisticsImplementor statistics = session.getFactory().getStatistics();
if (statistics.isStatisticsEnabled()) {
statistics.loadCollection(collectionDescriptor.getRole());
}
// todo (6.0) : there is other logic still needing to be implemented here. caching, etc
// see org.hibernate.engine.loading.internal.CollectionLoadContext#endLoadingCollection in 5.x
}
use of org.hibernate.engine.spi.BatchFetchQueue in project hibernate-orm by hibernate.
the class BatchFetchQueueHelper method removeBatchLoadableEntityKey.
/**
* Remove the entity key with the specified {@code id} and {@code persister} from
* the batch loadable entities {@link BatchFetchQueue}.
*/
public static void removeBatchLoadableEntityKey(Object id, EntityPersister persister, SharedSessionContractImplementor session) {
final EntityKey entityKey = session.generateEntityKey(id, persister);
final BatchFetchQueue batchFetchQueue = session.getPersistenceContextInternal().getBatchFetchQueue();
batchFetchQueue.removeBatchLoadableEntityKey(entityKey);
}
Aggregations