Java Code Examples for org.hibernate.engine.spi.SharedSessionContractImplementor#getEventListenerManager()

The following examples show how to use org.hibernate.engine.spi.SharedSessionContractImplementor#getEventListenerManager() . These examples are extracted from open source projects. 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
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 2
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 3
@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();
		}
	};
}