1 43 package net.jforum; 44 45 import java.sql.Connection ; 46 47 import net.jforum.exceptions.DatabaseException; 48 import net.jforum.util.preferences.ConfigKeys; 49 import net.jforum.util.preferences.SystemGlobals; 50 51 import com.mchange.v2.c3p0.ComboPooledDataSource; 52 import com.mchange.v2.c3p0.DataSources; 53 54 public class C3P0PooledConnection extends DBConnection 55 { 56 private ComboPooledDataSource ds; 57 58 62 public void init() throws Exception 63 { 64 this.ds = new ComboPooledDataSource(); 65 this.ds.setDriverClass(SystemGlobals.getValue(ConfigKeys.DATABASE_CONNECTION_DRIVER)); 66 this.ds.setJdbcUrl(SystemGlobals.getValue(ConfigKeys.DATABASE_CONNECTION_STRING)); 67 this.ds.setMinPoolSize(SystemGlobals.getIntValue(ConfigKeys.DATABASE_POOL_MIN)); 68 this.ds.setMaxPoolSize(SystemGlobals.getIntValue(ConfigKeys.DATABASE_POOL_MAX)); 69 this.ds.setIdleConnectionTestPeriod(SystemGlobals.getIntValue(ConfigKeys.DATABASE_PING_DELAY)); 70 } 71 72 75 public Connection getConnection() 76 { 77 try { 78 return this.ds.getConnection(); 79 } 80 catch (Exception e) { 81 throw new DatabaseException(e); 82 } 83 } 84 85 88 public void releaseConnection(Connection conn) 89 { 90 try { 91 conn.close(); 92 } 93 catch (Exception e) { 94 e.printStackTrace(); 95 } 96 } 97 98 101 public void realReleaseAllConnections() throws Exception 102 { 103 DataSources.destroy(this.ds); 104 } 105 } 106 | Popular Tags |