1 23 24 package org.dbforms.conprovider; 25 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 import java.sql.Connection ; 30 import java.sql.SQLException ; 31 32 33 34 41 public class ConnectionFactory { 42 43 private static ConnectionFactory instance = null; 44 45 46 private ConnectionProvider provider = null; 47 48 49 private Log cat = LogFactory.getLog(this.getClass()); 50 51 54 private ConnectionFactory() { 55 } 56 57 62 public static synchronized ConnectionFactory instance() { 63 if (instance == null) { 64 instance = new ConnectionFactory(); 65 } 66 67 return instance; 68 } 69 70 71 79 public Connection getConnection() throws SQLException { 80 return provider.getConnection(); 81 } 82 83 84 95 public Connection getConnection(int isolationLevel) 96 throws SQLException { 97 return provider.getConnection(isolationLevel); 98 } 99 100 101 108 public void setProvider(ConnectionProviderPrefs prefs) 109 throws Exception { 110 String providerClass = prefs.getConnectionProviderClass(); 111 provider = (ConnectionProvider) Class.forName(providerClass) 112 .newInstance(); 113 provider.setPrefs(prefs); 114 provider.init(); 115 116 cat.info("::setProvider - ConnectionProvider [" + providerClass 117 + "] successfully set and initialized"); 118 } 119 } 120 | Popular Tags |