Skip to content

Commit acea58a

Browse files
committed
checking in the constructor of NameServer for database connection and
table
1 parent 03f8878 commit acea58a

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

src/me/salimm/jrns/db/DBFactory.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.sql.Connection;
44
import java.sql.DriverManager;
55
import java.sql.SQLException;
6-
import java.sql.Statement;
76

87
import com.allConfig.conf.AbstractConfig;
98

@@ -75,20 +74,6 @@ public static Connection createSQLLiteConnection(String DB_URL, String USER, Str
7574
Connection conn = null;
7675
Class.forName(SQLLITE_CONN_DRIVER_CLASSPATH);
7776
conn = DriverManager.getConnection(DB_URL, USER, PASS);
78-
79-
String sql1 = "CREATE TABLE IF NOT EXISTS SERVICE (SID integer, NAME text);";
80-
// 0:in, 1: out
81-
String sql2 = "CREATE TABLE IF NOT EXISTS SERVICE_IO (SID integer, CLSPATH text, TYPE integer);";
82-
String sql3 = "CREATE TABLE IF NOT EXISTS SERVICE_PROVIDER (PID integer,SID integer, URL text, PORT integer);";
83-
84-
Statement stmt = conn.createStatement();
85-
86-
stmt.executeUpdate(sql1);
87-
stmt.executeUpdate(sql2);
88-
stmt.executeUpdate(sql3);
89-
90-
stmt.close();
91-
9277
return conn;
9378
}
9479

@@ -129,7 +114,7 @@ public static Connection getConnection(DBInfo dbInfo)
129114
} else if (dbInfo.getType().equals(DBType.ORACLE)) {
130115
return DBFactory.createOracleConnection(dbInfo.getDbUrl(), dbInfo.getDbUser(), dbInfo.getDbPass());
131116
} else if (dbInfo.getType().equals(DBType.SQLLITE)) {
132-
return DBFactory.createOracleConnection(dbInfo.getDbUrl(), dbInfo.getDbUser(), dbInfo.getDbPass());
117+
return DBFactory.createSQLLiteConnection(dbInfo.getDbUrl(), dbInfo.getDbUser(), dbInfo.getDbPass());
133118
}
134119
return null;
135120

src/me/salimm/jrns/server/NameServer.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package me.salimm.jrns.server;
22

3+
import java.sql.Connection;
34
import java.sql.SQLException;
5+
import java.sql.Statement;
46

57
import org.eclipse.jetty.server.Server;
68

@@ -31,6 +33,24 @@ public class NameServer implements Constants {
3133
public NameServer(AbstractConfig conf) throws ClassNotFoundException, SQLException, DatabaseNotSupported {
3234
this.conf = conf;
3335
this.dbUtils = DBFactory.getDBUtils(conf);
36+
37+
// init database
38+
Connection conn = DBFactory.getConnection(DBFactory.getDBInfo(conf));
39+
String sql1 = "CREATE TABLE IF NOT EXISTS SERVICE (SID integer, NAME text);";
40+
// 0:in, 1: out
41+
String sql2 = "CREATE TABLE IF NOT EXISTS SERVICE_IO (SID integer, CLSPATH text, TYPE integer);";
42+
String sql3 = "CREATE TABLE IF NOT EXISTS SERVICE_PROVIDER (PID integer,SID integer, URL text, PORT integer);";
43+
44+
Statement stmt = conn.createStatement();
45+
46+
stmt.executeUpdate(sql1);
47+
stmt.executeUpdate(sql2);
48+
stmt.executeUpdate(sql3);
49+
50+
stmt.close();
51+
System.out.println("Finished checking if schema exists....");
52+
53+
3454
}
3555

3656
public void start() throws Exception {

0 commit comments

Comments
 (0)