HHH-10302 Extract helper method for LoadEvent reuse and adapt code formatting to Hibernate style
This commit is contained in:
parent
85db76431c
commit
f0f544472c
|
@ -105,7 +105,7 @@ public class LoadEvent extends AbstractEvent {
|
|||
this.instanceToLoad = instanceToLoad;
|
||||
this.lockOptions = lockOptions;
|
||||
this.isAssociationFetch = isAssociationFetch;
|
||||
this.postLoadEvent = new PostLoadEvent(source);
|
||||
this.postLoadEvent = new PostLoadEvent( source );
|
||||
}
|
||||
|
||||
public Serializable getEntityId() {
|
||||
|
|
|
@ -941,22 +941,22 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
|
|||
public void load(Object object, Serializable id) throws HibernateException {
|
||||
LoadEvent event = loadEvent;
|
||||
loadEvent = null;
|
||||
if(event == null) {
|
||||
if ( event == null ) {
|
||||
event = new LoadEvent( id, object, this );
|
||||
} else {
|
||||
event.setEntityClassName(null);
|
||||
event.setEntityId(id);
|
||||
event.setInstanceToLoad(object);
|
||||
event.setLockMode(LoadEvent.DEFAULT_LOCK_MODE);
|
||||
event.setLockScope(LoadEvent.DEFAULT_LOCK_OPTIONS.getScope());
|
||||
event.setLockTimeout(LoadEvent.DEFAULT_LOCK_OPTIONS.getTimeOut());
|
||||
event.setEntityClassName( null );
|
||||
event.setEntityId( id );
|
||||
event.setInstanceToLoad( object );
|
||||
event.setLockMode( LoadEvent.DEFAULT_LOCK_MODE );
|
||||
event.setLockScope( LoadEvent.DEFAULT_LOCK_OPTIONS.getScope() );
|
||||
event.setLockTimeout( LoadEvent.DEFAULT_LOCK_OPTIONS.getTimeOut() );
|
||||
}
|
||||
fireLoad( event, LoadEventListener.RELOAD );
|
||||
if(loadEvent == null) {
|
||||
event.setEntityClassName(null);
|
||||
event.setEntityId(null);
|
||||
event.setInstanceToLoad(null);
|
||||
event.setResult(null);
|
||||
if ( loadEvent == null ) {
|
||||
event.setEntityClassName( null );
|
||||
event.setEntityId( null );
|
||||
event.setInstanceToLoad( null );
|
||||
event.setResult( null );
|
||||
loadEvent = event;
|
||||
}
|
||||
}
|
||||
|
@ -994,23 +994,14 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
|
|||
}
|
||||
LoadEvent event = loadEvent;
|
||||
loadEvent = null;
|
||||
if(event == null) {
|
||||
event = new LoadEvent( id, entityName, true, this );
|
||||
} else {
|
||||
event.setEntityClassName(entityName);
|
||||
event.setEntityId(id);
|
||||
event.setInstanceToLoad(null);
|
||||
event.setLockMode(LoadEvent.DEFAULT_LOCK_MODE);
|
||||
event.setLockScope(LoadEvent.DEFAULT_LOCK_OPTIONS.getScope());
|
||||
event.setLockTimeout(LoadEvent.DEFAULT_LOCK_OPTIONS.getTimeOut());
|
||||
}
|
||||
event = recycleEventInstance( event, id, entityName );
|
||||
fireLoad( event, LoadEventListener.IMMEDIATE_LOAD );
|
||||
Object result = event.getResult();
|
||||
if(loadEvent == null) {
|
||||
event.setEntityClassName(null);
|
||||
event.setEntityId(null);
|
||||
event.setInstanceToLoad(null);
|
||||
event.setResult(null);
|
||||
if ( loadEvent == null ) {
|
||||
event.setEntityClassName( null );
|
||||
event.setEntityId( null );
|
||||
event.setInstanceToLoad( null );
|
||||
event.setResult( null );
|
||||
loadEvent = event;
|
||||
}
|
||||
return result;
|
||||
|
@ -1028,31 +1019,40 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
|
|||
|
||||
LoadEvent event = loadEvent;
|
||||
loadEvent = null;
|
||||
if(event == null) {
|
||||
event = new LoadEvent( id, entityName, true, this );
|
||||
} else {
|
||||
event.setEntityClassName(entityName);
|
||||
event.setEntityId(id);
|
||||
event.setInstanceToLoad(null);
|
||||
event.setLockMode(LoadEvent.DEFAULT_LOCK_MODE);
|
||||
event.setLockScope(LoadEvent.DEFAULT_LOCK_OPTIONS.getScope());
|
||||
event.setLockTimeout(LoadEvent.DEFAULT_LOCK_OPTIONS.getTimeOut());
|
||||
}
|
||||
event = recycleEventInstance( event, id, entityName );
|
||||
fireLoad( event, type );
|
||||
Object result = event.getResult();
|
||||
if ( !nullable ) {
|
||||
UnresolvableObjectException.throwIfNull(result, id, entityName );
|
||||
UnresolvableObjectException.throwIfNull( result, id, entityName );
|
||||
}
|
||||
if(loadEvent == null) {
|
||||
event.setEntityClassName(null);
|
||||
event.setEntityId(null);
|
||||
event.setInstanceToLoad(null);
|
||||
event.setResult(null);
|
||||
if ( loadEvent == null ) {
|
||||
event.setEntityClassName( null );
|
||||
event.setEntityId( null );
|
||||
event.setInstanceToLoad( null );
|
||||
event.setResult( null );
|
||||
loadEvent = event;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to avoid creating many new instances of LoadEvent: it's an allocation hot spot.
|
||||
*/
|
||||
private LoadEvent recycleEventInstance(final LoadEvent event, final Serializable id, final String entityName) {
|
||||
if ( event == null ) {
|
||||
return new LoadEvent( id, entityName, true, this );
|
||||
}
|
||||
else {
|
||||
event.setEntityClassName( entityName );
|
||||
event.setEntityId( id );
|
||||
event.setInstanceToLoad( null );
|
||||
event.setLockMode( LoadEvent.DEFAULT_LOCK_MODE );
|
||||
event.setLockScope( LoadEvent.DEFAULT_LOCK_OPTIONS.getScope() );
|
||||
event.setLockTimeout( LoadEvent.DEFAULT_LOCK_OPTIONS.getTimeOut() );
|
||||
return event;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T load(Class<T> entityClass, Serializable id, LockMode lockMode) throws HibernateException {
|
||||
return this.byId( entityClass ).with( new LockOptions( lockMode ) ).getReference( id );
|
||||
|
|
Loading…
Reference in New Issue