HHH-10286 SessionFactoryImpl doesn't cache and reuse existing collection cache region access strategies

This commit is contained in:
Karl von Randow 2015-11-13 16:28:23 +13:00 committed by Steve Ebersole
parent 5cc2175033
commit 828a83dcbf
1 changed files with 21 additions and 16 deletions

View File

@ -388,22 +388,11 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
Map<String,CollectionMetadata> tmpCollectionMetadata = new HashMap<String,CollectionMetadata>();
for ( final Collection model : metadata.getCollectionBindings() ) {
final String cacheRegionName = cacheRegionPrefix + model.getCacheRegionName();
final AccessType accessType = AccessType.fromExternalName( model.getCacheConcurrencyStrategy() );
final CollectionRegionAccessStrategy accessStrategy;
if ( accessType != null && settings.isSecondLevelCacheEnabled() ) {
LOG.tracev( "Building shared cache region for collection data [{0}]", model.getRole() );
CollectionRegion collectionRegion = regionFactory.buildCollectionRegion(
cacheRegionName,
properties,
CacheDataDescriptionImpl.decode( model )
);
accessStrategy = collectionRegion.buildAccessStrategy( accessType );
cacheAccessStrategiesMap.put( cacheRegionName, accessStrategy );
cacheAccess.addCacheRegion( cacheRegionName, collectionRegion );
}
else {
accessStrategy = null;
}
final CollectionRegionAccessStrategy accessStrategy = determineCollectionRegionAccessStrategy(
regionFactory,
cacheAccessStrategiesMap,
model,
cacheRegionName);
final CollectionPersister persister = persisterFactory.createCollectionPersister(
model,
@ -640,6 +629,22 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
return accessStrategy;
}
private CollectionRegionAccessStrategy determineCollectionRegionAccessStrategy(final RegionFactory regionFactory, Map cacheAccessStrategiesMap, final Collection model,
final String cacheRegionName) {
CollectionRegionAccessStrategy accessStrategy = (CollectionRegionAccessStrategy) cacheAccessStrategiesMap.get(cacheRegionName);
if (accessStrategy == null && settings.isSecondLevelCacheEnabled()) {
final AccessType accessType = AccessType.fromExternalName(model.getCacheConcurrencyStrategy());
if (accessType != null) {
LOG.tracev("Building shared cache region for collection data [{0}]", model.getRole());
CollectionRegion collectionRegion = regionFactory.buildCollectionRegion(cacheRegionName, properties, CacheDataDescriptionImpl.decode(model));
accessStrategy = collectionRegion.buildAccessStrategy(accessType);
cacheAccessStrategiesMap.put(cacheRegionName, accessStrategy);
cacheAccess.addCacheRegion(cacheRegionName, collectionRegion);
}
}
return accessStrategy;
}
private JdbcConnectionAccess buildLocalConnectionAccess() {
return new JdbcConnectionAccess() {
@Override