use of org.hibernate.stat.Statistics in project hibernate-orm by hibernate.
the class QueryAndSQLTest method testClassQueries.
@Test
public void testClassQueries() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Night n = new Night();
Calendar c = new GregorianCalendar();
c.set(2000, 2, 2);
Date now = c.getTime();
c.add(Calendar.MONTH, -1);
Date aMonthAgo = c.getTime();
c.add(Calendar.MONTH, 2);
Date inAMonth = c.getTime();
n.setDate(now);
n.setDuration(14);
s.persist(n);
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
Query q = s.getNamedQuery("night.moreRecentThan");
q.setDate("date", aMonthAgo);
assertEquals(1, q.list().size());
q = s.getNamedQuery("night.moreRecentThan");
q.setDate("date", inAMonth);
assertEquals(0, q.list().size());
Statistics stats = sessionFactory().getStatistics();
stats.setStatisticsEnabled(true);
stats.clear();
q = s.getNamedQuery("night.duration");
q.setParameter("duration", 14l);
assertEquals(1, q.list().size());
assertEquals(1, stats.getQueryCachePutCount());
q = s.getNamedQuery("night.duration");
q.setParameter("duration", 14l);
s.delete(q.list().get(0));
assertEquals(1, stats.getQueryCacheHitCount());
tx.commit();
s.close();
}
use of org.hibernate.stat.Statistics in project hibernate-orm by hibernate.
the class AggressiveReleaseTest method testConnectionMaintanenceDuringFlush.
@Test
public void testConnectionMaintanenceDuringFlush() throws Throwable {
final Statistics statistics = sessionFactory().getStatistics();
prepare();
Session s = getSessionUnderTest();
List<Silly> entities = new ArrayList<Silly>();
for (int i = 0; i < 10; i++) {
Other other = new Other("other-" + i);
Silly silly = new Silly("silly-" + i, other);
entities.add(silly);
s.save(silly);
}
s.flush();
for (Silly silly : entities) {
silly.setName("new-" + silly.getName());
silly.getOther().setName("new-" + silly.getOther().getName());
}
long initialCount = statistics.getConnectCount();
s.flush();
assertEquals("connection not maintained through flush", initialCount + 1, statistics.getConnectCount());
s.createQuery("delete from Silly").executeUpdate();
s.createQuery("delete from Other").executeUpdate();
s.getTransaction().commit();
release(s);
done();
}
use of org.hibernate.stat.Statistics 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));
}
use of org.hibernate.stat.Statistics in project karaf by apache.
the class StatisticsPublisher method publishStatistics.
private void publishStatistics(ServiceReference<EntityManagerFactory> reference, EntityManagerFactory emf) {
String persitenceProvider = (String) reference.getProperty("osgi.unit.provider");
if (!"org.hibernate.ejb.HibernatePersistence".equals(persitenceProvider)) {
return;
}
if (reference.getProperty("org.apache.aries.jpa.proxy.factory") != null) {
return;
}
try {
EntityManager em = emf.createEntityManager();
SessionFactory sessionFactory = em.unwrap(Session.class).getSessionFactory();
final Statistics statistics = sessionFactory.getStatistics();
statistics.setStatisticsEnabled(true);
mbeanServer.registerMBean(getStatisticsMBean(statistics), getOName(reference));
} catch (Exception e) {
LOG.warn("Error publishing StatisticsMXBean" + e.getMessage(), e);
}
}
use of org.hibernate.stat.Statistics in project mamute by caelum.
the class HibernateStatisticsController method show.
@Get("/alsjkdalkjsjdhadskj")
@CustomBrutauthRules(ModeratorOnlyRule.class)
public void show() {
Statistics statistics = sf.getStatistics();
result.include("s", statistics);
}
Aggregations