Search in sources :

Example 1 with BeanPropertySqlParameterSource

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;
}
Also used : BeanPropertySqlParameterSource(org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with BeanPropertySqlParameterSource

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);
}
Also used : BeanPropertySqlParameterSource(org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource)

Example 3 with BeanPropertySqlParameterSource

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);
}
Also used : BeanPropertySqlParameterSource(org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource)

Example 4 with BeanPropertySqlParameterSource

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);
}
Also used : SqlParameterSource(org.springframework.jdbc.core.namedparam.SqlParameterSource) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) BeanPropertySqlParameterSource(org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource) BeanPropertySqlParameterSource(org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource)

Example 5 with BeanPropertySqlParameterSource

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);
}
Also used : BeanPropertySqlParameterSource(org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource) Password(org.summerb.microservices.users.impl.dom.Password)

Aggregations

BeanPropertySqlParameterSource (org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource)5 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1 SqlParameterSource (org.springframework.jdbc.core.namedparam.SqlParameterSource)1 Transactional (org.springframework.transaction.annotation.Transactional)1 Password (org.summerb.microservices.users.impl.dom.Password)1