summaryrefslogtreecommitdiff
path: root/src/main/DataFiller.java
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-05-09 11:10:17 +0200
committerPeter Wu <peter@lekensteyn.nl>2014-05-09 11:10:17 +0200
commitc98a8ad4326ef36fc4fe03ba710ab2ba962ad60c (patch)
tree8d281fa010e8c3d65fd4a8f184b03ca357807b5c /src/main/DataFiller.java
parent92957d639b8eeaddb570725f7dc9dc9cc0080b0f (diff)
downloadDatafiller-c98a8ad4326ef36fc4fe03ba710ab2ba962ad60c.tar.gz
Get rid of DBConnection
That construct was hiding the Connection instance. Very bad abstraction as I really need it to support transactions. While at it, make the prepared statement objects final such that it is detected when those are not properly initialized. In Main, use try-with-resources, remove a noisy "exit succesfull" [sic] message. Due to the extra try/catch for the db connection (RuntimeException is not OK my friend!), the indentation had to be changed.
Diffstat (limited to 'src/main/DataFiller.java')
-rw-r--r--src/main/DataFiller.java34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/main/DataFiller.java b/src/main/DataFiller.java
index a65a032..6e1ba9d 100644
--- a/src/main/DataFiller.java
+++ b/src/main/DataFiller.java
@@ -1,8 +1,8 @@
package main;
import data.Tweet;
-import database.DBConnection;
import database.QueryUtils;
+import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
@@ -20,57 +20,57 @@ public class DataFiller {
/**
* The main database connection to fill.
*/
- private final DBConnection m_connection;
+ private final Connection m_connection;
/**
* A single insert tweet that can be used.
*/
- private PreparedStatement m_insertTweet;
+ private final PreparedStatement m_insertTweet;
/**
* A single insert profiles that can be used.
*/
- private PreparedStatement m_insertProfile;
+ private final PreparedStatement m_insertProfile;
/**
* A single insert ispostedby that can be used.
*/
- private PreparedStatement m_insertPosted;
+ private final PreparedStatement m_insertPosted;
/**
* A single insert brand that can be used.
*/
- private PreparedStatement m_insertBrand;
+ private final PreparedStatement m_insertBrand;
/**
* A single insert hashtag that can be used.
*/
- private PreparedStatement m_insertHash;
+ private final PreparedStatement m_insertHash;
/**
* A single insert url that can be used.
*/
- private PreparedStatement m_insertUrl;
+ private final PreparedStatement m_insertUrl;
/**
* A single insert url that can be used.
*/
- private PreparedStatement m_insertMentions;
+ private final PreparedStatement m_insertMentions;
/**
* Create the datafiller object.
*
* @param connection The database connection to use.
*/
- public DataFiller(DBConnection connection) {
+ public DataFiller(Connection connection) {
try {
m_connection = connection;
- m_insertTweet = m_connection.create(QueryUtils.insertTweet());
- m_insertProfile = m_connection.create(QueryUtils.insertProfile());
- m_insertPosted = m_connection.create(QueryUtils.insertPosted());
- m_insertBrand = m_connection.create(QueryUtils.insertBrand());
- m_insertHash = m_connection.create(QueryUtils.insertHash());
- m_insertUrl = m_connection.create(QueryUtils.insertUrl());
- m_insertMentions = m_connection.create(QueryUtils.insertMentions());
+ m_insertTweet = m_connection.prepareStatement(QueryUtils.insertTweet());
+ m_insertProfile = m_connection.prepareStatement(QueryUtils.insertProfile());
+ m_insertPosted = m_connection.prepareStatement(QueryUtils.insertPosted());
+ m_insertBrand = m_connection.prepareStatement(QueryUtils.insertBrand());
+ m_insertHash = m_connection.prepareStatement(QueryUtils.insertHash());
+ m_insertUrl = m_connection.prepareStatement(QueryUtils.insertUrl());
+ m_insertMentions = m_connection.prepareStatement(QueryUtils.insertMentions());
} catch (SQLException ex) {
throw new RuntimeException(ex.getMessage());