示例#1
0
 /** 更新用户帐号信息 */
 @Override
 @UpdatesToCache({
   @UpdateToCache(mapName = CacheConstants.CACHE_USER_ID_TO_USER, key = "${user.id}"),
   @UpdateToCache(mapName = CacheConstants.CACHE_USERNAME_TO_USER_ID, key = "${user.username}"),
   @UpdateToCache(mapName = CacheConstants.CACHE_EMAIL_TO_USER_ID, key = "${user.email}"),
   @UpdateToCache(mapName = CacheConstants.CACHE_LOGIN_NAME_TO_USER_ID, key = "${user.username}"),
   @UpdateToCache(mapName = CacheConstants.CACHE_LOGIN_NAME_TO_USER_ID, key = "${user.email}")
 })
 public void update(User user) {
   super.getJdbcTemplate()
       .update(
           UPDATE_USER_SQL,
           user.getNickname(),
           user.getGender(),
           user.getJob(),
           user.getPhone(),
           user.getTelephone(),
           user.getAvatar(),
           user.getSignature(),
           user.getSpeciality(),
           user.getPreference(),
           user.getProvince(),
           user.getCity(),
           user.getDistrict(),
           user.getAddress(),
           user.getId());
   logger.debug("updated {}", user);
 }
示例#2
0
  /** 保存用户帐号 */
  @Override
  public void save(User user) {
    user.setCreatedOn(new Date());
    try {
      Connection connection = super.getConnection();
      PreparedStatement statement =
          connection.prepareStatement(SAVE_SQL, Statement.RETURN_GENERATED_KEYS);
      statement.setString(1, user.getUsername());
      statement.setString(2, user.getEmail());
      statement.setString(3, user.getPassword());
      statement.setString(4, user.getSalt());
      statement.setString(5, user.getNickname());
      statement.setString(6, user.getGender());
      statement.setString(7, user.getJob());
      statement.setString(8, user.getPhone());
      statement.setString(9, user.getTelephone());
      statement.setString(10, user.getAvatar());
      statement.setString(11, user.getSignature());
      statement.setString(12, user.getSpeciality());
      statement.setString(13, user.getPreference());
      statement.setString(14, user.getProvince());
      statement.setString(15, user.getCity());
      statement.setString(16, user.getDistrict());
      statement.setString(17, user.getAddress());
      statement.setTimestamp(18, new Timestamp(user.getCreatedOn().getTime()));

      statement.execute();
      ResultSet rs = statement.getGeneratedKeys();
      while (rs.next()) {
        user.setId(rs.getInt(1));
      }
      rs.close();
      statement.close();
      logger.debug("saved {}", user);
    } catch (SQLException e) {
      throw new BusinessException("Database exception", e);
    }
  }