Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/sbugs/logic/ConnectionPool.java


1   /*
2    * This program is free software; you can redistribute it and/or
3    * modify it under the terms of the GNU General Public License
4    * as published by the Free Software Foundation;  version 2 only.
5     *
6    * This program is distributed in the hope that it will be useful,
7    * but WITHOUT ANY WARRANTY; without even the implied warranty of
8    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9    * GNU General Public License for more details.
10   *
11   * You should have received a copy of the GNU General Public License
12   * along with this program; if not, write to the Free Software
13   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
14   */
15  package org.sbugs.logic;
16  
17  import java.util.*;
18  import java.sql.*;
19  import javax.sql.*;
20  
21  import com.codestudio.sql.PoolMan;
22  
23  /**
24  For now, we don't actually pool connections - we'll implement it later
25  when we actually need the peformance boost.
26  */
27  public class ConnectionPool
28  {
29    protected static ConnectionPool instance = new ConnectionPool();
30    
31    protected ResourceBundle jdbcProps;
32  
33      private DataSource source;
34    
35    protected ConnectionPool()
36    {
37      init();
38         }
39    
40    public static ConnectionPool getInstance() { return instance; }
41    
42    protected void init()
43    {
44      try
45      {
46        jdbcProps = ResourceBundle.getBundle( "org.sbugs.database" );
47      }
48      catch( MissingResourceException mre )
49      {
50        System.out.println( "[Con Pool]:Could not load database properties" );
51        mre.printStackTrace();
52      }
53    }
54    
55    public Connection getConnection() throws SQLException
56    {
57        DataSource ds = getDataSource();
58        return ds.getConnection();
59    }
60  
61      private DataSource getDataSource() throws SQLException
62      {
63    if( source == null )
64        {
65      source = PoolMan.findDataSource( jdbcProps.getString( "pool.jndiName" )  );
66        }
67    return source;
68      }
69  }