//
// This file is part of the OpenNMS(R) Application.
//
// OpenNMS(R) is Copyright (C) 2006 The OpenNMS Group, Inc.  All rights reserved.
// OpenNMS(R) is a derivative work, containing both original code, included code and modified
// code that was published under the GNU General Public License. Copyrights for modified
// and included code are below.
//
// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
//
// Original code base Copyright (C) 1999-2001 Oculan Corp.  All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program 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
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// For more information contact:
//      OpenNMS Licensing       <license@opennms.org>
//      http://www.opennms.org/
//      http://www.opennms.com/
//
package org.opennms.netmgt.dao.db;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.sql.DataSource;

public class SimpleDataSource implements DataSource {
    private String m_driver;
    private String m_url;
    private String m_user;
    private String m_password;

    public SimpleDataSource(String driver, String url,
                               String user, String password) throws ClassNotFoundException {
        m_driver = driver;
        m_url = url;
        m_user = user;
        m_password = password;
        
        Class.forName(m_driver);
    }

    public Connection getConnection() throws SQLException {
        return DriverManager.getConnection(m_url, m_user, m_password);
    }

    public Connection getConnection(String username, String password) throws SQLException {
        throw new UnsupportedOperationException("getConnection(String, String) not implemented");
    }

    public PrintWriter getLogWriter() throws SQLException {
        throw new UnsupportedOperationException("getLogWriter() not implemented");
    }

    public int getLoginTimeout() throws SQLException {
        throw new UnsupportedOperationException("getLoginTimeout() not implemented");
    }

    public void setLogWriter(PrintWriter out) throws SQLException {
        throw new UnsupportedOperationException("setLogWriter(PrintWriter) not implemented");
    }

    public void setLoginTimeout(int seconds) throws SQLException {
        throw new UnsupportedOperationException("setLoginTimeout(int) not implemented");
    }

    public <T> T unwrap(Class<T> iface) throws SQLException {
        return null;  //TODO
    }

    public boolean isWrapperFor(Class<?> iface) throws SQLException {
        return false;  //TODO
    }
}

@@ -417,24 +417,141 @@
 up, Inc.%0A//%0A
+// Modifications:%0A//%0A// 2007 Jun 10: Support login timeout (in hopefully a not-too-hackish way). - dj@opennms.org%0A//%0A
 // Original 
@@ -619,16 +619,16 @@
 served.%0A
-
 //%0A// Th
@@ -1843,16 +1843,54 @@
 assword;
+%0A    private Integer m_timeout = null;
 %0A%0A    pu
@@ -2234,32 +2234,69 @@
  SQLException %7B%0A
+        if (m_timeout == null) %7B%0A    
         return D
@@ -2350,16 +2350,325 @@
 sword);%0A
+        %7D else %7B%0A            int oldTimeout = DriverManager.getLoginTimeout();%0A            DriverManager.setLoginTimeout(m_timeout);%0A            Connection conn = DriverManager.getConnection(m_url, m_user, m_password);%0A            DriverManager.setLoginTimeout(oldTimeout);%0A            return conn;%0A        %7D%0A
     %7D%0A%0A 
@@ -3080,84 +3080,49 @@
     
-throw new UnsupportedOperationException(%22getLoginTimeout() not implemented%22)
+return m_timeout == null ? -1 : m_timeout
 ;%0A  
@@ -3374,87 +3374,27 @@
     
-throw new UnsupportedOperationException(%22setLoginTimeout(int) not implemented%22)
+m_timeout = seconds
 ;%0A  

Support login timeout (in hopefully a not-too-hackish way).