HHH-13997 : Add methods to SessionImpl and StatefulPersistenceContext; make Loader method protected

* Change visibility for Loader#registerNonExists
* Methods for creating PersistenceContext and ActionQueue
* Add StatefulPersistenceContext#initializeNonLazyCollections(Consumer<PersistentCollection> initializeAction)
This commit is contained in:
Davide D'Alto 2020-04-15 14:50:44 +01:00
parent 2d7022ecec
commit 9cd2236fd3
4 changed files with 17 additions and 4 deletions

0
.gradletasknamecache Normal file
View File

View File

@ -23,6 +23,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentMap;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.hibernate.AssertionFailure;
@ -984,6 +985,10 @@ public class StatefulPersistenceContext implements PersistenceContext {
@Override
public void initializeNonLazyCollections() throws HibernateException {
initializeNonLazyCollections( PersistentCollection::forceInitialization );
}
protected void initializeNonLazyCollections(Consumer<PersistentCollection> initializeAction ) {
if ( loadCounter == 0 ) {
LOG.trace( "Initializing non-lazy collections" );
@ -994,7 +999,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
int size;
while ( nonlazyCollections != null && ( size = nonlazyCollections.size() ) > 0 ) {
//note that each iteration of the loop may add new elements
nonlazyCollections.remove( size - 1 ).forceInitialization();
initializeAction.accept( nonlazyCollections.remove( size - 1 ) );
}
}
finally {

View File

@ -221,8 +221,8 @@ public class SessionImpl
public SessionImpl(SessionFactoryImpl factory, SessionCreationOptions options) {
super( factory, options );
this.actionQueue = new ActionQueue( this );
this.persistenceContext = new StatefulPersistenceContext( this );
this.persistenceContext = createPersistenceContext();
this.actionQueue = createActionQueue();
this.autoClear = options.shouldAutoClear();
this.autoClose = options.shouldAutoClose();
@ -269,6 +269,14 @@ public class SessionImpl
}
}
protected StatefulPersistenceContext createPersistenceContext() {
return new StatefulPersistenceContext( this );
}
protected ActionQueue createActionQueue() {
return new ActionQueue( this );
}
private LockOptions getLockOptionsForRead() {
return this.lockOptions == null ? fastSessionServices.defaultLockOptions : this.lockOptions;
}

View File

@ -1298,7 +1298,7 @@ public abstract class Loader {
* result set, register the fact that the the object is missing with the
* session.
*/
private void registerNonExists(
protected void registerNonExists(
final EntityKey[] keys,
final Loadable[] persisters,
final SharedSessionContractImplementor session) {