?? dbpool.java
字號(hào):
package common.db;
import java.io.File;
import java.sql.Connection;
import java.sql.Statement;
import java.util.Properties;
/**
* DBPool主要是為了解耦使用從各種連接池或hibernate的session
* 獲取JDBC Connection的問(wèn)題
* @author lixu
*
*/
public abstract class DBPool {
/**********配置文件常量定義***********************/
public static final String URI ="db.uri";
public static final String USER ="db.user";
public static final String PASSWORD ="db.password";
public static final String DRIVER ="db.driver";
public static final String ALIAS ="db.alias";
public static final String MAX_CONN ="db.conn.max";
public static final String MIN_CONN ="db.conn.min";
public static final String TEST_SQL ="db.test.sql";
private static DBPool instance;
/**
* 獲取DBPool實(shí)例
* 僅從系統(tǒng)上下文中檢查common.db.DBPool的設(shè)置
* 獲取類名后動(dòng)態(tài)加載
* @return
*/
public static DBPool newInstance()
{
String classFullName = System.getProperty("common.db.DBPool", "common.db.ProxoolDBPoolProgrammatically");
try
{
if(instance == null)
instance = (DBPool)Class.forName(classFullName).newInstance();
}
catch(Exception e)
{
System.err.println("DBPool.newInstance error:"+e.getMessage());
throw new RuntimeException(e);
}
return instance;
}
/**
* 通過(guò)XML配置文件初始化連接池
* @param xml
* @throws Exception
*/
public void init(File xml) throws Exception
{
throw new UnsupportedOperationException("Unsupport init with xml file!");
}
/**
* 通過(guò)Properties配置文件初始化連接池
* @param propFile
* @throws Exception
*/
public void init(String propFile) throws Exception
{
throw new UnsupportedOperationException("Unsupport init with xml file!");
}
/**
* 通過(guò)屬性列表初始化連接池
* @param props
* @throws Exception
*/
public void init(Properties props) throws Exception
{
throw new UnsupportedOperationException("Unsupport init with Properties!");
}
/**
* 創(chuàng)建一個(gè)JDBC Connection
* @return
* @throws Exception
*/
public abstract Connection open() throws Exception;
/**
* 銷毀整個(gè)連接池
* @param reason 銷毀的原因
*/
public abstract void destroyPool(String reason);
/**
* 關(guān)閉一個(gè)連接
* @param conn
*/
public void close(Connection conn)
{
try
{
if(conn!=null)
conn.close();
}
catch(Exception e)
{
e.printStackTrace(System.err);
}
}
/**
* 關(guān)閉游標(biāo)工具
* @param state
*/
public static void close(Statement state)
{
try
{
if(state!=null)
state.close();
}
catch(Exception e)
{
e.printStackTrace(System.err);
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -