1 6 7 package org.jfox.jdbc.datasource; 8 9 import java.sql.Connection ; 10 import java.sql.DriverManager ; 11 12 import org.jfox.pool.PoolableObject; 13 import org.jfox.pool.SimpleObjectFactory; 14 15 18 19 public class ConnectionFactory extends SimpleObjectFactory { 20 private String dbDriver = null; private String dbURL = null; private String user = null; private String password = null; 25 public ConnectionFactory(Class classType, String dbDriver, String dbURL, String user, String password) throws Exception { 26 super(classType); 27 this.dbDriver = dbDriver; 28 this.dbURL = dbURL; 29 this.user = user; 30 this.password = password; 31 Class.forName(this.dbDriver); 32 } 33 34 public PoolableObject makeObject() throws Exception { 35 PoolableConnection pconn = (PoolableConnection) super.makeObject(); 36 Connection conn = DriverManager.getConnection(dbURL, user, password); 37 pconn.setConnection(conn); 38 return pconn; 39 } 40 41 public void destroyObject(PoolableObject object) throws Exception { 42 if(object instanceof PoolableConnection) { 43 ((PoolableConnection) object).getConnection().close(); 44 } 45 super.destroyObject(object); 46 } 47 48 public static void main(String [] args) { 49 50 } 51 } | Popular Tags |