X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=webservices%2Fcompbio%2Fstat%2Fcollector%2FStatDB.java;h=32b7fde414b7f0b4a4f64afda4844fc2fbc38d28;hb=b03d78f393289b6d54811023e851d13e650f4db3;hp=f9f5e1a28dcbc0bda2db9d55968454a0da588a9a;hpb=a0fab8b5a5e691130d39e4075bbaf70c957891e3;p=jabaws.git diff --git a/webservices/compbio/stat/collector/StatDB.java b/webservices/compbio/stat/collector/StatDB.java index f9f5e1a..32b7fde 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; @@ -35,28 +52,28 @@ public class StatDB { static Connection conn; - private synchronized static Connection getDBConnection() - throws SQLException { + private synchronized static Connection getDBConnection() throws SQLException { 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); + } catch (ClassNotFoundException e) { + log.error(e.getMessage(), e); + } } return conn; } + public StatDB() throws SQLException { this.conn = getDBConnection(); } @@ -89,11 +106,8 @@ public class StatDB { * @throws SQLException */ private void createStatTable() throws SQLException { - - /* - * Creating a statement object that we can use for running various SQL - * statements commands against the database. - */ + // Creating a statement object that we can use for running various SQL + // statements commands against the database. Statement s = conn.createStatement(); String create = "create table exec_stat(" + "number INT GENERATED ALWAYS AS IDENTITY," @@ -177,7 +191,6 @@ public class StatDB { if (exist) { date = res.getDate(1); } - res.close(); st.close(); return date;