Пример #1
0
  private static NetworkIntegerSetting loadPrimitives(ResultSet rs) throws SQLException {
    NetworkIntegerSetting out = new NetworkIntegerSetting();

    out.setId(DatabaseUtils.getInt(rs, "id"));
    out.setValue(DatabaseUtils.getInt(rs, "setting_value"));
    out.setSettingEnum(NetworkIntegerSettingEnum.getById(DatabaseUtils.getInt(rs, "setting_id")));

    return out;
  }
Пример #2
0
  public static Integer insert(
      Connection conn,
      Integer networkId,
      NetworkIntegerSettingEnum settingEnum,
      Integer settingValue)
      throws SQLException {

    conn = start(conn);

    String sql =
        "insert into `network_integer_settings` ("
            + "`network_id`, "
            + "`setting_id`, "
            + "`setting_value` "
            + ") values (?, ?, ?);";

    PreparedStatement ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
    ps.setInt(1, networkId);
    ps.setInt(2, settingEnum.getId());
    ps.setInt(3, settingValue);
    ps.execute();

    Integer generatedId = DatabaseUtils.getFirstGeneratedKey(ps.getGeneratedKeys());

    end(conn, ps, null);
    return generatedId;
  }