日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

Ibatis ISqlMapper工廠類案例

系統 1830 0

namespace Model
{
public class MapperFactory
{
//聲明一個ISqlMapper接口類型的數據映射器 _mapper,其初始值為null
private static volatile ISqlMapper _mapper = null;
//private static log4net.Appender.AdoNetAppender adoApd = null;

static MapperFactory()
{
RefreshMapperSetting();
}

/// <summary>
/// 監視變化,并提供變化后的處理方法
/// </summary>
/// <param name="obj"></param>
protected static void Configure(object obj)
{
//將數據映射器初始值置空
_mapper = null;
}

/// <summary>
/// 定義InitMapper方法-用于創建sql數據映射器
/// </summary>
protected static void InitMapper()
{
RefreshMapperSetting();
}

public static void RefreshMapperSetting()
{
//調用委托ConfigureHandler,創建委托變量handler
//用于SqlMap.config改變后的處理方法
ConfigureHandler handler = new ConfigureHandler(Configure);

//新建一個DomSqlMapBuilder類的實例builder
//此變量用于配置和監視SqlMap.config的變化
DomSqlMapBuilder builder = new DomSqlMapBuilder();

//加入程序中自定義的鍵值對
//你可以在配置監視之前加上自己的一些鍵值對內容
NameValueCollection nvcProperties = new NameValueCollection();

nvcProperties.Add("DataSource", "PACTERA_GZF-PC");
nvcProperties.Add("DataBase", "TestOne");
nvcProperties.Add("UserName", "sa");
nvcProperties.Add("Password", "sa");
nvcProperties.Add("Timeout", "60");
builder.Properties = nvcProperties;

//啟用在配置之前的檢查
builder.ValidateSqlMapConfig = true;

//使用builder的ConfigureAndWatch生成一個ISqlMapper類型的數據映射器
_mapper = builder.ConfigureAndWatch("SqlMap.config", handler);

}

/// <summary>
/// 定義一個返回值為接口類型的方法Instance,用于實現sqlMapper實例化
/// </summary>
/// <returns></returns>
public static ISqlMapper Instance()
{
if (_mapper == null)
{
lock (typeof(SqlMapper))
{
if (_mapper == null) // double-check
{
//引用InitMapper,創建sqlMapper實例
InitMapper();
}
}
}

return _mapper;
}

/// <summary>
/// 定義一個Get方法,返回_mapper
/// </summary>
/// <returns></returns>
public static ISqlMapper Get()
{
return Instance();
}
}
}

Ibatis ISqlMapper工廠類案例


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 晴隆县| 米泉市| 泰和县| 夹江县| 高密市| 武隆县| 镇江市| 湖州市| 罗定市| 庆城县| 吉隆县| 玉树县| 巩留县| 吉木乃县| 深泽县| 湟中县| 河源市| 绥滨县| 家居| 益阳市| 瓦房店市| 习水县| 凌海市| 神木县| 宝应县| 古丈县| 洪洞县| 南乐县| 高台县| 屏南县| 宁南县| 临夏县| 宁明县| 广汉市| 金塔县| 淅川县| 五大连池市| 榆林市| 上犹县| 基隆市| 彭阳县|