HHH-6858 reuse reference to PersistenceContext
This commit is contained in:
parent
fb0255a87a
commit
ddb3a8cd18
|
@ -87,19 +87,19 @@ public abstract class AbstractFlushingEventListener implements Serializable {
|
||||||
final PersistenceContext persistenceContext = session.getPersistenceContext();
|
final PersistenceContext persistenceContext = session.getPersistenceContext();
|
||||||
session.getInterceptor().preFlush( new LazyIterator( persistenceContext.getEntitiesByKey() ) );
|
session.getInterceptor().preFlush( new LazyIterator( persistenceContext.getEntitiesByKey() ) );
|
||||||
|
|
||||||
prepareEntityFlushes(session);
|
prepareEntityFlushes( session, persistenceContext );
|
||||||
// we could move this inside if we wanted to
|
// we could move this inside if we wanted to
|
||||||
// tolerate collection initializations during
|
// tolerate collection initializations during
|
||||||
// collection dirty checking:
|
// collection dirty checking:
|
||||||
prepareCollectionFlushes(session);
|
prepareCollectionFlushes( persistenceContext );
|
||||||
// now, any collections that are initialized
|
// now, any collections that are initialized
|
||||||
// inside this block do not get updated - they
|
// inside this block do not get updated - they
|
||||||
// are ignored until the next flush
|
// are ignored until the next flush
|
||||||
|
|
||||||
persistenceContext.setFlushing(true);
|
persistenceContext.setFlushing(true);
|
||||||
try {
|
try {
|
||||||
flushEntities(event);
|
flushEntities( event, persistenceContext );
|
||||||
flushCollections(session);
|
flushCollections( session, persistenceContext );
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
persistenceContext.setFlushing(false);
|
persistenceContext.setFlushing(false);
|
||||||
|
@ -140,11 +140,11 @@ public abstract class AbstractFlushingEventListener implements Serializable {
|
||||||
* any newly referenced entity that must be passed to saveOrUpdate(),
|
* any newly referenced entity that must be passed to saveOrUpdate(),
|
||||||
* and also apply orphan delete
|
* and also apply orphan delete
|
||||||
*/
|
*/
|
||||||
private void prepareEntityFlushes(EventSource session) throws HibernateException {
|
private void prepareEntityFlushes(EventSource session, PersistenceContext persistenceContext) throws HibernateException {
|
||||||
|
|
||||||
LOG.debug( "Processing flush-time cascades" );
|
LOG.debug( "Processing flush-time cascades" );
|
||||||
|
|
||||||
final Map.Entry[] list = IdentityMap.concurrentEntries( session.getPersistenceContext().getEntityEntries() );
|
final Map.Entry[] list = IdentityMap.concurrentEntries( persistenceContext.getEntityEntries() );
|
||||||
//safe from concurrent modification because of how entryList() is implemented on IdentityMap
|
//safe from concurrent modification because of how entryList() is implemented on IdentityMap
|
||||||
final int size = list.length;
|
final int size = list.length;
|
||||||
final Object anything = getAnything();
|
final Object anything = getAnything();
|
||||||
|
@ -180,14 +180,14 @@ public abstract class AbstractFlushingEventListener implements Serializable {
|
||||||
* Initialize the flags of the CollectionEntry, including the
|
* Initialize the flags of the CollectionEntry, including the
|
||||||
* dirty check.
|
* dirty check.
|
||||||
*/
|
*/
|
||||||
private void prepareCollectionFlushes(SessionImplementor session) throws HibernateException {
|
private void prepareCollectionFlushes(PersistenceContext persistenceContext) throws HibernateException {
|
||||||
|
|
||||||
// Initialize dirty flags for arrays + collections with composite elements
|
// Initialize dirty flags for arrays + collections with composite elements
|
||||||
// and reset reached, doupdate, etc.
|
// and reset reached, doupdate, etc.
|
||||||
|
|
||||||
LOG.debug( "Dirty checking collections" );
|
LOG.debug( "Dirty checking collections" );
|
||||||
|
|
||||||
final List list = IdentityMap.entries( session.getPersistenceContext().getCollectionEntries() );
|
final List list = IdentityMap.entries( persistenceContext.getCollectionEntries() );
|
||||||
final int size = list.size();
|
final int size = list.size();
|
||||||
for ( int i = 0; i < size; i++ ) {
|
for ( int i = 0; i < size; i++ ) {
|
||||||
Map.Entry e = ( Map.Entry ) list.get( i );
|
Map.Entry e = ( Map.Entry ) list.get( i );
|
||||||
|
@ -200,7 +200,7 @@ public abstract class AbstractFlushingEventListener implements Serializable {
|
||||||
* 2. schedule any entity updates
|
* 2. schedule any entity updates
|
||||||
* 3. search out any reachable collections
|
* 3. search out any reachable collections
|
||||||
*/
|
*/
|
||||||
private void flushEntities(FlushEvent event) throws HibernateException {
|
private void flushEntities(final FlushEvent event, final PersistenceContext persistenceContext) throws HibernateException {
|
||||||
|
|
||||||
LOG.trace( "Flushing entities and processing referenced collections" );
|
LOG.trace( "Flushing entities and processing referenced collections" );
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ public abstract class AbstractFlushingEventListener implements Serializable {
|
||||||
.getEventListenerGroup( EventType.FLUSH_ENTITY )
|
.getEventListenerGroup( EventType.FLUSH_ENTITY )
|
||||||
.listeners();
|
.listeners();
|
||||||
|
|
||||||
final Map.Entry[] list = IdentityMap.concurrentEntries( source.getPersistenceContext().getEntityEntries() );
|
final Map.Entry[] list = IdentityMap.concurrentEntries( persistenceContext.getEntityEntries() );
|
||||||
final int size = list.length;
|
final int size = list.length;
|
||||||
for ( int i = 0; i < size; i++ ) {
|
for ( int i = 0; i < size; i++ ) {
|
||||||
|
|
||||||
|
@ -244,11 +244,11 @@ public abstract class AbstractFlushingEventListener implements Serializable {
|
||||||
* process any unreferenced collections and then inspect all known collections,
|
* process any unreferenced collections and then inspect all known collections,
|
||||||
* scheduling creates/removes/updates
|
* scheduling creates/removes/updates
|
||||||
*/
|
*/
|
||||||
private void flushCollections(EventSource session) throws HibernateException {
|
private void flushCollections(final EventSource session, final PersistenceContext persistenceContext) throws HibernateException {
|
||||||
|
|
||||||
LOG.trace( "Processing unreferenced collections" );
|
LOG.trace( "Processing unreferenced collections" );
|
||||||
|
|
||||||
List list = IdentityMap.entries( session.getPersistenceContext().getCollectionEntries() );
|
List list = IdentityMap.entries( persistenceContext.getCollectionEntries() );
|
||||||
int size = list.size();
|
int size = list.size();
|
||||||
for ( int i = 0; i < size; i++ ) {
|
for ( int i = 0; i < size; i++ ) {
|
||||||
Map.Entry me = ( Map.Entry ) list.get( i );
|
Map.Entry me = ( Map.Entry ) list.get( i );
|
||||||
|
@ -262,7 +262,7 @@ public abstract class AbstractFlushingEventListener implements Serializable {
|
||||||
|
|
||||||
LOG.trace( "Scheduling collection removes/(re)creates/updates" );
|
LOG.trace( "Scheduling collection removes/(re)creates/updates" );
|
||||||
|
|
||||||
list = IdentityMap.entries( session.getPersistenceContext().getCollectionEntries() );
|
list = IdentityMap.entries( persistenceContext.getCollectionEntries() );
|
||||||
size = list.size();
|
size = list.size();
|
||||||
ActionQueue actionQueue = session.getActionQueue();
|
ActionQueue actionQueue = session.getActionQueue();
|
||||||
for ( int i = 0; i < size; i++ ) {
|
for ( int i = 0; i < size; i++ ) {
|
||||||
|
|
|
@ -36,6 +36,7 @@ import org.hibernate.MappingException;
|
||||||
import org.hibernate.bytecode.instrumentation.spi.LazyPropertyInitializer;
|
import org.hibernate.bytecode.instrumentation.spi.LazyPropertyInitializer;
|
||||||
import org.hibernate.engine.spi.EntityEntry;
|
import org.hibernate.engine.spi.EntityEntry;
|
||||||
import org.hibernate.engine.spi.EntityKey;
|
import org.hibernate.engine.spi.EntityKey;
|
||||||
|
import org.hibernate.engine.spi.PersistenceContext;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
import org.hibernate.event.service.spi.EventListenerRegistry;
|
import org.hibernate.event.service.spi.EventListenerRegistry;
|
||||||
|
@ -460,6 +461,7 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer {
|
||||||
final Type[] subTypes = virtualIdComponent.getSubtypes();
|
final Type[] subTypes = virtualIdComponent.getSubtypes();
|
||||||
final Type[] copierSubTypes = mappedIdentifierType.getSubtypes();
|
final Type[] copierSubTypes = mappedIdentifierType.getSubtypes();
|
||||||
final Iterable<PersistEventListener> persistEventListeners = persistEventListeners( session );
|
final Iterable<PersistEventListener> persistEventListeners = persistEventListeners( session );
|
||||||
|
final PersistenceContext persistenceContext = session.getPersistenceContext();
|
||||||
final int length = subTypes.length;
|
final int length = subTypes.length;
|
||||||
for ( int i = 0 ; i < length; i++ ) {
|
for ( int i = 0 ; i < length; i++ ) {
|
||||||
if ( propertyValues[i] == null ) {
|
if ( propertyValues[i] == null ) {
|
||||||
|
@ -488,7 +490,7 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer {
|
||||||
for ( PersistEventListener listener : persistEventListeners ) {
|
for ( PersistEventListener listener : persistEventListeners ) {
|
||||||
listener.onPersist( event );
|
listener.onPersist( event );
|
||||||
}
|
}
|
||||||
pcEntry = session.getPersistenceContext().getEntry( propertyValues[i] );
|
pcEntry = persistenceContext.getEntry( propertyValues[i] );
|
||||||
if ( pcEntry == null || pcEntry.getId() == null ) {
|
if ( pcEntry == null || pcEntry.getId() == null ) {
|
||||||
throw new HibernateException( "Unable to process implicit derived identity cascade" );
|
throw new HibernateException( "Unable to process implicit derived identity cascade" );
|
||||||
}
|
}
|
||||||
|
@ -507,6 +509,7 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer {
|
||||||
public void setIdentifier(Object entity, Serializable id, EntityMode entityMode, SessionImplementor session) {
|
public void setIdentifier(Object entity, Serializable id, EntityMode entityMode, SessionImplementor session) {
|
||||||
final Object[] extractedValues = mappedIdentifierType.getPropertyValues( id, entityMode );
|
final Object[] extractedValues = mappedIdentifierType.getPropertyValues( id, entityMode );
|
||||||
final Object[] injectionValues = new Object[ extractedValues.length ];
|
final Object[] injectionValues = new Object[ extractedValues.length ];
|
||||||
|
final PersistenceContext persistenceContext = session.getPersistenceContext();
|
||||||
for ( int i = 0; i < virtualIdComponent.getSubtypes().length; i++ ) {
|
for ( int i = 0; i < virtualIdComponent.getSubtypes().length; i++ ) {
|
||||||
final Type virtualPropertyType = virtualIdComponent.getSubtypes()[i];
|
final Type virtualPropertyType = virtualIdComponent.getSubtypes()[i];
|
||||||
final Type idClassPropertyType = mappedIdentifierType.getSubtypes()[i];
|
final Type idClassPropertyType = mappedIdentifierType.getSubtypes()[i];
|
||||||
|
@ -522,10 +525,10 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer {
|
||||||
session.getFactory().getEntityPersister( associatedEntityName )
|
session.getFactory().getEntityPersister( associatedEntityName )
|
||||||
);
|
);
|
||||||
// it is conceivable there is a proxy, so check that first
|
// it is conceivable there is a proxy, so check that first
|
||||||
Object association = session.getPersistenceContext().getProxy( entityKey );
|
Object association = persistenceContext.getProxy( entityKey );
|
||||||
if ( association == null ) {
|
if ( association == null ) {
|
||||||
// otherwise look for an initialized version
|
// otherwise look for an initialized version
|
||||||
association = session.getPersistenceContext().getEntity( entityKey );
|
association = persistenceContext.getEntity( entityKey );
|
||||||
}
|
}
|
||||||
injectionValues[i] = association;
|
injectionValues[i] = association;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue