org.hibernate.engine.spi.SessionEventListenerManager Java Examples

The following examples show how to use org.hibernate.engine.spi.SessionEventListenerManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TableGenerator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private PreparedStatement prepareStatement(
		Connection connection,
		String sql,
		SqlStatementLogger statementLogger,
		SessionEventListenerManager statsCollector) throws SQLException {
	statementLogger.logStatement( sql, FormatStyle.BASIC.getFormatter() );
	try {
		statsCollector.jdbcPrepareStatementStart();
		return connection.prepareStatement( sql );
	}
	finally {
		statsCollector.jdbcPrepareStatementEnd();
	}
}
 
Example #2
Source File: TableGenerator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private int executeUpdate(PreparedStatement ps, SessionEventListenerManager statsCollector) throws SQLException {
	try {
		statsCollector.jdbcExecuteStatementStart();
		return ps.executeUpdate();
	}
	finally {
		statsCollector.jdbcExecuteStatementEnd();
	}

}
 
Example #3
Source File: TableGenerator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private ResultSet executeQuery(PreparedStatement ps, SessionEventListenerManager statsCollector) throws SQLException {
	try {
		statsCollector.jdbcExecuteStatementStart();
		return ps.executeQuery();
	}
	finally {
		statsCollector.jdbcExecuteStatementEnd();
	}
}
 
Example #4
Source File: TableStructure.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private PreparedStatement prepareStatement(
		Connection connection,
		String sql,
		SqlStatementLogger statementLogger,
		SessionEventListenerManager statsCollector) throws SQLException {
	statementLogger.logStatement( sql, FormatStyle.BASIC.getFormatter() );
	try {
		statsCollector.jdbcPrepareStatementStart();
		return connection.prepareStatement( sql );
	}
	finally {
		statsCollector.jdbcPrepareStatementEnd();
	}
}
 
Example #5
Source File: TableStructure.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private int executeUpdate(PreparedStatement ps, SessionEventListenerManager statsCollector) throws SQLException {
	try {
		statsCollector.jdbcExecuteStatementStart();
		return ps.executeUpdate();
	}
	finally {
		statsCollector.jdbcExecuteStatementEnd();
	}

}
 
Example #6
Source File: TableStructure.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private ResultSet executeQuery(PreparedStatement ps, SessionEventListenerManager statsCollector) throws SQLException {
	try {
		statsCollector.jdbcExecuteStatementStart();
		return ps.executeQuery();
	}
	finally {
		statsCollector.jdbcExecuteStatementEnd();
	}
}
 
Example #7
Source File: MultipleHiLoPerTableGenerator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private PreparedStatement prepareStatement(
		Connection connection,
		String sql,
		SqlStatementLogger statementLogger,
		SessionEventListenerManager statsCollector) throws SQLException {
	statementLogger.logStatement( sql, FormatStyle.BASIC.getFormatter() );
	try {
		statsCollector.jdbcPrepareStatementStart();
		return connection.prepareStatement( sql );
	}
	finally {
		statsCollector.jdbcPrepareStatementEnd();
	}
}
 
Example #8
Source File: MultipleHiLoPerTableGenerator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private int executeUpdate(PreparedStatement ps, SessionEventListenerManager statsCollector) throws SQLException {
	try {
		statsCollector.jdbcExecuteStatementStart();
		return ps.executeUpdate();
	}
	finally {
		statsCollector.jdbcExecuteStatementEnd();
	}

}
 
Example #9
Source File: MultipleHiLoPerTableGenerator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private ResultSet executeQuery(PreparedStatement ps, SessionEventListenerManager statsCollector)
		throws SQLException {
	try {
		statsCollector.jdbcExecuteStatementStart();
		return ps.executeQuery();
	}
	finally {
		statsCollector.jdbcExecuteStatementEnd();
	}
}
 
Example #10
Source File: EntityInsertAction.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private boolean cacheAfterInsert(EntityDataAccess cache, Object ck) {
	SharedSessionContractImplementor session = getSession();
	final SessionEventListenerManager eventListenerManager = session.getEventListenerManager();
	try {
		eventListenerManager.cachePutStart();
		return cache.afterInsert( session, ck, cacheEntry, version );
	}
	finally {
		eventListenerManager.cachePutEnd();
	}
}
 
Example #11
Source File: EntityUpdateAction.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private boolean cacheAfterUpdate(EntityDataAccess cache, Object ck) {
	final SharedSessionContractImplementor session = getSession();
	SessionEventListenerManager eventListenerManager = session.getEventListenerManager();
	try {
		eventListenerManager.cachePutStart();
		return cache.afterUpdate( session, ck, cacheEntry, nextVersion, previousVersion, lock );
	}
	finally {
		eventListenerManager.cachePutEnd();
	}
}
 
Example #12
Source File: DefaultReactiveAutoFlushEventListener.java    From hibernate-reactive with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public CompletionStage<Void> reactiveOnAutoFlush(AutoFlushEvent event) throws HibernateException {
	final EventSource source = event.getSession();
	final SessionEventListenerManager eventListenerManager = source.getEventListenerManager();

	eventListenerManager.partialFlushStart();
	CompletionStage<Void> autoFlushStage = CompletionStages.nullFuture();
	if ( flushMightBeNeeded( source ) ) {
		// Need to get the number of collection removals before flushing to executions
		// (because flushing to executions can add collection removal actions to the action queue).
		final ActionQueue actionQueue = source.getActionQueue();
		final int oldSize = actionQueue.numberOfCollectionRemovals();

		autoFlushStage = flushEverythingToExecutions( event )
				.thenCompose( v -> {
					if ( flushIsReallyNeeded( event, source ) ) {
						LOG.trace( "Need to execute flush" );
						event.setFlushRequired( true );

						return performExecutions( source )
								.thenRun( () -> postFlush( source ) )
								.thenRun( () -> postPostFlush( source ) )
								.thenRun( () -> {
									final StatisticsImplementor statistics = source.getFactory().getStatistics();
									if ( statistics.isStatisticsEnabled() ) {
										statistics.flush();
									}
								} );

					}
					else {
						LOG.trace( "Don't need to execute flush" );
						event.setFlushRequired( false );
						actionQueue.clearFromFlushNeededCheck( oldSize );
						return CompletionStages.nullFuture();
					}
				} );
	}
	autoFlushStage.whenComplete( (v, x) -> {
		source.getEventListenerManager().flushEnd( event.getNumberOfEntitiesProcessed(), event.getNumberOfCollectionsProcessed() );
		CompletionStages.returnNullorRethrow( x );
	} );

	return autoFlushStage;
}
 
Example #13
Source File: TableStructure.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public AccessCallback buildCallback(final SharedSessionContractImplementor session) {
	final SqlStatementLogger statementLogger = session.getFactory().getServiceRegistry()
			.getService( JdbcServices.class )
			.getSqlStatementLogger();
	if ( selectQuery == null || updateQuery == null ) {
		throw new AssertionFailure( "SequenceStyleGenerator's TableStructure was not properly initialized" );
	}

	final SessionEventListenerManager statsCollector = session.getEventListenerManager();

	return new AccessCallback() {
		@Override
		public IntegralDataTypeHolder getNextValue() {
			return session.getTransactionCoordinator().createIsolationDelegate().delegateWork(
					new AbstractReturningWork<IntegralDataTypeHolder>() {
						@Override
						public IntegralDataTypeHolder execute(Connection connection) throws SQLException {
							final IntegralDataTypeHolder value = makeValue();
							int rows;
							do {
								try (PreparedStatement selectStatement = prepareStatement(
										connection,
										selectQuery,
										statementLogger,
										statsCollector
								)) {
									final ResultSet selectRS = executeQuery( selectStatement, statsCollector );
									if ( !selectRS.next() ) {
										final String err = "could not read a hi value - you need to populate the table: " + tableNameText;
										LOG.error( err );
										throw new IdentifierGenerationException( err );
									}
									value.initialize( selectRS, 1 );
									selectRS.close();
								}
								catch (SQLException sqle) {
									LOG.error( "could not read a hi value", sqle );
									throw sqle;
								}


								try (PreparedStatement updatePS = prepareStatement(
										connection,
										updateQuery,
										statementLogger,
										statsCollector
								)) {
									final int increment = applyIncrementSizeToSourceValues ? incrementSize : 1;
									final IntegralDataTypeHolder updateValue = value.copy().add( increment );
									updateValue.bind( updatePS, 1 );
									value.bind( updatePS, 2 );
									rows = executeUpdate( updatePS, statsCollector );
								}
								catch (SQLException e) {
									LOG.unableToUpdateQueryHiValue( tableNameText, e );
									throw e;
								}
							} while ( rows == 0 );

							accessCounter++;

							return value;
						}
					},
					true
			);
		}

		@Override
		public String getTenantIdentifier() {
			return session.getTenantIdentifier();
		}
	};
}
 
Example #14
Source File: AbstractSharedSessionContract.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public SessionEventListenerManager getEventListenerManager() {
	return sessionEventsManager;
}
 
Example #15
Source File: AbstractProxySharedSessionContractImplementor.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public SessionEventListenerManager getEventListenerManager() {
	return target.getEventListenerManager();
}