use of org.hibernate.cache.cfg.spi.DomainDataRegionConfig in project hibernate-orm by hibernate.
the class EnabledCaching method prime.
@Override
public void prime(Set<DomainDataRegionConfig> cacheRegionConfigs) {
for (DomainDataRegionConfig regionConfig : cacheRegionConfigs) {
final DomainDataRegion region = getRegionFactory().buildDomainDataRegion(regionConfig, this);
regionsByName.put(region.getName(), region);
if (!StringTypeDescriptor.INSTANCE.areEqual(region.getName(), regionConfig.getRegionName())) {
throw new HibernateException(String.format(Locale.ROOT, "Region [%s] returned from RegionFactory [%s] was named differently than requested name. Expecting `%s`, but found `%s`", region, getRegionFactory().getClass().getName(), regionConfig.getRegionName(), region.getName()));
}
for (EntityDataCachingConfig entityAccessConfig : regionConfig.getEntityCaching()) {
final EntityDataAccess entityDataAccess = entityAccessMap.put(entityAccessConfig.getNavigableRole(), region.getEntityDataAccess(entityAccessConfig.getNavigableRole()));
legacySecondLevelCacheNames.add(StringHelper.qualifyConditionally(getSessionFactory().getSessionFactoryOptions().getCacheRegionPrefix(), region.getName()));
}
if (regionConfig.getNaturalIdCaching().isEmpty()) {
legacyNaturalIdAccessesForRegion.put(region.getName(), Collections.emptySet());
} else {
final HashSet<NaturalIdDataAccess> accesses = new HashSet<>();
for (NaturalIdDataCachingConfig naturalIdAccessConfig : regionConfig.getNaturalIdCaching()) {
final NaturalIdDataAccess naturalIdDataAccess = naturalIdAccessMap.put(naturalIdAccessConfig.getNavigableRole(), region.getNaturalIdDataAccess(naturalIdAccessConfig.getNavigableRole()));
accesses.add(naturalIdDataAccess);
}
legacyNaturalIdAccessesForRegion.put(region.getName(), accesses);
}
for (CollectionDataCachingConfig collectionAccessConfig : regionConfig.getCollectionCaching()) {
final CollectionDataAccess collectionDataAccess = collectionAccessMap.put(collectionAccessConfig.getNavigableRole(), region.getCollectionDataAccess(collectionAccessConfig.getNavigableRole()));
legacySecondLevelCacheNames.add(StringHelper.qualifyConditionally(getSessionFactory().getSessionFactoryOptions().getCacheRegionPrefix(), region.getName()));
}
}
}
use of org.hibernate.cache.cfg.spi.DomainDataRegionConfig in project hibernate-orm by hibernate.
the class MetamodelImpl method primeSecondLevelCacheRegions.
private void primeSecondLevelCacheRegions(MetadataImplementor mappingMetadata) {
final Map<String, DomainDataRegionConfigImpl.Builder> regionConfigBuilders = new ConcurrentHashMap<>();
for (PersistentClass bootEntityDescriptor : mappingMetadata.getEntityBindings()) {
final AccessType accessType = AccessType.fromExternalName(bootEntityDescriptor.getCacheConcurrencyStrategy());
if (accessType != null) {
if (bootEntityDescriptor.isCached()) {
regionConfigBuilders.computeIfAbsent(bootEntityDescriptor.getRootClass().getCacheRegionName(), DomainDataRegionConfigImpl.Builder::new).addEntityConfig(bootEntityDescriptor, accessType);
}
if (RootClass.class.isInstance(bootEntityDescriptor) && bootEntityDescriptor.hasNaturalId() && bootEntityDescriptor.getNaturalIdCacheRegionName() != null) {
regionConfigBuilders.computeIfAbsent(bootEntityDescriptor.getNaturalIdCacheRegionName(), DomainDataRegionConfigImpl.Builder::new).addNaturalIdConfig((RootClass) bootEntityDescriptor, accessType);
}
}
}
for (Collection collection : mappingMetadata.getCollectionBindings()) {
final AccessType accessType = AccessType.fromExternalName(collection.getCacheConcurrencyStrategy());
if (accessType != null) {
regionConfigBuilders.computeIfAbsent(collection.getCacheRegionName(), DomainDataRegionConfigImpl.Builder::new).addCollectionConfig(collection, accessType);
}
}
final Set<DomainDataRegionConfig> regionConfigs;
if (regionConfigBuilders.isEmpty()) {
regionConfigs = Collections.emptySet();
} else {
regionConfigs = new HashSet<>();
for (DomainDataRegionConfigImpl.Builder builder : regionConfigBuilders.values()) {
regionConfigs.add(builder.build());
}
}
getSessionFactory().getCache().prime(regionConfigs);
}
Aggregations