diff options
author | Maurice Laveaux <m.laveaux@student.tue.nl> | 2014-05-07 12:31:49 +0200 |
---|---|---|
committer | Maurice Laveaux <m.laveaux@student.tue.nl> | 2014-05-07 12:31:49 +0200 |
commit | 2f203acc7f28afce9e704cf27fd59d11e28ec2d5 (patch) | |
tree | d89a422c041932d04d56b2152933dc21540454a7 /src/database/QueryUtils.java | |
parent | 4386d1efcd0c423c2fa0e199e65e1c29792bf54c (diff) | |
download | Datafiller-2f203acc7f28afce9e704cf27fd59d11e28ec2d5.tar.gz |
Added classes to refactor the database code.
* DBConnection creates a persistent conn.
* DBQuery resolves and executes queries.
* QueryUtils creates sql query text.
Diffstat (limited to 'src/database/QueryUtils.java')
-rw-r--r-- | src/database/QueryUtils.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/database/QueryUtils.java b/src/database/QueryUtils.java new file mode 100644 index 0000000..a120d1c --- /dev/null +++ b/src/database/QueryUtils.java @@ -0,0 +1,40 @@ +package database; + +import org.json.JSONObject; + +/** + * Utilities to create queries. + * + * @author Maurice Laveaux + */ +public class QueryUtils { + + /** + * Create an insert tweet. + * + * @return A valid database query. + */ + public static DBQuery insertProfile() { + String query = "INSERT INTO twitteruser (userid,displayname,timezone,tweetcount," + + "followercount,followedcount,location) " + + "SELECT ?, ?, ?, ?, ?, ?, ? " + + "WHERE NOT EXISTS " + + "(SELECT * FROM twitteruser WHERE userid= ? )"; + return new DBQuery(query); + } + + public static DBQuery insertTweet() { + String query = "INSERT INTO tweet (tweetid,createdat,favcount,retweetcount,text) " + + "SELECT ?, ?, ?, ?, ? WHERE NOT EXISTS (SELECT * FROM tweet WHERE tweetid= ? )"; + return new DBQuery(query); + } + + public static void setInsertParams(DBQuery query, JSONObject tweet) { + /*query.getPrepared().setLong(1, tweet.getLong("id")); + pst.setString(2, tweet.getString("created_at")); + pst.setLong(3, tweet.getLong("favorite_count")); + pst.setLong(4, tweet.getLong("retweet_count")); + pst.setString(5, tweet.getString("text")); + pst.setLong(6, tweet.getLong("id"));*/ + } +} |