Search in sources :

Example 1 with DomainDataRegionConfig

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()));
        }
    }
}
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)

Example 2 with DomainDataRegionConfig

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);
}
Also used : DomainDataRegionConfigImpl(org.hibernate.cache.cfg.internal.DomainDataRegionConfigImpl) Collection(org.hibernate.mapping.Collection) DomainDataRegionConfig(org.hibernate.cache.cfg.spi.DomainDataRegionConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AccessType(org.hibernate.cache.spi.access.AccessType) PersistentClass(org.hibernate.mapping.PersistentClass)

Aggregations

DomainDataRegionConfig (org.hibernate.cache.cfg.spi.DomainDataRegionConfig)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 HibernateException (org.hibernate.HibernateException)1 DomainDataRegionConfigImpl (org.hibernate.cache.cfg.internal.DomainDataRegionConfigImpl)1 CollectionDataCachingConfig (org.hibernate.cache.cfg.spi.CollectionDataCachingConfig)1 EntityDataCachingConfig (org.hibernate.cache.cfg.spi.EntityDataCachingConfig)1 NaturalIdDataCachingConfig (org.hibernate.cache.cfg.spi.NaturalIdDataCachingConfig)1 DomainDataRegion (org.hibernate.cache.spi.DomainDataRegion)1 AccessType (org.hibernate.cache.spi.access.AccessType)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 Collection (org.hibernate.mapping.Collection)1 PersistentClass (org.hibernate.mapping.PersistentClass)1