?? connpoolhandler.java~19~
字號:
/*****************************************************************************
* (C) Copyright 2004 。
* 保留對所有使用、復(fù)制、修改和發(fā)布整個軟件和相關(guān)文檔的權(quán)利。
* 本計算機程序受著作權(quán)法和國際公約的保護,未經(jīng)授權(quán)擅自復(fù)制或
* 傳播本程序的全部或部分,可能受到嚴(yán)厲的民事和刑事制裁,并
* 在法律允許的范圍內(nèi)受到最大可能的起訴。
*/
/*****************************************************************************
* @作者:Golden Peng
* @版本: 1.0
* @時間: 2002-10-08
*/
/*****************************************************************************
* 修改記錄清單
* 修改人 :
* 修改記錄:
* 修改時間:
* 修改描述:
*
*/
package com.corp.bisc.ebiz.base;
/**
* Title:
* ConnPoolHandler 類封裝了connection pool的概念,它向開發(fā)者提供了獲取connection的方法,而不必關(guān)心其實現(xiàn)。
* 該類不可手工創(chuàng)建,而應(yīng)該通過ConnPoolHandler.getHandle()獲取。該類的實例,會自動保證只有一個,從而可以
* 提高效率。
* Copyright: Copyright (c) 2001
* Company:
* @author Li Xiang
* @version 1.0
*/
import java.util.*;
import javax.sql.*;
import java.sql.*;
import org.w3c.dom.*;
import com.corp.bisc.ebiz.util.*;
import com.corp.bisc.ebiz.exception.*;
public class ConnPoolHandler extends ObjectBase
{
private String defaultDataSourceName;
private DBConnectionManager conMgr=null;
/**
* ConnPoolHandler 構(gòu)造函數(shù)。
*/
public ConnPoolHandler()
{
super();
}
/**
* 功能描述:釋放系統(tǒng)默認的數(shù)據(jù)庫連接
* @param conn
*/
public void closeConnection(Connection conn)
{
try{
conMgr.freeConnection(defaultDataSourceName,conn) ;
}catch(Exception ex)
{
log.error("釋放數(shù)據(jù)庫連接錯誤");
}
}
/**
* 功能描述:釋放數(shù)據(jù)庫連接,針對連接名稱sDsName
* @param sDsName
* @param conn
*/
public void closeConnection(String sDsName,Connection conn)
{
try{
if(sDsName==null || sDsName.length()==0) sDsName=defaultDataSourceName;
conMgr.freeConnection(sDsName,conn) ;
}catch(Exception ex)
{
log.error("釋放數(shù)據(jù)庫連接錯誤");
}
}
/**
* 功能描述:釋放數(shù)據(jù)庫中全部數(shù)據(jù)庫連接
*/
public void releaseConnection()
{
conMgr.release() ;
}
/**
*功能描述:取系統(tǒng)配置中默認的數(shù)據(jù)庫連接
* @return
* @throws PortalException
*/
public Connection getConnection() throws PortalException
{
Connection conn = conMgr.getConnection(defaultDataSourceName);
return conn;
}
/**
* 功能描述:根據(jù)連接名稱取數(shù)據(jù)庫連接
* @param sDSName
* @return
* @throws PortalException
*/
public Connection getConnection(String sDsName) throws PortalException
{
if(sDsName==null || sDsName.length()==0) sDsName=defaultDataSourceName;
Connection conn =conMgr.getConnection(sDsName) ;
return conn;
}
/**
* 初始化實例。該方法只會被WebPortalServlet調(diào)用一次
* @return void
*/
/**
* 功能描述:初始化實例。該方法只會被WebPortalServlet調(diào)用一次
* @param aNode 針對PortalConfig中的<ServiceManager>
* <ServiceProvider name="DB" >
* <init><init>
* <driver name="">
* <database name="" user="" password="">
* @throws InvalidConfigException
*/
public void init(Node aNode) throws InvalidConfigException
{
Node initNode = XMLUtil.selectSingleNode2(aNode , "init");
Hashtable props = XMLToHashtable(initNode);
Vector vtSource = XMLUtil.selectNodes2(aNode, "database");
Vector vtDriver = XMLUtil.selectNodes2(aNode, "driver");
DSConfig dsConfig;
ArrayList dsConfigList=new ArrayList();
ArrayList driverNameList=new ArrayList();
for (int i = 0; i < vtSource.size(); i++)
{
Element aSource = (Element)vtSource.elementAt(i);
dsConfig = new DSConfig();
dsConfig.name = aSource.getAttribute("name");
dsConfig.user = aSource.getAttribute("userid");
dsConfig.password = aSource.getAttribute("password");
dsConfig.URL = aSource.getAttribute("url");
dsConfig.autoCommit = "true".equals(aSource.getAttribute("autocommit"));
dsConfig.maxConn =Integer.parseInt(aSource.getAttribute("maxconn"));
String defaultText = aSource.getAttribute("default");
if (defaultText != null)
{
if (defaultText.equals("true"))
defaultDataSourceName = dsConfig.name;
else if (!defaultText.equals("false"))
throw new InvalidConfigException("ServiceManager/ServiceProvider[@name=DB]/database[@name=" + defaultText + ']');
}
dsConfigList.add(dsConfig);
}
for (int i = 0; i < vtDriver.size(); i++)
{
Element aSource = (Element)vtDriver.elementAt(i);
String driverName;
driverName = aSource.getAttribute("name");
driverNameList.add(driverName);
}
//建立數(shù)據(jù)庫連接實例針對PortalConfig.xml類型
conMgr=DBConnectionManager.getInstance(driverNameList,dsConfigList) ;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -