HHH-13465 Allow inlined access to the PersistenceContext for internal methods

This commit is contained in:
Sanne Grinovero 2019-06-24 18:31:40 +01:00
parent 65d542f3c9
commit 2e81c32265
102 changed files with 541 additions and 376 deletions

View File

@ -16,6 +16,7 @@ import org.hibernate.engine.internal.Versioning;
import org.hibernate.engine.spi.CachedNaturalIdValueSource;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.engine.spi.Status;
import org.hibernate.persister.entity.EntityPersister;
@ -123,7 +124,7 @@ public abstract class AbstractEntityInsertAction extends EntityAction {
public final void makeEntityManaged() {
nullifyTransientReferencesIfNotAlready();
final Object version = Versioning.getVersion( getState(), getPersister() );
getSession().getPersistenceContext().addEntity(
getSession().getPersistenceContextInternal().addEntity(
getInstance(),
( getPersister().isMutable() ? Status.MANAGED : Status.READ_ONLY ),
getState(),
@ -155,7 +156,7 @@ public abstract class AbstractEntityInsertAction extends EntityAction {
// IMPL NOTE: non-flushed changes code calls this method with session == null...
// guard against NullPointerException
if ( session != null ) {
final EntityEntry entityEntry = session.getPersistenceContext().getEntry( getInstance() );
final EntityEntry entityEntry = session.getPersistenceContextInternal().getEntry( getInstance() );
this.state = entityEntry.getLoadedState();
}
}
@ -165,7 +166,7 @@ public abstract class AbstractEntityInsertAction extends EntityAction {
*/
protected void handleNaturalIdPreSaveNotifications() {
// before save, we need to add a local (transactional) natural id cross-reference
getSession().getPersistenceContext().getNaturalIdHelper().manageLocalNaturalIdCrossReference(
getSession().getPersistenceContextInternal().getNaturalIdHelper().manageLocalNaturalIdCrossReference(
getPersister(),
getId(),
state,
@ -180,9 +181,10 @@ public abstract class AbstractEntityInsertAction extends EntityAction {
* @param generatedId The generated entity identifier
*/
public void handleNaturalIdPostSaveNotifications(Serializable generatedId) {
final PersistenceContext.NaturalIdHelper naturalIdHelper = getSession().getPersistenceContextInternal().getNaturalIdHelper();
if ( isEarlyInsert() ) {
// with early insert, we still need to add a local (transactional) natural id cross-reference
getSession().getPersistenceContext().getNaturalIdHelper().manageLocalNaturalIdCrossReference(
naturalIdHelper.manageLocalNaturalIdCrossReference(
getPersister(),
generatedId,
state,
@ -191,7 +193,7 @@ public abstract class AbstractEntityInsertAction extends EntityAction {
);
}
// after save, we need to manage the shared cache entries
getSession().getPersistenceContext().getNaturalIdHelper().manageSharedNaturalIdCrossReference(
naturalIdHelper.manageSharedNaturalIdCrossReference(
getPersister(),
generatedId,
state,

View File

@ -114,7 +114,7 @@ public abstract class CollectionAction implements Executable, Serializable, Comp
Serializable finalKey = key;
if ( key instanceof DelayedPostInsertIdentifier ) {
// need to look it up from the persistence-context
finalKey = session.getPersistenceContext().getEntry( collection.getOwner() ).getId();
finalKey = session.getPersistenceContextInternal().getEntry( collection.getOwner() ).getId();
if ( finalKey == key ) {
// we may be screwed here since the collection action is about to execute
// and we do not know the final owner key value

View File

@ -18,6 +18,7 @@ import org.hibernate.event.spi.PostCollectionRecreateEventListener;
import org.hibernate.event.spi.PreCollectionRecreateEvent;
import org.hibernate.event.spi.PreCollectionRecreateEventListener;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.stat.spi.StatisticsImplementor;
/**
* The action for recreating a collection
@ -47,13 +48,15 @@ public final class CollectionRecreateAction extends CollectionAction {
final PersistentCollection collection = getCollection();
preRecreate();
getPersister().recreate( collection, getKey(), getSession() );
getSession().getPersistenceContext().getCollectionEntry( collection ).afterAction( collection );
final SharedSessionContractImplementor session = getSession();
getPersister().recreate( collection, getKey(), session);
session.getPersistenceContextInternal().getCollectionEntry( collection ).afterAction( collection );
evict();
postRecreate();
if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) {
getSession().getFactory().getStatistics().recreateCollection( getPersister().getRole() );
final StatisticsImplementor statistics = session.getFactory().getStatistics();
if ( statistics.isStatisticsEnabled() ) {
statistics.recreateCollection( getPersister().getRole() );
}
}

View File

@ -19,6 +19,7 @@ import org.hibernate.event.spi.PostCollectionRemoveEventListener;
import org.hibernate.event.spi.PreCollectionRemoveEvent;
import org.hibernate.event.spi.PreCollectionRemoveEventListener;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.stat.spi.StatisticsImplementor;
/**
* The action for removing a collection
@ -54,7 +55,7 @@ public final class CollectionRemoveAction extends CollectionAction {
// the loaded owner will be set to null after the collection is removed,
// so capture its value as the affected owner so it is accessible to
// both pre- and post- events
this.affectedOwner = session.getPersistenceContext().getLoadedCollectionOwnerOrNull( collection );
this.affectedOwner = session.getPersistenceContextInternal().getLoadedCollectionOwnerOrNull( collection );
}
/**
@ -88,24 +89,27 @@ public final class CollectionRemoveAction extends CollectionAction {
public void execute() throws HibernateException {
preRemove();
final SharedSessionContractImplementor session = getSession();
if ( !emptySnapshot ) {
// an existing collection that was either non-empty or uninitialized
// is replaced by null or a different collection
// (if the collection is uninitialized, hibernate has no way of
// knowing if the collection is actually empty without querying the db)
getPersister().remove( getKey(), getSession() );
getPersister().remove( getKey(), session);
}
final PersistentCollection collection = getCollection();
if ( collection != null ) {
getSession().getPersistenceContext().getCollectionEntry( collection ).afterAction( collection );
session.getPersistenceContextInternal().getCollectionEntry( collection ).afterAction( collection );
}
evict();
postRemove();
if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) {
getSession().getFactory().getStatistics().removeCollection( getPersister().getRole() );
final StatisticsImplementor statistics = session.getFactory().getStatistics();
if ( statistics.isStatisticsEnabled() ) {
statistics.removeCollection( getPersister().getRole() );
}
}

View File

@ -20,6 +20,7 @@ import org.hibernate.event.spi.PreCollectionUpdateEvent;
import org.hibernate.event.spi.PreCollectionUpdateEventListener;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.stat.spi.StatisticsImplementor;
/**
* The action for updating a collection
@ -88,12 +89,13 @@ public final class CollectionUpdateAction extends CollectionAction {
persister.insertRows( collection, id, session );
}
getSession().getPersistenceContext().getCollectionEntry( collection ).afterAction( collection );
session.getPersistenceContextInternal().getCollectionEntry( collection ).afterAction( collection );
evict();
postUpdate();
if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) {
getSession().getFactory().getStatistics().updateCollection( getPersister().getRole() );
final StatisticsImplementor statistics = session.getFactory().getStatistics();
if ( statistics.isStatisticsEnabled() ) {
statistics.updateCollection( getPersister().getRole() );
}
}

View File

@ -101,7 +101,7 @@ public abstract class EntityAction
*/
public final Serializable getId() {
if ( id instanceof DelayedPostInsertIdentifier ) {
final EntityEntry entry = session.getPersistenceContext().getEntry( instance );
final EntityEntry entry = session.getPersistenceContextInternal().getEntry( instance );
final Serializable eeId = entry == null ? null : entry.getId();
return eeId instanceof DelayedPostInsertIdentifier ? null : eeId;
}

View File

@ -24,6 +24,7 @@ import org.hibernate.event.spi.PostDeleteEventListener;
import org.hibernate.event.spi.PreDeleteEvent;
import org.hibernate.event.spi.PreDeleteEventListener;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.stat.spi.StatisticsImplementor;
/**
* The action for performing an entity deletion.
@ -61,7 +62,7 @@ public class EntityDeleteAction extends EntityAction {
this.state = state;
// before remove we need to remove the local (transactional) natural id cross-reference
naturalIdValues = session.getPersistenceContext().getNaturalIdHelper().removeLocalNaturalIdCrossReference(
naturalIdValues = session.getPersistenceContextInternal().getNaturalIdHelper().removeLocalNaturalIdCrossReference(
getPersister(),
getId(),
state
@ -103,7 +104,7 @@ public class EntityDeleteAction extends EntityAction {
// After actually deleting a row, record the fact that the instance no longer
// exists on the database (needed for identity-column key generation), and
// remove it from the session cache
final PersistenceContext persistenceContext = session.getPersistenceContext();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final EntityEntry entry = persistenceContext.removeEntry( instance );
if ( entry == null ) {
throw new AssertionFailure( "possible nonthreadsafe access to session" );
@ -121,8 +122,9 @@ public class EntityDeleteAction extends EntityAction {
postDelete();
if ( getSession().getFactory().getStatistics().isStatisticsEnabled() && !veto ) {
getSession().getFactory().getStatistics().deleteEntity( getPersister().getEntityName() );
final StatisticsImplementor statistics = getSession().getFactory().getStatistics();
if ( statistics.isStatisticsEnabled() && !veto ) {
statistics.deleteEntity( getPersister().getEntityName() );
}
}

View File

@ -11,8 +11,10 @@ import java.io.Serializable;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.event.service.spi.EventListenerGroup;
import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.EventType;
import org.hibernate.event.spi.PostCommitInsertEventListener;
import org.hibernate.event.spi.PostInsertEvent;
@ -20,6 +22,7 @@ import org.hibernate.event.spi.PostInsertEventListener;
import org.hibernate.event.spi.PreInsertEvent;
import org.hibernate.event.spi.PreInsertEventListener;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.stat.spi.StatisticsImplementor;
/**
* The action for performing entity insertions when entity is using IDENTITY column identifier generation
@ -85,9 +88,10 @@ public final class EntityIdentityInsertAction extends AbstractEntityInsertAction
//need to do that here rather than in the save event listener to let
//the post insert events to have a id-filled entity when IDENTITY is used (EJB3)
persister.setIdentifier( instance, generatedId, session );
session.getPersistenceContext().registerInsertedKey( getPersister(), generatedId );
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
persistenceContext.registerInsertedKey( getPersister(), generatedId );
entityKey = session.generateEntityKey( generatedId, persister );
session.getPersistenceContext().checkUniqueness( entityKey, getInstance() );
persistenceContext.checkUniqueness( entityKey, getInstance() );
}
@ -101,8 +105,9 @@ public final class EntityIdentityInsertAction extends AbstractEntityInsertAction
postInsert();
if ( session.getFactory().getStatistics().isStatisticsEnabled() && !isVeto() ) {
session.getFactory().getStatistics().insertEntity( getPersister().getEntityName() );
final StatisticsImplementor statistics = session.getFactory().getStatistics();
if ( statistics.isStatisticsEnabled() && !isVeto() ) {
statistics.insertEntity( getPersister().getEntityName() );
}
markExecuted();
@ -137,8 +142,9 @@ public final class EntityIdentityInsertAction extends AbstractEntityInsertAction
}
private void postInsert() {
final EventSource eventSource = eventSource();
if ( isDelayed ) {
getSession().getPersistenceContext().replaceDelayedEntityIdentityInsertKeys( delayedEntityKey, generatedId );
eventSource.getPersistenceContextInternal().replaceDelayedEntityIdentityInsertKeys( delayedEntityKey, generatedId );
}
final EventListenerGroup<PostInsertEventListener> listenerGroup = listenerGroup( EventType.POST_INSERT );
@ -150,7 +156,7 @@ public final class EntityIdentityInsertAction extends AbstractEntityInsertAction
generatedId,
getState(),
getPersister(),
eventSource()
eventSource
);
for ( PostInsertEventListener listener : listenerGroup.listeners() ) {
listener.onPostInsert( event );

View File

@ -28,6 +28,7 @@ import org.hibernate.event.spi.PreInsertEvent;
import org.hibernate.event.spi.PreInsertEventListener;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.stat.internal.StatsHelper;
import org.hibernate.stat.spi.StatisticsImplementor;
/**
* The action for performing an entity insertion, for entities not defined to use IDENTITY generation.
@ -88,7 +89,7 @@ public final class EntityInsertAction extends AbstractEntityInsertAction {
if ( !veto ) {
persister.insert( id, getState(), instance, session );
PersistenceContext persistenceContext = session.getPersistenceContext();
PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final EntityEntry entry = persistenceContext.getEntry( instance );
if ( entry == null ) {
throw new AssertionFailure( "possible non-threadsafe access to session" );
@ -109,6 +110,7 @@ public final class EntityInsertAction extends AbstractEntityInsertAction {
final SessionFactoryImplementor factory = session.getFactory();
final StatisticsImplementor statistics = factory.getStatistics();
if ( isCachePutEnabled( persister, session ) ) {
final CacheEntry ce = persister.buildCacheEntry(
instance,
@ -122,8 +124,8 @@ public final class EntityInsertAction extends AbstractEntityInsertAction {
final boolean put = cacheInsert( persister, ck );
if ( put && factory.getStatistics().isStatisticsEnabled() ) {
factory.getStatistics().entityCachePut(
if ( put && statistics.isStatisticsEnabled() ) {
statistics.entityCachePut(
StatsHelper.INSTANCE.getRootEntityRole( persister ),
cache.getRegion().getName()
);
@ -134,8 +136,8 @@ public final class EntityInsertAction extends AbstractEntityInsertAction {
postInsert();
if ( factory.getStatistics().isStatisticsEnabled() && !veto ) {
factory.getStatistics().insertEntity( getPersister().getEntityName() );
if ( statistics.isStatisticsEnabled() && !veto ) {
statistics.insertEntity( getPersister().getEntityName() );
}
markExecuted();

View File

@ -17,6 +17,7 @@ import org.hibernate.cache.spi.entry.CacheEntry;
import org.hibernate.engine.internal.Versioning;
import org.hibernate.engine.spi.CachedNaturalIdValueSource;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SessionEventListenerManager;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
@ -30,6 +31,7 @@ import org.hibernate.event.spi.PreUpdateEvent;
import org.hibernate.event.spi.PreUpdateEventListener;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.stat.internal.StatsHelper;
import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.type.TypeHelper;
/**
@ -84,7 +86,7 @@ public final class EntityUpdateAction extends EntityAction {
this.rowId = rowId;
this.previousNaturalIdValues = determinePreviousNaturalIdValues( persister, previousState, session, id );
session.getPersistenceContext().getNaturalIdHelper().manageLocalNaturalIdCrossReference(
session.getPersistenceContextInternal().getNaturalIdHelper().manageLocalNaturalIdCrossReference(
persister,
id,
state,
@ -102,11 +104,12 @@ public final class EntityUpdateAction extends EntityAction {
return null;
}
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
if ( previousState != null ) {
return session.getPersistenceContext().getNaturalIdHelper().extractNaturalIdValues( previousState, persister );
return persistenceContext.getNaturalIdHelper().extractNaturalIdValues( previousState, persister );
}
return session.getPersistenceContext().getNaturalIdSnapshot( id, persister );
return persistenceContext.getNaturalIdSnapshot( id, persister );
}
@Override
@ -156,7 +159,7 @@ public final class EntityUpdateAction extends EntityAction {
);
}
final EntityEntry entry = session.getPersistenceContext().getEntry( instance );
final EntityEntry entry = session.getPersistenceContextInternal().getEntry( instance );
if ( entry == null ) {
throw new AssertionFailure( "possible nonthreadsafe access to session" );
}
@ -185,6 +188,7 @@ public final class EntityUpdateAction extends EntityAction {
entry.postUpdate( instance, state, nextVersion );
}
final StatisticsImplementor statistics = factory.getStatistics();
if ( persister.canWriteToCache() ) {
if ( persister.isCacheInvalidationRequired() || entry.getStatus()!= Status.MANAGED ) {
persister.getCacheAccessStrategy().remove( session, ck);
@ -195,8 +199,8 @@ public final class EntityUpdateAction extends EntityAction {
cacheEntry = persister.getCacheEntryStructure().structure( ce );
final boolean put = cacheUpdate( persister, previousVersion, ck );
if ( put && factory.getStatistics().isStatisticsEnabled() ) {
factory.getStatistics().entityCachePut(
if ( put && statistics.isStatisticsEnabled() ) {
statistics.entityCachePut(
StatsHelper.INSTANCE.getRootEntityRole( persister ),
getPersister().getCacheAccessStrategy().getRegion().getName()
);
@ -204,7 +208,7 @@ public final class EntityUpdateAction extends EntityAction {
}
}
session.getPersistenceContext().getNaturalIdHelper().manageSharedNaturalIdCrossReference(
session.getPersistenceContextInternal().getNaturalIdHelper().manageSharedNaturalIdCrossReference(
persister,
id,
state,
@ -214,8 +218,8 @@ public final class EntityUpdateAction extends EntityAction {
postUpdate();
if ( factory.getStatistics().isStatisticsEnabled() && !veto ) {
factory.getStatistics().updateEntity( getPersister().getEntityName() );
if ( statistics.isStatisticsEnabled() && !veto ) {
statistics.updateEntity( getPersister().getEntityName() );
}
}

View File

@ -54,7 +54,7 @@ public final class QueuedOperationCollectionAction extends CollectionAction {
// The other CollectionAction types call CollectionEntry#afterAction, which
// clears the dirty flag. We don't want to call CollectionEntry#afterAction unless
// there is no other CollectionAction that will be executed on the same collection.
final CollectionEntry ce = getSession().getPersistenceContext().getCollectionEntry( getCollection() );
final CollectionEntry ce = getSession().getPersistenceContextInternal().getCollectionEntry( getCollection() );
if ( !ce.isDoremove() && !ce.isDoupdate() && !ce.isDorecreate() ) {
ce.afterAction( getCollection() );
}

View File

@ -181,7 +181,7 @@ public class UnresolvedEntityInsertActions {
*/
@SuppressWarnings({ "unchecked" })
public Set<AbstractEntityInsertAction> resolveDependentActions(Object managedEntity, SessionImplementor session) {
final EntityEntry entityEntry = session.getPersistenceContext().getEntry( managedEntity );
final EntityEntry entityEntry = session.getPersistenceContextInternal().getEntry( managedEntity );
if ( entityEntry.getStatus() != Status.MANAGED && entityEntry.getStatus() != Status.READ_ONLY ) {
throw new IllegalArgumentException( "EntityEntry did not have status MANAGED or READ_ONLY: " + entityEntry );
}

View File

@ -183,7 +183,7 @@ public class EnhancementAsProxyLazinessInterceptor extends AbstractLazyLoadInter
if ( isTemporarySession ) {
// Add an entry for this entity in the PC of the temp Session
session.getPersistenceContext().addEntity(
session.getPersistenceContextInternal().addEntity(
target,
Status.READ_ONLY,
// loaded state

View File

@ -210,7 +210,7 @@ public class EnhancementHelper {
final SessionFactoryImplementor sf = (SessionFactoryImplementor)
SessionFactoryRegistry.INSTANCE.getSessionFactory( interceptor.getSessionFactoryUuid() );
final SharedSessionContractImplementor session = (SharedSessionContractImplementor) sf.openSession();
session.getPersistenceContext().setDefaultReadOnly( true );
session.getPersistenceContextInternal().setDefaultReadOnly( true );
session.setHibernateFlushMode( FlushMode.MANUAL );
return session;
}

View File

@ -87,7 +87,7 @@ public class LazyAttributeLoadingInterceptor extends AbstractLazyLoadInterceptor
final Object[] loadedState = null;
// 2) does a row exist in the db for this entity?
final boolean existsInDb = true;
session.getPersistenceContext().addEntity(
session.getPersistenceContextInternal().addEntity(
target,
Status.READ_ONLY,
loadedState,

View File

@ -25,6 +25,7 @@ import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.engine.internal.ForeignKeys;
import org.hibernate.engine.spi.CollectionEntry;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
@ -162,7 +163,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
new LazyInitializationWork<Boolean>() {
@Override
public Boolean doWork() {
final CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this );
final CollectionEntry entry = session.getPersistenceContextInternal().getCollectionEntry( AbstractPersistentCollection.this );
if ( entry != null ) {
final CollectionPersister persister = entry.getLoadedPersister();
@ -253,7 +254,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
( (Session) session ).beginTransaction();
}
session.getPersistenceContext().addUninitializedDetachedCollection(
session.getPersistenceContextInternal().addUninitializedDetachedCollection(
session.getFactory().getCollectionPersister( getRole() ),
this
);
@ -289,7 +290,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
final SessionFactoryImplementor sf = (SessionFactoryImplementor)
SessionFactoryRegistry.INSTANCE.getSessionFactory( sessionFactoryUuid );
final SharedSessionContractImplementor session = (SharedSessionContractImplementor) sf.openSession();
session.getPersistenceContext().setDefaultReadOnly( true );
session.getPersistenceContextInternal().setDefaultReadOnly( true );
session.setFlushMode( FlushMode.MANUAL );
return session;
}
@ -300,7 +301,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
new LazyInitializationWork<Boolean>() {
@Override
public Boolean doWork() {
final CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this );
final CollectionEntry entry = session.getPersistenceContextInternal().getCollectionEntry( AbstractPersistentCollection.this );
final CollectionPersister persister = entry.getLoadedPersister();
if ( persister.isExtraLazy() ) {
if ( hasQueuedOperations() ) {
@ -328,7 +329,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
new LazyInitializationWork<Boolean>() {
@Override
public Boolean doWork() {
final CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this );
final CollectionEntry entry = session.getPersistenceContextInternal().getCollectionEntry( AbstractPersistentCollection.this );
final CollectionPersister persister = entry.getLoadedPersister();
if ( persister.isExtraLazy() ) {
if ( hasQueuedOperations() ) {
@ -360,7 +361,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
@Override
public Object doWork() {
final CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this );
final CollectionEntry entry = session.getPersistenceContextInternal().getCollectionEntry( AbstractPersistentCollection.this );
final CollectionPersister persister = entry.getLoadedPersister();
isExtraLazy = persister.isExtraLazy();
if ( isExtraLazy ) {
@ -394,7 +395,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
protected boolean isConnectedToSession() {
return session != null
&& session.isOpen()
&& session.getPersistenceContext().containsCollection( this );
&& session.getPersistenceContextInternal().containsCollection( this );
}
protected boolean isInitialized() {
@ -449,7 +450,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
*/
@SuppressWarnings({"JavaDoc"})
protected boolean isInverseCollection() {
final CollectionEntry ce = session.getPersistenceContext().getCollectionEntry( this );
final CollectionEntry ce = session.getPersistenceContextInternal().getCollectionEntry( this );
return ce != null && ce.getLoadedPersister().isInverse();
}
@ -459,7 +460,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
*/
@SuppressWarnings({"JavaDoc"})
protected boolean isInverseCollectionNoOrphanDelete() {
final CollectionEntry ce = session.getPersistenceContext().getCollectionEntry( this );
final CollectionEntry ce = session.getPersistenceContextInternal().getCollectionEntry( this );
return ce != null
&&
ce.getLoadedPersister().isInverse() &&
@ -472,7 +473,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
*/
@SuppressWarnings({"JavaDoc"})
protected boolean isInverseOneToManyOrNoOrphanDelete() {
final CollectionEntry ce = session.getPersistenceContext().getCollectionEntry( this );
final CollectionEntry ce = session.getPersistenceContextInternal().getCollectionEntry( this );
return ce != null
&& ce.getLoadedPersister().isInverse()
&& ( ce.getLoadedPersister().isOneToMany() || !ce.getLoadedPersister().hasOrphanDelete() );
@ -714,7 +715,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
sb.append( MessageHelper.collectionInfoString( roleCurrent, keyCurrent ) );
}
else {
final CollectionEntry ce = session.getPersistenceContext().getCollectionEntry( this );
final CollectionEntry ce = session.getPersistenceContextInternal().getCollectionEntry( this );
if ( ce != null ) {
sb.append(
MessageHelper.collectionInfoString(
@ -1249,9 +1250,10 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
// collect EntityIdentifier(s) of the *current* elements - add them into a HashSet for fast access
final java.util.Set currentIds = new HashSet();
final java.util.Set currentSaving = new IdentitySet();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
for ( Object current : currentElements ) {
if ( current != null && ForeignKeys.isNotTransient( entityName, current, null, session ) ) {
final EntityEntry ee = session.getPersistenceContext().getEntry( current );
final EntityEntry ee = persistenceContext.getEntry( current );
if ( ee != null && ee.getStatus() == Status.SAVING ) {
currentSaving.add( current );
}

View File

@ -48,7 +48,7 @@ public class OptimisticForceIncrementLockingStrategy implements LockingStrategy
if ( !lockable.isVersioned() ) {
throw new HibernateException( "[" + lockMode + "] not supported for non-versioned entities [" + lockable.getEntityName() + "]" );
}
final EntityEntry entry = session.getPersistenceContext().getEntry( object );
final EntityEntry entry = session.getPersistenceContextInternal().getEntry( object );
// Register the EntityIncrementVersionProcess action to run just prior to transaction commit.
( (EventSource) session ).getActionQueue().registerProcess( new EntityIncrementVersionProcess( object, entry ) );
}

View File

@ -49,7 +49,7 @@ public class OptimisticLockingStrategy implements LockingStrategy {
if ( !lockable.isVersioned() ) {
throw new OptimisticLockException( object, "[" + lockMode + "] not supported for non-versioned entities [" + lockable.getEntityName() + "]" );
}
final EntityEntry entry = session.getPersistenceContext().getEntry( object );
final EntityEntry entry = session.getPersistenceContextInternal().getEntry( object );
// Register the EntityVerifyVersionProcess action to run just prior to transaction commit.
( (EventSource) session ).getActionQueue().registerProcess( new EntityVerifyVersionProcess( object, entry ) );
}

View File

@ -47,7 +47,7 @@ public class PessimisticForceIncrementLockingStrategy implements LockingStrategy
if ( !lockable.isVersioned() ) {
throw new HibernateException( "[" + lockMode + "] not supported for non-versioned entities [" + lockable.getEntityName() + "]" );
}
final EntityEntry entry = session.getPersistenceContext().getEntry( object );
final EntityEntry entry = session.getPersistenceContextInternal().getEntry( object );
final EntityPersister persister = entry.getPersister();
final Object nextVersion = persister.forceVersionIncrement( entry.getId(), entry.getVersion(), session );
entry.forceLocked( object, nextVersion );

View File

@ -309,7 +309,7 @@ public abstract class AbstractEntityEntry implements Serializable, EntityEntry {
return !isExistsInDatabase();
}
else {
return session.getPersistenceContext().getNullifiableEntityKeys().contains( getEntityKey() );
return session.getPersistenceContextInternal().getNullifiableEntityKeys().contains( getEntityKey() );
}
}

View File

@ -79,7 +79,7 @@ public class BatchFetchQueueHelper {
EntityPersister persister,
SharedSessionContractImplementor session) {
final EntityKey entityKey = session.generateEntityKey( id, persister );
final BatchFetchQueue batchFetchQueue = session.getPersistenceContext().getBatchFetchQueue();
final BatchFetchQueue batchFetchQueue = session.getPersistenceContextInternal().getBatchFetchQueue();
batchFetchQueue.removeBatchLoadableEntityKey( entityKey );
}
}

View File

@ -18,6 +18,7 @@ import org.hibernate.engine.spi.CascadeStyle;
import org.hibernate.engine.spi.CascadingAction;
import org.hibernate.engine.spi.CollectionEntry;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.Status;
import org.hibernate.event.spi.EventSource;
import org.hibernate.internal.CoreLogging;
@ -83,6 +84,7 @@ public final class Cascade {
if ( traceEnabled ) {
LOG.tracev( "Processing cascade {0} for: {1}", action, persister.getEntityName() );
}
final PersistenceContext persistenceContext = eventSource.getPersistenceContextInternal();
final Type[] types = persister.getPropertyTypes();
final String[] propertyNames = persister.getPropertyNames();
@ -105,7 +107,7 @@ public final class Cascade {
// If parent is a detached entity being merged,
// then parent will not be in the PersistencContext
// (so lazy attributes must not be initialized).
if ( eventSource.getPersistenceContext().getEntry( parent ) == null ) {
if ( persistenceContext.getEntry( parent ) == null ) {
// parent was not in the PersistenceContext
continue;
}
@ -271,7 +273,8 @@ public final class Cascade {
if ( style.hasOrphanDelete() && action.deleteOrphans() ) {
// value is orphaned if loaded state for this property shows not null
// because it is currently null.
final EntityEntry entry = eventSource.getPersistenceContext().getEntry( parent );
final PersistenceContext persistenceContext = eventSource.getPersistenceContextInternal();
final EntityEntry entry = persistenceContext.getEntry( parent );
if ( entry != null && entry.getStatus() != Status.SAVING ) {
Object loadedValue;
if ( componentPathStackDepth == 0 ) {
@ -299,15 +302,13 @@ public final class Cascade {
// orphaned if the association was nulled (child == null) or receives a new value while the
// entity is managed (without first nulling and manually flushing).
if ( child == null || ( loadedValue != null && child != loadedValue ) ) {
EntityEntry valueEntry = eventSource
.getPersistenceContext().getEntry(
loadedValue );
EntityEntry valueEntry = persistenceContext.getEntry( loadedValue );
if ( valueEntry == null && loadedValue instanceof HibernateProxy ) {
// un-proxy and re-associate for cascade operation
// useful for @OneToOne defined as FetchType.LAZY
loadedValue = eventSource.getPersistenceContext().unproxyAndReassociate( loadedValue );
valueEntry = eventSource.getPersistenceContext().getEntry( loadedValue );
loadedValue = persistenceContext.unproxyAndReassociate( loadedValue );
valueEntry = persistenceContext.getEntry( loadedValue );
// HHH-11965
// Should the unwrapped proxy value be equal via reference to the entity's property value
@ -485,12 +486,13 @@ public final class Cascade {
: null;
if ( style.reallyDoCascade( action ) ) {
//not really necessary, but good for consistency...
eventSource.getPersistenceContext().addChildParent( child, parent );
final PersistenceContext persistenceContext = eventSource.getPersistenceContextInternal();
persistenceContext.addChildParent( child, parent );
try {
action.cascade( eventSource, child, entityName, anything, isCascadeDeleteEnabled );
}
finally {
eventSource.getPersistenceContext().removeChildParent( child );
persistenceContext.removeChildParent( child );
}
}
}
@ -570,7 +572,7 @@ public final class Cascade {
//TODO: suck this logic into the collection!
final Collection orphans;
if ( pc.wasInitialized() ) {
final CollectionEntry ce = eventSource.getPersistenceContext().getCollectionEntry( pc );
final CollectionEntry ce = eventSource.getPersistenceContextInternal().getCollectionEntry( pc );
orphans = ce==null
? java.util.Collections.EMPTY_LIST
: ce.getOrphans( entityName, pc );

View File

@ -53,7 +53,7 @@ public final class Collections {
}
private static void processDereferencedCollection(PersistentCollection coll, SessionImplementor session) {
final PersistenceContext persistenceContext = session.getPersistenceContext();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final CollectionEntry entry = persistenceContext.getCollectionEntry( coll );
final CollectionPersister loadedPersister = entry.getLoadedPersister();
@ -111,7 +111,7 @@ public final class Collections {
private static void processNeverReferencedCollection(PersistentCollection coll, SessionImplementor session)
throws HibernateException {
final PersistenceContext persistenceContext = session.getPersistenceContext();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final CollectionEntry entry = persistenceContext.getCollectionEntry( coll );
if ( LOG.isDebugEnabled() ) {
@ -147,7 +147,8 @@ public final class Collections {
Object entity,
SessionImplementor session) {
collection.setOwner( entity );
final CollectionEntry ce = session.getPersistenceContext().getCollectionEntry( collection );
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final CollectionEntry ce = persistenceContext.getCollectionEntry( collection );
if ( ce == null ) {
// refer to comment in StatefulPersistenceContext.addCollection()

View File

@ -160,7 +160,7 @@ public final class ForeignKeys {
if ( isDelete &&
value == LazyPropertyInitializer.UNFETCHED_PROPERTY &&
type.isEntityType() &&
!session.getPersistenceContext().getNullifiableEntityKeys().isEmpty() ) {
!session.getPersistenceContextInternal().getNullifiableEntityKeys().isEmpty() ) {
// IMPLEMENTATION NOTE: If cascade-remove was mapped for the attribute,
// then value should have been initialized previously, when the remove operation was
// cascaded to the property (because CascadingAction.DELETE.performOnLazyProperty()
@ -225,7 +225,7 @@ public final class ForeignKeys {
// id is not "unsaved" (that is, we rely on foreign keys to keep
// database integrity)
final EntityEntry entityEntry = session.getPersistenceContext().getEntry( object );
final EntityEntry entityEntry = session.getPersistenceContextInternal().getEntry( object );
if ( entityEntry == null ) {
return isTransient( entityName, object, null, session );
}
@ -254,7 +254,7 @@ public final class ForeignKeys {
return true;
}
if ( session.getPersistenceContext().isEntryFor( entity ) ) {
if ( session.getPersistenceContextInternal().isEntryFor( entity ) ) {
return true;
}
@ -303,7 +303,7 @@ public final class ForeignKeys {
}
// hit the database, after checking the session cache for a snapshot
final Object[] snapshot = session.getPersistenceContext().getDatabaseSnapshot(
final Object[] snapshot = session.getPersistenceContextInternal().getDatabaseSnapshot(
persister.getIdentifier( entity, session ),
persister
);

View File

@ -1410,7 +1410,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
setEntityReadOnly( object, readOnly );
// PersistenceContext.proxyFor( entity ) returns entity if there is no proxy for that entity
// so need to check the return value to be sure it is really a proxy
final Object maybeProxy = getSession().getPersistenceContext().proxyFor( object );
final Object maybeProxy = getSession().getPersistenceContextInternal().proxyFor( object );
if ( maybeProxy instanceof HibernateProxy ) {
setProxyReadOnly( (HibernateProxy) maybeProxy, readOnly );
}

View File

@ -83,7 +83,7 @@ public final class TwoPhaseLoad {
final LockMode lockMode,
final SharedSessionContractImplementor session) {
final Object version = Versioning.getVersion( values, persister );
session.getPersistenceContext().addEntry(
session.getPersistenceContextInternal().addEntry(
object,
Status.LOADING,
values,
@ -152,7 +152,7 @@ public final class TwoPhaseLoad {
final SharedSessionContractImplementor session,
final PreLoadEvent preLoadEvent,
final Iterable<PreLoadEventListener> preLoadEventListeners) {
final PersistenceContext persistenceContext = session.getPersistenceContext();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final EntityEntry entityEntry = persistenceContext.getEntry( entity );
if ( entityEntry == null ) {
throw new AssertionFailure( "possible non-threadsafe access to the session" );
@ -167,7 +167,7 @@ public final class TwoPhaseLoad {
final SharedSessionContractImplementor session,
final PreLoadEvent preLoadEvent,
final Iterable<PreLoadEventListener> preLoadEventListeners) throws HibernateException {
final PersistenceContext persistenceContext = session.getPersistenceContext();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final EntityPersister persister = entityEntry.getPersister();
final Serializable id = entityEntry.getId();
final Object[] hydratedState = entityEntry.getLoadedState();
@ -264,7 +264,7 @@ public final class TwoPhaseLoad {
// 2) Session#clear + some form of load
//
// we need to be careful not to clobber the lock here in the cache so that it can be rolled back if need be
if ( session.getPersistenceContext().wasInsertedDuringTransaction( persister, id ) ) {
if ( session.getPersistenceContextInternal().wasInsertedDuringTransaction( persister, id ) ) {
cache.update(
session,
cacheKey,
@ -380,18 +380,17 @@ public final class TwoPhaseLoad {
String entityName,
String associationName,
Type type) {
if ( type.isAssociationType() || type.isCollectionType() ) {
// Performance: check type.isCollectionType() first, as type.isAssociationType() is megamorphic
if ( type.isCollectionType() || type.isAssociationType() ) {
Boolean overridingEager = isEagerFetchProfile( session, entityName, associationName );
if ( LOG.isDebugEnabled() ) {
if ( overridingEager != null ) {
LOG.debugf(
"Overriding eager fetching using active fetch profile. EntityName: %s, associationName: %s, eager fetching: %s",
entityName,
associationName,
overridingEager
);
}
if ( overridingEager != null ) {
LOG.debugf(
"Overriding eager fetching using active fetch profile. EntityName: %s, associationName: %s, eager fetching: %s",
entityName,
associationName,
overridingEager
);
}
return overridingEager;
@ -438,7 +437,7 @@ public final class TwoPhaseLoad {
if ( session.isEventSource() ) {
final PersistenceContext persistenceContext
= session.getPersistenceContext();
= session.getPersistenceContextInternal();
final EntityEntry entityEntry = persistenceContext.getEntry( entity );
postLoadEvent.setEntity( entity ).setId( entityEntry.getId() ).setPersister( entityEntry.getPersister() );
@ -497,7 +496,7 @@ public final class TwoPhaseLoad {
final EntityPersister persister,
final LockMode lockMode,
final SharedSessionContractImplementor session) {
session.getPersistenceContext().addEntity(
session.getPersistenceContextInternal().addEntity(
object,
Status.LOADING,
null,
@ -527,7 +526,7 @@ public final class TwoPhaseLoad {
final LockMode lockMode,
final Object version,
final SharedSessionContractImplementor session) {
session.getPersistenceContext().addEntity(
session.getPersistenceContextInternal().addEntity(
object,
Status.LOADING,
null,

View File

@ -23,6 +23,7 @@ import org.hibernate.cache.spi.entry.CollectionCacheEntry;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.engine.spi.CollectionEntry;
import org.hibernate.engine.spi.CollectionKey;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.engine.spi.Status;
@ -163,6 +164,7 @@ public class CollectionLoadContext {
// the #endRead processing.
List<LoadingCollectionEntry> matches = null;
final Iterator itr = localLoadingCollectionKeys.iterator();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
while ( itr.hasNext() ) {
final CollectionKey collectionKey = (CollectionKey) itr.next();
final LoadingCollectionEntry lce = loadContexts.locateLoadingCollectionEntry( collectionKey );
@ -175,7 +177,7 @@ public class CollectionLoadContext {
}
matches.add( lce );
if ( lce.getCollection().getOwner() == null ) {
session.getPersistenceContext().addUnownedCollection(
persistenceContext.addUnownedCollection(
new CollectionKey(
persister,
lce.getKey()
@ -310,7 +312,8 @@ public class CollectionLoadContext {
* @param persister The persister
*/
private void addCollectionToCache(LoadingCollectionEntry lce, CollectionPersister persister) {
final SharedSessionContractImplementor session = getLoadContext().getPersistenceContext().getSession();
final PersistenceContext persistenceContext = getLoadContext().getPersistenceContext();
final SharedSessionContractImplementor session = persistenceContext.getSession();
final SessionFactoryImplementor factory = session.getFactory();
if ( LOG.isDebugEnabled() ) {
@ -331,7 +334,7 @@ public class CollectionLoadContext {
final Object version;
if ( persister.isVersioned() ) {
Object collectionOwner = getLoadContext().getPersistenceContext().getCollectionOwner( lce.getKey(), persister );
Object collectionOwner = persistenceContext.getCollectionOwner( lce.getKey(), persister );
if ( collectionOwner == null ) {
// generally speaking this would be caused by the collection key being defined by a property-ref, thus
// the collection key and the owner key would not match up. In this case, try to use the key of the
@ -342,7 +345,7 @@ public class CollectionLoadContext {
final Object linkedOwner = lce.getCollection().getOwner();
if ( linkedOwner != null ) {
final Serializable ownerKey = persister.getOwnerEntityPersister().getIdentifier( linkedOwner, session );
collectionOwner = getLoadContext().getPersistenceContext().getCollectionOwner( ownerKey, persister );
collectionOwner = persistenceContext.getCollectionOwner( ownerKey, persister );
}
}
if ( collectionOwner == null ) {
@ -353,7 +356,7 @@ public class CollectionLoadContext {
);
}
}
version = getLoadContext().getPersistenceContext().getEntry( collectionOwner ).getVersion();
version = persistenceContext.getEntry( collectionOwner ).getVersion();
}
else {
version = null;
@ -372,7 +375,7 @@ public class CollectionLoadContext {
if ( persister.getElementType().isAssociationType() ) {
for ( Serializable id : entry.getState() ) {
EntityPersister entityPersister = ( (QueryableCollection) persister ).getElementPersister();
if ( session.getPersistenceContext().wasInsertedDuringTransaction( entityPersister, id ) ) {
if ( persistenceContext.wasInsertedDuringTransaction( entityPersister, id ) ) {
isPutFromLoad = false;
break;
}

View File

@ -393,7 +393,7 @@ public class CascadingActions {
}
private boolean isInManagedState(Object child, EventSource session) {
EntityEntry entry = session.getPersistenceContext().getEntry( child );
EntityEntry entry = session.getPersistenceContextInternal().getEntry( child );
return entry != null &&
(
entry.getStatus() == Status.MANAGED ||

View File

@ -204,7 +204,7 @@ public final class CollectionEntry implements Serializable {
collection.setSnapshot(loadedKey, role, snapshot);
if ( loadedPersister.getBatchSize() > 1 ) {
( (AbstractPersistentCollection) collection ).getSession()
.getPersistenceContext()
.getPersistenceContextInternal()
.getBatchFetchQueue()
.removeBatchLoadableCollection( this );
}

View File

@ -470,7 +470,7 @@ public final class QueryParameters {
public boolean isReadOnly(SharedSessionContractImplementor session) {
return isReadOnlyInitialized
? isReadOnly()
: session.getPersistenceContext().isDefaultReadOnly();
: session.getPersistenceContextInternal().isDefaultReadOnly();
}
/**

View File

@ -466,6 +466,11 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
return delegate.getExceptionConverter();
}
@Override
public PersistenceContext getPersistenceContextInternal() {
return delegate.getPersistenceContextInternal();
}
@Override
public SessionEventListenerManager getEventListenerManager() {
return delegate.getEventListenerManager();

View File

@ -91,7 +91,13 @@ public interface SharedSessionContractImplementor
SessionEventListenerManager getEventListenerManager();
/**
* Get the persistence context for this session
* Get the persistence context for this session.
* See also {@link #getPersistenceContextInternal()} for
* an alternative.
*
* This method is not extremely fast: if you need to access
* the PersistenceContext multiple times, prefer keeping
* a reference to it over invoking this method multiple times.
*/
PersistenceContext getPersistenceContext();
@ -504,4 +510,19 @@ public interface SharedSessionContractImplementor
Class<T> resultClass,
Selection selection,
HibernateEntityManagerImplementor.QueryOptions queryOptions);
/**
* This is similar to {@link #getPersistenceContext()}, with
* two main differences:
* a) this version performs better as
* it allows for inlining and probably better prediction
* b) see SessionImpl{@link #getPersistenceContext()} : it
* does some checks on the current state of the Session.
*
* Choose wisely: performance is important, correctness comes first.
*
* @return the PersistenceContext associated to this session.
*/
PersistenceContext getPersistenceContextInternal();
}

View File

@ -19,6 +19,7 @@ import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.engine.internal.Cascade;
import org.hibernate.engine.internal.CascadePoint;
import org.hibernate.engine.internal.Collections;
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
import org.hibernate.engine.spi.ActionQueue;
import org.hibernate.engine.spi.CascadingAction;
import org.hibernate.engine.spi.CascadingActions;
@ -77,7 +78,7 @@ public abstract class AbstractFlushingEventListener implements JpaBootstrapSensi
EventSource session = event.getSession();
final PersistenceContext persistenceContext = session.getPersistenceContext();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
session.getInterceptor().preFlush( new LazyIterator( persistenceContext.getEntitiesByKey() ) );
prepareEntityFlushes( session, persistenceContext );
@ -111,7 +112,7 @@ public abstract class AbstractFlushingEventListener implements JpaBootstrapSensi
return;
}
final EventSource session = event.getSession();
final PersistenceContext persistenceContext = session.getPersistenceContext();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
LOG.debugf(
"Flushed: %s insertions, %s updates, %s deletions to %s objects",
session.getActionQueue().numberOfInsertions(),
@ -154,12 +155,13 @@ public abstract class AbstractFlushingEventListener implements JpaBootstrapSensi
private void cascadeOnFlush(EventSource session, EntityPersister persister, Object object, Object anything)
throws HibernateException {
session.getPersistenceContext().incrementCascadeLevel();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
persistenceContext.incrementCascadeLevel();
try {
Cascade.cascade( getCascadingAction(), CascadePoint.BEFORE_FLUSH, session, persister, object, anything );
}
finally {
session.getPersistenceContext().decrementCascadeLevel();
persistenceContext.decrementCascadeLevel();
}
}
@ -347,17 +349,20 @@ public abstract class AbstractFlushingEventListener implements JpaBootstrapSensi
// during-flush callbacks more leniency in regards to initializing proxies and
// lazy collections during their processing.
// For more information, see HHH-2763
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final JdbcCoordinator jdbcCoordinator = session.getJdbcCoordinator();
try {
session.getJdbcCoordinator().flushBeginning();
session.getPersistenceContext().setFlushing( true );
jdbcCoordinator.flushBeginning();
persistenceContext.setFlushing( true );
// we need to lock the collection caches before executing entity inserts/updates in order to
// account for bi-directional associations
session.getActionQueue().prepareActions();
session.getActionQueue().executeActions();
final ActionQueue actionQueue = session.getActionQueue();
actionQueue.prepareActions();
actionQueue.executeActions();
}
finally {
session.getPersistenceContext().setFlushing( false );
session.getJdbcCoordinator().flushEnding();
persistenceContext.setFlushing( false );
jdbcCoordinator.flushEnding();
}
}
@ -375,7 +380,7 @@ public abstract class AbstractFlushingEventListener implements JpaBootstrapSensi
LOG.trace( "Post flush" );
final PersistenceContext persistenceContext = session.getPersistenceContext();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
persistenceContext.getCollectionsByKey().clear();
// the database has changed now, so the subselect results need to be invalidated
@ -406,6 +411,6 @@ public abstract class AbstractFlushingEventListener implements JpaBootstrapSensi
}
protected void postPostFlush(SessionImplementor session) {
session.getInterceptor().postFlush( new LazyIterator( session.getPersistenceContext().getEntitiesByKey() ) );
session.getInterceptor().postFlush( new LazyIterator( session.getPersistenceContextInternal().getEntitiesByKey() ) );
}
}

View File

@ -12,6 +12,7 @@ import org.hibernate.LockMode;
import org.hibernate.engine.internal.Versioning;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.Status;
import org.hibernate.event.spi.AbstractEvent;
import org.hibernate.event.spi.EventSource;
@ -54,7 +55,8 @@ public abstract class AbstractReassociateEventListener implements Serializable {
final EventSource source = event.getSession();
final EntityKey key = source.generateEntityKey( id, persister );
source.getPersistenceContext().checkUniqueness( key, object );
final PersistenceContext persistenceContext = source.getPersistenceContext();
persistenceContext.checkUniqueness( key, object );
//get a snapshot
Object[] values = persister.getPropertyValues( object );
@ -67,7 +69,7 @@ public abstract class AbstractReassociateEventListener implements Serializable {
);
Object version = Versioning.getVersion( values, persister );
EntityEntry newEntry = source.getPersistenceContext().addEntity(
EntityEntry newEntry = persistenceContext.addEntity(
object,
( persister.isMutable() ? Status.MANAGED : Status.READ_ONLY ),
values,

View File

@ -23,6 +23,7 @@ import org.hibernate.engine.spi.CascadingAction;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.EntityEntryExtraState;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SelfDirtinessTracker;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.Status;
@ -174,10 +175,11 @@ public abstract class AbstractSaveEventListener
final EntityKey key;
if ( !useIdentityColumn ) {
key = source.generateEntityKey( id, persister );
Object old = source.getPersistenceContext().getEntity( key );
final PersistenceContext persistenceContext = source.getPersistenceContextInternal();
Object old = persistenceContext.getEntity( key );
if ( old != null ) {
if ( source.getPersistenceContext().getEntry( old ).getStatus() == Status.DELETED ) {
source.forceFlush( source.getPersistenceContext().getEntry( old ) );
if ( persistenceContext.getEntry( old ).getStatus() == Status.DELETED ) {
source.forceFlush( persistenceContext.getEntry( old ) );
}
else {
throw new NonUniqueObjectException( id, persister.getEntityName() );
@ -246,11 +248,12 @@ public abstract class AbstractSaveEventListener
boolean inTrx = source.isTransactionInProgress();
boolean shouldDelayIdentityInserts = !inTrx && !requiresImmediateIdAccess;
final PersistenceContext persistenceContext = source.getPersistenceContextInternal();
// Put a placeholder in entries, so we don't recurse back and try to save() the
// same object again. QUESTION: should this be done before onSave() is called?
// likewise, should it be done before onUpdate()?
EntityEntry original = source.getPersistenceContext().addEntry(
EntityEntry original = persistenceContext.addEntry(
entity,
Status.SAVING,
null,
@ -305,7 +308,7 @@ public abstract class AbstractSaveEventListener
insert.handleNaturalIdPostSaveNotifications( id );
}
EntityEntry newEntry = source.getPersistenceContext().getEntry( entity );
EntityEntry newEntry = persistenceContext.getEntry( entity );
if ( newEntry != original ) {
EntityEntryExtraState extraState = newEntry.getExtraState( EntityEntryExtraState.class );
@ -423,7 +426,8 @@ public abstract class AbstractSaveEventListener
Object anything) {
// cascade-save to many-to-one BEFORE the parent is saved
source.getPersistenceContext().incrementCascadeLevel();
final PersistenceContext persistenceContext = source.getPersistenceContextInternal();
persistenceContext.incrementCascadeLevel();
try {
Cascade.cascade(
getCascadeAction(),
@ -435,7 +439,7 @@ public abstract class AbstractSaveEventListener
);
}
finally {
source.getPersistenceContext().decrementCascadeLevel();
persistenceContext.decrementCascadeLevel();
}
}
@ -453,8 +457,9 @@ public abstract class AbstractSaveEventListener
Object entity,
Object anything) {
final PersistenceContext persistenceContext = source.getPersistenceContextInternal();
// cascade-save to collections AFTER the collection owner was saved
source.getPersistenceContext().incrementCascadeLevel();
persistenceContext.incrementCascadeLevel();
try {
Cascade.cascade(
getCascadeAction(),
@ -466,7 +471,7 @@ public abstract class AbstractSaveEventListener
);
}
finally {
source.getPersistenceContext().decrementCascadeLevel();
persistenceContext.decrementCascadeLevel();
}
}

View File

@ -8,6 +8,7 @@ package org.hibernate.event.internal;
import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.event.spi.AutoFlushEvent;
import org.hibernate.event.spi.AutoFlushEventListener;
import org.hibernate.event.spi.EventSource;
@ -78,9 +79,10 @@ public class DefaultAutoFlushEventListener extends AbstractFlushingEventListener
}
private boolean flushMightBeNeeded(final EventSource source) {
final PersistenceContext persistenceContext = source.getPersistenceContextInternal();
return !source.getHibernateFlushMode().lessThan( FlushMode.AUTO )
&& source.getDontFlushFromFind() == 0
&& ( source.getPersistenceContext().getNumberOfManagedEntities() > 0 ||
source.getPersistenceContext().getCollectionEntries().size() > 0 );
&& ( persistenceContext.getNumberOfManagedEntities() > 0 ||
persistenceContext.getCollectionEntries().size() > 0 );
}
}

View File

@ -84,7 +84,7 @@ public class DefaultDeleteEventListener implements DeleteEventListener, Callback
final EventSource source = event.getSession();
final PersistenceContext persistenceContext = source.getPersistenceContext();
final PersistenceContext persistenceContext = source.getPersistenceContextInternal();
Object entity = persistenceContext.unproxyAndReassociate( event.getObject() );
EntityEntry entityEntry = persistenceContext.getEntry( entity );
@ -255,7 +255,7 @@ public class DefaultDeleteEventListener implements DeleteEventListener, Callback
);
}
final PersistenceContext persistenceContext = session.getPersistenceContext();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final Type[] propTypes = persister.getPropertyTypes();
final Object version = entityEntry.getVersion();
@ -359,7 +359,8 @@ public class DefaultDeleteEventListener implements DeleteEventListener, Callback
CacheMode cacheMode = session.getCacheMode();
session.setCacheMode( CacheMode.GET );
session.getPersistenceContext().incrementCascadeLevel();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
persistenceContext.incrementCascadeLevel();
try {
// cascade-delete to collections BEFORE the collection owner is deleted
Cascade.cascade(
@ -372,7 +373,7 @@ public class DefaultDeleteEventListener implements DeleteEventListener, Callback
);
}
finally {
session.getPersistenceContext().decrementCascadeLevel();
persistenceContext.decrementCascadeLevel();
session.setCacheMode( cacheMode );
}
}
@ -385,7 +386,8 @@ public class DefaultDeleteEventListener implements DeleteEventListener, Callback
CacheMode cacheMode = session.getCacheMode();
session.setCacheMode( CacheMode.GET );
session.getPersistenceContext().incrementCascadeLevel();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
persistenceContext.incrementCascadeLevel();
try {
// cascade-delete to many-to-one AFTER the parent was deleted
Cascade.cascade(
@ -398,7 +400,7 @@ public class DefaultDeleteEventListener implements DeleteEventListener, Callback
);
}
finally {
session.getPersistenceContext().decrementCascadeLevel();
persistenceContext.decrementCascadeLevel();
session.setCacheMode( cacheMode );
}
}

View File

@ -50,7 +50,7 @@ public class DefaultEvictEventListener implements EvictEventListener {
}
final EventSource source = event.getSession();
final PersistenceContext persistenceContext = source.getPersistenceContext();
final PersistenceContext persistenceContext = source.getPersistenceContextInternal();
if ( object instanceof HibernateProxy ) {
final LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
@ -108,8 +108,9 @@ public class DefaultEvictEventListener implements EvictEventListener {
LOG.tracev( "Evicting {0}", MessageHelper.infoString( persister ) );
}
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
if ( persister.hasNaturalIdentifier() ) {
session.getPersistenceContext().getNaturalIdHelper().handleEviction(
persistenceContext.getNaturalIdHelper().handleEviction(
object,
persister,
key.getIdentifier()
@ -127,8 +128,8 @@ public class DefaultEvictEventListener implements EvictEventListener {
// This is now handled by removeEntity()
//session.getPersistenceContext().removeDatabaseSnapshot(key);
session.getPersistenceContext().removeEntity( key );
session.getPersistenceContext().removeEntry( object );
persistenceContext.removeEntity( key );
persistenceContext.removeEntry( object );
Cascade.cascade( CascadingActions.EVICT, CascadePoint.AFTER_EVICT, session, persister, object );
}

View File

@ -21,6 +21,7 @@ import org.hibernate.engine.internal.Nullability;
import org.hibernate.engine.internal.Versioning;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SelfDirtinessTracker;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.Status;
@ -35,6 +36,7 @@ import org.hibernate.jpa.event.spi.CallbackRegistryConsumer;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.type.Type;
/**
@ -97,9 +99,10 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
final Type[] propertyTypes = persister.getPropertyTypes();
final boolean[] propertyUpdateability = persister.getPropertyUpdateability();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final Object[] snapshot = loaded == null
? session.getPersistenceContext().getNaturalIdSnapshot( entry.getId(), persister )
: session.getPersistenceContext().getNaturalIdHelper().extractNaturalIdValues( loaded, persister );
? persistenceContext.getNaturalIdSnapshot( entry.getId(), persister )
: persistenceContext.getNaturalIdHelper().extractNaturalIdValues( loaded, persister );
for ( int i = 0; i < naturalIdentifierPropertiesIndexes.length; i++ ) {
final int naturalIdentifierPropertyIndex = naturalIdentifierPropertiesIndexes[i];
@ -693,13 +696,15 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
}
private Object[] getDatabaseSnapshot(SessionImplementor session, EntityPersister persister, Serializable id) {
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
if ( persister.isSelectBeforeUpdateRequired() ) {
Object[] snapshot = session.getPersistenceContext()
Object[] snapshot = persistenceContext
.getDatabaseSnapshot( id, persister );
if ( snapshot == null ) {
//do we even really need this? the update will fail anyway....
if ( session.getFactory().getStatistics().isStatisticsEnabled() ) {
session.getFactory().getStatistics()
final StatisticsImplementor statistics = session.getFactory().getStatistics();
if ( statistics.isStatisticsEnabled() ) {
statistics
.optimisticFailure( persister.getEntityName() );
}
throw new StaleObjectStateException( persister.getEntityName(), id );
@ -708,6 +713,6 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
}
// TODO: optimize away this lookup for entities w/o unsaved-value="undefined"
final EntityKey entityKey = session.generateEntityKey( id, persister );
return session.getPersistenceContext().getCachedDatabaseSnapshot( entityKey );
return persistenceContext.getCachedDatabaseSnapshot( entityKey );
}
}

View File

@ -11,6 +11,7 @@ import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.FlushEvent;
import org.hibernate.event.spi.FlushEventListener;
import org.hibernate.stat.spi.StatisticsImplementor;
/**
* Defines the default flush event listeners used by hibernate for
@ -27,7 +28,7 @@ public class DefaultFlushEventListener extends AbstractFlushingEventListener imp
*/
public void onFlush(FlushEvent event) throws HibernateException {
final EventSource source = event.getSession();
final PersistenceContext persistenceContext = source.getPersistenceContext();
final PersistenceContext persistenceContext = source.getPersistenceContextInternal();
if ( persistenceContext.getNumberOfManagedEntities() > 0 ||
persistenceContext.getCollectionEntries().size() > 0 ) {
@ -48,8 +49,9 @@ public class DefaultFlushEventListener extends AbstractFlushingEventListener imp
postPostFlush( source );
if ( source.getFactory().getStatistics().isStatisticsEnabled() ) {
source.getFactory().getStatistics().flush();
final StatisticsImplementor statistics = source.getFactory().getStatistics();
if ( statistics.isStatisticsEnabled() ) {
statistics.flush();
}
}
}

View File

@ -23,6 +23,7 @@ import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.stat.spi.StatisticsImplementor;
/**
* @author Gavin King
@ -37,7 +38,7 @@ public class DefaultInitializeCollectionEventListener implements InitializeColle
PersistentCollection collection = event.getCollection();
SessionImplementor source = event.getSession();
CollectionEntry ce = source.getPersistenceContext().getCollectionEntry( collection );
CollectionEntry ce = source.getPersistenceContextInternal().getCollectionEntry( collection );
if ( ce == null ) {
throw new HibernateException( "collection was evicted" );
}
@ -76,8 +77,9 @@ public class DefaultInitializeCollectionEventListener implements InitializeColle
LOG.trace( "Collection initialized" );
}
if ( source.getFactory().getStatistics().isStatisticsEnabled() ) {
source.getFactory().getStatistics().fetchCollection(
final StatisticsImplementor statistics = source.getFactory().getStatistics();
if ( statistics.isStatisticsEnabled() ) {
statistics.fetchCollection(
ce.getLoadedPersister().getRole()
);
}
@ -119,15 +121,16 @@ public class DefaultInitializeCollectionEventListener implements InitializeColle
final Object ck = cacheAccessStrategy.generateCacheKey( id, persister, factory, source.getTenantIdentifier() );
final Object ce = CacheHelper.fromSharedCache( source, ck, persister.getCacheAccessStrategy() );
if ( factory.getStatistics().isStatisticsEnabled() ) {
final StatisticsImplementor statistics = factory.getStatistics();
if ( statistics.isStatisticsEnabled() ) {
if ( ce == null ) {
factory.getStatistics().collectionCacheMiss(
statistics.collectionCacheMiss(
persister.getNavigableRole(),
cacheAccessStrategy.getRegion().getName()
);
}
else {
factory.getStatistics().collectionCacheHit(
statistics.collectionCacheHit(
persister.getNavigableRole(),
cacheAccessStrategy.getRegion().getName()
);
@ -143,7 +146,7 @@ public class DefaultInitializeCollectionEventListener implements InitializeColle
factory
);
final PersistenceContext persistenceContext = source.getPersistenceContext();
final PersistenceContext persistenceContext = source.getPersistenceContextInternal();
cacheEntry.assemble( collection, persister, persistenceContext.getCollectionOwner( id, persister ) );
persistenceContext.getCollectionEntry( collection ).postInitialize( collection );
// addInitializedCollection(collection, persister, id);

View File

@ -21,6 +21,7 @@ import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.Status;
import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.LoadEvent;
import org.hibernate.event.spi.LoadEventListener;
import org.hibernate.internal.CoreLogging;
@ -30,6 +31,7 @@ import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
import org.hibernate.tuple.entity.EntityMetamodel;
import org.hibernate.type.EmbeddedComponentType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
@ -180,18 +182,19 @@ public class DefaultLoadEventListener implements LoadEventListener {
final EntityKey keyToLoad,
final LoadEventListener.LoadType options) {
final EventSource session = event.getSession();
if ( event.getInstanceToLoad() != null ) {
if ( event.getSession().getPersistenceContext().getEntry( event.getInstanceToLoad() ) != null ) {
if ( session.getPersistenceContextInternal().getEntry( event.getInstanceToLoad() ) != null ) {
throw new PersistentObjectException(
"attempted to load into an instance that was already associated with the session: " +
MessageHelper.infoString(
persister,
event.getEntityId(),
event.getSession().getFactory()
session.getFactory()
)
);
}
persister.setIdentifier( event.getInstanceToLoad(), event.getEntityId(), event.getSession() );
persister.setIdentifier( event.getInstanceToLoad(), event.getEntityId(), session);
}
final Object entity = doLoad( event, persister, keyToLoad, options );
@ -199,7 +202,7 @@ public class DefaultLoadEventListener implements LoadEventListener {
boolean isOptionalInstance = event.getInstanceToLoad() != null;
if ( entity == null && ( !options.isAllowNulls() || isOptionalInstance ) ) {
event.getSession()
session
.getFactory()
.getEntityNotFoundDelegate()
.handleEntityNotFound( event.getEntityClassName(), event.getEntityId() );
@ -235,21 +238,22 @@ public class DefaultLoadEventListener implements LoadEventListener {
);
}
final PersistenceContext persistenceContext = event.getSession().getPersistenceContext();
final PersistenceContext persistenceContext = event.getSession().getPersistenceContextInternal();
final boolean allowBytecodeProxy = event.getSession()
.getFactory()
.getSessionFactoryOptions()
.isEnhancementAsProxyEnabled();
final boolean entityHasHibernateProxyFactory = persister.getEntityMetamodel()
final EntityMetamodel entityMetamodel = persister.getEntityMetamodel();
final boolean entityHasHibernateProxyFactory = entityMetamodel
.getTuplizer()
.getProxyFactory() != null;
// Check for the case where we can use the entity itself as a proxy
if ( options.isAllowProxyCreation()
&& allowBytecodeProxy
&& persister.getEntityMetamodel().getBytecodeEnhancementMetadata().isEnhancedForLazyLoading() ) {
&& entityMetamodel.getBytecodeEnhancementMetadata().isEnhancedForLazyLoading() ) {
// if there is already a managed entity instance associated with the PC, return it
final Object managed = persistenceContext.getEntity( keyToLoad );
if ( managed != null ) {
@ -282,7 +286,7 @@ public class DefaultLoadEventListener implements LoadEventListener {
}
// specialized handling for entities with subclasses with a HibernateProxy factory
if ( persister.getEntityMetamodel().hasSubclasses() ) {
if ( entityMetamodel.hasSubclasses() ) {
// entities with subclasses that define a ProxyFactory can create
// a HibernateProxy so long as NO_PROXY was not specified.
if ( event.getShouldUnwrapProxy() != null && event.getShouldUnwrapProxy() ) {
@ -460,7 +464,7 @@ public class DefaultLoadEventListener implements LoadEventListener {
}
}
return event.getSession().getPersistenceContext().proxyFor( persister, keyToLoad, entity );
return event.getSession().getPersistenceContextInternal().proxyFor( persister, keyToLoad, entity );
}
@ -483,10 +487,11 @@ public class DefaultLoadEventListener implements LoadEventListener {
final EntityKey keyToLoad,
final LoadEventListener.LoadType options) {
final EventSource session = event.getSession();
if ( LOG.isTraceEnabled() ) {
LOG.tracev(
"Attempting to resolve: {0}",
MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
MessageHelper.infoString( persister, event.getEntityId(), session.getFactory() )
);
}
@ -506,7 +511,7 @@ public class DefaultLoadEventListener implements LoadEventListener {
if ( LOG.isTraceEnabled() ) {
LOG.tracev(
"Resolved object in second-level cache: {0}",
MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
MessageHelper.infoString( persister, event.getEntityId(), session.getFactory() )
);
}
}
@ -514,17 +519,18 @@ public class DefaultLoadEventListener implements LoadEventListener {
if ( LOG.isTraceEnabled() ) {
LOG.tracev(
"Object not resolved in any cache: {0}",
MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
MessageHelper.infoString( persister, event.getEntityId(), session.getFactory() )
);
}
entity = loadFromDatasource( event, persister );
}
if ( entity != null && persister.hasNaturalIdentifier() ) {
event.getSession().getPersistenceContext().getNaturalIdHelper().cacheNaturalIdCrossReferenceFromLoad(
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
persistenceContext.getNaturalIdHelper().cacheNaturalIdCrossReferenceFromLoad(
persister,
event.getEntityId(),
event.getSession().getPersistenceContext().getNaturalIdHelper().extractNaturalIdValues(
persistenceContext.getNaturalIdHelper().extractNaturalIdValues(
entity,
persister
)

View File

@ -16,6 +16,7 @@ import org.hibernate.engine.internal.CascadePoint;
import org.hibernate.engine.internal.ForeignKeys;
import org.hibernate.engine.spi.CascadingActions;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.LockEvent;
@ -59,12 +60,12 @@ public class DefaultLockEventListener extends AbstractLockUpgradeEventListener i
}
SessionImplementor source = event.getSession();
Object entity = source.getPersistenceContext().unproxyAndReassociate( event.getObject() );
final PersistenceContext persistenceContext = source.getPersistenceContextInternal();
Object entity = persistenceContext.unproxyAndReassociate( event.getObject() );
//TODO: if object was an uninitialized proxy, this is inefficient,
// resulting in two SQL selects
EntityEntry entry = source.getPersistenceContext().getEntry(entity);
EntityEntry entry = persistenceContext.getEntry(entity);
if (entry==null) {
final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
final Serializable id = persister.getIdentifier( entity, source );
@ -84,7 +85,8 @@ public class DefaultLockEventListener extends AbstractLockUpgradeEventListener i
private void cascadeOnLock(LockEvent event, EntityPersister persister, Object entity) {
EventSource source = event.getSession();
source.getPersistenceContext().incrementCascadeLevel();
final PersistenceContext persistenceContext = source.getPersistenceContextInternal();
persistenceContext.incrementCascadeLevel();
try {
Cascade.cascade(
CascadingActions.LOCK,
@ -96,7 +98,7 @@ public class DefaultLockEventListener extends AbstractLockUpgradeEventListener i
);
}
finally {
source.getPersistenceContext().decrementCascadeLevel();
persistenceContext.decrementCascadeLevel();
}
}

View File

@ -21,6 +21,7 @@ import org.hibernate.engine.spi.CascadingAction;
import org.hibernate.engine.spi.CascadingActions;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
import org.hibernate.engine.spi.SelfDirtinessTracker;
@ -141,14 +142,15 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
// Check the persistence context for an entry relating to this
// entity to be merged...
EntityEntry entry = source.getPersistenceContext().getEntry( entity );
final PersistenceContext persistenceContext = source.getPersistenceContextInternal();
EntityEntry entry = persistenceContext.getEntry( entity );
if ( entry == null ) {
EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
Serializable id = persister.getIdentifier( entity, source );
if ( id != null ) {
final EntityKey key = source.generateEntityKey( id, persister );
final Object managedEntity = source.getPersistenceContext().getEntity( key );
entry = source.getPersistenceContext().getEntry( managedEntity );
final Object managedEntity = persistenceContext.getEntity( key );
entry = persistenceContext.getEntry( managedEntity );
if ( entry != null ) {
// we have specialized case of a detached entity from the
// perspective of the merge operation. Specifically, we
@ -356,7 +358,7 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
EntityPersister persister,
EventSource source) {
if ( incoming instanceof HibernateProxy ) {
return source.getPersistenceContext().unproxy( managed );
return source.getPersistenceContextInternal().unproxy( managed );
}
if ( incoming instanceof PersistentAttributeInterceptable
@ -424,13 +426,14 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
}
private boolean existsInDatabase(Object entity, EventSource source, EntityPersister persister) {
EntityEntry entry = source.getPersistenceContext().getEntry( entity );
final PersistenceContext persistenceContext = source.getPersistenceContextInternal();
EntityEntry entry = persistenceContext.getEntry( entity );
if ( entry == null ) {
Serializable id = persister.getIdentifier( entity, source );
if ( id != null ) {
final EntityKey key = source.generateEntityKey( id, persister );
final Object managedEntity = source.getPersistenceContext().getEntity( key );
entry = source.getPersistenceContext().getEntry( managedEntity );
final Object managedEntity = persistenceContext.getEntity( key );
entry = persistenceContext.getEntry( managedEntity );
}
}
@ -508,7 +511,8 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
final Object entity,
final Map copyCache
) {
source.getPersistenceContext().incrementCascadeLevel();
final PersistenceContext persistenceContext = source.getPersistenceContextInternal();
persistenceContext.incrementCascadeLevel();
try {
Cascade.cascade(
getCascadeAction(),
@ -520,7 +524,7 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
);
}
finally {
source.getPersistenceContext().decrementCascadeLevel();
persistenceContext.decrementCascadeLevel();
}
}

View File

@ -98,7 +98,7 @@ public class DefaultPersistEventListener
event.setEntityName( entityName );
}
final EntityEntry entityEntry = source.getPersistenceContext().getEntry( entity );
final EntityEntry entityEntry = source.getPersistenceContextInternal().getEntry( entity );
EntityState entityState = getEntityState( entity, entityName, entityEntry, source );
if ( entityState == EntityState.DETACHED ) {
// JPA 2, in its version of a "foreign generated", allows the id attribute value
@ -160,7 +160,7 @@ public class DefaultPersistEventListener
//TODO: check that entry.getIdentifier().equals(requestedId)
final Object entity = source.getPersistenceContext().unproxy( event.getObject() );
final Object entity = source.getPersistenceContextInternal().unproxy( event.getObject() );
final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
if ( createCache.put( entity, entity ) == null ) {
@ -186,7 +186,7 @@ public class DefaultPersistEventListener
LOG.trace( "Saving transient instance" );
final EventSource source = event.getSession();
final Object entity = source.getPersistenceContext().unproxy( event.getObject() );
final Object entity = source.getPersistenceContextInternal().unproxy( event.getObject() );
if ( createCache.put( entity, entity ) == null ) {
saveWithGeneratedId( entity, event.getEntityName(), createCache, source, false );
@ -197,7 +197,7 @@ public class DefaultPersistEventListener
private void entityIsDeleted(PersistEvent event, Map createCache) {
final EventSource source = event.getSession();
final Object entity = source.getPersistenceContext().unproxy( event.getObject() );
final Object entity = source.getPersistenceContextInternal().unproxy( event.getObject() );
final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
if ( LOG.isTraceEnabled() ) {

View File

@ -12,6 +12,7 @@ import org.hibernate.action.internal.EntityIncrementVersionProcess;
import org.hibernate.action.internal.EntityVerifyVersionProcess;
import org.hibernate.classic.Lifecycle;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.PostLoadEvent;
import org.hibernate.event.spi.PostLoadEventListener;
import org.hibernate.jpa.event.spi.CallbackRegistry;
@ -41,7 +42,8 @@ public class DefaultPostLoadEventListener implements PostLoadEventListener, Call
callbackRegistry.postLoad( entity );
final EntityEntry entry = event.getSession().getPersistenceContext().getEntry( entity );
final EventSource session = event.getSession();
final EntityEntry entry = session.getPersistenceContextInternal().getEntry( entity );
if ( entry == null ) {
throw new AssertionFailure( "possible non-threadsafe access to the session" );
}
@ -52,22 +54,22 @@ public class DefaultPostLoadEventListener implements PostLoadEventListener, Call
final Object nextVersion = persister.forceVersionIncrement(
entry.getId(),
entry.getVersion(),
event.getSession()
session
);
entry.forceLocked( entity, nextVersion );
}
else if ( LockMode.OPTIMISTIC_FORCE_INCREMENT.equals( lockMode ) ) {
final EntityIncrementVersionProcess incrementVersion = new EntityIncrementVersionProcess( entity, entry );
event.getSession().getActionQueue().registerProcess( incrementVersion );
session.getActionQueue().registerProcess( incrementVersion );
}
else if ( LockMode.OPTIMISTIC.equals( lockMode ) ) {
final EntityVerifyVersionProcess verifyVersion = new EntityVerifyVersionProcess( entity, entry );
event.getSession().getActionQueue().registerProcess( verifyVersion );
session.getActionQueue().registerProcess( verifyVersion );
}
if ( event.getPersister().implementsLifecycle() ) {
//log.debug( "calling onLoad()" );
( (Lifecycle) event.getEntity() ).onLoad( event.getSession(), event.getId() );
( (Lifecycle) event.getEntity() ).onLoad( session, event.getId() );
}
}

View File

@ -23,6 +23,7 @@ import org.hibernate.engine.internal.CascadePoint;
import org.hibernate.engine.spi.CascadingActions;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.RefreshEvent;
import org.hibernate.event.spi.RefreshEventListener;
@ -63,21 +64,22 @@ public class DefaultRefreshEventListener implements RefreshEventListener {
else {
isTransient = !source.contains( event.getObject() );
}
if ( source.getPersistenceContext().reassociateIfUninitializedProxy( event.getObject() ) ) {
final PersistenceContext persistenceContext = source.getPersistenceContextInternal();
if ( persistenceContext.reassociateIfUninitializedProxy( event.getObject() ) ) {
if ( isTransient ) {
source.setReadOnly( event.getObject(), source.isDefaultReadOnly() );
}
return;
}
final Object object = source.getPersistenceContext().unproxyAndReassociate( event.getObject() );
final Object object = persistenceContext.unproxyAndReassociate( event.getObject() );
if ( refreshedAlready.containsKey( object ) ) {
LOG.trace( "Already refreshed" );
return;
}
final EntityEntry e = source.getPersistenceContext().getEntry( object );
final EntityEntry e = persistenceContext.getEntry( object );
final EntityPersister persister;
final Serializable id;
@ -97,7 +99,7 @@ public class DefaultRefreshEventListener implements RefreshEventListener {
);
}
final EntityKey key = source.generateEntityKey( id, persister );
if ( source.getPersistenceContext().getEntry( key ) != null ) {
if ( persistenceContext.getEntry( key ) != null ) {
throw new PersistentObjectException(
"attempted to refresh transient instance when persistent instance was already associated with the Session: " +
MessageHelper.infoString( persister, id, source.getFactory() )
@ -138,7 +140,7 @@ public class DefaultRefreshEventListener implements RefreshEventListener {
if ( e != null ) {
final EntityKey key = source.generateEntityKey( id, persister );
source.getPersistenceContext().removeEntity( key );
persistenceContext.removeEntity( key );
if ( persister.hasCollections() ) {
new EvictVisitor( source, object ).process( object, persister );
}
@ -212,7 +214,7 @@ public class DefaultRefreshEventListener implements RefreshEventListener {
if ( postRefreshLockMode != null ) {
// if we get here, there was a previous entry and we need to re-set its lock-mode
// - however, the refresh operation actually creates a new entry, so get it
source.getPersistenceContext().getEntry( result ).setLockMode( postRefreshLockMode );
persistenceContext.getEntry( result ).setLockMode( postRefreshLockMode );
}
// Keep the same read-only/modifiable setting for the entity that it had before refreshing;

View File

@ -17,6 +17,7 @@ import org.hibernate.engine.internal.CascadePoint;
import org.hibernate.engine.spi.CascadingAction;
import org.hibernate.engine.spi.CascadingActions;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.Status;
import org.hibernate.event.spi.EventSource;
@ -46,14 +47,15 @@ public class DefaultReplicateEventListener extends AbstractSaveEventListener imp
*/
public void onReplicate(ReplicateEvent event) {
final EventSource source = event.getSession();
if ( source.getPersistenceContext().reassociateIfUninitializedProxy( event.getObject() ) ) {
final PersistenceContext persistenceContext = source.getPersistenceContextInternal();
if ( persistenceContext.reassociateIfUninitializedProxy( event.getObject() ) ) {
LOG.trace( "Uninitialized proxy passed to replicate()" );
return;
}
Object entity = source.getPersistenceContext().unproxyAndReassociate( event.getObject() );
Object entity = persistenceContext.unproxyAndReassociate( event.getObject() );
if ( source.getPersistenceContext().isEntryFor( entity ) ) {
if ( persistenceContext.isEntryFor( entity ) ) {
LOG.trace( "Ignoring persistent instance passed to replicate()" );
//hum ... should we cascade anyway? throw an exception? fine like it is?
return;
@ -181,7 +183,7 @@ public class DefaultReplicateEventListener extends AbstractSaveEventListener imp
new OnReplicateVisitor( source, id, entity, true ).process( entity, persister );
source.getPersistenceContext().addEntity(
source.getPersistenceContextInternal().addEntity(
entity,
( persister.isMutable() ? Status.MANAGED : Status.READ_ONLY ),
null,
@ -201,7 +203,8 @@ public class DefaultReplicateEventListener extends AbstractSaveEventListener imp
EntityPersister persister,
ReplicationMode replicationMode,
EventSource source) {
source.getPersistenceContext().incrementCascadeLevel();
final PersistenceContext persistenceContext = source.getPersistenceContextInternal();
persistenceContext.incrementCascadeLevel();
try {
Cascade.cascade(
CascadingActions.REPLICATE,
@ -213,7 +216,7 @@ public class DefaultReplicateEventListener extends AbstractSaveEventListener imp
);
}
finally {
source.getPersistenceContext().decrementCascadeLevel();
persistenceContext.decrementCascadeLevel();
}
}

View File

@ -11,7 +11,9 @@ import java.util.concurrent.TimeUnit;
import org.hibernate.HibernateException;
import org.hibernate.cache.spi.access.NaturalIdDataAccess;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.ResolveNaturalIdEvent;
import org.hibernate.event.spi.ResolveNaturalIdEventListener;
import org.hibernate.internal.CoreLogging;
@ -93,7 +95,7 @@ public class DefaultResolveNaturalIdEventListener
* @return The entity from the cache, or null.
*/
protected Serializable resolveFromCache(final ResolveNaturalIdEvent event) {
return event.getSession().getPersistenceContext().getNaturalIdHelper().findCachedNaturalIdResolution(
return event.getSession().getPersistenceContextInternal().getNaturalIdHelper().findCachedNaturalIdResolution(
event.getEntityPersister(),
event.getOrderedNaturalIdValues()
);
@ -108,7 +110,8 @@ public class DefaultResolveNaturalIdEventListener
* @return The object loaded from the datasource, or null if not found.
*/
protected Serializable loadFromDatasource(final ResolveNaturalIdEvent event) {
final SessionFactoryImplementor factory = event.getSession().getFactory();
final EventSource session = event.getSession();
final SessionFactoryImplementor factory = session.getFactory();
final boolean stats = factory.getStatistics().isStatisticsEnabled();
long startTime = 0;
if ( stats ) {
@ -118,7 +121,7 @@ public class DefaultResolveNaturalIdEventListener
final Serializable pk = event.getEntityPersister().loadEntityIdByNaturalId(
event.getOrderedNaturalIdValues(),
event.getLockOptions(),
event.getSession()
session
);
if ( stats ) {
@ -132,7 +135,8 @@ public class DefaultResolveNaturalIdEventListener
//PK can be null if the entity doesn't exist
if (pk != null) {
event.getSession().getPersistenceContext().getNaturalIdHelper().cacheNaturalIdCrossReferenceFromLoad(
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
persistenceContext.getNaturalIdHelper().cacheNaturalIdCrossReferenceFromLoad(
event.getEntityPersister(),
pk,
event.getOrderedNaturalIdValues()

View File

@ -24,7 +24,7 @@ public class DefaultSaveEventListener extends DefaultSaveOrUpdateEventListener {
protected Serializable performSaveOrUpdate(SaveOrUpdateEvent event) {
// this implementation is supposed to tolerate incorrect unsaved-value
// mappings, for the purpose of backward-compatibility
EntityEntry entry = event.getSession().getPersistenceContext().getEntry( event.getEntity() );
EntityEntry entry = event.getSession().getPersistenceContextInternal().getEntry( event.getEntity() );
if ( entry!=null && entry.getStatus() != Status.DELETED ) {
return entityIsPersistent(event);
}

View File

@ -20,6 +20,7 @@ import org.hibernate.engine.spi.CascadingAction;
import org.hibernate.engine.spi.CascadingActions;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.Status;
@ -66,9 +67,10 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener
}
else {
//initialize properties of the event:
final Object entity = source.getPersistenceContext().unproxyAndReassociate( object );
final PersistenceContext persistenceContext = source.getPersistenceContextInternal();
final Object entity = persistenceContext.unproxyAndReassociate( object );
event.setEntity( entity );
event.setEntry( source.getPersistenceContext().getEntry( entity ) );
event.setEntry( persistenceContext.getEntry( entity ) );
//return the id in the event object
event.setResultId( performSaveOrUpdate( event ) );
}
@ -76,7 +78,7 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener
}
protected boolean reassociateIfUninitializedProxy(Object object, SessionImplementor source) {
return source.getPersistenceContext().reassociateIfUninitializedProxy( object );
return source.getPersistenceContextInternal().reassociateIfUninitializedProxy( object );
}
protected Serializable performSaveOrUpdate(SaveOrUpdateEvent event) {
@ -175,7 +177,7 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener
Serializable id = saveWithGeneratedOrRequestedId( event );
source.getPersistenceContext().reassociateProxy( event.getObject(), id );
source.getPersistenceContextInternal().reassociateProxy( event.getObject(), id );
return id;
}
@ -208,18 +210,19 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener
LOG.trace( "Updating detached instance" );
if ( event.getSession().getPersistenceContext().isEntryFor( event.getEntity() ) ) {
final EventSource session = event.getSession();
if ( session.getPersistenceContextInternal().isEntryFor( event.getEntity() ) ) {
//TODO: assertion only, could be optimized away
throw new AssertionFailure( "entity was persistent" );
}
Object entity = event.getEntity();
EntityPersister persister = event.getSession().getEntityPersister( event.getEntityName(), entity );
EntityPersister persister = session.getEntityPersister( event.getEntityName(), entity );
event.setRequestedId(
getUpdateId(
entity, persister, event.getRequestedId(), event.getSession()
entity, persister, event.getRequestedId(), session
)
);
@ -279,7 +282,8 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener
final EventSource source = event.getSession();
final EntityKey key = source.generateEntityKey( event.getRequestedId(), persister );
source.getPersistenceContext().checkUniqueness( key, entity );
final PersistenceContext persistenceContext = source.getPersistenceContextInternal();
persistenceContext.checkUniqueness( key, entity );
if ( invokeUpdateLifecycle( entity, persister, source ) ) {
reassociate( event, event.getObject(), event.getRequestedId(), persister );
@ -302,7 +306,7 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener
entry.getState(); //TODO: half-assemble this stuff
}*/
source.getPersistenceContext().addEntity(
persistenceContext.addEntity(
entity,
( persister.isMutable() ? Status.MANAGED : Status.READ_ONLY ),
null, // cachedState,
@ -350,12 +354,13 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener
*/
private void cascadeOnUpdate(SaveOrUpdateEvent event, EntityPersister persister, Object entity) {
final EventSource source = event.getSession();
source.getPersistenceContext().incrementCascadeLevel();
final PersistenceContext persistenceContext = source.getPersistenceContextInternal();
persistenceContext.incrementCascadeLevel();
try {
Cascade.cascade( CascadingActions.SAVE_UPDATE, CascadePoint.AFTER_UPDATE, source, persister, entity );
}
finally {
source.getPersistenceContext().decrementCascadeLevel();
persistenceContext.decrementCascadeLevel();
}
}

View File

@ -25,7 +25,7 @@ public class DefaultUpdateEventListener extends DefaultSaveOrUpdateEventListener
protected Serializable performSaveOrUpdate(SaveOrUpdateEvent event) {
// this implementation is supposed to tolerate incorrect unsaved-value
// mappings, for the purpose of backward-compatibility
EntityEntry entry = event.getSession().getPersistenceContext().getEntry( event.getEntity() );
EntityEntry entry = event.getSession().getPersistenceContextInternal().getEntry( event.getEntity() );
if ( entry!=null ) {
if ( entry.getStatus()== Status.DELETED ) {
throw new ObjectDeletedException( "deleted instance passed to update()", null, event.getEntityName() );

View File

@ -39,7 +39,7 @@ public class DirtyCollectionSearchVisitor extends AbstractVisitor {
final SessionImplementor session = getSession();
final PersistentCollection persistentCollection;
if ( type.isArrayType() ) {
persistentCollection = session.getPersistenceContext().getCollectionHolder( collection );
persistentCollection = session.getPersistenceContextInternal().getCollectionHolder( collection );
// if no array holder we found an unwrappered array (this can't occur,
// because we now always call wrap() before getting to here)
// return (ah==null) ? true : searchForDirtyCollections(ah, type);

View File

@ -11,6 +11,7 @@ import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.engine.spi.CollectionEntry;
import org.hibernate.engine.spi.CollectionKey;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.event.spi.EventSource;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
@ -45,26 +46,28 @@ public class EvictVisitor extends AbstractVisitor {
public void evictCollection(Object value, CollectionType type) {
final PersistentCollection collection;
final EventSource session = getSession();
if ( type.hasHolder() ) {
collection = getSession().getPersistenceContext().removeCollectionHolder(value);
collection = session.getPersistenceContextInternal().removeCollectionHolder(value);
}
else if ( value instanceof PersistentCollection ) {
collection = (PersistentCollection) value;
}
else if ( value == LazyPropertyInitializer.UNFETCHED_PROPERTY ) {
collection = (PersistentCollection) type.resolve( value, getSession(), this.owner );
collection = (PersistentCollection) type.resolve( value, session, this.owner );
}
else {
return; //EARLY EXIT!
}
if ( collection != null && collection.unsetSession( getSession() ) ) {
if ( collection != null && collection.unsetSession(session) ) {
evictCollection(collection);
}
}
private void evictCollection(PersistentCollection collection) {
CollectionEntry ce = (CollectionEntry) getSession().getPersistenceContext().getCollectionEntries().remove(collection);
final PersistenceContext persistenceContext = getSession().getPersistenceContextInternal();
CollectionEntry ce = (CollectionEntry) persistenceContext.getCollectionEntries().remove(collection);
if ( LOG.isDebugEnabled() ) {
LOG.debugf(
"Evicting collection: %s",
@ -74,11 +77,11 @@ public class EvictVisitor extends AbstractVisitor {
getSession() ) );
}
if (ce.getLoadedPersister() != null && ce.getLoadedPersister().getBatchSize() > 1) {
getSession().getPersistenceContext().getBatchFetchQueue().removeBatchLoadableCollection(ce);
persistenceContext.getBatchFetchQueue().removeBatchLoadableCollection(ce);
}
if ( ce.getLoadedPersister() != null && ce.getLoadedKey() != null ) {
//TODO: is this 100% correct?
getSession().getPersistenceContext().getCollectionsByKey().remove(
persistenceContext.getCollectionsByKey().remove(
new CollectionKey( ce.getLoadedPersister(), ce.getLoadedKey() )
);
}

View File

@ -36,17 +36,18 @@ public class FlushVisitor extends AbstractVisitor {
if ( collection != null ) {
final PersistentCollection coll;
final EventSource session = getSession();
if ( type.hasHolder() ) {
coll = getSession().getPersistenceContext().getCollectionHolder(collection);
coll = session.getPersistenceContextInternal().getCollectionHolder(collection);
}
else if ( collection == LazyPropertyInitializer.UNFETCHED_PROPERTY ) {
coll = (PersistentCollection) type.resolve( collection, getSession(), owner );
coll = (PersistentCollection) type.resolve( collection, session, owner );
}
else {
coll = (PersistentCollection) collection;
}
Collections.processReachableCollection( coll, type, owner, getSession() );
Collections.processReachableCollection( coll, type, owner, session);
}
return null;

View File

@ -374,7 +374,7 @@ class MergeContext implements Map {
}
private String printEntity(Object entity) {
if ( session.getPersistenceContext().getEntry( entity ) != null ) {
if ( session.getPersistenceContextInternal().getEntry( entity ) != null ) {
return MessageHelper.infoString( session.getEntityName( entity ), session.getIdentifier( entity ) );
}
// Entity was not found in current persistence context. Use Object#toString() method.

View File

@ -51,7 +51,7 @@ public class OnReplicateVisitor extends ReattachVisitor {
final PersistentCollection wrapper = (PersistentCollection) collection;
wrapper.setCurrentSession( (SessionImplementor) session );
if ( wrapper.wasInitialized() ) {
session.getPersistenceContext().addNewCollection( persister, wrapper );
session.getPersistenceContextInternal().addNewCollection( persister, wrapper );
}
else {
reattachCollection( wrapper, type );

View File

@ -35,7 +35,7 @@ public class PostUpdateEventListenerStandardImpl implements PostUpdateEventListe
}
private void handlePostUpdate(Object entity, EventSource source) {
EntityEntry entry = source.getPersistenceContext().getEntry( entity );
EntityEntry entry = source.getPersistenceContextInternal().getEntry( entity );
// mimic the preUpdate filter
if ( Status.DELETED != entry.getStatus()) {
callbackRegistry.postUpdate(entity);

View File

@ -64,19 +64,20 @@ public abstract class ProxyVisitor extends AbstractVisitor {
*/
protected void reattachCollection(PersistentCollection collection, CollectionType type)
throws HibernateException {
final EventSource session = getSession();
if ( collection.wasInitialized() ) {
CollectionPersister collectionPersister = getSession().getFactory()
CollectionPersister collectionPersister = session.getFactory()
.getCollectionPersister( type.getRole() );
getSession().getPersistenceContext()
session.getPersistenceContext()
.addInitializedDetachedCollection( collectionPersister, collection );
}
else {
if ( !isCollectionSnapshotValid(collection) ) {
if ( !isCollectionSnapshotValid( collection ) ) {
throw new HibernateException( "could not reassociate uninitialized transient collection" );
}
CollectionPersister collectionPersister = getSession().getFactory()
CollectionPersister collectionPersister = session.getFactory()
.getCollectionPersister( collection.getRole() );
getSession().getPersistenceContext()
session.getPersistenceContext()
.addUninitializedDetachedCollection( collectionPersister, collection );
}
}

View File

@ -88,7 +88,7 @@ public class WrapVisitor extends ProxyVisitor {
else {
CollectionPersister persister = session.getFactory().getCollectionPersister( collectionType.getRole() );
final PersistenceContext persistenceContext = session.getPersistenceContext();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
//TODO: move into collection type, so we can use polymorphism!
if ( collectionType.hasHolder() ) {

View File

@ -50,20 +50,20 @@ public abstract class AbstractCollectionEvent extends AbstractEvent {
}
protected static CollectionPersister getLoadedCollectionPersister( PersistentCollection collection, EventSource source ) {
CollectionEntry ce = source.getPersistenceContext().getCollectionEntry( collection );
CollectionEntry ce = source.getPersistenceContextInternal().getCollectionEntry( collection );
return ( ce == null ? null : ce.getLoadedPersister() );
}
protected static Object getLoadedOwnerOrNull( PersistentCollection collection, EventSource source ) {
return source.getPersistenceContext().getLoadedCollectionOwnerOrNull( collection );
return source.getPersistenceContextInternal().getLoadedCollectionOwnerOrNull( collection );
}
protected static Serializable getLoadedOwnerIdOrNull( PersistentCollection collection, EventSource source ) {
return source.getPersistenceContext().getLoadedCollectionOwnerIdOrNull( collection );
return source.getPersistenceContextInternal().getLoadedCollectionOwnerIdOrNull( collection );
}
protected static Serializable getOwnerIdOrNull( Object owner, EventSource source ) {
EntityEntry ownerEntry = source.getPersistenceContext().getEntry( owner );
EntityEntry ownerEntry = source.getPersistenceContextInternal().getEntry( owner );
return ( ownerEntry == null ? null : ownerEntry.getId() );
}
@ -74,7 +74,7 @@ public abstract class AbstractCollectionEvent extends AbstractEvent {
String entityName =
( collectionPersister == null ? null : collectionPersister.getOwnerEntityPersister().getEntityName() );
if ( affectedOwner != null ) {
EntityEntry ee = source.getPersistenceContext().getEntry( affectedOwner );
EntityEntry ee = source.getPersistenceContextInternal().getEntry( affectedOwner );
if ( ee != null && ee.getEntityName() != null) {
entityName = ee.getEntityName();
}

View File

@ -18,6 +18,7 @@ import java.util.Locale;
import java.util.TimeZone;
import org.hibernate.HibernateException;
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
import org.hibernate.engine.spi.QueryParameters;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.hql.internal.HolderInstantiator;
@ -101,10 +102,11 @@ public abstract class AbstractScrollableResults implements ScrollableResultsImpl
// not absolutely necessary, but does help with aggressive release
//session.getJDBCContext().getConnectionManager().closeQueryStatement( ps, resultSet );
session.getJdbcCoordinator().getResourceRegistry().release( ps );
session.getJdbcCoordinator().afterStatementExecution();
final JdbcCoordinator jdbcCoordinator = session.getJdbcCoordinator();
jdbcCoordinator.getResourceRegistry().release( ps );
jdbcCoordinator.afterStatementExecution();
try {
session.getPersistenceContext().getLoadContexts().cleanup( resultSet );
session.getPersistenceContextInternal().getLoadContexts().cleanup( resultSet );
}
catch (Throwable ignore) {
// ignore this error for now

View File

@ -305,7 +305,7 @@ public class CriteriaImpl implements Criteria, Serializable {
}
return ( isReadOnlyInitialized() ?
readOnly :
getSession().getPersistenceContext().isDefaultReadOnly()
getSession().getPersistenceContextInternal().isDefaultReadOnly()
);
}

View File

@ -14,6 +14,7 @@ import java.util.NoSuchElementException;
import org.hibernate.HibernateException;
import org.hibernate.JDBCException;
import org.hibernate.engine.HibernateIterator;
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
import org.hibernate.event.spi.EventSource;
import org.hibernate.hql.internal.HolderInstantiator;
import org.hibernate.type.EntityType;
@ -63,7 +64,8 @@ public final class IteratorImpl implements HibernateIterator {
public void close() throws JDBCException {
if ( ps != null ) {
LOG.debug( "Closing iterator" );
session.getJdbcCoordinator().getResourceRegistry().release( ps );
final JdbcCoordinator jdbcCoordinator = session.getJdbcCoordinator();
jdbcCoordinator.getResourceRegistry().release( ps );
try {
session.getPersistenceContext().getLoadContexts().cleanup( rs );
}
@ -71,7 +73,7 @@ public final class IteratorImpl implements HibernateIterator {
// ignore this error for now
LOG.debugf( "Exception trying to cleanup load context : %s", ignore.getMessage() );
}
session.getJdbcCoordinator().afterStatementExecution();
jdbcCoordinator.afterStatementExecution();
ps = null;
rs = null;
hasNext = false;

View File

@ -190,7 +190,7 @@ public class ScrollableResultsImpl extends AbstractScrollableResults implements
return;
}
final PersistenceContext persistenceContext = getSession().getPersistenceContext();
final PersistenceContext persistenceContext = getSession().getPersistenceContextInternal();
persistenceContext.beforeLoad();
try {
final Object result = getLoader().loadSingleRow(

View File

@ -2403,6 +2403,11 @@ public final class SessionImpl
return persistenceContext;
}
@Override
public PersistenceContext getPersistenceContextInternal() {
return persistenceContext;
}
@Override
public SessionStatistics getStatistics() {
pulseTransactionCoordinator();
@ -3165,14 +3170,16 @@ public final class SessionImpl
return;
}
for ( Serializable pk : getPersistenceContext().getNaturalIdHelper()
final PersistenceContext persistenceContext = getPersistenceContextInternal();
final boolean debugEnabled = log.isDebugEnabled();
for ( Serializable pk : persistenceContext.getNaturalIdHelper()
.getCachedPkResolutions( entityPersister ) ) {
final EntityKey entityKey = generateEntityKey( pk, entityPersister );
final Object entity = getPersistenceContext().getEntity( entityKey );
final EntityEntry entry = getPersistenceContext().getEntry( entity );
final Object entity = persistenceContext.getEntity( entityKey );
final EntityEntry entry = persistenceContext.getEntry( entity );
if ( entry == null ) {
if ( log.isDebugEnabled() ) {
if ( debugEnabled ) {
log.debug(
"Cached natural-id/pk resolution linked to null EntityEntry in persistence context : "
+ MessageHelper.infoString( entityPersister, pk, getFactory() )
@ -3190,7 +3197,7 @@ public final class SessionImpl
continue;
}
getPersistenceContext().getNaturalIdHelper().handleSynchronization(
persistenceContext.getNaturalIdHelper().handleSynchronization(
entityPersister,
pk,
entity

View File

@ -253,7 +253,7 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen
@Override
public Object immediateLoad(String entityName, Serializable id) throws HibernateException {
if ( getPersistenceContext().isLoadFinished() ) {
if ( getPersistenceContextInternal().isLoadFinished() ) {
throw new SessionException( "proxies cannot be fetched by a stateless session" );
}
// unless we are still in the process of handling a top-level load
@ -461,14 +461,15 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen
public Object getEntityUsingInterceptor(EntityKey key) throws HibernateException {
checkOpen();
final Object result = getPersistenceContext().getEntity( key );
final PersistenceContext persistenceContext = getPersistenceContext();
final Object result = persistenceContext.getEntity( key );
if ( result != null ) {
return result;
}
final Object newObject = getInterceptor().getEntity( key.getEntityName(), key.getIdentifier() );
if ( newObject != null ) {
getPersistenceContext().addEntity( key, newObject );
persistenceContext.addEntity( key, newObject );
return newObject;
}
@ -669,6 +670,12 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen
return NO_INFLUENCERS;
}
@Override
public PersistenceContext getPersistenceContextInternal() {
//In this case implemented the same as #getPersistenceContext
return temporaryPersistenceContext;
}
@Override
public int executeNativeUpdate(
NativeSQLQuerySpecification nativeSQLQuerySpecification,

View File

@ -411,7 +411,7 @@ public abstract class Loader {
session,
queryParameters.isReadOnly( session )
);
session.getPersistenceContext().initializeNonLazyCollections();
session.getPersistenceContextInternal().initializeNonLazyCollections();
return result;
}
@ -471,7 +471,7 @@ public abstract class Loader {
session,
queryParameters.isReadOnly( session )
);
session.getPersistenceContext().initializeNonLazyCollections();
session.getPersistenceContextInternal().initializeNonLazyCollections();
return result;
}
@ -753,9 +753,10 @@ public abstract class Loader {
if ( returnProxies ) {
// now get an existing proxy for each row element (if there is one)
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
for ( int i = 0; i < entitySpan; i++ ) {
Object entity = row[i];
Object proxy = session.getPersistenceContext().proxyFor( persisters[i], keys[i], entity );
Object proxy = persistenceContext.proxyFor( persisters[i], keys[i], entity );
if ( entity != proxy ) {
// force the proxy to resolve itself
( (HibernateProxy) proxy ).getHibernateLazyInitializer().setImplementation( entity );
@ -1066,6 +1067,7 @@ public abstract class Loader {
final Loadable[] loadables = getEntityPersisters();
final String[] aliases = getAliases();
final String subselectQueryString = SubselectFetch.createSubselectFetchQueryFragment( queryParameters );
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
for ( Object key : keys ) {
final EntityKey[] rowKeys = (EntityKey[]) key;
for ( int i = 0; i < rowKeys.length; i++ ) {
@ -1081,7 +1083,7 @@ public abstract class Loader {
namedParameterLocMap
);
session.getPersistenceContext()
persistenceContext
.getBatchFetchQueue()
.addSubselect( rowKeys[i], subselectFetch );
}
@ -1196,6 +1198,7 @@ public abstract class Loader {
// split off from initializeEntity. It *must* occur after
// endCollectionLoad to ensure the collection is in the
// persistence context.
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
if ( hydratedObjects != null && hydratedObjects.size() > 0 ) {
final Iterable<PostLoadEventListener> postLoadEventListeners;
@ -1214,7 +1217,7 @@ public abstract class Loader {
TwoPhaseLoad.postLoad( hydratedObject, session, post, postLoadEventListeners );
if ( afterLoadActions != null ) {
for ( AfterLoadAction afterLoadAction : afterLoadActions ) {
final EntityEntry entityEntry = session.getPersistenceContext().getEntry( hydratedObject );
final EntityEntry entityEntry = persistenceContext.getEntry( hydratedObject );
if ( entityEntry == null ) {
// big problem
throw new HibernateException(
@ -1233,7 +1236,7 @@ public abstract class Loader {
final SharedSessionContractImplementor session,
final CollectionPersister collectionPersister) {
//this is a query and we are loading multiple instances of the same collection role
session.getPersistenceContext()
session.getPersistenceContextInternal()
.getLoadContexts()
.getCollectionLoadContext( (ResultSet) resultSetId )
.endLoadingCollections( collectionPersister );
@ -1311,6 +1314,7 @@ public abstract class Loader {
if ( owners != null ) {
EntityType[] ownerAssociationTypes = getOwnerAssociationTypes();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
for ( int i = 0; i < keys.length; i++ ) {
int owner = owners[i];
@ -1318,7 +1322,6 @@ public abstract class Loader {
EntityKey ownerKey = keys[owner];
if ( keys[i] == null && ownerKey != null ) {
final PersistenceContext persistenceContext = session.getPersistenceContext();
/*final boolean isPrimaryKey;
final boolean isSpecialOneToOne;
@ -1375,7 +1378,7 @@ public abstract class Loader {
final SharedSessionContractImplementor session)
throws HibernateException, SQLException {
final PersistenceContext persistenceContext = session.getPersistenceContext();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final Serializable collectionRowKey = (Serializable) persister.readKey(
rs,
@ -1451,6 +1454,7 @@ public abstract class Loader {
// for each of the passed-in keys, to account for the possibility
// that the collection is empty and has no rows in the result set
CollectionPersister[] collectionPersisters = getCollectionPersisters();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
for ( CollectionPersister collectionPersister : collectionPersisters ) {
for ( Serializable key : keys ) {
//handle empty collections
@ -1461,7 +1465,7 @@ public abstract class Loader {
);
}
session.getPersistenceContext()
persistenceContext
.getLoadContexts()
.getCollectionLoadContext( (ResultSet) resultSetId )
.getLoadingCollection( collectionPersister, key );
@ -1529,7 +1533,7 @@ public abstract class Loader {
final ResultSet rs,
final SharedSessionContractImplementor session) throws HibernateException, SQLException {
Object version = session.getPersistenceContext().getEntry( entity ).getVersion();
Object version = session.getPersistenceContextInternal().getEntry( entity ).getVersion();
if ( version != null ) {
// null version means the object is in the process of being loaded somewhere else in the ResultSet
@ -1678,7 +1682,7 @@ public abstract class Loader {
}
if ( LockMode.NONE != requestedLockMode && upgradeLocks() ) {
final EntityEntry entry = session.getPersistenceContext().getEntry( object );
final EntityEntry entry = session.getPersistenceContextInternal().getEntry( object );
if ( entry.getLockMode().lessThan( requestedLockMode ) ) {
//we only check the version when _upgrading_ lock modes
if ( persister.isVersioned() ) {
@ -1877,7 +1881,7 @@ public abstract class Loader {
persister.getEntityMode(),
session.getFactory()
);
session.getPersistenceContext().addEntity( euk, object );
session.getPersistenceContextInternal().addEntity( euk, object );
}
}
@ -2704,7 +2708,7 @@ public abstract class Loader {
.getEntityMetamodel()
.hasImmutableNaturalId();
final PersistenceContext persistenceContext = session.getPersistenceContext();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
boolean defaultReadOnlyOrig = persistenceContext.isDefaultReadOnly();
if ( queryParameters.isReadOnlyInitialized() ) {
// The read-only/modifiable mode for the query was explicitly set.

View File

@ -84,7 +84,7 @@ public class DynamicBatchingCollectionInitializerBuilder extends BatchingCollect
@Override
public void initialize(Serializable id, SharedSessionContractImplementor session) throws HibernateException {
// first, figure out how many batchable ids we have...
final Serializable[] batch = session.getPersistenceContext()
final Serializable[] batch = session.getPersistenceContextInternal()
.getBatchFetchQueue()
.getCollectionBatch( collectionPersister(), id, maxBatchSize );
final int numberOfIds = ArrayHelper.countNonNull( batch );
@ -193,7 +193,7 @@ public class DynamicBatchingCollectionInitializerBuilder extends BatchingCollect
);
try {
final PersistenceContext persistenceContext = session.getPersistenceContext();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
boolean defaultReadOnlyOrig = persistenceContext.isDefaultReadOnly();
if ( queryParameters.isReadOnlyInitialized() ) {
// The read-only/modifiable mode for the query was explicitly set.

View File

@ -67,7 +67,7 @@ public class LegacyBatchingCollectionInitializerBuilder extends BatchingCollecti
@Override
public void initialize(Serializable id, SharedSessionContractImplementor session) throws HibernateException {
Serializable[] batch = session.getPersistenceContext().getBatchFetchQueue()
Serializable[] batch = session.getPersistenceContextInternal().getBatchFetchQueue()
.getCollectionBatch( collectionPersister(), id, batchSizes[0] );
for ( int i=0; i<batchSizes.length-1; i++) {

View File

@ -70,7 +70,7 @@ public class PaddedBatchingCollectionInitializerBuilder extends BatchingCollecti
@Override
public void initialize(Serializable id, SharedSessionContractImplementor session) throws HibernateException {
final Serializable[] batch = session.getPersistenceContext()
final Serializable[] batch = session.getPersistenceContextInternal()
.getBatchFetchQueue()
.getCollectionBatch( collectionPersister(), id, batchSizes[0] );
final int numberOfIds = ArrayHelper.countNonNull( batch );

View File

@ -18,7 +18,9 @@ import org.hibernate.loader.Loader;
import org.hibernate.loader.collection.BasicCollectionLoader;
import org.hibernate.loader.collection.CollectionInitializer;
import org.hibernate.loader.collection.OneToManyLoader;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.type.Type;
/**
* LoadPlan-based implementation of the the legacy batch collection initializer.
@ -72,20 +74,22 @@ public class LegacyBatchingCollectionInitializerBuilder extends AbstractBatching
@Override
public void initialize(Serializable id, SharedSessionContractImplementor session) throws HibernateException {
final CollectionPersister collectionPersister = getCollectionPersister();
Serializable[] batch = session.getPersistenceContext().getBatchFetchQueue()
.getCollectionBatch( getCollectionPersister(), id, batchSizes[0] );
.getCollectionBatch( collectionPersister, id, batchSizes[0] );
for ( int i=0; i<batchSizes.length-1; i++) {
final Type keyType = collectionPersister.getKeyType();
for ( int i = 0; i < batchSizes.length - 1; i++ ) {
final int smallBatchSize = batchSizes[i];
if ( batch[smallBatchSize-1]!=null ) {
if ( batch[smallBatchSize-1] != null ) {
Serializable[] smallBatch = new Serializable[smallBatchSize];
System.arraycopy(batch, 0, smallBatch, 0, smallBatchSize);
loaders[i].loadCollectionBatch( session, smallBatch, getCollectionPersister().getKeyType() );
loaders[i].loadCollectionBatch( session, smallBatch, keyType );
return; //EARLY EXIT!
}
}
loaders[batchSizes.length-1].loadCollection( session, id, getCollectionPersister().getKeyType() );
loaders[batchSizes.length-1].loadCollection( session, id, keyType );
}
}
}

View File

@ -158,14 +158,15 @@ public class DynamicBatchingEntityLoaderBuilder extends BatchingEntityLoaderBuil
performOrderedBatchLoad( idsInBatch, lockOptions, persister, session );
}
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
for ( Integer position : elementPositionsLoadedByBatch ) {
// the element value at this position in the result List should be
// the EntityKey for that entity; reuse it!
final EntityKey entityKey = (EntityKey) result.get( position );
Object entity = session.getPersistenceContext().getEntity( entityKey );
Object entity = persistenceContext.getEntity( entityKey );
if ( entity != null && !loadOptions.isReturnOfDeletedEntitiesEnabled() ) {
// make sure it is not DELETED
final EntityEntry entry = session.getPersistenceContext().getEntry( entity );
final EntityEntry entry = persistenceContext.getEntry( entity );
if ( entry.getStatus() == Status.DELETED || entry.getStatus() == Status.GONE ) {
// the entity is locally deleted, and the options ask that we not return such entities...
entity = null;
@ -339,7 +340,6 @@ public class DynamicBatchingEntityLoaderBuilder extends BatchingEntityLoaderBuil
return qp;
}
@Override
protected UniqueEntityLoader buildBatchingLoader(
OuterJoinLoadable persister,
@ -395,7 +395,7 @@ public class DynamicBatchingEntityLoaderBuilder extends BatchingEntityLoaderBuil
Object optionalObject,
SharedSessionContractImplementor session,
LockOptions lockOptions) {
final Serializable[] batch = session.getPersistenceContext()
final Serializable[] batch = session.getPersistenceContextInternal()
.getBatchFetchQueue()
.getEntityBatch( persister(), id, maxBatchSize, persister().getEntityMode() );
@ -508,7 +508,7 @@ public class DynamicBatchingEntityLoaderBuilder extends BatchingEntityLoaderBuil
);
try {
final PersistenceContext persistenceContext = session.getPersistenceContext();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
boolean defaultReadOnlyOrig = persistenceContext.isDefaultReadOnly();
if ( queryParameters.isReadOnlyInitialized() ) {
// The read-only/modifiable mode for the query was explicitly set.

View File

@ -81,7 +81,7 @@ public class LegacyBatchingEntityLoaderBuilder extends BatchingEntityLoaderBuild
@Override
public Object load(Serializable id, Object optionalObject, SharedSessionContractImplementor session, LockOptions lockOptions) {
final Serializable[] batch = session.getPersistenceContext()
final Serializable[] batch = session.getPersistenceContextInternal()
.getBatchFetchQueue()
.getEntityBatch( persister(), id, batchSizes[0], persister().getEntityMode() );

View File

@ -91,7 +91,7 @@ class PaddedBatchingEntityLoaderBuilder extends BatchingEntityLoaderBuilder {
@Override
public Object load(Serializable id, Object optionalObject, SharedSessionContractImplementor session, LockOptions lockOptions) {
final Serializable[] batch = session.getPersistenceContext()
final Serializable[] batch = session.getPersistenceContextInternal()
.getBatchFetchQueue()
.getEntityBatch( persister(), id, batchSizes[0], persister().getEntityMode() );

View File

@ -94,7 +94,7 @@ public class LegacyBatchingEntityLoaderBuilder extends AbstractBatchingEntityLoa
@Override
public Object load(Serializable id, Object optionalObject, SharedSessionContractImplementor session, LockOptions lockOptions) {
final Serializable[] batch = session.getPersistenceContext()
final Serializable[] batch = session.getPersistenceContextInternal()
.getBatchFetchQueue()
.getEntityBatch( persister(), id, batchSizes[0], persister().getEntityMode() );

View File

@ -100,7 +100,7 @@ public abstract class AbstractLoadPlanBasedLoader {
boolean returnProxies,
ResultTransformer forcedResultTransformer,
List<AfterLoadAction> afterLoadActions) throws SQLException {
final PersistenceContext persistenceContext = session.getPersistenceContext();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final boolean defaultReadOnlyOrig = persistenceContext.isDefaultReadOnly();
if ( queryParameters.isReadOnlyInitialized() ) {
// The read-only/modifiable mode for the query was explicitly set.

View File

@ -45,7 +45,7 @@ public class CollectionReferenceInitializerImpl implements CollectionReferenceIn
try {
// read the collection key for this reference for the current row.
final PersistenceContext persistenceContext = context.getSession().getPersistenceContext();
final PersistenceContext persistenceContext = context.getSession().getPersistenceContextInternal();
final Serializable collectionRowKey = (Serializable) collectionReference.getCollectionPersister().readKey(
resultSet,
aliases.getCollectionColumnAliases().getSuffixedKeyAliases(),
@ -121,7 +121,7 @@ public class CollectionReferenceInitializerImpl implements CollectionReferenceIn
Serializable collectionRowKey,
ResultSet resultSet,
ResultSetProcessingContextImpl context) {
final Object collectionOwner = context.getSession().getPersistenceContext().getCollectionOwner(
final Object collectionOwner = context.getSession().getPersistenceContextInternal().getCollectionOwner(
collectionRowKey,
collectionReference.getCollectionPersister()
);
@ -148,7 +148,7 @@ public class CollectionReferenceInitializerImpl implements CollectionReferenceIn
@Override
public void endLoading(ResultSetProcessingContextImpl context) {
context.getSession().getPersistenceContext()
context.getSession().getPersistenceContextInternal()
.getLoadContexts()
.getCollectionLoadContext( context.getResultSet() )
.endLoadingCollections( collectionReference.getCollectionPersister() );

View File

@ -21,6 +21,7 @@ import org.hibernate.engine.internal.TwoPhaseLoad;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.EntityUniqueKey;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.CoreLogging;
import org.hibernate.loader.EntityAliases;
@ -33,6 +34,7 @@ import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.entity.Loadable;
import org.hibernate.persister.entity.UniqueKeyLoadable;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
import org.hibernate.type.VersionType;
@ -283,7 +285,7 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize
final EntityKey ownerEntityKey = fetchOwnerState.getEntityKey();
if ( ownerEntityKey != null ) {
context.getSession().getPersistenceContext().addNullProperty(
context.getSession().getPersistenceContextInternal().addNullProperty(
ownerEntityKey,
fetchedType.getPropertyName()
);
@ -301,7 +303,8 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize
final Serializable id = entityKey.getIdentifier();
// Get the persister for the _subclass_
final Loadable concreteEntityPersister = (Loadable) context.getSession().getFactory().getMetamodel().entityPersister( concreteEntityTypeName );
final SharedSessionContractImplementor session = context.getSession();
final Loadable concreteEntityPersister = (Loadable) session.getFactory().getMetamodel().entityPersister( concreteEntityTypeName );
if ( log.isTraceEnabled() ) {
log.tracev(
@ -309,7 +312,7 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize
MessageHelper.infoString(
concreteEntityPersister,
id,
context.getSession().getFactory()
session.getFactory()
)
);
}
@ -322,10 +325,10 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize
entityInstance,
concreteEntityPersister,
lockModeToAcquire,
context.getSession()
session
);
final EntityPersister rootEntityPersister = context.getSession().getFactory().getMetamodel().entityPersister(
final EntityPersister rootEntityPersister = session.getFactory().getMetamodel().entityPersister(
concreteEntityPersister.getRootEntityName()
);
final Object[] values;
@ -339,13 +342,13 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize
? entityReferenceAliases.getColumnAliases().getSuffixedPropertyAliases()
: entityReferenceAliases.getColumnAliases().getSuffixedPropertyAliases( concreteEntityPersister ),
context.getLoadPlan().areLazyAttributesForceFetched(),
context.getSession()
session
);
context.getProcessingState( entityReference ).registerHydratedState( values );
}
catch (SQLException e) {
throw context.getSession().getFactory().getServiceRegistry().getService( JdbcServices.class ).getSqlExceptionHelper().convert(
throw session.getFactory().getServiceRegistry().getService( JdbcServices.class ).getSqlExceptionHelper().convert(
e,
"Could not read entity state from ResultSet : " + entityKey
);
@ -365,7 +368,7 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize
}
}
catch (SQLException e) {
throw context.getSession().getFactory().getServiceRegistry().getService( JdbcServices.class ).getSqlExceptionHelper().convert(
throw session.getFactory().getServiceRegistry().getService( JdbcServices.class ).getSqlExceptionHelper().convert(
e,
"Could not read entity row-id from ResultSet : " + entityKey
);
@ -389,12 +392,12 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize
EntityUniqueKey euk = new EntityUniqueKey(
entityReference.getEntityPersister().getEntityName(),
ukName,
type.semiResolve( values[index], context.getSession(), entityInstance ),
type.semiResolve( values[index], session, entityInstance ),
type,
concreteEntityPersister.getEntityMode(),
context.getSession().getFactory()
session.getFactory()
);
context.getSession().getPersistenceContext().addEntity( euk, entityInstance );
session.getPersistenceContextInternal().addEntity( euk, entityInstance );
}
}
@ -405,7 +408,7 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize
rowId,
entityInstance,
lockModeToAcquire,
context.getSession()
session
);
context.registerHydratedEntity( entityReference, entityKey, entityInstance );
@ -457,7 +460,9 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize
Object existing) {
final LockMode requestedLockMode = context.resolveLockMode( entityReference );
if ( requestedLockMode != LockMode.NONE ) {
final LockMode currentLockMode = context.getSession().getPersistenceContext().getEntry( existing ).getLockMode();
final SharedSessionContractImplementor session = context.getSession();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final LockMode currentLockMode = persistenceContext.getEntry( existing ).getLockMode();
final boolean isVersionCheckNeeded = entityReference.getEntityPersister().isVersioned()
&& currentLockMode.lessThan( requestedLockMode );
@ -466,7 +471,7 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize
if ( isVersionCheckNeeded ) {
//we only check the version when *upgrading* lock modes
checkVersion(
context.getSession(),
session,
resultSet,
entityReference.getEntityPersister(),
entityReferenceAliases.getColumnAliases(),
@ -474,7 +479,7 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize
existing
);
//we need to upgrade the lock mode to the mode requested
context.getSession().getPersistenceContext().getEntry( existing ).setLockMode( requestedLockMode );
persistenceContext.getEntry( existing ).setLockMode( requestedLockMode );
}
}
}
@ -486,7 +491,7 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize
EntityAliases entityAliases,
EntityKey entityKey,
Object entityInstance) {
final Object version = session.getPersistenceContext().getEntry( entityInstance ).getVersion();
final Object version = session.getPersistenceContextInternal().getEntry( entityInstance ).getVersion();
if ( version != null ) {
//null version means the object is in the process of being loaded somewhere else in the ResultSet
@ -508,8 +513,9 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize
}
if ( !versionType.isEqual( version, currentVersion ) ) {
if ( session.getFactory().getStatistics().isStatisticsEnabled() ) {
session.getFactory().getStatistics().optimisticFailure( persister.getEntityName() );
final StatisticsImplementor statistics = session.getFactory().getStatistics();
if ( statistics.isStatisticsEnabled() ) {
statistics.optimisticFailure( persister.getEntityName() );
}
throw new StaleObjectStateException( persister.getEntityName(), entityKey.getIdentifier() );
}

View File

@ -52,7 +52,7 @@ public class EntityReturnReader implements ReturnReader {
final Object entityInstance = context.getProcessingState( entityReturn ).getEntityInstance();
if ( context.shouldReturnProxies() ) {
final Object proxy = context.getSession().getPersistenceContext().proxyFor(
final Object proxy = context.getSession().getPersistenceContextInternal().proxyFor(
entityReturn.getEntityPersister(),
entityKey,
entityInstance

View File

@ -17,6 +17,7 @@ import java.util.Set;
import org.hibernate.LockMode;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.QueryParameters;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.engine.spi.SubselectFetch;
@ -234,7 +235,7 @@ public class ResultSetProcessingContextImpl implements ResultSetProcessingContex
throw new IllegalStateException( "Could not locate fetch owner EntityKey" );
}
session.getPersistenceContext().addNullProperty(
session.getPersistenceContextInternal().addNullProperty(
ownerEntityKey,
fetchedType.getPropertyName()
);
@ -351,8 +352,9 @@ public class ResultSetProcessingContextImpl implements ResultSetProcessingContex
namedParameterLocMap
);
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
for ( EntityKey key : entry.getValue() ) {
session.getPersistenceContext().getBatchFetchQueue().addSubselect( key, subselectFetch );
persistenceContext.getBatchFetchQueue().addSubselect( key, subselectFetch );
}
}
}

View File

@ -14,6 +14,7 @@ import java.util.List;
import org.hibernate.cfg.NotYetImplementedException;
import org.hibernate.dialect.pagination.LimitHelper;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.QueryParameters;
import org.hibernate.engine.spi.RowSelection;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
@ -133,7 +134,7 @@ public class ResultSetProcessorImpl implements ResultSetProcessor {
rowReader.finishUp( context, afterLoadActionList );
context.wrapUp();
session.getPersistenceContext().initializeNonLazyCollections();
session.getPersistenceContextInternal().initializeNonLazyCollections();
return loadResults;
}
@ -155,15 +156,17 @@ public class ResultSetProcessorImpl implements ResultSetProcessor {
// that the collection is empty and has no rows in the result set
//
// todo : move this inside CollectionReturn ?
CollectionPersister persister = ( (CollectionReturn) loadPlan.getReturns().get( 0 ) ).getCollectionPersister();
final CollectionPersister persister = ( (CollectionReturn) loadPlan.getReturns().get( 0 ) ).getCollectionPersister();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final boolean debugEnabled = LOG.isDebugEnabled();
for ( Serializable key : collectionKeys ) {
if ( LOG.isDebugEnabled() ) {
if ( debugEnabled ) {
LOG.debugf(
"Preparing collection intializer : %s",
"Preparing collection initializer : %s",
MessageHelper.collectionInfoString( persister, key, session.getFactory() )
);
}
session.getPersistenceContext()
persistenceContext
.getLoadContexts()
.getCollectionLoadContext( resultSet )
.getLoadingCollection( persister, key );

View File

@ -730,7 +730,7 @@ public abstract class AbstractCollectionPersister
return null;
}
final PersistenceContext persistenceContext = session.getPersistenceContext();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
SubselectFetch subselect = persistenceContext.getBatchFetchQueue()
.getSubselect( session.generateEntityKey( key, getOwnerEntityPersister() ) );

View File

@ -64,6 +64,7 @@ import org.hibernate.engine.internal.StatefulPersistenceContext;
import org.hibernate.engine.internal.Versioning;
import org.hibernate.engine.jdbc.batch.internal.BasicBatchKey;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.spi.CachedNaturalIdValueSource;
import org.hibernate.engine.spi.CascadeStyle;
@ -75,6 +76,7 @@ import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.PersistenceContext.NaturalIdHelper;
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
@ -1054,7 +1056,8 @@ public abstract class AbstractEntityPersister
}
public Object initializeLazyProperty(String fieldName, Object entity, SharedSessionContractImplementor session) {
final EntityEntry entry = session.getPersistenceContext().getEntry( entity );
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final EntityEntry entry = persistenceContext.getEntry( entity );
final PersistentAttributeInterceptor interceptor = ( (PersistentAttributeInterceptable) entity ).$$_hibernate_getInterceptor();
assert interceptor != null : "Expecting bytecode interceptor to be non-null";
@ -1075,11 +1078,11 @@ public abstract class AbstractEntityPersister
// see if there is already a collection instance associated with the session
// NOTE : can this ever happen?
final Serializable key = getCollectionKey( persister, entity, entry, session );
PersistentCollection collection = session.getPersistenceContext().getCollection( new CollectionKey( persister, key ) );
PersistentCollection collection = persistenceContext.getCollection( new CollectionKey( persister, key ) );
if ( collection == null ) {
collection = collectionType.instantiate( session, persister, key );
collection.setOwner( entity );
session.getPersistenceContext().addUninitializedCollection( persister, collection, key );
persistenceContext.addUninitializedCollection( persister, collection, key );
}
// // HHH-11161 Initialize, if the collection is not extra lazy
@ -1089,12 +1092,12 @@ public abstract class AbstractEntityPersister
interceptor.attributeInitialized( fieldName );
if ( collectionType.isArrayType() ) {
session.getPersistenceContext().addCollectionHolder( collection );
persistenceContext.addCollectionHolder( collection );
}
// update the "state" of the entity's EntityEntry to over-write UNFETCHED_PROPERTY reference
// for the collection to the just loaded collection
final EntityEntry ownerEntry = session.getPersistenceContext().getEntry( entity );
final EntityEntry ownerEntry = persistenceContext.getEntry( entity );
if ( ownerEntry == null ) {
// not good
throw new AssertionFailure(
@ -3614,7 +3617,7 @@ public abstract class AbstractEntityPersister
final boolean[] propsToUpdate;
final String[] updateStrings;
EntityEntry entry = session.getPersistenceContext().getEntry( object );
EntityEntry entry = session.getPersistenceContextInternal().getEntry( object );
// Ensure that an immutable or non-modifiable entity is not being updated unless it is
// in the process of being deleted.
@ -3751,9 +3754,10 @@ public abstract class AbstractEntityPersister
//
// Note, it potentially could be a proxy, so doAfterTransactionCompletion the location the safe way...
final EntityKey key = session.generateEntityKey( id, this );
Object entity = session.getPersistenceContext().getEntity( key );
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
Object entity = persistenceContext.getEntity( key );
if ( entity != null ) {
EntityEntry entry = session.getPersistenceContext().getEntry( entity );
EntityEntry entry = persistenceContext.getEntry( entity );
loadedState = entry.getLoadedState();
}
}
@ -4686,13 +4690,14 @@ public abstract class AbstractEntityPersister
return;
}
final NaturalIdHelper naturalIdHelper = session.getPersistenceContext().getNaturalIdHelper();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final NaturalIdHelper naturalIdHelper = persistenceContext.getNaturalIdHelper();
final Serializable id = getIdentifier( entity, session );
// for reattachment of mutable natural-ids, we absolutely positively have to grab the snapshot from the
// database, because we have no other way to know if the state changed while detached.
final Object[] naturalIdSnapshot;
final Object[] entitySnapshot = session.getPersistenceContext().getDatabaseSnapshot( id, this );
final Object[] entitySnapshot = persistenceContext.getDatabaseSnapshot( id, this );
if ( entitySnapshot == StatefulPersistenceContext.NO_ROW ) {
naturalIdSnapshot = null;
}
@ -5289,20 +5294,20 @@ public abstract class AbstractEntityPersister
Object[] snapshot = new Object[naturalIdPropertyCount];
try {
PreparedStatement ps = session
.getJdbcCoordinator()
final JdbcCoordinator jdbcCoordinator = session.getJdbcCoordinator();
PreparedStatement ps = jdbcCoordinator
.getStatementPreparer()
.prepareStatement( sql );
try {
getIdentifierType().nullSafeSet( ps, id, 1, session );
ResultSet rs = session.getJdbcCoordinator().getResultSetReturn().extract( ps );
ResultSet rs = jdbcCoordinator.getResultSetReturn().extract( ps );
try {
//if there is no resulting row, return null
if ( !rs.next() ) {
return null;
}
final EntityKey key = session.generateEntityKey( id, this );
Object owner = session.getPersistenceContext().getEntity( key );
Object owner = session.getPersistenceContextInternal().getEntity( key );
for ( int i = 0; i < naturalIdPropertyCount; i++ ) {
snapshot[i] = extractionTypes[i].hydrate(
rs, getPropertyAliases(
@ -5317,12 +5322,12 @@ public abstract class AbstractEntityPersister
return snapshot;
}
finally {
session.getJdbcCoordinator().getResourceRegistry().release( rs, ps );
jdbcCoordinator.getResourceRegistry().release( rs, ps );
}
}
finally {
session.getJdbcCoordinator().getResourceRegistry().release( ps );
session.getJdbcCoordinator().afterStatementExecution();
jdbcCoordinator.getResourceRegistry().release( ps );
jdbcCoordinator.afterStatementExecution();
}
}
catch (SQLException e) {

View File

@ -77,7 +77,7 @@ public final class NamedQueryLoader implements UniqueEntityLoader {
// now look up the object we are really interested in!
// (this lets us correctly handle proxies and multi-row or multi-column queries)
return session.getPersistenceContext().getEntity( session.generateEntityKey( id, persister ) );
return session.getPersistenceContextInternal().getEntity( session.generateEntityKey( id, persister ) );
}
}

View File

@ -263,7 +263,7 @@ public final class MessageHelper {
}
else {
Object collectionOwner = collection == null ? null : collection.getOwner();
EntityEntry entry = collectionOwner == null ? null : session.getPersistenceContext().getEntry(collectionOwner);
EntityEntry entry = collectionOwner == null ? null : session.getPersistenceContextInternal().getEntry(collectionOwner);
ownerKey = entry == null ? null : entry.getId();
}
s.append( ownerIdentifierType.toLoggableString(

View File

@ -97,7 +97,7 @@ public class PropertyAccessStrategyBackRefImpl implements PropertyAccessStrategy
return UNKNOWN;
}
else {
return session.getPersistenceContext().getOwnerId( entityName, propertyName, owner, mergeMap );
return session.getPersistenceContextInternal().getOwnerId( entityName, propertyName, owner, mergeMap );
}
}

View File

@ -80,7 +80,7 @@ public class PropertyAccessStrategyIndexBackRefImpl implements PropertyAccessStr
return PropertyAccessStrategyBackRefImpl.UNKNOWN;
}
else {
return session.getPersistenceContext().getIndexInOwner( entityName, propertyName, owner, mergeMap );
return session.getPersistenceContextInternal().getIndexInOwner( entityName, propertyName, owner, mergeMap );
}
}

View File

@ -15,6 +15,7 @@ import org.hibernate.SessionException;
import org.hibernate.TransientObjectException;
import org.hibernate.boot.spi.SessionFactoryOptions;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.CoreLogging;
@ -255,7 +256,7 @@ public abstract class AbstractLazyInitializer implements LazyInitializer {
getIdentifier(),
session.getFactory().getMetamodel().entityPersister( getEntityName() )
);
final Object entity = session.getPersistenceContext().getEntity( key );
final Object entity = session.getPersistenceContextInternal().getEntity( key );
if ( entity != null ) {
setImplementation( entity );
}
@ -299,7 +300,7 @@ public abstract class AbstractLazyInitializer implements LazyInitializer {
private Object getProxyOrNull() {
final EntityKey entityKey = generateEntityKeyOrNull( getIdentifier(), session, getEntityName() );
if ( entityKey != null && session != null && session.isOpenOrWaitingForAutoClose() ) {
return session.getPersistenceContext().getProxy( entityKey );
return session.getPersistenceContextInternal().getProxy( entityKey );
}
return null;
}
@ -319,7 +320,7 @@ public abstract class AbstractLazyInitializer implements LazyInitializer {
@Override
public final Object getImplementation(SharedSessionContractImplementor s) throws HibernateException {
final EntityKey entityKey = generateEntityKeyOrNull( getIdentifier(), s, getEntityName() );
return (entityKey == null ? null : s.getPersistenceContext().getEntity( entityKey ));
return ( entityKey == null ? null : s.getPersistenceContext().getEntity( entityKey ) );
}
/**
@ -369,8 +370,9 @@ public abstract class AbstractLazyInitializer implements LazyInitializer {
this.readOnly = readOnly;
if ( initialized ) {
EntityKey key = generateEntityKeyOrNull( getIdentifier(), session, getEntityName() );
if ( key != null && session.getPersistenceContext().containsEntity( key ) ) {
session.getPersistenceContext().setReadOnly( target, readOnly );
final PersistenceContext persistenceContext = session.getPersistenceContext();
if ( key != null && persistenceContext.containsEntity( key ) ) {
persistenceContext.setReadOnly( target, readOnly );
}
}
}

View File

@ -247,7 +247,7 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
@Override
public boolean isReadOnly() {
return ( readOnly == null ?
producer.getPersistenceContext().isDefaultReadOnly() :
producer.getPersistenceContextInternal().isDefaultReadOnly() :
readOnly
);
}

View File

@ -24,19 +24,19 @@ public class SessionStatisticsImpl implements SessionStatistics {
}
public int getEntityCount() {
return session.getPersistenceContext().getNumberOfManagedEntities();
return session.getPersistenceContextInternal().getNumberOfManagedEntities();
}
public int getCollectionCount() {
return session.getPersistenceContext().getCollectionEntries().size();
return session.getPersistenceContextInternal().getCollectionEntries().size();
}
public Set getEntityKeys() {
return Collections.unmodifiableSet( session.getPersistenceContext().getEntitiesByKey().keySet() );
return Collections.unmodifiableSet( session.getPersistenceContextInternal().getEntitiesByKey().keySet() );
}
public Set getCollectionKeys() {
return Collections.unmodifiableSet( session.getPersistenceContext().getCollectionsByKey().keySet() );
return Collections.unmodifiableSet( session.getPersistenceContextInternal().getCollectionsByKey().keySet() );
}
public String toString() {

View File

@ -385,7 +385,7 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer {
public void setIdentifier(Object entity, Serializable id, EntityMode entityMode, SharedSessionContractImplementor session) {
final Object[] extractedValues = mappedIdentifierType.getPropertyValues( id, entityMode );
final Object[] injectionValues = new Object[extractedValues.length];
final PersistenceContext persistenceContext = session.getPersistenceContext();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
for ( int i = 0; i < virtualIdComponent.getSubtypes().length; i++ ) {
final Type virtualPropertyType = virtualIdComponent.getSubtypes()[i];
final Type idClassPropertyType = mappedIdentifierType.getSubtypes()[i];
@ -438,7 +438,7 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer {
}
if ( session != null ) {
final EntityEntry pcEntry = session.getPersistenceContext().getEntry( entity );
final EntityEntry pcEntry = session.getPersistenceContextInternal().getEntry( entity );
if ( pcEntry != null ) {
// entity managed; return ID.
return pcEntry.getId();

View File

@ -369,8 +369,9 @@ public abstract class CollectionType extends AbstractType implements Association
* @return The collection owner's key
*/
public Serializable getKeyOfOwner(Object owner, SharedSessionContractImplementor session) {
final PersistenceContext pc = session.getPersistenceContextInternal();
EntityEntry entityEntry = session.getPersistenceContext().getEntry( owner );
EntityEntry entityEntry = pc.getEntry( owner );
if ( entityEntry == null ) {
// This just handles a particular case of component
// projection, perhaps get rid of it and throw an exception
@ -637,7 +638,7 @@ public abstract class CollectionType extends AbstractType implements Association
}
CollectionEntry ce = session.getPersistenceContext().getCollectionEntry( result );
CollectionEntry ce = session.getPersistenceContextInternal().getCollectionEntry( result );
if ( ce != null ) {
ce.resetStoredSnapshot( result, targetSnapshot );
}
@ -769,7 +770,7 @@ public abstract class CollectionType extends AbstractType implements Association
public Object getCollection(Serializable key, SharedSessionContractImplementor session, Object owner, Boolean overridingEager) {
final CollectionPersister persister = getPersister( session );
final PersistenceContext persistenceContext = session.getPersistenceContext();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final CollectionKey collectionKey = new CollectionKey( persister, key );
// check if collection is currently being loaded

View File

@ -588,7 +588,7 @@ public class ComponentType extends AbstractType implements CompositeType, Proced
if ( componentTuplizer.hasParentProperty() && parent != null ) {
componentTuplizer.setParent(
result,
session.getPersistenceContext().proxyFor( parent ),
session.getPersistenceContextInternal().proxyFor( parent ),
session.getFactory()
);
}

View File

@ -739,7 +739,7 @@ public abstract class EntityType extends AbstractType implements AssociationType
session.getFactory()
);
final PersistenceContext persistenceContext = session.getPersistenceContext();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
Object result = persistenceContext.getEntity( euk );
if ( result == null ) {
result = persister.loadByUniqueKey( uniqueKeyPropertyName, key, session );

View File

@ -204,8 +204,9 @@ public class ManyToOneType extends EntityType {
final EntityPersister persister = getAssociatedEntityPersister( session.getFactory() );
if ( persister.isBatchLoadable() ) {
final EntityKey entityKey = session.generateEntityKey( id, persister );
if ( !session.getPersistenceContext().containsEntity( entityKey ) ) {
session.getPersistenceContext().getBatchFetchQueue().addBatchLoadableEntityKey( entityKey );
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
if ( !persistenceContext.containsEntity( entityKey ) ) {
persistenceContext.getBatchFetchQueue().addBatchLoadableEntityKey( entityKey );
}
}
}
@ -238,7 +239,8 @@ public class ManyToOneType extends EntityType {
public Object resolve(Object value, SharedSessionContractImplementor session, Object owner, Boolean overridingEager) throws HibernateException {
Object resolvedValue = super.resolve(value, session, owner, overridingEager);
if ( isLogicalOneToOne && value != null && getPropertyName() != null ) {
EntityEntry entry = session.getPersistenceContext().getEntry( owner );
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
EntityEntry entry = persistenceContext.getEntry( owner );
if ( entry != null ) {
final Loadable ownerPersister = (Loadable) session.getFactory().getMetamodel().entityPersister( entry.getEntityName() );
EntityUniqueKey entityKey = new EntityUniqueKey(
@ -249,7 +251,7 @@ public class ManyToOneType extends EntityType {
ownerPersister.getEntityMode(),
session.getFactory()
);
session.getPersistenceContext().addEntity( entityKey, owner );
persistenceContext.addEntity( entityKey, owner );
}
}
return resolvedValue;

View File

@ -103,7 +103,7 @@ public class OneToOneType extends EntityType {
final EntityPersister ownerPersister = session.getFactory().getMetamodel().entityPersister( entityName );
final Serializable id = session.getContextEntityIdentifier( owner );
final EntityKey entityKey = session.generateEntityKey( id, ownerPersister );
return session.getPersistenceContext().isPropertyNull( entityKey, getPropertyName() );
return session.getPersistenceContextInternal().isPropertyNull( entityKey, getPropertyName() );
}
else {
return false;

View File

@ -283,7 +283,7 @@ public class BatchFetchNotFoundIgnoreDefaultStyleTest extends BaseCoreFunctional
final EntityPersister persister =
sessionImplementor.getFactory().getMetamodel().entityPersister( Task.class );
final BatchFetchQueue batchFetchQueue =
sessionImplementor.getPersistenceContext().getBatchFetchQueue();
sessionImplementor.getPersistenceContextInternal().getBatchFetchQueue();
assertEquals( expected, batchFetchQueue.containsEntityKey( new EntityKey( id, persister ) ) );
}

View File

@ -49,10 +49,10 @@ import static org.junit.Assert.assertTrue;
public abstract class AbstractDereferencedCollectionTest extends BaseCoreFunctionalTestCase {
protected EntityEntry getEntityEntry(Session s, Object entity) {
return ( (SessionImplementor) s ).getPersistenceContext().getEntry( entity );
return ( (SessionImplementor) s ).getPersistenceContextInternal().getEntry( entity );
}
protected CollectionEntry getCollectionEntry(Session s, PersistentCollection collection) {
return ( (SessionImplementor) s ).getPersistenceContext().getCollectionEntry( collection );
return ( (SessionImplementor) s ).getPersistenceContextInternal().getCollectionEntry( collection );
}
}

View File

@ -117,7 +117,7 @@ public class AggregatedCollectionEventListener
this.event = event;
// make a copy of the collection?
this.snapshotAtTimeOfEventHandling = event.getSession()
.getPersistenceContext()
.getPersistenceContextInternal()
.getCollectionEntry( event.getCollection() )
.getSnapshot();
}

Some files were not shown because too many files have changed in this diff Show More