示例#1
0
  void joinChannel(Channel channel) {
    Connection con = null;
    try {
      con = pool.getConnection(timeout);

      PreparedStatement s = con.prepareStatement("INSERT INTO `channels` (`channel`) VALUES (?)");
      s.setString(1, channel.getName().toLowerCase());
      s.executeUpdate();
      s.close();

      if (!this.channel_data.containsKey(channel.getName().toLowerCase())) {
        ChannelInfo new_channel = new ChannelInfo(channel.getName().toLowerCase());
        new_channel.setDefaultOptions();

        this.channel_data.put(channel.getName().toLowerCase(), new_channel);
      }

      this.saveChannelSettings(this.channel_data.get(channel.getName().toLowerCase()));
    } catch (SQLException ex) {
      Logger.getLogger(DBAccess.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
      try {
        if (con != null) {
          con.close();
        }
      } catch (SQLException ex) {
        Logger.getLogger(DBAccess.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }
示例#2
0
  private void getChannelList() {
    Connection con = null;
    ChannelInfo ci;

    this.channel_data.clear();

    try {
      con = pool.getConnection(timeout);

      ResultSet rs;
      try (Statement s = con.createStatement()) {
        rs = s.executeQuery("SELECT * FROM `channels`");
        PreparedStatement s2;
        ResultSet rs2;
        while (rs.next()) {
          ci = new ChannelInfo(rs.getString("channel"));
          ci.setDefaultOptions();

          ci.setReactiveChatter(
              rs.getInt("reactive_chatter_level"), rs.getInt("chatter_name_multiplier"));

          ci.setRandomChatter(rs.getInt("random_chatter_level"));

          ci.setTwitterTimers(
              rs.getFloat("tweet_bucket_max"), rs.getFloat("tweet_bucket_charge_rate"));

          ci.setWarAutoMuzzle(rs.getBoolean("auto_muzzle_wars"));

          ci.velociraptorSightings = rs.getInt("velociraptor_sightings");
          ci.activeVelociraptors = rs.getInt("active_velociraptors");
          ci.deadVelociraptors = rs.getInt("dead_velociraptors");
          ci.killedVelociraptors = rs.getInt("killed_velociraptors");

          if (rs.getDate("last_sighting_date") != null) {
            long time = rs.getDate("last_sighting_date").getTime();
            ci.lastSighting = new java.util.Date(time);
          }

          s2 =
              con.prepareStatement(
                  "SELECT `setting`, `value` FROM `channel_chatter_settings` WHERE `channel` = ?");
          s2.setString(1, rs.getString("channel"));
          s2.executeQuery();

          rs2 = s2.getResultSet();
          while (rs2.next()) {
            ci.addChatterSetting(rs2.getString("setting"), rs2.getBoolean("value"));
          }

          s2.close();
          rs2.close();

          s2 =
              con.prepareStatement(
                  "SELECT `setting`, `value` FROM `channel_command_settings` WHERE `channel` = ?");
          s2.setString(1, rs.getString("channel"));
          s2.executeQuery();

          rs2 = s2.getResultSet();
          while (rs2.next()) {
            ci.addCommandSetting(rs2.getString("setting"), rs2.getBoolean("value"));
          }

          s2.close();
          rs2.close();

          s2 =
              con.prepareStatement(
                  "SELECT `account` FROM `channel_twitter_feeds` WHERE `channel` = ?");
          s2.setString(1, rs.getString("channel"));
          s2.executeQuery();

          rs2 = s2.getResultSet();
          while (rs2.next()) {
            ci.addTwitterAccount(rs2.getString("account"));
          }

          s2.close();
          rs2.close();

          this.channel_data.put(ci.channel, ci);

          this.saveChannelSettings(ci);
        }
      }
      rs.close();
    } catch (SQLException ex) {
      Logger.getLogger(DBAccess.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
      try {
        if (con != null) {
          con.close();
        }
      } catch (SQLException ex) {
        Logger.getLogger(DBAccess.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }