1 package org.jahia.tools.db; 2 3 import java.util.*; 4 import java.sql.*; 5 import org.jahia.tools.*; 6 7 8 12 public class DBServices 13 { 14 private static org.apache.log4j.Logger logger = 15 org.apache.log4j.Logger.getLogger(DBServices.class); 16 private static DBServices m_Instance = null; 17 private ConnectionPool m_ConnPool = null; 18 19 private static String m_DB_DRIVER; 21 private static String m_DB_URL; 22 private static String m_DB_USERNAME; 23 private static String m_DB_PASSWORD; 24 private static int m_DB_INITIALCONNECTIONS; 25 private static int m_DB_MAXCONNECTIONS; 26 27 28 31 protected DBServices() 32 { 33 try 34 { 35 m_ConnPool = new ConnectionPool( m_DB_DRIVER, m_DB_URL, m_DB_USERNAME, m_DB_PASSWORD, m_DB_INITIALCONNECTIONS, m_DB_MAXCONNECTIONS, true ); 36 } 37 catch (SQLException se) 38 { 39 logger.debug("Error in creation connectionPool : " + se.getMessage() + "\n" ); 40 logger.error("FaqDBService: Error in creation connectionPool", se); 41 } 42 } 43 44 45 48 public static DBServices getInstance(String db_Driver, String db_URL, String db_Username, String db_Password, int db_InitialConnections, int db_MaxConnections) 49 { 50 if ( m_Instance == null ) 51 { 52 m_DB_DRIVER = db_Driver; 53 m_DB_URL = db_URL; 54 m_DB_USERNAME = db_Username; 55 m_DB_PASSWORD = db_Password; 56 m_DB_INITIALCONNECTIONS = db_InitialConnections; 57 m_DB_MAXCONNECTIONS = db_MaxConnections; 58 m_Instance = new DBServices(); 59 logger.debug("DBService: getInstance: m_instance initialised " ); 60 } 61 return m_Instance; 62 } 63 64 65 66 69 public static DBServices getInstance() throws SQLException 70 { 71 if ( m_Instance == null ) 72 { 73 System.out.println("Error m_Instance null !!!!!" ); 74 throw new SQLException(); 75 } 76 else 77 { 78 return m_Instance; 79 } 80 } 81 82 86 public Connection getConnection() 87 throws SQLException 88 { 89 return m_ConnPool.getConnection(); 90 } 91 92 93 94 97 public void freeConnection( Connection connexion ) 98 { 99 m_ConnPool.free( connexion ); 100 } 101 102 105 public void closeAllConnection(){ 106 m_ConnPool.closeAllConnections(); 107 } 108 } 109 | Popular Tags |