final AuthorizationCodeResponse response)
throws OmhException {
// Validate the parameter.
if(response == null) {
throw new OmhException("The response is null.");
}
// Get the DAO.
SqlDao dao = SqlDao.getInstance();
// Get the transaction manager.
PlatformTransactionManager transactionManager =
dao.getTransactionManager();
// Create a new transaction definition and name it.
DefaultTransactionDefinition transactionDefinition =
new DefaultTransactionDefinition();
transactionDefinition
.setName("Adding an authorization code response.");
// Create the new transaction.
TransactionStatus transactionStatus =
transactionManager.getTransaction(transactionDefinition);
// Get the JDBC template.
JdbcTemplate jdbcTemplate = dao.getJdbcTemplate();
// Add the authorization code response.
try {
jdbcTemplate
.update(
"INSERT INTO " + AuthorizationCodeResponseBin.DB_NAME +
" (" +
UserBin.DB_NAME + "_id" + ", " +
AuthorizationCodeBin.DB_NAME + "_id" + ", " +
AuthorizationCodeResponse.JSON_KEY_GRANTED + " " +
") " +
"VALUES" +
" (" +
"(" +
"SELECT " + SqlDao.KEY_DATABASE_ID + " " +
"FROM " + UserBin.DB_NAME + " " +
"WHERE " + User.JSON_KEY_USERNAME + " = ?" +
"), " +
"(" +
"SELECT " + SqlDao.KEY_DATABASE_ID + " " +
"FROM " + AuthorizationCodeBin.DB_NAME + " " +
"WHERE " +
AuthorizationCode.JSON_KEY_CODE + " = ?" +
"), " +
"?" +
")",
new Object[] {
response.getOwnerUsername(),
response.getAuthorizationCode(),
response.getGranted()
}
);
}
catch(DataAccessException e) {
transactionManager.rollback(transactionStatus);
throw
new OmhException(
"There was a problem storing the authorization code " +
"response.",
e);
}
// Commit the transaction.
try {
transactionManager.commit(transactionStatus);
}
catch(DataAccessException e) {
transactionManager.rollback(transactionStatus);
throw
new OmhException(
"There was a problem storing the authorization code " +
"response.",
e);
}
}