2 * Permission is hereby granted, free of charge, to any person obtaining a
3 * copy of this software and associated documentation files (the "Software"),
4 * to deal in the Software without restriction, including without limitation
5 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
6 * and/or sell copies of the Software, and to permit persons to whom the
7 * Software is furnished to do so, subject to the following conditions:
9 * The above copyright notice and this permission notice shall be included in
10 * all copies or substantial portions of the Software.
11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
14 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 package net
.bionicmessage
.utils
;
21 import java
.util
.Hashtable
;
22 import java
.sql
.Connection
;
23 import java
.sql
.SQLException
;
26 * A 'factory' singleton-type thingy that ensures only ONE connection to a JDBC
30 public class JDBCConnectionFactory
{
32 private static JDBCConnectionFactory instance
=
34 private static Hashtable
<String
, Connection
> connectionTable
= null;
36 private JDBCConnectionFactory() {
37 connectionTable
= new Hashtable();
40 public static JDBCConnectionFactory
getInstance() {
41 if (instance
== null) {
42 return new JDBCConnectionFactory();
47 public static Connection
getConnection(String jdbcID
) throws SQLException
{
48 if (connectionTable
.get(jdbcID
) != null) {
49 return connectionTable
.get(jdbcID
);
52 Connection conn
= java
.sql
.DriverManager
.getConnection(jdbcID
);
53 connectionTable
.put(jdbcID
, conn
);
57 public static void removeConnection(String jdbcID
) {
58 connectionTable
.remove(jdbcID
);
61 public static boolean doesConnectionExist(String jdbcID
) {
62 if (connectionTable
.get(jdbcID
) != null) {