Search in sources :

Example 1 with PhoneNumber

use of org.hibernate.jcache.test.domain.PhoneNumber in project hibernate-orm by hibernate.

the class HibernateCacheTest method testGeneralUsage.

@Test
public void testGeneralUsage() {
    EventManager mgr = new EventManager(sessionFactory());
    Statistics stats = sessionFactory().getStatistics();
    // create 3 persons Steve, Orion, Tim
    Person stevePerson = new Person();
    stevePerson.setFirstname("Steve");
    stevePerson.setLastname("Harris");
    Long steveId = mgr.createAndStorePerson(stevePerson);
    mgr.addEmailToPerson(steveId, "steve@tc.com");
    mgr.addEmailToPerson(steveId, "sharrif@tc.com");
    mgr.addTalismanToPerson(steveId, "rabbit foot");
    mgr.addTalismanToPerson(steveId, "john de conqueroo");
    PhoneNumber p1 = new PhoneNumber();
    p1.setNumberType("Office");
    p1.setPhone(111111);
    mgr.addPhoneNumberToPerson(steveId, p1);
    PhoneNumber p2 = new PhoneNumber();
    p2.setNumberType("Home");
    p2.setPhone(222222);
    mgr.addPhoneNumberToPerson(steveId, p2);
    Person orionPerson = new Person();
    orionPerson.setFirstname("Orion");
    orionPerson.setLastname("Letizi");
    Long orionId = mgr.createAndStorePerson(orionPerson);
    mgr.addEmailToPerson(orionId, "orion@tc.com");
    mgr.addTalismanToPerson(orionId, "voodoo doll");
    Long timId = mgr.createAndStorePerson("Tim", "Teck");
    mgr.addEmailToPerson(timId, "teck@tc.com");
    mgr.addTalismanToPerson(timId, "magic decoder ring");
    Long engMeetingId = mgr.createAndStoreEvent("Eng Meeting", stevePerson, new Date());
    mgr.addPersonToEvent(steveId, engMeetingId);
    mgr.addPersonToEvent(orionId, engMeetingId);
    mgr.addPersonToEvent(timId, engMeetingId);
    Long docMeetingId = mgr.createAndStoreEvent("Doc Meeting", orionPerson, new Date());
    mgr.addPersonToEvent(steveId, docMeetingId);
    mgr.addPersonToEvent(orionId, docMeetingId);
    for (Event event : (List<Event>) mgr.listEvents()) {
        mgr.listEmailsOfEvent(event.getId());
    }
    QueryStatistics queryStats = stats.getQueryStatistics("from Event");
    assertThat("Cache Miss Count", queryStats.getCacheMissCount(), equalTo(1L));
    assertThat("Cache Hit Count", queryStats.getCacheHitCount(), equalTo(0L));
    assertThat("Cache Put Count", queryStats.getCachePutCount(), equalTo(1L));
}
Also used : EventManager(org.hibernate.jcache.test.domain.EventManager) QueryStatistics(org.hibernate.stat.QueryStatistics) PhoneNumber(org.hibernate.jcache.test.domain.PhoneNumber) Event(org.hibernate.jcache.test.domain.Event) List(java.util.List) Statistics(org.hibernate.stat.Statistics) QueryStatistics(org.hibernate.stat.QueryStatistics) CacheRegionStatistics(org.hibernate.stat.CacheRegionStatistics) Person(org.hibernate.jcache.test.domain.Person) Date(java.util.Date) Test(org.junit.Test) BaseFunctionalTest(org.hibernate.jcache.test.BaseFunctionalTest)

Aggregations

Date (java.util.Date)1 List (java.util.List)1 BaseFunctionalTest (org.hibernate.jcache.test.BaseFunctionalTest)1 Event (org.hibernate.jcache.test.domain.Event)1 EventManager (org.hibernate.jcache.test.domain.EventManager)1 Person (org.hibernate.jcache.test.domain.Person)1 PhoneNumber (org.hibernate.jcache.test.domain.PhoneNumber)1 CacheRegionStatistics (org.hibernate.stat.CacheRegionStatistics)1 QueryStatistics (org.hibernate.stat.QueryStatistics)1 Statistics (org.hibernate.stat.Statistics)1 Test (org.junit.Test)1