Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Centralised database junk

  • Loading branch information...
commit 2deaed86c973915a17fd2ef49200d9d5970c66c0 1 parent 3cf7daa
@predominant authored
View
61 RouteMeServer/src/routeme/server/DatabaseManager.java
@@ -0,0 +1,61 @@
+package routeme.server;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import routeme.server.response.ResponseServer;
+
+public class DatabaseManager {
+
+ protected Properties properties;
+
+ public DatabaseManager() {
+ try {
+ System.out.println("Resolving MySQL driver");
+ Class.forName("com.mysql.jdbc.Driver");
+ } catch (ClassNotFoundException e) {
+ System.out.println("Unable to load MySQL Driver");
+ System.exit(1);
+ }
+
+ this.properties = this.getProperties();
+ }
+
+ public Connection getConnection() {
+ Connection conn = null;
+ Properties prop = this.properties;
+
+ try {
+ System.out.println("Attempting MySQL connection");
+ conn = DriverManager.getConnection(
+ "jdbc:mysql://" +
+ prop.getProperty("hostname") + "/" +
+ prop.getProperty("database") + "?" +
+ "user=" + prop.getProperty("username") + "&" +
+ "password=" + prop.getProperty("password"));
+
+ } catch (SQLException e) {
+ System.out.println("Failed to connect to MySQL database");
+ System.exit(3);
+ }
+
+ return conn;
+ }
+
+ protected Properties getProperties() {
+ Properties prop = new Properties();
+
+ try {
+ prop.load(new FileInputStream("database.properties"));
+ } catch (IOException e) {
+ System.out.println("Failed to load database.properties file");
+ System.exit(2);
+ }
+ return prop;
+ }
+
+}
View
48 RouteMeServer/src/routeme/server/response/ResponseServer.java
@@ -9,22 +9,19 @@
import java.sql.Statement;
import java.util.Properties;
+import routeme.server.DatabaseManager;
import twitter4j.Tweet;
public class ResponseServer {
+ DatabaseManager db;
+
public ResponseServer() {
- try {
- System.out.println("Resolving MySQL driver");
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException e) {
- System.out.println("Unable to load MySQL Driver");
- System.exit(1);
- }
+ this.db = new DatabaseManager();
}
- public void start(Properties prop) {
- Connection conn = this.getConnection(prop);
+ public void start() {
+ Connection conn = this.db.getConnection();
while (true) {
try {
@@ -80,26 +77,6 @@ protected boolean processTweet(String tweet) {
return true;
}
- protected Connection getConnection(Properties prop) {
- Connection conn = null;
-
- try {
- System.out.println("Attempting MySQL connection");
- conn = DriverManager.getConnection(
- "jdbc:mysql://" +
- prop.getProperty("hostname") + "/" +
- prop.getProperty("database") + "?" +
- "user=" + prop.getProperty("username") + "&" +
- "password=" + prop.getProperty("password"));
-
- } catch (SQLException e) {
- System.out.println("Failed to connect to MySQL database");
- System.exit(3);
- }
-
- return conn;
- }
-
/**
* @param args
*/
@@ -108,16 +85,7 @@ public static void main(String[] args) {
System.out.println("Starting RouteMe ResponseServer");
System.out.println("=============================================");
- Properties prop = new Properties();
-
- try {
- prop.load(new FileInputStream("database.properties"));
- ResponseServer server = new ResponseServer();
- server.start(prop);
- } catch (IOException e) {
- System.out.println("Failed to load database.properties file");
- System.exit(2);
- }
-
+ ResponseServer server = new ResponseServer();
+ server.start();
}
}
View
13 RouteMeServer/src/routeme/server/timeline/TimelineServer.java
@@ -0,0 +1,13 @@
+package routeme.server.timeline;
+
+public class TimelineServer {
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.