List of usage examples for org.hibernate.stat SessionStatistics getEntityKeys
Set getEntityKeys();
From source file:org.jboss.as.test.integration.hibernate.SFSBHibernate2LcacheStats.java
License:Open Source License
public Planet prepareData(String planetName, String galaxyName, String starName, Set<Satellite> satellites, Integer id) {/*w ww . ja va 2 s . c o m*/ Session session = sessionFactory.openSession(); Planet planet = new Planet(); planet.setPlanetId(id); planet.setPlanetName(planetName); planet.setGalaxy(galaxyName); planet.setStar(starName); // Transaction trans = session.beginTransaction(); try { session.save(planet); if (satellites != null && satellites.size() > 0) { Iterator<Satellite> itrSat = satellites.iterator(); while (itrSat.hasNext()) { Satellite sat = itrSat.next(); session.save(sat); } planet.setSatellites(new HashSet<Satellite>()); planet.getSatellites().addAll(satellites); } session.saveOrUpdate(planet); SessionStatistics stats = session.getStatistics(); assertEquals(2, stats.getEntityKeys().size()); assertEquals(2, stats.getEntityCount()); // session.flush(); // session.close(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("transactional failure while persisting planet entity", e); } // trans.commit(); session.close(); return planet; }
From source file:org.jpos.ee.DB.java
License:Open Source License
@SuppressWarnings({ "unchecked" })
public void printStats() {
if (getLog() != null) {
LogEvent info = getLog().createInfo();
if (session != null) {
info.addMessage("==== STATISTICS ====");
SessionStatistics statistics = session().getStatistics();
info.addMessage("==== ENTITIES ====");
Set<EntityKey> entityKeys = statistics.getEntityKeys();
for (EntityKey ek : entityKeys) {
info.addMessage(String.format("[%s] %s", ek.getIdentifier(), ek.getEntityName()));
}/*from w w w . j av a 2 s.c o m*/
info.addMessage("==== COLLECTIONS ====");
Set<CollectionKey> collectionKeys = statistics.getCollectionKeys();
for (CollectionKey ck : collectionKeys) {
info.addMessage(String.format("[%s] %s", ck.getKey(), ck.getRole()));
}
info.addMessage("=====================");
} else {
info.addMessage("Session is not open");
}
Logger.log(info);
}
}
From source file:org.jpos.transaction.DebugDB.java
License:Open Source License
@Override public int prepare(long id, Serializable context) { Context ctx = (Context) context; DB db = (DB) ctx.get(TxnConstants.DB); Session session = db.session();//from ww w .j a v a2 s . co m SessionStatistics statistics = session.getStatistics(); Set<EntityKey> entityKeys = statistics.getEntityKeys(); ctx.log(String.format("ENTITIES: (%d)", statistics.getEntityCount())); for (EntityKey ek : entityKeys) { Object obj = session.get(ek.getEntityName(), ek.getIdentifier()); LockMode lockMode = session.getCurrentLockMode(obj); ctx.log(String.format("[%s] %s %s", ek.getIdentifier(), ek.getEntityName(), lockMode)); } ctx.log("==== COLLECTIONS ===="); Set<CollectionKey> collectionKeys = statistics.getCollectionKeys(); for (CollectionKey ck : collectionKeys) { ctx.log(String.format("[%s] %s", ck.getKey(), ck.getRole())); } ctx.log("====================="); return PREPARED | READONLY | NO_JOIN; }
From source file:org.openbravo.dal.service.OBDal.java
License:Open Source License
/** * Utility method to log all entities loaded into the current hibernate session. Useful to debug * slow flush() calls./*from w w w .j a va 2 s . c om*/ */ private void dumpSessionEntities() { SessionStatistics sessStat = SessionHandler.getInstance().getSession().getStatistics(); log.debug("Dumping all entities in session"); for (Object o : sessStat.getEntityKeys()) { log.debug(o); } }
From source file:org.openbravo.test.dal.ComputedColumnsTest.java
License:Open Source License
@SuppressWarnings("unchecked") private boolean dalObjectLoaded(String entityName, String id) { SessionStatistics stats = SessionHandler.getInstance().getSession().getStatistics(); for (EntityKey k : (Set<EntityKey>) stats.getEntityKeys()) { if (entityName.equals(k.getEntityName()) && id.equals(k.getIdentifier())) { return true; }/*from w ww . j av a 2s . c om*/ } return false; }
From source file:org.zanata.model.CacheReliabilityTest.java
License:Open Source License
private void printStats(SessionStatistics stats) { System.out.println("Session Keys: " + stats.getEntityKeys()); }