Search in sources :

Example 6 with CollectionStatistics

use of org.hibernate.stat.CollectionStatistics in project hibernate-orm by hibernate.

the class PersistentSetTest method testCompositeElementCollectionDirtyChecking.

@Test
@FailureExpected(jiraKey = "HHH-2485")
public void testCompositeElementCollectionDirtyChecking() {
    Session session = openSession();
    session.beginTransaction();
    Container container = new Container("p1");
    Container.Content c1 = new Container.Content("c1");
    container.getContents().add(c1);
    session.save(container);
    session.getTransaction().commit();
    session.close();
    CollectionStatistics stats = sessionFactory().getStatistics().getCollectionStatistics(Container.class.getName() + ".contents");
    long recreateCount = stats.getRecreateCount();
    long updateCount = stats.getUpdateCount();
    session = openSession();
    session.beginTransaction();
    container = (Container) session.get(Container.class, container.getId());
    assertEquals(1, container.getContents().size());
    session.getTransaction().commit();
    session.close();
    assertEquals(1, container.getContents().size());
    assertEquals(recreateCount, stats.getRecreateCount());
    assertEquals(updateCount, stats.getUpdateCount());
    session = openSession();
    session.beginTransaction();
    container = (Container) session.get(Container.class, container.getId());
    assertEquals(1, container.getContents().size());
    session.delete(container);
    session.getTransaction().commit();
    session.close();
}
Also used : Session(org.hibernate.Session) CollectionStatistics(org.hibernate.stat.CollectionStatistics) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected)

Example 7 with CollectionStatistics

use of org.hibernate.stat.CollectionStatistics in project hibernate-orm by hibernate.

the class PersistentSetTest method testCollectionMerging.

@Test
public void testCollectionMerging() {
    Session session = openSession();
    session.beginTransaction();
    Parent parent = new Parent("p1");
    Child child = new Child("c1");
    parent.getChildren().add(child);
    child.setParent(parent);
    session.save(parent);
    session.getTransaction().commit();
    session.close();
    CollectionStatistics stats = sessionFactory().getStatistics().getCollectionStatistics(Parent.class.getName() + ".children");
    long recreateCount = stats.getRecreateCount();
    long updateCount = stats.getUpdateCount();
    session = openSession();
    session.beginTransaction();
    parent = (Parent) session.merge(parent);
    session.getTransaction().commit();
    session.close();
    assertEquals(1, parent.getChildren().size());
    assertEquals(recreateCount, stats.getRecreateCount());
    assertEquals(updateCount, stats.getUpdateCount());
    session = openSession();
    session.beginTransaction();
    parent = (Parent) session.get(Parent.class, "p1");
    assertEquals(1, parent.getChildren().size());
    session.delete(parent);
    session.getTransaction().commit();
    session.close();
}
Also used : Session(org.hibernate.Session) CollectionStatistics(org.hibernate.stat.CollectionStatistics) Test(org.junit.Test)

Example 8 with CollectionStatistics

use of org.hibernate.stat.CollectionStatistics in project keycloak by keycloak.

the class HibernateStatsReporter method logCollections.

protected void logCollections(StringBuilder builder, String lineSep, Statistics stats) {
    builder.append("Important collections statistics: ").append(lineSep);
    for (String col : stats.getCollectionRoleNames()) {
        CollectionStatistics collectionStats = stats.getCollectionStatistics(col);
        if (collectionStats.getRecreateCount() > LIMIT || collectionStats.getUpdateCount() > LIMIT || collectionStats.getRemoveCount() > LIMIT || collectionStats.getLoadCount() > LIMIT || collectionStats.getFetchCount() > LIMIT) {
            builder.append(col).append(" - ").append("recreated: ").append(collectionStats.getRecreateCount()).append(", updated: ").append(collectionStats.getUpdateCount()).append(", removed: ").append(collectionStats.getRemoveCount()).append(", loaded: ").append(collectionStats.getLoadCount()).append(", fetched: ").append(collectionStats.getFetchCount()).append(lineSep);
        }
    }
    builder.append(lineSep);
}
Also used : CollectionStatistics(org.hibernate.stat.CollectionStatistics)

Aggregations

CollectionStatistics (org.hibernate.stat.CollectionStatistics)8 Session (org.hibernate.Session)5 Test (org.junit.Test)5 FailureExpected (org.hibernate.testing.FailureExpected)2 Date (java.util.Date)1 List (java.util.List)1 StatsEntry (org.bedework.calfacade.BwStats.StatsEntry)1 EmptyInterceptor (org.hibernate.EmptyInterceptor)1 Interceptor (org.hibernate.Interceptor)1 EntityStatistics (org.hibernate.stat.EntityStatistics)1 SecondLevelCacheStatistics (org.hibernate.stat.SecondLevelCacheStatistics)1 Statistics (org.hibernate.stat.Statistics)1