/** * Flushes the current state to the database. */ public void flush() { if (SessionHandler.isSessionHandlerPresent()) { long s1 = System.currentTimeMillis(); SessionHandler.getInstance().getSession().flush(); if (log.isDebugEnabled()) { long s2 = System.currentTimeMillis(); SessionStatistics sessStat = SessionHandler.getInstance().getSession().getStatistics(); dumpSessionEntities(); log.debug( "Flush of " + sessStat.getEntityCount() + " entities and " + sessStat.getCollectionCount() + " collections took: " + (s2 - s1), new Throwable()); } } }
/** * Utility method to log all entities loaded into the current hibernate session. Useful to debug * slow flush() calls. */ private void dumpSessionEntities() { SessionStatistics sessStat = SessionHandler.getInstance().getSession().getStatistics(); log.debug("Dumping all entities in session"); for (Object o : sessStat.getEntityKeys()) { log.debug(o); } }
@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; } } return false; }
public void testSessionStatistics() throws Exception { Session s = openSession(); Transaction tx = s.beginTransaction(); Statistics stats = getSessions().getStatistics(); stats.clear(); boolean isStats = stats.isStatisticsEnabled(); stats.setStatisticsEnabled(true); Continent europe = fillDb(s); tx.commit(); s.clear(); tx = s.beginTransaction(); SessionStatistics sessionStats = s.getStatistics(); assertEquals( 0, sessionStats.getEntityKeys().size() ); assertEquals( 0, sessionStats.getEntityCount() ); assertEquals( 0, sessionStats.getCollectionKeys().size() ); assertEquals( 0, sessionStats.getCollectionCount() ); europe = (Continent) s.get( Continent.class, europe.getId() ); Hibernate.initialize( europe.getCountries() ); Hibernate.initialize( europe.getCountries().iterator().next() ); assertEquals( 2, sessionStats.getEntityKeys().size() ); assertEquals( 2, sessionStats.getEntityCount() ); assertEquals( 1, sessionStats.getCollectionKeys().size() ); assertEquals( 1, sessionStats.getCollectionCount() ); tx.commit(); s.close(); stats.setStatisticsEnabled( isStats); }
@Override public SessionStatistics getStatistics() { return session.getStatistics(); }
@Override public SessionStatistics getStatistics() { checkTransactionSynchStatus(); return new SessionStatisticsImpl(this); }
public SessionStatistics getStatistics() { checkTransactionSynchStatus(); return new SessionStatisticsImpl(this); }
/** * Get the statistics for this session. * * @return The session statistics being collected for this session */ public SessionStatistics getStatistics();
/** * Get the statistics for this session. */ public SessionStatistics getStatistics();