Database.java [src/cokeyconverter] Revision: default  Date:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cokeyconverter;

import java.sql.Connection;
import java.sql.SQLException;
import org.apache.tomcat.jdbc.pool.PoolProperties;

/**
 *
 * @author <a href="mailto:shaun.case@colostate.edu">Shaun Case</a>
 */
public class Database {

    public static synchronized Connection getConnection(String connectString, String driverName) throws SQLException {
        Connection ret_val = null;
        PoolProperties p = new PoolProperties();
        p.setUrl(connectString);
        p.setDefaultReadOnly(true);
        p.setDefaultAutoCommit(false);
        p.setDriverClassName(driverName);
        p.setJmxEnabled(false);
        p.setTestOnBorrow(true);
        p.setValidationQuery("SELECT 1");
        p.setTestOnReturn(false);
        p.setValidationInterval(30000);
        p.setTimeBetweenEvictionRunsMillis(30000);
        p.setMaxWait(300000);
        p.setRemoveAbandonedTimeout(300);  //Experimentally find an optimal value for this...
        p.setRemoveAbandoned(true);
        p.setJmxEnabled(false);
        p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"
                + "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer;"
                + "org.apache.tomcat.jdbc.pool.interceptor.ResetAbandonedTimer");   

        ret_val = new org.apache.tomcat.jdbc.pool.DataSource(p).getConnection();

        return ret_val;
    }

}