📄 connpoolhandler.java~26~
字号:
/*****************************************************************************
* (C) Copyright 2004 。
* 保留对所有使用、复制、修改和发布整个软件和相关文档的权利。
* 本计算机程序受著作权法和国际公约的保护,未经授权擅自复制或
* 传播本程序的全部或部分,可能受到严厉的民事和刑事制裁,并
* 在法律允许的范围内受到最大可能的起诉。
*/
/*****************************************************************************
* @作者:Golden Peng
* @版本: 1.0
* @时间: 2002-10-08
*/
/*****************************************************************************
* 修改记录清单
* 修改人 :
* 修改记录:
* 修改时间:
* 修改描述:
*
*/
package com.corp.bisc.ebiz.base;
/**
* Title:
* ConnPoolHandler 类封装了connection pool的概念,它向开发者提供了获取connection的方法,而不必关心其实现。
* 该类不可手工创建,而应该通过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 构造函数。
*/
public ConnPoolHandler()
{
super();
}
/**
* 功能描述:释放系统默认的数据库连接
* @param conn
*/
public void closeConnection(Connection conn)
{
try{
conMgr.freeConnection(defaultDataSourceName,conn) ;
}catch(Exception ex)
{
log.error("释放数据库连接错误");
}
}
/**
* 功能描述:释放数据库连接,针对连接名称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("释放数据库连接错误");
}
}
/**
* 功能描述:释放数据库中全部数据库连接
*/
public void releaseConnection()
{
conMgr.release() ;
}
/**
*功能描述:取系统配置中默认的数据库连接
* @return
* @throws PortalException
*/
public Connection getConnection() throws PortalException
{
Connection conn = conMgr.getConnection(defaultDataSourceName);
return conn;
}
/**
* 功能描述:根据连接名称取数据库连接
* @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调用一次
* @return void
*/
/**
* 功能描述:初始化实例。该方法只会被WebPortalServlet调用一次
* @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");
System.out.println("dbxml=" + XMLUtil.Node2String(aNode)) ;
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"));
System.out.println(dsConfig.name );
System.out.println(dsConfig.user );
System.out.println(dsConfig.password );
System.out.println(dsConfig.URL );
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);
System.out.println(dsConfig.name );
System.out.println(dsConfig.user );
System.out.println(dsConfig.password );
System.out.println(dsConfig.URL );
}
for (int i = 0; i < vtDriver.size(); i++)
{
Element aSource = (Element)vtDriver.elementAt(i);
String driverName;
driverName = aSource.getAttribute("name");
driverNameList.add(driverName);
}
//建立数据库连接实例针对PortalConfig.xml类型
conMgr=DBConnectionManager.getInstance(driverNameList,dsConfigList) ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -