コード例 #1
0
  public static void insertTweet(Status tweet) throws SQLException {
    try {
      System.out.println(tweet.getCreatedAt() + ": " + tweet.getText());

      if (tweet.getRetweetedStatus() != null) {
        insertRetweet(tweet);
        return;
      }

      PreparedStatement insertTweetStmt = SqlHelper.getInsertTweetStmt();
      insertTweetStmt.setLong(1, tweet.getId());
      if (tweet.getGeoLocation() != null) {
        insertTweetStmt.setFloat(2, (float) tweet.getGeoLocation().getLatitude());
        insertTweetStmt.setFloat(3, (float) tweet.getGeoLocation().getLongitude());
      } else {
        insertTweetStmt.setFloat(2, 0);
        insertTweetStmt.setFloat(3, 0);
      }
      insertTweetStmt.setString(4, tweet.getText());
      insertTweetStmt.setInt(5, (int) tweet.getRetweetCount());
      insertTweetStmt.setTimestamp(6, new Timestamp(tweet.getCreatedAt().getTime()));
      insertTweetStmt.setLong(7, tweet.getInReplyToStatusId());
      insertTweetStmt.setLong(8, tweet.getUser().getId());
      insertTweetStmt.executeUpdate();
    } catch (MySQLIntegrityConstraintViolationException e) {
      // ignore, this is just a duplicate tweet entry, that's rather normal
    }
  }
コード例 #2
0
 public static void insertRetweet(Status status) throws SQLException {
   try {
     PreparedStatement insertRetweetStmt = SqlHelper.getInsertRetweetStmt();
     insertRetweetStmt.setLong(1, status.getRetweetedStatus().getId());
     insertRetweetStmt.setLong(2, status.getUser().getId());
     insertRetweetStmt.setTimestamp(3, new Timestamp(status.getCreatedAt().getTime()));
     insertRetweetStmt.executeUpdate();
   } catch (MySQLIntegrityConstraintViolationException e) {
     // ignore, this is just a duplicate tweet entry, that's rather normal
   }
 }
コード例 #3
0
  public static void insertDummyTweet(long id, String message) throws SQLException {
    System.out.println("INSERT DUMMY TWEET");

    PreparedStatement insertTweetStmt = SqlHelper.getInsertTweetStmt();
    insertTweetStmt.setLong(1, id);
    insertTweetStmt.setFloat(2, 0);
    insertTweetStmt.setFloat(3, 0);
    insertTweetStmt.setString(
        4, "[ERROR TWEET]: " + message.substring(message.indexOf("message - ") + 10));
    insertTweetStmt.setInt(5, 0);
    insertTweetStmt.setTimestamp(6, new Timestamp(new Date().getTime()));
    insertTweetStmt.setLong(7, -1);
    insertTweetStmt.setLong(8, -1);
    insertTweetStmt.executeUpdate();
  }
コード例 #4
0
 public static Long insertLabel(Long parent_id, String name) throws SQLException {
   try {
     // System.out.println("Insert: " + name + ", " + parent_id);
     PreparedStatement insertLabelStmt = SqlHelper.getInsertLabelStmt();
     insertLabelStmt.setString(1, name);
     if (parent_id != null) insertLabelStmt.setLong(2, parent_id);
     else insertLabelStmt.setNull(2, java.sql.Types.BIGINT);
     insertLabelStmt.executeUpdate();
     ResultSet keys = insertLabelStmt.getGeneratedKeys();
     keys.next();
     return keys.getLong(1);
   } catch (MySQLIntegrityConstraintViolationException e) {
     // ignore, this is just a duplicate tweet entry, that's rather normal
   }
   return null;
 }
コード例 #5
0
  public static void insertUser(User user) throws SQLException {
    try {
      PreparedStatement insertUserStmt = SqlHelper.getInsertUserStmt();
      insertUserStmt.setLong(1, user.getId());
      insertUserStmt.setString(2, user.getScreenName());
      insertUserStmt.setString(3, user.getName());
      insertUserStmt.setString(4, user.getDescription());
      insertUserStmt.setString(5, user.getLang());
      insertUserStmt.setInt(6, user.getFollowersCount());
      insertUserStmt.setInt(7, user.getStatusesCount());
      insertUserStmt.setString(8, user.getURL());
      insertUserStmt.setString(9, user.getProfileImageURL());
      insertUserStmt.executeUpdate();

    } catch (MySQLIntegrityConstraintViolationException e) {
      // ignore, this is just a duplicate user entry, that's normal
    }
  }