use of org.hibernate.engine.spi.SessionEventListenerManager in project hibernate-orm by hibernate.
the class CacheHelper method fromSharedCache.
public static Serializable fromSharedCache(SharedSessionContractImplementor session, Object cacheKey, RegionAccessStrategy cacheAccessStrategy) {
final SessionEventListenerManager eventListenerManager = session.getEventListenerManager();
Serializable cachedValue = null;
eventListenerManager.cacheGetStart();
try {
cachedValue = (Serializable) cacheAccessStrategy.get(session, cacheKey, session.getTimestamp());
} finally {
eventListenerManager.cacheGetEnd(cachedValue != null);
}
return cachedValue;
}
use of org.hibernate.engine.spi.SessionEventListenerManager in project hibernate-orm by hibernate.
the class TableStructure method buildCallback.
@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();
}
};
}
Aggregations