use of org.hibernate.cache.spi.DomainDataRegion in project hibernate-orm by hibernate.
the class BasicStructuredCachingOfConvertedValueTest method basicCacheStructureTest.
@Test
@TestForIssue(jiraKey = "HHH-9615")
@SuppressWarnings("unchecked")
public void basicCacheStructureTest() {
EntityPersister persister = sessionFactory().getMetamodel().entityPersisters().get(Address.class.getName());
DomainDataRegion region = persister.getCacheAccessStrategy().getRegion();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// test during store...
PostalAreaConverter.clearCounts();
Session session = openSession();
session.getTransaction().begin();
session.save(new Address(1, "123 Main St.", null, PostalArea._78729));
session.getTransaction().commit();
session.close();
{
inSession(s -> {
final EntityDataAccess entityDataAccess = region.getEntityDataAccess(persister.getNavigableRole());
final Object cacheKey = entityDataAccess.generateCacheKey(1, persister, sessionFactory(), null);
final Object cachedItem = entityDataAccess.get(s, cacheKey);
final Map<String, ?> state = (Map) cachedItem;
// this is the point of the Jira.. that this "should be" the converted value
assertThat(state.get("postalArea"), instanceOf(PostalArea.class));
});
}
assertThat(PostalAreaConverter.toDatabaseCallCount, is(1));
assertThat(PostalAreaConverter.toDomainCallCount, is(0));
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// test during load...
PostalAreaConverter.clearCounts();
sessionFactory().getCache().evictAll();
session = openSession();
session.getTransaction().begin();
Address address = session.get(Address.class, 1);
session.getTransaction().commit();
session.close();
{
inSession(s -> {
final EntityDataAccess entityDataAccess = region.getEntityDataAccess(persister.getNavigableRole());
final Object cacheKey = entityDataAccess.generateCacheKey(1, persister, sessionFactory(), null);
final Object cachedItem = entityDataAccess.get(s, cacheKey);
final Map<String, ?> state = (Map) cachedItem;
// this is the point of the Jira.. that this "should be" the converted value
assertThat(state.get("postalArea"), instanceOf(PostalArea.class));
});
}
assertThat(PostalAreaConverter.toDatabaseCallCount, is(0));
assertThat(PostalAreaConverter.toDomainCallCount, is(1));
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// cleanup
session = openSession();
session.getTransaction().begin();
session.delete(address);
session.getTransaction().commit();
session.close();
}
use of org.hibernate.cache.spi.DomainDataRegion 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.spi.DomainDataRegion in project hibernate-orm by hibernate.
the class DeprecatedNaturalIdCacheStatisticsImpl method getElementCountOnDisk.
@Override
public long getElementCountOnDisk() {
long count = 0;
HashSet<Region> processedRegions = null;
for (NaturalIdDataAccess accessStrategy : accessStrategies) {
final DomainDataRegion region = accessStrategy.getRegion();
if (ExtendedStatisticsSupport.class.isInstance(region)) {
}
if (region instanceof ExtendedStatisticsSupport) {
if (processedRegions == null) {
processedRegions = new HashSet<>();
}
if (processedRegions.add(region)) {
count += ((ExtendedStatisticsSupport) region).getElementCountOnDisk();
}
}
}
if (count == 0) {
return NO_EXTENDED_STAT_SUPPORT_RETURN;
}
return count;
}
use of org.hibernate.cache.spi.DomainDataRegion in project hibernate-orm by hibernate.
the class DeprecatedNaturalIdCacheStatisticsImpl method getSizeInMemory.
@Override
public long getSizeInMemory() {
long count = 0;
HashSet<Region> processedRegions = null;
for (NaturalIdDataAccess accessStrategy : accessStrategies) {
final DomainDataRegion region = accessStrategy.getRegion();
if (ExtendedStatisticsSupport.class.isInstance(region)) {
}
if (region instanceof ExtendedStatisticsSupport) {
if (processedRegions == null) {
processedRegions = new HashSet<>();
}
if (processedRegions.add(region)) {
count += ((ExtendedStatisticsSupport) region).getElementCountOnDisk();
}
}
}
if (count == 0) {
return NO_EXTENDED_STAT_SUPPORT_RETURN;
}
return count;
}
use of org.hibernate.cache.spi.DomainDataRegion in project hibernate-orm by hibernate.
the class DeprecatedNaturalIdCacheStatisticsImpl method getElementCountInMemory.
@Override
public long getElementCountInMemory() {
long count = 0;
HashSet<Region> processedRegions = null;
for (NaturalIdDataAccess accessStrategy : accessStrategies) {
final DomainDataRegion region = accessStrategy.getRegion();
if (ExtendedStatisticsSupport.class.isInstance(region)) {
}
if (region instanceof ExtendedStatisticsSupport) {
if (processedRegions == null) {
processedRegions = new HashSet<>();
}
if (processedRegions.add(region)) {
count += ((ExtendedStatisticsSupport) region).getElementCountInMemory();
}
}
}
if (count == 0) {
return NO_EXTENDED_STAT_SUPPORT_RETURN;
}
return count;
}
Aggregations