*/
@Override
public void updateUser(final User user) throws OmhException {
// Validate the parameter.
if(user == null) {
throw new OmhException("The user 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 a user.");
// Create the new transaction.
TransactionStatus transactionStatus =
transactionManager.getTransaction(transactionDefinition);
// Get the JDBC template.
JdbcTemplate jdbcTemplate = dao.getJdbcTemplate();
// Add the authentication token.
try {
jdbcTemplate
.update(
"UPDATE " + UserBin.DB_NAME + " " +
"SET " +
User.JSON_KEY_PASSWORD + " = ?, " +
User.JSON_KEY_EMAIL + " = ?, " +
User.JSON_KEY_REGISTRATION_KEY + " = ?, " +
User.JSON_KEY_DATE_REGISTERED + " = ?, " +
User.JSON_KEY_DATE_ACTIVATED + " = ? " +
"WHERE " + User.JSON_KEY_USERNAME + " = ?",
new Object[] {
user.getPassword(),
user.getEmail().toString(),
user.getRegistratioKey(),
user.getDateRegistered(),
user.getDateActivated(),
user.getUsername()
}
);
// Commit the transaction.
transactionManager.commit(transactionStatus);
}
catch(DataAccessException e) {
transactionManager.rollback(transactionStatus);
throw new OmhException("There was a problem storing the user.", e);
}
}