1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
package database;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.json.JSONException;
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 String insertProfile() {
return "INSERT INTO twitteruser (userid,displayname,timezone,tweetcount,"
+ "followercount,followedcount,location) "
+ "SELECT ?, ?, ?, ?, ?, ?, ? "
+ "WHERE NOT EXISTS "
+ "(SELECT * FROM twitteruser WHERE userid= ? )";
}
public static String insertTweet() {
return "INSERT INTO tweet (tweetid,createdat,favcount,retweetcount,text) "
+ "SELECT ?, ?, ?, ?, ? "
+ "WHERE NOT EXISTS "
+ "(SELECT * FROM tweet WHERE tweetid=? )";
}
public static String insetHash() {
return "INSERT INTO hashtag (tweetid, hashtag) "
+ "SELECT ?, ? ";
}
public static void setInsertParams(PreparedStatement statement, JSONObject tweet) throws JSONException, SQLException {
statement.setLong( 1, tweet.getLong( "id"));
statement.setString(2, tweet.getString("created_at"));
statement.setLong( 3, tweet.getLong( "favorite_count"));
statement.setLong( 4, tweet.getLong( "retweet_count"));
statement.setString(5, tweet.getString("text"));
statement.setLong( 6, tweet.getLong( "id"));
}
}
|