1 package org.jahia.tools.db; 2 3 4 9 10 11 import java.util.*; 12 import java.sql.*; 13 14 15 22 public class AddressBookDBServices 23 { 24 private static AddressBookDBServices m_Instance = null; 25 private ConnectionPool m_ConnPool = null; 26 27 private static String m_DB_DRIVER; 29 private static String m_DB_URL; 30 private static String m_DB_USERNAME; 31 private static String m_DB_PASSWORD; 32 private static int m_DB_INITIALCONNECTIONS; 33 private static int m_DB_MAXCONNECTIONS; 34 35 36 39 protected AddressBookDBServices() 40 { 41 try { 42 m_ConnPool = new ConnectionPool( m_DB_DRIVER, m_DB_URL, m_DB_USERNAME, m_DB_PASSWORD, m_DB_INITIALCONNECTIONS, m_DB_MAXCONNECTIONS, true ); 43 } catch (SQLException se) { 44 System.out.println("Error in creation connectionPool : " + se.getMessage() + "\n" ); 45 } 46 } 47 48 60 public static AddressBookDBServices getInstance(String db_Driver, String db_URL, String db_Username, String db_Password, int db_InitialConnections, int db_MaxConnections) 61 { 62 if ( m_Instance == null ) 63 { 64 m_DB_DRIVER = db_Driver; 65 m_DB_URL = db_URL; 66 m_DB_USERNAME = db_Username; 67 m_DB_PASSWORD = db_Password; 68 m_DB_INITIALCONNECTIONS = db_InitialConnections; 69 m_DB_MAXCONNECTIONS = db_MaxConnections; 70 71 m_Instance = new AddressBookDBServices(); 72 } 73 return m_Instance; 74 } 75 76 77 78 86 public static AddressBookDBServices getInstance() throws SQLException 87 { 88 if ( m_Instance == null ) 89 { 90 throw new SQLException(); 91 } 92 else 93 { 94 return m_Instance; 95 } 96 } 97 98 105 public Connection getConnection() 106 throws SQLException 107 { 108 return m_ConnPool.getConnection(); 109 } 110 111 112 113 119 public void freeConnection( Connection connexion ) 120 { 121 m_ConnPool.free( connexion ); 122 } 123 124 125 } 126 | Popular Tags |