Search in sources :

Example 1 with BatchFetchQueue

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)));
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) EntityKey(org.hibernate.engine.spi.EntityKey) SessionImplementor(org.hibernate.engine.spi.SessionImplementor) BatchFetchQueue(org.hibernate.engine.spi.BatchFetchQueue)

Example 2 with BatchFetchQueue

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);
    }
}
Also used : BatchFetchQueue(org.hibernate.engine.spi.BatchFetchQueue)

Example 3 with BatchFetchQueue

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);
}
Also used : BatchFetchQueue(org.hibernate.engine.spi.BatchFetchQueue)

Example 4 with BatchFetchQueue

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
}
Also used : EntityEntry(org.hibernate.engine.spi.EntityEntry) CollectionEntry(org.hibernate.engine.spi.CollectionEntry) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) StatisticsImplementor(org.hibernate.stat.spi.StatisticsImplementor) BatchFetchQueue(org.hibernate.engine.spi.BatchFetchQueue)

Example 5 with BatchFetchQueue

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);
}
Also used : EntityKey(org.hibernate.engine.spi.EntityKey) BatchFetchQueue(org.hibernate.engine.spi.BatchFetchQueue)

Aggregations

BatchFetchQueue (org.hibernate.engine.spi.BatchFetchQueue)9 EntityKey (org.hibernate.engine.spi.EntityKey)5 EntityEntry (org.hibernate.engine.spi.EntityEntry)2 SessionImplementor (org.hibernate.engine.spi.SessionImplementor)2 SharedSessionContractImplementor (org.hibernate.engine.spi.SharedSessionContractImplementor)2 EntityPersister (org.hibernate.persister.entity.EntityPersister)2 PersistentCollection (org.hibernate.collection.spi.PersistentCollection)1 JdbcEnvironment (org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)1 JdbcServices (org.hibernate.engine.jdbc.spi.JdbcServices)1 CollectionEntry (org.hibernate.engine.spi.CollectionEntry)1 CollectionKey (org.hibernate.engine.spi.CollectionKey)1 PersistenceContext (org.hibernate.engine.spi.PersistenceContext)1 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)1 SubselectFetch (org.hibernate.engine.spi.SubselectFetch)1 PluralAttributeMapping (org.hibernate.metamodel.mapping.PluralAttributeMapping)1 QueryOptions (org.hibernate.query.spi.QueryOptions)1 QueryParameterBindings (org.hibernate.query.spi.QueryParameterBindings)1 SqlAstTranslatorFactory (org.hibernate.sql.ast.SqlAstTranslatorFactory)1 Callback (org.hibernate.sql.exec.spi.Callback)1 ExecutionContext (org.hibernate.sql.exec.spi.ExecutionContext)1