??????????????????????????????????????????????????JDBC???????????????????URL???????????????Щ?????????????????????????????????嶨?????£?

public class ConnectionParam implements Serializable
{
private String driver;    //?????????????
private String url;     //?????????URL
private String user;     //??????????
private String password;    //?????????
private int minConnection = 0;  //???????????
private int maxConnection = 50;  //????????
private long timeoutValue = 600000;//????????????
private long waitTime = 30000;  //??????????????п??????????????

????????????????????ConnectionFactory???????????????????????????????????????????????????????????????????????????????????£?

/**
* ?????????????????????????????????????????????????
* @author liusoft
*/
public class ConnectionFactory
{
//?ù??????????????????????????????????
static Hashtable connectionPools = null;
static{
connectionPools = new Hashtable(2??0.75F);
}
/**
* ???????????л?????????????????????
* @param dataSource ????????????????
* @return DataSource ????????????????????
* @throws NameNotFoundException ????????????????
*/
public static DataSource lookup(String dataSource)
throws NameNotFoundException
{
Object ds = null;
ds = connectionPools.get(dataSource);
if(ds == null || !(ds instanceof DataSource))
throw new NameNotFoundException(dataSource);
return (DataSource)ds;
}
/**
* ????????????????????????e?????????????????????
* @param name  ?????????????
* @param param ?????????ò??????????????ConnectionParam
* @return DataSource ????????????????????
* @throws NameAlreadyBoundException ???????name??????????????
* @throws ClassNotFoundException  ?????????????????е???????????
* @throws IllegalAccessException  ??????????е???????????????
* @throws InstantiationException  ??????????????????
* @throws SQLException    ?????????????????????
*/
public static DataSource bind(String name?? ConnectionParam param)
throws NameAlreadyBoundException??ClassNotFoundException??
IllegalAccessException??InstantiationException??SQLException
{
DataSourceImpl source = null;
try{
lookup(name);
throw new NameAlreadyBoundException(name);
}catch(NameNotFoundException e){
source = new DataSourceImpl(param);
source.initConnection();
connectionPools.put(name?? source);
}
return source;
}
/**
* ???°???????????
* @param name  ?????????????
* @param param ?????????ò??????????????ConnectionParam
* @return DataSource ????????????????????
* @throws NameAlreadyBoundException ???????name??????????????
* @throws ClassNotFoundException  ?????????????????е???????????
* @throws IllegalAccessException  ??????????е???????????????
* @throws InstantiationException  ??????????????????
* @throws SQLException    ?????????????????????
*/
public static DataSource rebind(String name?? ConnectionParam param)
throws NameAlreadyBoundException??ClassNotFoundException??
IllegalAccessException??InstantiationException??SQLException
{
try{
unbind(name);
}catch(Exception e){}
return bind(name?? param);
}
/**
* ???????????????????
* @param name
* @throws NameNotFoundException
*/
public static void unbind(String name) throws NameNotFoundException
{
DataSource dataSource = lookup(name);
if(dataSource instanceof DataSourceImpl){
DataSourceImpl dsi = (DataSourceImpl)dataSource;
try{
dsi.stop();
dsi.close();
}catch(Exception e){
}finally{
dsi = null;
}
}
connectionPools.remove(name);
}
}