datasrcutil.java

来自「主要是航空预订系统」· Java 代码 · 共 65 行

JAVA
65
字号
package com.air.persistence;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.air.exceptions.AirException;
import com.air.util.settings.SystemSettings;

public final class DataSrcUtil
{
	private static Log log = LogFactory.getLog(DataSrcUtil.class);
	/**
	 * private constructor of DataSrcUtil, prevent instantiation
	 */
	private DataSrcUtil()
	{
	}
	private static class DataSrcUtilHolder
	{
		static final DataSrcUtil dataSrcUtil = new DataSrcUtil();
	}
	/**
	 * @return an instance of DataSrcUtil
	 */
	public static DataSrcUtil getInstance()
	{
		return DataSrcUtilHolder.dataSrcUtil;
	}
	public IsqlDataSource getDataSource() throws AirException
	{
		String datasourceclassname = SystemSettings.getInstance().getDBDataSourceClassName();
		IsqlDataSource drc = null;
		try
		{
			drc = (IsqlDataSource)getClass().getClassLoader().loadClass( datasourceclassname ).newInstance();
		}
		catch (ClassNotFoundException cnfex)
		{
			log.error("getDataSource() -- caught ClassNotFoundException: ", cnfex);
			throw new AirException( "getDataSource() -- caught ClassNotFoundException: ", cnfex );
		}
		catch( InstantiationException initex)
		{
			log.error("getDataSource() -- caught InstantiationException: ", initex);
			throw new AirException( "getDataSource() -- caught InstantiationException: ", initex );
		}
		catch( IllegalAccessException illegex)
		{
			log.error("getDataSource() -- caught IllegalAccessException: ", illegex);
			throw new AirException( "getDataSource() -- caught IllegalAccessException: ", illegex );
		}
		catch( Exception ex)
		{
			log.error("getDataSource() -- caught Exception: ", ex);
			throw new AirException( "getDataSource() -- caught Exception: ", ex );
		}
		catch( Throwable trex)
		{
			log.error("getDataSource() -- caught Throwable: ", trex);
			throw new AirException( "getDataSource() -- caught Throwable: ", trex );
		}
		return drc;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?