Last active
February 2, 2023 16:40
-
-
Save turing85/4bf34d5cecf10835a38d212e9f17dfd4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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