Skip to content

Instantly share code, notes, and snippets.

@turing85
Last active February 2, 2023 16:40
Show Gist options
  • Save turing85/4bf34d5cecf10835a38d212e9f17dfd4 to your computer and use it in GitHub Desktop.
Save turing85/4bf34d5cecf10835a38d212e9f17dfd4 to your computer and use it in GitHub Desktop.
@Override
protected void doStart() throws Exception {
super.doStart();
transactionTemplate.execute(new TransactionCallback<Boolean>() {
@Override
public Boolean doInTransaction(TransactionStatus status) {
Savepoint savepoint = status.createSavepoint():
try {
// we will receive an exception if the table doesn't exists or we cannot access it
jdbcTemplate.execute(getTableExistsString());
log.debug("Expected table for JdbcMessageIdRepository exist");
} catch (DataAccessException e) {
status.rollbackToSavepoint(savepoint);
if (createTableIfNotExists) {
try {
log.debug("creating table for JdbcMessageIdRepository because it doesn't exist...");
jdbcTemplate.execute(getCreateString());
log.info("table created with query '{}'", getCreateString());
} catch (DataAccessException dae) {
// we will fail if we cannot create it
log.error(
"Can't create table for JdbcMessageIdRepository with query '{}' because of: {}. This may be a permissions problem. Please create this table and try again.",
getCreateString(), dae.getMessage());
throw dae;
}
} else {
throw e;
}
} finally {
status.releaseSavepoint(savepoint);
}
return Boolean.TRUE;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment