use of org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource in project topjava10 by JavaWebinar.
the class JdbcUserRepositoryImpl method save.
@Override
@Transactional
public User save(User user) {
BeanPropertySqlParameterSource parameterSource = new BeanPropertySqlParameterSource(user);
if (user.isNew()) {
Number newKey = insertUser.executeAndReturnKey(parameterSource);
user.setId(newKey.intValue());
insertRoles(user);
} else {
// Simplest implementation.
// More complicated : get user roles from DB and compare them with user.roles (assume that roles are changed rarely).
// If roles are changed, calculate difference in java and delete/insert them.
deleteRoles(user);
insertRoles(user);
namedParameterJdbcTemplate.update("UPDATE users SET name=:name, email=:email, password=:password, " + "registered=:registered, enabled=:enabled, calories_per_day=:caloriesPerDay WHERE id=:id", parameterSource);
}
return user;
}
use of org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource in project summerb by skarpushin.
the class AuthTokenDaoImpl method createAuthToken.
@Override
public void createAuthToken(AuthToken authToken) {
BeanPropertySqlParameterSource params = new BeanPropertySqlParameterSource(authToken);
jdbcInsert.execute(params);
}
use of org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource in project summerb by skarpushin.
the class UserDaoImpl method createUser.
@Override
public void createUser(User user) throws DuplicateKeyException {
BeanPropertySqlParameterSource params = new BeanPropertySqlParameterSource(user);
jdbcInsert.execute(params);
}
use of org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource in project tutorials by eugenp.
the class EmployeeDAO method getEmployeeUsingBeanPropertySqlParameterSource.
public int getEmployeeUsingBeanPropertySqlParameterSource() {
final Employee employee = new Employee();
employee.setFirstName("James");
final String SELECT_BY_ID = "SELECT COUNT(*) FROM EMPLOYEE WHERE FIRST_NAME = :firstName";
final SqlParameterSource namedParameters = new BeanPropertySqlParameterSource(employee);
return namedParameterJdbcTemplate.queryForObject(SELECT_BY_ID, namedParameters, Integer.class);
}
use of org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource in project summerb by skarpushin.
the class PasswordDaoImpl method updateUserPassword.
@Override
public int updateUserPassword(String userUuid, String newPasswordHash) {
Password pwd = new Password();
pwd.setUserUuid(userUuid);
pwd.setPasswordHash(newPasswordHash);
pwd.setRestorationToken(null);
BeanPropertySqlParameterSource params = new BeanPropertySqlParameterSource(pwd);
return jdbc.update(sqlPutPassword, params);
}
Aggregations