Search in sources :

Example 1 with PhoneNumber

use of org.hibernate.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.test.domain.EventManager) QueryStatistics(org.hibernate.stat.QueryStatistics) PhoneNumber(org.hibernate.test.domain.PhoneNumber) Event(org.hibernate.test.domain.Event) List(java.util.List) QueryStatistics(org.hibernate.stat.QueryStatistics) SecondLevelCacheStatistics(org.hibernate.stat.SecondLevelCacheStatistics) Statistics(org.hibernate.stat.Statistics) Person(org.hibernate.test.domain.Person) Date(java.util.Date) Test(org.junit.Test)

Aggregations

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