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();
}
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();
}
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);
}
Aggregations