From 2b673df3123e3e1fd4edd6861abe316336e1d69c Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 10 May 2014 19:42:56 +0200 Subject: Convert long to int where possible, fix retweetid If there is no retweet, the retweetid must really be NULL, not 0. In order to better match the database, convert some types to integers too. --- src/database/NamedPreparedStatement.java | 21 +++++++++++++++------ src/database/QueryUtils.java | 10 +++++----- 2 files changed, 20 insertions(+), 11 deletions(-) (limited to 'src/database') diff --git a/src/database/NamedPreparedStatement.java b/src/database/NamedPreparedStatement.java index c899376..ebb775b 100644 --- a/src/database/NamedPreparedStatement.java +++ b/src/database/NamedPreparedStatement.java @@ -4,6 +4,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Timestamp; +import java.sql.Types; import java.util.ArrayList; import java.util.Calendar; import java.util.List; @@ -50,21 +51,29 @@ public class NamedPreparedStatement { return indices; } - public void setLong(String name, long l) throws SQLException { + public void setInt(String name, Integer i) throws SQLException { for (int paramIndex : getParamIndices(name)) { - stmt.setLong(paramIndex, l); + if (i == null) { + stmt.setNull(paramIndex, Types.INTEGER); + } else { + stmt.setInt(paramIndex, i); + } } } - public void setString(String name, String str) throws SQLException { + public void setLong(String name, Long l) throws SQLException { for (int paramIndex : getParamIndices(name)) { - stmt.setString(paramIndex, str); + if (l == null) { + stmt.setNull(paramIndex, Types.BIGINT); + } else { + stmt.setLong(paramIndex, l); + } } } - public void setString(String name, int i) throws SQLException { + public void setString(String name, String str) throws SQLException { for (int paramIndex : getParamIndices(name)) { - stmt.setInt(paramIndex, i); + stmt.setString(paramIndex, str); } } diff --git a/src/database/QueryUtils.java b/src/database/QueryUtils.java index c307b40..4f87428 100644 --- a/src/database/QueryUtils.java +++ b/src/database/QueryUtils.java @@ -96,7 +96,7 @@ public class QueryUtils { Tweet tweet) throws SQLException { tweetStatement.setLong("tweetid", tweet.id); tweetStatement.setTimestamp("createdat", tweet.created_at); - tweetStatement.setLong("favcount", tweet.favorite_count); + tweetStatement.setInt("favcount", tweet.favorite_count); tweetStatement.setLong("retweetcount", tweet.retweet_count); tweetStatement.setString("text", tweet.text); if (tweet.coordinates != null) { @@ -110,7 +110,7 @@ public class QueryUtils { if (tweet.retweeted_status != null) { tweetStatement.setLong("retweetid", tweet.retweeted_status.id); } else { - tweetStatement.setLong("retweetid", 0); + tweetStatement.setLong("retweetid", null); } tweetStatement.setLong("replyid", tweet.in_reply_to_user_id); // TODO: place is not a string... @@ -125,9 +125,9 @@ public class QueryUtils { profileStatement.setLong("userid", twuser.id); profileStatement.setString("displayname", twuser.name); profileStatement.setString("timezone", twuser.time_zone); - profileStatement.setLong("tweetcount", twuser.statuses_count); - profileStatement.setLong("followercount", twuser.followers_count); - profileStatement.setLong("followedcount", twuser.friends_count); + profileStatement.setInt("tweetcount", twuser.statuses_count); + profileStatement.setInt("followercount", twuser.followers_count); + profileStatement.setInt("followedcount", twuser.friends_count); profileStatement.setString("location", twuser.location); profileStatement.setString("tweetname", twuser.screen_name); profileStatement.setTimestamp("createdat", twuser.created_at); -- cgit v1.2.1