Search in sources :

Example 1 with Name

use of org.hibernate.test.cache.infinispan.functional.entities.Name in project hibernate-orm by hibernate.

the class CacheKeysFactoryTest method test.

private void test(String cacheKeysFactory, String keyClassName) throws Exception {
    SessionFactory sessionFactory = getSessionFactory(cacheKeysFactory);
    withTxSession(false, sessionFactory, s -> {
        Person person = new Person("John", "Black", 39);
        s.persist(person);
    });
    TestInfinispanRegionFactory regionFactory = (TestInfinispanRegionFactory) ((CacheImplementor) sessionFactory.getCache()).getRegionFactory();
    Cache<Object, Object> cache = regionFactory.getCacheManager().getCache(Person.class.getName());
    Iterator<Object> iterator = cache.getAdvancedCache().getDataContainer().keySet().iterator();
    assertTrue(iterator.hasNext());
    Object key = iterator.next();
    assertEquals(keyClassName, key.getClass().getSimpleName());
    withTxSession(false, sessionFactory, s -> {
        Person person = s.load(Person.class, new Name("John", "Black"));
        assertEquals(39, person.getAge());
    });
}
Also used : SessionFactory(org.hibernate.SessionFactory) Person(org.hibernate.test.cache.infinispan.functional.entities.Person) TestInfinispanRegionFactory(org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory) Name(org.hibernate.test.cache.infinispan.functional.entities.Name)

Example 2 with Name

use of org.hibernate.test.cache.infinispan.functional.entities.Name in project hibernate-orm by hibernate.

the class EqualityTest method testEqualityFromType.

@Test
public void testEqualityFromType() throws Exception {
    Person john = new Person("John", "Black", 26);
    Person peter = new Person("Peter", "White", 32);
    withTxSession(s -> {
        s.persist(john);
        s.persist(peter);
    });
    Statistics statistics = sessionFactory().getStatistics();
    statistics.clear();
    for (int i = 0; i < 5; ++i) {
        withTxSession(s -> {
            Person p1 = s.get(Person.class, john.getName());
            assertPersonEquals(john, p1);
            Person p2 = s.get(Person.class, peter.getName());
            assertPersonEquals(peter, p2);
            Person p3 = s.get(Person.class, new Name("Foo", "Bar"));
            assertNull(p3);
        });
    }
    assertTrue(statistics.getSecondLevelCacheHitCount() > 0);
    assertTrue(statistics.getSecondLevelCacheMissCount() > 0);
}
Also used : Person(org.hibernate.test.cache.infinispan.functional.entities.Person) Statistics(org.hibernate.stat.Statistics) Name(org.hibernate.test.cache.infinispan.functional.entities.Name) Test(org.junit.Test)

Aggregations

Name (org.hibernate.test.cache.infinispan.functional.entities.Name)2 Person (org.hibernate.test.cache.infinispan.functional.entities.Person)2 SessionFactory (org.hibernate.SessionFactory)1 Statistics (org.hibernate.stat.Statistics)1 TestInfinispanRegionFactory (org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory)1 Test (org.junit.Test)1