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

Ibatis ISqlMapper工廠類案例

系統(tǒng) 1804 0

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

static MapperFactory()
{
RefreshMapperSetting();
}

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

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

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

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

//加入程序中自定義的鍵值對(duì)
//你可以在配置監(jiān)視之前加上自己的一些鍵值對(duì)內(nèi)容
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生成一個(gè)ISqlMapper類型的數(shù)據(jù)映射器
_mapper = builder.ConfigureAndWatch("SqlMap.config", handler);

}

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

return _mapper;
}

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

Ibatis ISqlMapper工廠類案例


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

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

【本文對(duì)您有幫助就好】

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 监利县| 英吉沙县| 广东省| 延川县| 南皮县| 延安市| 黎平县| 五寨县| 黑山县| 伊金霍洛旗| 沾化县| 垦利县| 虎林市| 章丘市| 宁晋县| 景德镇市| 盐山县| 微博| 沈阳市| 砚山县| 微山县| 正定县| 沂水县| 沙雅县| 阿巴嘎旗| 潼南县| 怀安县| 广西| 随州市| 达孜县| 乐清市| 泗水县| 芦溪县| 夏津县| 凉山| 孟州市| 凤山县| 绵竹市| 大冶市| 凌海市| 安塞县|