summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-05-08 19:05:43 +0200
committerPeter Wu <peter@lekensteyn.nl>2014-05-08 19:05:43 +0200
commitfaa3102b2b79952c9def9d3c27cadb2c9048287d (patch)
treeed51f13b104ec37e28f50cd1b7943e5a0c560fd5
parent9fe9d1b848156928a0d3efde4fff80a78f1bf9e1 (diff)
downloadDatafiller-faa3102b2b79952c9def9d3c27cadb2c9048287d.tar.gz
Get rid of unused crap
-rw-r--r--src/database/Post.java173
-rw-r--r--src/io/DataReader.java57
-rw-r--r--src/io/InputReader.java56
-rw-r--r--src/main/ResultListener.java16
4 files changed, 0 insertions, 302 deletions
diff --git a/src/database/Post.java b/src/database/Post.java
deleted file mode 100644
index 03ca11e..0000000
--- a/src/database/Post.java
+++ /dev/null
@@ -1,173 +0,0 @@
-package database;
-
-
-
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-import java.io.File;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-/**
- *
- * @author s129778
- */
-public class Post implements Runnable {
-
- Thread runner;
- JSONObject tweet;
- JSONObject twuser;
-
- Connection con = null;
- Statement st = null;
- ResultSet rs = null;
- PreparedStatement pst = null;
- String url = "jdbc:postgresql://131.155.240.72:5432/Twitter";
- String user = "postgres";
- String password = "2IOC02";
-
- public Post() {
- }
-
- public void start() {
- runner.start();
- }
-
- public Post(JSONObject tweet, JSONObject user) {
- //create new tread
-
- runner = new Thread(this, "post");
- this.twuser = user;
- this.tweet = tweet;
- }
-
- public void run() {
- try {
- con = DriverManager.getConnection(url, user, password);
- st = con.createStatement();
- rs = st.executeQuery("SELECT VERSION()");
-
- //st.executeUpdate("CREATE TABLE name (ID INT)");
- //st.executeUpdate("DROP TABLE name");
- //st.executeQuery("SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'name' AND pid <> pg_backend_pid();");
- //st.executeUpdate("DROP DATABASE name");
- //st.executeUpdate("CREATE ROLE joe2 PASSWORD 'ok' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;");
- //select query
- String query = "SELECT * FROM tweet WHERE tweetid<=9000000 ORDER BY tweetid";
- pst = con.prepareStatement(query);
- rs = pst.executeQuery();
- //process select query
- while (rs.next()) {
- int id = rs.getInt("tweetid");
- System.out.println("ID = " + id);
- System.out.println(rs.getTimestamp("createdat"));
- }
-
- //insert query with check for existance
- //for(int i=0;i<900000;i++){
- String update = "INSERT INTO tweet (tweetid,createdat,favcount,retweetcount,text) SELECT ? , ? ,?,?, ? WHERE NOT EXISTS (SELECT * FROM tweet WHERE tweetid= ? )";
- pst = con.prepareStatement(update);
- pst.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"));
- pst.executeUpdate();
-
- update = "INSERT INTO ispostedby (tweetid,userid) SELECT ? , ? WHERE NOT EXISTS (SELECT * FROM ispostedby WHERE tweetid= ? )";
- pst = con.prepareStatement(update);
- pst.setLong(1, tweet.getLong("id"));
- pst.setLong(2, twuser.getLong("id"));
- pst.setLong(3, tweet.getLong("id"));
- pst.executeUpdate();
-
- //update = "INSERT INTO twitteruser (userid,displayname,timezone,tweetcount,followercount,followedcount,location,brand) Select 1";
- update = "INSERT INTO twitteruser (userid,displayname,timezone,tweetcount,followercount,followedcount,location) SELECT ? ,? ,? ,? , ?, ? ,? WHERE NOT EXISTS (SELECT * FROM twitteruser WHERE userid= ? )";
- pst = con.prepareStatement(update);
- pst.setLong(1, twuser.getLong("id"));
- pst.setString(2, twuser.getString("name"));
- pst.setString(3, twuser.getString("time_zone"));
- pst.setLong(4, twuser.getLong("statuses_count"));
- pst.setLong(5, twuser.getLong("followers_count"));
- pst.setLong(6, twuser.getLong("friends_count"));
- pst.setString(7, twuser.getString("location"));
- pst.setLong(8, twuser.getLong("id"));
- pst.executeUpdate();
-
- ArrayList<String> brands = getBrands();
- for (String brand : brands) {
- update = "INSERT INTO likesbrand (userid,brand) SELECT ? , ? WHERE NOT EXISTS (SELECT * FROM likesbrand WHERE userid= ? AND brand = ?)";
- pst = con.prepareStatement(update);
-
- pst.setLong(1, twuser.getLong("id"));
- pst.setString(2, brand);
- pst.setLong(3, twuser.getLong("id"));
- pst.setString(4, brand);
- pst.executeUpdate();
- }
- //}
- //update
- //pst = con.prepareStatement("UPDATE tweet set text = 'j' where tweetid=1;");
- //pst.executeUpdate();
-
- //delete
- //pst = con.prepareStatement("DELETE from tweet where tweetid=1;");
- //pst.executeUpdate();
- } catch (JSONException ex) {
- Logger.getLogger(Post.class.getName()).log(Level.SEVERE, null, ex);
- } catch (SQLException ex) {
- Logger lgr = Logger.getLogger(Post.class.getName());
- lgr.log(Level.SEVERE, ex.getMessage(), ex);
-
- } finally {
- try {
- if (rs != null) {
- rs.close();
- }
- if (st != null) {
- st.close();
- }
- if (con != null) {
- con.close();
- }
-
- } catch (SQLException ex) {
- Logger lgr = Logger.getLogger(Post.class.getName());
- lgr.log(Level.WARNING, ex.getMessage(), ex);
- }
- }
-
- }
-
- ArrayList<String> getBrands() {
- ArrayList<String> result = new ArrayList<String>();
- String text = null;
- try {
- text = tweet.getString("text");
- text = text.toLowerCase();
- } catch (JSONException ex) {
- Logger.getLogger(Post.class.getName()).log(Level.SEVERE, null, ex);
- }
- if (text.contains("samsung") || text.contains("galaxy")) {
- result.add("Samsung");
- System.out.println("samsung");
- } else {
- result.add("geen");
- System.out.println(text);
- }
- return result;
- }
-}
diff --git a/src/io/DataReader.java b/src/io/DataReader.java
deleted file mode 100644
index 21a1036..0000000
--- a/src/io/DataReader.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package io;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.util.Scanner;
-import java.util.logging.Level;
-import main.ResultListener;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-/**
- * Create a data reader that reads the input file.
- *
- * @author Maurice Laveaux
- */
-public class DataReader {
-
- /* The listener that receives the data input. */
- private final ResultListener m_listener;
-
- /* The input stream for the given file. */
- private final FileInputStream m_input;
-
- /**
- * @param filename The filename to read from.
- * @param listener The listener of the read tweets.
- */
- public DataReader(final String filename, final ResultListener listener) {
- try {
- m_listener = listener;
- m_input = new FileInputStream(filename);
- } catch (FileNotFoundException ex) {
- throw new IllegalArgumentException("the given filename \"" + filename + "\" doesn't exist.");
- }
-
- }
- public void startloop(){
- Scanner scanner=null;
- scanner = new Scanner(m_input);
- try {
- while(scanner.hasNextLine()){
-
-
- JSONObject tweet = new JSONObject(scanner.nextLine());
-
- m_listener.tweetReceived(tweet);
-
- }
-
-
-
- } catch (Exception e){
- e.printStackTrace();
- }
- }
-}
diff --git a/src/io/InputReader.java b/src/io/InputReader.java
deleted file mode 100644
index 985a59b..0000000
--- a/src/io/InputReader.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package io;
-
-import java.util.Scanner;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import main.ResultListener;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-/**
- * Read from standard input and inserts these tweets into the database.
- *
- * @author Maurice Laveaux
- */
-public class InputReader {
-
- /* The listener for standard input tweets. */
- private final ResultListener m_listener;
-
- /**
- * @param listener The given listener for the input.
- */
- public InputReader(final ResultListener listener) {
- m_listener = listener;
- }
-
- /* Create a reader for the standard input, read each line and tweetReceived
- * listener when a valid JSONObject is generated.
- */
- public void startLoop() {
- Scanner input = new Scanner(System.in);
-
- while (input.hasNext()) {
- try {
- String line = input.nextLine();
- if(line.equals("exit")) {
- return;
- }
-
- JSONObject tweet = new JSONObject(line);
-
- if (!tweet.has("user")) {
- throw new JSONException("not a valid tweet JSON object");
- }
-
- m_listener.tweetReceived(tweet);
- } catch (JSONException ex) {
- getLogger().log(Level.INFO, null, ex);
- }
- }
- }
-
- private Logger getLogger() {
- return Logger.getLogger(InputReader.class.getName());
- }
-}
diff --git a/src/main/ResultListener.java b/src/main/ResultListener.java
deleted file mode 100644
index 9194a63..0000000
--- a/src/main/ResultListener.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package main;
-
-import org.json.JSONObject;
-
-/**
- * This class is used to obtain resulting JSON tweets.
- * @author Maurice Laveaux
- */
-public interface ResultListener {
-
- /**
- * Notify the result listener that a tweet was generated.
- * @param tweet A single tweet that should be processed.
- */
- public abstract void tweetReceived(JSONObject tweet);
-}