HHH-13552 Store the Collection Persister in a field of CollectionType

This commit is contained in:
Sanne Grinovero 2019-08-09 15:49:43 +01:00
parent 6510c34e93
commit 80f8f0845c
1 changed files with 28 additions and 2 deletions

View File

@ -63,6 +63,10 @@ public abstract class CollectionType extends AbstractType implements Association
private final String role;
private final String foreignKeyPropertyName;
// the need for the persister if very hot in many use cases: cache it in a field
// TODO initialize it at constructor time
private volatile CollectionPersister persister;
/**
* @deprecated Use the other contructor
*/
@ -319,11 +323,33 @@ public abstract class CollectionType extends AbstractType implements Association
* @return The underlying collection persister
*/
private CollectionPersister getPersister(SharedSessionContractImplementor session) {
CollectionPersister p = this.persister;
if ( p != null ) {
return p;
}
else {
return getPersister( session.getFactory() );
}
}
private CollectionPersister getPersister(SessionFactoryImplementor factory) {
return factory.getMetamodel().collectionPersister( role );
CollectionPersister p = this.persister;
if ( p != null ) {
return p;
}
else {
synchronized ( this ) {
p = this.persister;
if ( p != null ) {
return p;
}
else {
p = factory.getMetamodel().collectionPersister( role );
this.persister = p;
return p;
}
}
}
}
@Override