亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

ibatis中怎么加入c3p0連接池

發布時間:2021-08-11 15:34:02 來源:億速云 閱讀:114 作者:Leah 欄目:編程語言

本篇文章給大家分享的是有關ibatis中怎么加入c3p0連接池,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

首先打開iBatis的源碼包,找到com.ibatis.sqlmap.engine.datasource包,在里面新建個類,C3p0DataSourceFactory,并實現DataSourceFactory接口,里面的代碼是Java代碼
private DataSource dataSource;  

public DataSource getDataSource() {  
return dataSource;  
}  

public void initialize(Map map) {  
C3p0Configuration c3p0 = new C3p0Configuration(map);  
dataSource = c3p0.getDataSource();  

private DataSource dataSource;

public DataSource getDataSource() {
return dataSource;
}

public void initialize(Map map) {
C3p0Configuration c3p0 = new C3p0Configuration(map);
dataSource = c3p0.getDataSource();
}


在ibatis下加入c3p0連接池的下一步是到com.ibatis.common.jdbc包里,新建類C3p0Configuration,里面的代碼是。。。太長了,原來在dbcp那部分里,還有單獨加載配置文件的方法,我覺得如果連這個xml都讀不了,那別的一樣沒法讀。
Java代碼
private static final Probe PROBE = ProbeFactory.getProbe();  
private DataSource dataSource;  

/** 
* Constructor to supply a map of properties 
*  
* @param properties 
*            - the map of configuration properties 
*/ 
public C3p0Configuration(Map properties) {  
try {  
dataSource = legacyC3p0Configuration(properties);  
} catch (Exception e) {  
throw new RuntimeException(  
"Error initializing C3p0DataSourceFactory.  Cause: " + e, e);  
}  
}  

/** 
* Getter for DataSource 
*  
* @return The DataSource 
*/ 
public DataSource getDataSource() {  
return dataSource;  
}  

private boolean notEmpty(String s) {  
return s != null && s.length() > 0;  
}  

private boolean notSelfString(String s, String compareStr) {  
return !s.equalsIgnoreCase(compareStr);  
}  

private DataSource legacyC3p0Configuration(Map map) {  

ComboPooledDataSource combo = null;  

try {  
if (map.containsKey("JDBC.Driver")) {  

combo = new ComboPooledDataSource();  

String driverClass = (String) map.get("JDBC.Driver");  
String jdbcUrl = (String) map.get("JDBC.ConnectionURL");  
String user = (String) map.get("JDBC.Username");  
String password = (String) map.get("JDBC.Password");  

Class.forName(driverClass);  
combo.setDriverClass(driverClass);  
combo.setJdbcUrl(jdbcUrl);  
combo.setUser(user);  
combo.setPassword(password);  

String acquireIncrement = (String) map  
.get("Pool.acquireIncrement");  
if (notEmpty(acquireIncrement)  
&& notSelfString(acquireIncrement, "acquireIncrement"))  
combo.setAcquireIncrement(Integer  
.parseInt(acquireIncrement));  

...................... 

private static final Probe PROBE = ProbeFactory.getProbe();
private DataSource dataSource;

/**
* Constructor to supply a map of properties
*
* @param properties
*            - the map of configuration properties
*/
public C3p0Configuration(Map properties) {
try {
dataSource = legacyC3p0Configuration(properties);
} catch (Exception e) {
throw new RuntimeException(
"Error initializing C3p0DataSourceFactory.  Cause: " + e, e);
}
}

/**
* Getter for DataSource
*
* @return The DataSource
*/
public DataSource getDataSource() {
return dataSource;
}

private boolean notEmpty(String s) {
return s != null && s.length() > 0;
}

private boolean notSelfString(String s, String compareStr) {
return !s.equalsIgnoreCase(compareStr);
}

private DataSource legacyC3p0Configuration(Map map) {

ComboPooledDataSource combo = null;

try {
if (map.containsKey("JDBC.Driver")) {

combo = new ComboPooledDataSource();

String driverClass = (String) map.get("JDBC.Driver");
String jdbcUrl = (String) map.get("JDBC.ConnectionURL");
String user = (String) map.get("JDBC.Username");
String password = (String) map.get("JDBC.Password");

Class.forName(driverClass);
combo.setDriverClass(driverClass);
combo.setJdbcUrl(jdbcUrl);
combo.setUser(user);
combo.setPassword(password);

String acquireIncrement = (String) map
.get("Pool.acquireIncrement");
if (notEmpty(acquireIncrement)
&& notSelfString(acquireIncrement, "acquireIncrement"))
combo.setAcquireIncrement(Integer
.parseInt(acquireIncrement));

......................


***在com.ibatis.sqlmap.engine.config包里,找到SqlMapConfiguration,在里面找到,加上C3P0就可以實現在ibatis下加入c3p0連接池了
Java代碼
// DATA SOURCE ALIASES  
typeHandlerFactory.putTypeAlias("SIMPLE", SimpleDataSourceFactory.class.getName());  
typeHandlerFactory.putTypeAlias("DBCP", DbcpDataSourceFactory.class.getName());  
typeHandlerFactory.putTypeAlias("C3P0", C3p0DataSourceFactory.class.getName());  
typeHandlerFactory.putTypeAlias("JNDI", JndiDataSourceFactory.class.getName());

以上就是ibatis中怎么加入c3p0連接池,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

兴文县| 太仓市| 若羌县| 蓬莱市| 新宁县| 梧州市| 大英县| 蒙自县| 拜城县| 昌都县| 民县| 新巴尔虎左旗| 迁安市| 新和县| 张北县| 南澳县| 东乌珠穆沁旗| 丹东市| 红河县| 佛学| 庆云县| 汉沽区| 兴国县| 赤水市| 克拉玛依市| 神池县| 盐山县| 潼关县| 崇文区| 鄂伦春自治旗| 永寿县| 宁蒗| 孙吴县| 八宿县| 台北县| 宁晋县| 合川市| 慈利县| 呼伦贝尔市| 黔东| 稻城县|