use of org.hibernate.testing.cache.EntityRegionImpl 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());
EntityRegionImpl region = (EntityRegionImpl) 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();
{
final Object cachedItem = region.getDataMap().values().iterator().next();
final Map<String, ?> state = (Map) ((ReadWriteEntityRegionAccessStrategy.Item) cachedItem).getValue();
// 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();
region.evictAll();
session = openSession();
session.getTransaction().begin();
Address address = session.get(Address.class, 1);
session.getTransaction().commit();
session.close();
{
final Object cachedItem = region.getDataMap().values().iterator().next();
final Map<String, ?> state = (Map) ((ReadWriteEntityRegionAccessStrategy.Item) cachedItem).getValue();
// 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.testing.cache.EntityRegionImpl in project hibernate-orm by hibernate.
the class BasicUnstructuredCachingOfConvertedValueTest method basicCacheStructureTest.
@Test
@TestForIssue(jiraKey = "HHH-9615")
@SuppressWarnings("unchecked")
public void basicCacheStructureTest() {
EntityPersister persister = sessionFactory().getMetamodel().entityPersisters().get(Address.class.getName());
EntityRegionImpl region = (EntityRegionImpl) 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();
{
final Object cachedItem = region.getDataMap().values().iterator().next();
final StandardCacheEntryImpl state = (StandardCacheEntryImpl) ((ReadWriteEntityRegionAccessStrategy.Item) cachedItem).getValue();
assertThat(state.getDisassembledState()[postalAreaAttributeIndex], instanceOf(PostalArea.class));
}
assertThat(PostalAreaConverter.toDatabaseCallCount, is(1));
assertThat(PostalAreaConverter.toDomainCallCount, is(0));
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// test during load...
PostalAreaConverter.clearCounts();
region.evictAll();
session = openSession();
session.getTransaction().begin();
Address address = session.get(Address.class, 1);
session.getTransaction().commit();
session.close();
{
final Object cachedItem = region.getDataMap().values().iterator().next();
final StandardCacheEntryImpl state = (StandardCacheEntryImpl) ((ReadWriteEntityRegionAccessStrategy.Item) cachedItem).getValue();
assertThat(state.getDisassembledState()[postalAreaAttributeIndex], 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();
}
Aggregations