1 package compbio.ws.execstat;
\r
3 import java.sql.Connection;
\r
4 import java.sql.DriverManager;
\r
5 import java.sql.PreparedStatement;
\r
6 import java.sql.SQLException;
\r
7 import java.sql.Statement;
\r
8 import java.sql.Timestamp;
\r
10 import compbio.ws.execstat.StatProcessor.JobStat;
\r
12 public class StatWriter {
\r
14 /* the default framework is embedded */
\r
15 // private final String framework = "embedded";
\r
16 private static final String driver = "org.apache.derby.jdbc.EmbeddedDriver";
\r
17 private static final String protocol = "jdbc:derby:";
\r
18 private static final String statDBName = "ExecutionStatistic";
\r
20 static Connection getDBConnection() throws SQLException {
\r
22 System.setProperty("derby.system.home", ".");
\r
24 Connection conn = DriverManager.getConnection(protocol + statDBName
\r
27 // We want to control transactions manually. Autocommit is on by
\r
29 conn.setAutoCommit(true);
\r
33 // ServiceName,jobname,start,finish,inputSize,resultSize,isCancelled,isCollected
\r
34 static void createStatTable() throws SQLException {
\r
35 Connection conn = getDBConnection();
\r
37 * Creating a statement object that we can use for running various SQL
\r
38 * statements commands against the database.
\r
40 Statement s = conn.createStatement();
\r
41 String create = "create table exec_stat("
\r
42 + "number INT GENERATED ALWAYS AS IDENTITY,"
\r
43 + "service_name VARCHAR(15) NOT NULL, "
\r
44 + "job_id VARCHAR(35) NOT NULL PRIMARY KEY, "
\r
45 + "start TIMESTAMP," + "finish TIMESTAMP,"
\r
46 + "inputsize BIGINT," + "resultsize BIGINT,"
\r
47 + "isCancelled SMALLINT NOT NULL,"
\r
48 + "isCollected SMALLINT NOT NULL)";
\r
49 // We create a table...
\r
50 System.out.println(create);
\r
56 static void insertData(JobStat jobstatus) throws SQLException {
\r
57 Connection conn = getDBConnection();
\r
58 String insert = "insert into exec_stat (service_name, job_id, start, finish, "
\r
59 + "inputsize, resultsize, isCancelled, isCollected) "
\r
60 + "VALUES (?, ?, ?, ?, ?, ?, ?, ? )";
\r
61 PreparedStatement pstm = conn.prepareStatement(insert);
\r
63 pstm.setString(1, "webservice");
\r
64 pstm.setString(2, "@Clustal#980273495452357");
\r
65 pstm.setTimestamp(3, new Timestamp(190385934834l));
\r
66 pstm.setTimestamp(4, new Timestamp(190332423423l));
\r
67 pstm.setLong(5, 1232);
\r
68 pstm.setLong(6, 1432422);
\r
69 pstm.setShort(7, (short) 1);
\r
70 pstm.setShort(8, (short) 0);
\r
71 pstm.executeUpdate();
\r
76 void shutdownDBServer() {
\r
77 // ## DATABASE SHUTDOWN SECTION ##
\r
79 * In embedded mode, an application should shut down Derby. Shutdown
\r
80 * throws the XJ015 exception to confirm success.
\r
82 boolean gotSQLExc = false;
\r
84 DriverManager.getConnection("jdbc:derby:;shutdown=true");
\r
85 } catch (SQLException se) {
\r
86 if (se.getSQLState().equals("XJ015")) {
\r
91 System.out.println("Database did not shut down normally");
\r
93 System.out.println("Database shut down normally");
\r
96 public static void main(String[] args) throws SQLException {
\r
97 // createStatTable();
\r