public static void queryExecuted(SessionFactoryImplementor sessionFactoryImplementor, String sql) { if (sessionFactoryImplementor != null && sessionFactoryImplementor.getStatistics().isStatisticsEnabled()) { StatisticsImplementor statisticsImplementor = sessionFactoryImplementor.getStatisticsImplementor(); if (statisticsImplementor instanceof SampledStatistics) { ((SampledStatistics) statisticsImplementor).incrementDBSQLExecution(); } } }
private void closePreparedStatement(PreparedStatement ps) throws SQLException { try { log.trace("closing statement"); ps.close(); if ( factory.getStatistics().isStatisticsEnabled() ) { factory.getStatisticsImplementor().closeStatement(); } } finally { if ( !releasing ) { // If we are in the process of releasing, no sense // checking for aggressive-release possibility. connectionManager.afterStatement(); } } }
private void closePreparedStatement(PreparedStatement ps) throws SQLException { try { log.trace("closing statement"); ps.close(); if ( factory.getStatistics().isStatisticsEnabled() ) { factory.getStatisticsImplementor().closeStatement(); } } finally { if ( !releasing ) { // If we are in the process of releasing, no sense // checking for aggressive-release possibility. connectionManager.afterStatement(); } } }
public void connectionOpened() { if ( owner.getFactory().getStatistics().isStatisticsEnabled() ) { owner.getFactory().getStatisticsImplementor().connect(); } }
public void afterTransactionCompletion(boolean success, Transaction tx) { log.trace( "after transaction completion" ); if ( getFactory().getStatistics().isStatisticsEnabled() ) { getFactory().getStatisticsImplementor().endTransaction(success); } connectionManager.afterTransaction(); // releaseConnectionAfterTransaction(); isTransactionCallbackRegistered = false; isHibernateTransactionActive = false; owner.afterTransactionCompletion(success, tx); }
public void afterTransactionCompletion(boolean success, Transaction tx) { log.trace( "after transaction completion" ); if ( getFactory().getStatistics().isStatisticsEnabled() ) { getFactory().getStatisticsImplementor().endTransaction(success); } connectionManager.afterTransaction(); isTransactionCallbackRegistered = false; hibernateTransaction = null; owner.afterTransactionCompletion(success, tx); }
public void connectionOpened() { if ( !isTransactionCallbackRegistered ) { // If there is no current transaction callback registered // when we obtain a connection, try to register one now. // Note that this is not going to handle the case of // multiple-transactions-per-connection when the user is // manipulating transactions (need to use Hibernate txn) registerSynchronizationIfPossible(); } if ( owner.getFactory().getStatistics().isStatisticsEnabled() ) { owner.getFactory().getStatisticsImplementor().connect(); } }
protected boolean check(int rows, Serializable id, int tableNumber, Expectation expectation, PreparedStatement statement) throws HibernateException { try { expectation.verifyOutcome( rows, statement, -1 ); } catch( StaleStateException e ) { if ( !isNullableTable( tableNumber ) ) { if ( getFactory().getStatistics().isStatisticsEnabled() ) { getFactory().getStatisticsImplementor() .optimisticFailure( getEntityName() ); } throw new StaleObjectStateException( getEntityName(), id ); } } catch( TooManyRowsAffectedException e ) { throw new HibernateException( "Duplicate identifier in table for: " + MessageHelper.infoString( this, id, getFactory() ) ); } catch ( Throwable t ) { return false; } return true; }
/** Handle the given flush event. * * @param event The flush event to be handled. * @throws HibernateException */ public void onFlush(FlushEvent event) throws HibernateException { final SessionImplementor source = event.getSession(); if ( source.getPersistenceContext().hasNonReadOnlyEntities() ) { flushEverythingToExecutions(event); performExecutions(source); postFlush(source); if ( source.getFactory().getStatistics().isStatisticsEnabled() ) { source.getFactory().getStatisticsImplementor().flush(); } } } }
/** Handle the given flush event. * * @param event The flush event to be handled. * @throws HibernateException */ public void onFlush(FlushEvent event) throws HibernateException { final EventSource source = event.getSession(); if ( source.getPersistenceContext().hasNonReadOnlyEntities() ) { flushEverythingToExecutions(event); performExecutions(source); postFlush(source); if ( source.getFactory().getStatistics().isStatisticsEnabled() ) { source.getFactory().getStatisticsImplementor().flush(); } } } }
public void execute() throws HibernateException { getPersister().recreate( collection, getKey(), getSession() ); evict(); if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) { getSession().getFactory().getStatisticsImplementor() .recreateCollection( getPersister().getRole() ); } }
public void execute() throws HibernateException { if ( !emptySnapshot ) getPersister().remove( getKey(), getSession() ); evict(); if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) { getSession().getFactory().getStatisticsImplementor() .removeCollection( getPersister().getRole() ); } }
/** * Return the query results as an iterator */ public Iterator iterate(QueryParameters queryParameters, SessionImplementor session) throws HibernateException { boolean stats = session.getFactory().getStatistics().isStatisticsEnabled(); long startTime = 0; if ( stats ) startTime = System.currentTimeMillis(); try { PreparedStatement st = prepareQueryStatement( queryParameters, false, session ); ResultSet rs = getResultSet( st, false, queryParameters.getRowSelection(), session ); HolderInstantiator hi = new HolderInstantiator(holderConstructor, false, false, null); Iterator result = new IteratorImpl( rs, st, session, returnTypes, getColumnNames(), hi ); if ( stats ) { session.getFactory().getStatisticsImplementor().queryExecuted( "HQL: " + queryString, 0, System.currentTimeMillis() - startTime ); } return result; } catch ( SQLException sqle ) { throw JDBCExceptionHelper.convert( getFactory().getSQLExceptionConverter(), sqle, "could not execute query using iterate", getSQLString() ); } }
public void execute() throws HibernateException { final PersistentCollection collection = getCollection(); getPersister().recreate( collection, getKey(), getSession() ); getSession().getPersistenceContext() .getCollectionEntry(collection) .afterAction(collection); evict(); if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) { getSession().getFactory().getStatisticsImplementor() .recreateCollection( getPersister().getRole() ); } }
private Object[] getDatabaseSnapshot(SessionImplementor session, EntityPersister persister, Serializable id) { if ( persister.isSelectBeforeUpdateRequired() ) { Object[] snapshot = session.getPersistenceContext() .getDatabaseSnapshot(id, persister); if (snapshot==null) { //do we even really need this? the update will fail anyway.... if ( session.getFactory().getStatistics().isStatisticsEnabled() ) { session.getFactory().getStatisticsImplementor() .optimisticFailure( persister.getEntityName() ); } throw new StaleObjectStateException( persister.getEntityName(), id ); } else { return snapshot; } } else { //TODO: optimize away this lookup for entities w/o unsaved-value="undefined" EntityKey entityKey = new EntityKey( id, persister, session.getEntityMode() ); return session.getPersistenceContext() .getCachedDatabaseSnapshot( entityKey ); } }
public void execute() throws HibernateException { if ( !emptySnapshot ) getPersister().remove( getKey(), getSession() ); final PersistentCollection collection = getCollection(); if (collection!=null) { getSession().getPersistenceContext() .getCollectionEntry(collection) .afterAction(collection); } evict(); if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) { getSession().getFactory().getStatisticsImplementor() .removeCollection( getPersister().getRole() ); } }
public void afterTransactionCompletion(boolean success) throws HibernateException { EntityPersister persister = getPersister(); if ( success && isCachePutEnabled( persister, getSession() ) ) { final CacheKey ck = new CacheKey( getId(), persister.getIdentifierType(), persister.getRootEntityName(), getSession().getEntityMode(), getSession().getFactory() ); boolean put = persister.getCache().afterInsert(ck, cacheEntry, version ); if ( put && getSession().getFactory().getStatistics().isStatisticsEnabled() ) { getSession().getFactory().getStatisticsImplementor() .secondLevelCachePut( getPersister().getCache().getRegionName() ); } } }
public void execute() throws HibernateException { EntityPersister persister = getPersister(); SessionImplementor session = getSession(); Object instance = getInstance(); PreInsertEvent preEvent = new PreInsertEvent( instance, null, state, persister, session ); final boolean veto = session.getListeners().getPreInsertEventListener().onPreInsert( preEvent ); // Don't need to lock the cache here, since if someone // else inserted the same pk first, the insert would fail if ( !veto ) generatedId = persister.insert( state, instance, session ); //TODO: this bit actually has to be called after all cascades! // but since identity insert is called *synchronously*, // instead of asynchronously as other actions, it isn't /*if ( persister.hasCache() && !persister.isCacheInvalidationRequired() ) { cacheEntry = new CacheEntry(object, persister, session); persister.getCache().insert(generatedId, cacheEntry); }*/ PostInsertEvent postEvent = new PostInsertEvent( instance, generatedId, state, getPersister(), session ); session.getListeners().getPostInsertEventListener().onPostInsert( postEvent ); if ( getSession().getFactory().getStatistics().isStatisticsEnabled() && !veto ) { getSession().getFactory().getStatisticsImplementor() .insertEntity( getPersister().getEntityName() ); } }
public void afterTransactionCompletion(boolean success) throws CacheException { EntityPersister persister = getPersister(); if ( persister.hasCache() ) { final CacheKey ck = new CacheKey( getId(), persister.getIdentifierType(), persister.getRootEntityName(), getSession().getEntityMode(), getSession().getFactory() ); if ( success && cacheEntry!=null /*!persister.isCacheInvalidationRequired()*/ ) { boolean put = persister.getCache().afterUpdate(ck, cacheEntry, nextVersion, lock ); if ( put && getSession().getFactory().getStatistics().isStatisticsEnabled() ) { getSession().getFactory().getStatisticsImplementor() .secondLevelCachePut( getPersister().getCache().getRegionName() ); } } else { persister.getCache().release(ck, lock ); } } postCommitUpdate(); }
public void afterTransactionCompletion(boolean success) throws CacheException { EntityPersister persister = getPersister(); if ( persister.hasCache() ) { final CacheKey ck = new CacheKey( getId(), persister.getIdentifierType(), persister.getRootEntityName(), getSession().getEntityMode(), getSession().getFactory() ); if ( success && !persister.isCacheInvalidationRequired() ) { boolean put = persister.getCache().afterUpdate(ck, cacheEntry, nextVersion, lock ); if ( put && getSession().getFactory().getStatistics().isStatisticsEnabled() ) { getSession().getFactory().getStatisticsImplementor() .secondLevelCachePut( getPersister().getCache().getRegionName() ); } } else { persister.getCache().release(ck, lock ); } } }