summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-05-09 14:44:19 +0200
committerPeter Wu <peter@lekensteyn.nl>2014-05-09 14:44:19 +0200
commit36152ad981e3c6cd37c3771e3d4a393535400f91 (patch)
treeea533ae8d6dec8876dfae8de61553792df204736
parentb1a7bb58774ecee3c2ef79f684bc255cb8e6ef7c (diff)
downloadDatafiller-36152ad981e3c6cd37c3771e3d4a393535400f91.tar.gz
First try to get a reader, then try to open database
Connecting to the database is probably more expensive, so try to read data first.
-rw-r--r--src/main/Main.java47
1 files changed, 24 insertions, 23 deletions
diff --git a/src/main/Main.java b/src/main/Main.java
index a9abf4a..b21ea16 100644
--- a/src/main/Main.java
+++ b/src/main/Main.java
@@ -49,32 +49,13 @@ public class Main {
parseGlobalOptions(args);
}
- public void run() {
+ private void tweetsToDb(ITweetReader reader) throws IOException {
+ Tweet tweet;
try (Connection connection = cb.create()) {
-
/* create the object that fills the database */
DataFiller filler = new DataFiller(connection);
-
- ITweetReader reader = null;
- try {
- if (m_filename == null) {
- reader = new TweetReader(System.in);
- } else {
- reader = new FileTweetReader(m_filename);
- }
-
- Tweet tweet;
- while ((tweet = reader.getTweet()) != null) {
- filler.processTweet(tweet);
- }
- } catch (JsonSyntaxException ex) {
- System.err.println("Got an invalid tweet: " + ex);
- } catch (IOException ex) {
- System.err.println("Cannot open tweets: " + ex);
- } finally {
- if (reader != null) {
- reader.close();
- }
+ while ((tweet = reader.getTweet()) != null) {
+ filler.processTweet(tweet);
}
} catch (SQLException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE,
@@ -82,6 +63,26 @@ public class Main {
}
}
+ public void run() {
+ ITweetReader reader = null;
+ try {
+ if (m_filename == null) {
+ reader = new TweetReader(System.in);
+ } else {
+ reader = new FileTweetReader(m_filename);
+ }
+ tweetsToDb(reader);
+ } catch (JsonSyntaxException ex) {
+ System.err.println("Got an invalid tweet: " + ex);
+ } catch (IOException ex) {
+ System.err.println("Cannot open tweets: " + ex);
+ } finally {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+ }
+
private void parseGlobalOptions(String[] args)
throws IllegalArgumentException {
/* parse global options */