Search in sources :

Example 1 with NaturalIdDataCachingConfig

use of org.hibernate.cache.cfg.spi.NaturalIdDataCachingConfig 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()));
        }
    }
}
Also used : NaturalIdDataCachingConfig(org.hibernate.cache.cfg.spi.NaturalIdDataCachingConfig) EntityDataCachingConfig(org.hibernate.cache.cfg.spi.EntityDataCachingConfig) HibernateException(org.hibernate.HibernateException) DomainDataRegionConfig(org.hibernate.cache.cfg.spi.DomainDataRegionConfig) NaturalIdDataAccess(org.hibernate.cache.spi.access.NaturalIdDataAccess) DomainDataRegion(org.hibernate.cache.spi.DomainDataRegion) CollectionDataAccess(org.hibernate.cache.spi.access.CollectionDataAccess) CollectionDataCachingConfig(org.hibernate.cache.cfg.spi.CollectionDataCachingConfig) EntityDataAccess(org.hibernate.cache.spi.access.EntityDataAccess) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 HibernateException (org.hibernate.HibernateException)1 CollectionDataCachingConfig (org.hibernate.cache.cfg.spi.CollectionDataCachingConfig)1 DomainDataRegionConfig (org.hibernate.cache.cfg.spi.DomainDataRegionConfig)1 EntityDataCachingConfig (org.hibernate.cache.cfg.spi.EntityDataCachingConfig)1 NaturalIdDataCachingConfig (org.hibernate.cache.cfg.spi.NaturalIdDataCachingConfig)1 DomainDataRegion (org.hibernate.cache.spi.DomainDataRegion)1 CollectionDataAccess (org.hibernate.cache.spi.access.CollectionDataAccess)1 EntityDataAccess (org.hibernate.cache.spi.access.EntityDataAccess)1 NaturalIdDataAccess (org.hibernate.cache.spi.access.NaturalIdDataAccess)1