Skip to content

Instantly share code, notes, and snippets.

@sbcd90
Forked from mdellabitta/gist:1444003
Created November 19, 2015 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbcd90/22783669d115363e58ed to your computer and use it in GitHub Desktop.
Save sbcd90/22783669d115363e58ed to your computer and use it in GitHub Desktop.
how do do spring jdbc transactions with jdbctemplate/transactiontemplate
public class ExodusWriter {
private JdbcTemplate jdbcTemplate;
private TransactionTemplate transactionTemplate;
public ExodusWriter(DataSource dataSource) {
DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(dataSource);
jdbcTemplate = new JdbcTemplate(transactionManager.getDataSource());
transactionTemplate = new TransactionTemplate(transactionManager);
}
public void writeImageID(final String imageID, final String uuid) throws Exception {
transactionTemplate.execute(new TransactionCallback<Object>() {
@Override
public Object doInTransaction(TransactionStatus status) {
jdbcTemplate.update("delete from image_to_uuid where image_id = ?", imageID);
jdbcTemplate.update("insert into image_to_uuid (image_id, uuid) values (?, ?)", imageID, uuid);
return null;
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment