X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=webservices%2Fcompbio%2Fstat%2Fcollector%2FStatDB.java;h=b469c442c32ddda0a7dfc7f9e8cde67a45f85c49;hb=af761a5bb8fb0f1fa5f4d8ae8cb245050c3aab59;hp=c2dd29a1b154d51d9b314abbcc63e676c762ae9a;hpb=1e8254e6a48302dd3e47e1f68cc51f6a6b9c33db;p=jabaws.git diff --git a/webservices/compbio/stat/collector/StatDB.java b/webservices/compbio/stat/collector/StatDB.java index c2dd29a..b469c44 100644 --- a/webservices/compbio/stat/collector/StatDB.java +++ b/webservices/compbio/stat/collector/StatDB.java @@ -1,3 +1,20 @@ +/* Copyright (c) 2011 Peter Troshin + * + * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0 + * + * This library is free software; you can redistribute it and/or modify it under the terms of the + * Apache License version 2 as published by the Apache Software Foundation + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache + * License for more details. + * + * A copy of the license is in apache_license.txt. It is also available here: + * @see: http://www.apache.org/licenses/LICENSE-2.0.txt + * + * Any republication or derived work distributed in source code form + * must include this copyright and license notice. + */ package compbio.stat.collector; import java.sql.Connection; @@ -41,19 +58,26 @@ public class StatDB { if (conn != null && !conn.isClosed()) { return conn; } else { - String dbpath = PropertyHelperManager.getLocalPath(); - log.info("Looking for JABAWS access statistics database at: " - + dbpath); - System.setProperty("derby.system.home", dbpath); - conn = DriverManager.getConnection(protocol + statDBName - + ";create=false"); - - conn.setAutoCommit(true); - /* - * Runtime.getRuntime().addShutdownHook(new Thread() { - * - * @Override public void run() { shutdownDBServer(); } }); - */ + try { + String dbpath = PropertyHelperManager.getLocalPath(); + log.info("Looking for JABAWS access statistics database at: " + + dbpath); + System.setProperty("derby.system.home", dbpath); + // Apparently under Tomcat webapp you cannot rely on Java + // auto discovery and have to register the driver explicitly + Class.forName(driver); + conn = DriverManager.getConnection(protocol + statDBName + + ";create=false"); + + conn.setAutoCommit(true); + /* + * Runtime.getRuntime().addShutdownHook(new Thread() { + * + * @Override public void run() { shutdownDBServer(); } }); + */ + } catch (ClassNotFoundException e) { + log.error(e.getMessage(), e); + } } return conn; } @@ -76,6 +100,7 @@ public class StatDB { Connection conn = DriverManager.getConnection(protocol + statDBName + ";create=false"); conn.setAutoCommit(true); + log.debug("Connecting to the TEST database!"); return conn; } @@ -111,6 +136,16 @@ public class StatDB { conn.close(); } + static void clearStatTable() throws SQLException { + Connection conn = getDBConnection(); + String query = "delete from exec_stat"; + Statement st = conn.createStatement(); + st.executeUpdate(query); + st.close(); + conn.commit(); + conn.close(); + } + void insertData(Set jobstatus) throws SQLException { log.info("Inserting " + jobstatus.size() + " new records into the statistics database"); @@ -195,7 +230,7 @@ public class StatDB { public int getIncompleteCount(Timestamp from, Timestamp to) throws SQLException { // !js.hasResult() - String incompleteQuery = "select count(*) from exec_stat where start BETWEEN ? and ? and resultsize<=0 "; + String incompleteQuery = "select count(*) from exec_stat where start BETWEEN ? and ? and resultsize<=0 and isCancelled=0"; return getIntResult(from, to, incompleteQuery); } @@ -327,7 +362,15 @@ public class StatDB { log.info("Database shut down normally"); } } - public static void main(String[] args) throws SQLException { + public static void main(String[] args) { + // This is called from Ant cleanStatTable task + try { + clearStatTable(); + shutdownDBServer(); + } catch (SQLException e) { + System.err.println("Fails to clean up JABAWS stat database!"); + e.printStackTrace(); + } // new StatDB().createStatTable(); // insertData(null); /*