diff options
author | Maurice Laveaux <m.laveaux@student.tue.nl> | 2014-05-07 12:33:50 +0200 |
---|---|---|
committer | Maurice Laveaux <m.laveaux@student.tue.nl> | 2014-05-07 12:33:50 +0200 |
commit | a3303f1fe119f963edec13c48286cc5d8cdcc5eb (patch) | |
tree | c2fef6ff8c7662ebc868f6a7fbd81353222e9822 /src/main/DataFiller.java | |
parent | 2f203acc7f28afce9e704cf27fd59d11e28ec2d5 (diff) | |
download | Datafiller-a3303f1fe119f963edec13c48286cc5d8cdcc5eb.tar.gz |
Two different inputs (file and stdin).
* DataFiller fills the database with given input.
Diffstat (limited to 'src/main/DataFiller.java')
-rw-r--r-- | src/main/DataFiller.java | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/main/DataFiller.java b/src/main/DataFiller.java new file mode 100644 index 0000000..461bd21 --- /dev/null +++ b/src/main/DataFiller.java @@ -0,0 +1,43 @@ +package main; + +import database.DBConnection; +import database.DBQuery; +import database.QueryUtils; +import org.json.JSONObject; + +/** + * Process that incoming tweets and fill the database. + * + * @author Maurice Laveaux + */ +public class DataFiller implements ResultListener { + + /** + * The main database connection to fill. + */ + private final DBConnection m_connection; + + /** + * A single insert tweet that can be used often. + */ + private DBQuery m_insertTweet; + + /** + * Create the datafiller object. + * + * @param connection The database connection to use. + */ + public DataFiller(DBConnection connection) { + m_insertTweet = QueryUtils.insertTweet(); + + m_connection = connection; + m_connection.prepare(m_insertTweet); + } + + @Override + public void tweetReceived(JSONObject tweet) { + QueryUtils.setInsertParams(m_insertTweet, tweet); + + m_insertTweet.execute(); + } +} |