自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iBATIS.NET多數(shù)據(jù)庫支持淺析

開發(fā) 后端
iBATIS.NET多數(shù)據(jù)庫支持淺析向你介紹iBATIS.NET的特性,iBATIS.NET多數(shù)據(jù)庫支持是編程人員的福音。

談到iBATIS.NET多數(shù)據(jù)庫支持我們首先來看看它本身的幫助文檔,在iBATIS.NET的幫助文檔中有介紹多數(shù)據(jù)庫支持,但是沒有寫全代碼,后來查看其源碼,并結合幫助文檔,找到了解決方法,其實道理就是另行實現(xiàn)一個Mapper.

iBATIS.NET多數(shù)據(jù)庫支持實例如AnthorMapper:

  1. Apache Notice#region Apache Notice      
  2.  
  3. #endregion      
  4.      
  5. using IBatisNet.Common.Utilities;      
  6. using IBatisNet.DataMapper;      
  7. using IBatisNet.DataMapper.Configuration;      
  8.      
  9. namespace IBatisNet.DataMapper      
  10. {      
  11.     /**//// ﹤summary﹥     
  12.     /// A singleton class to access the default SqlMapper defined by the SqlMap.Config      
  13.     /// ﹤/summary﹥     
  14.     public sealed class AnthorMapper      
  15.     {     
  16.         Fields#region Fields      
  17.         private static volatile ISqlMapper _mapper = null;     
  18.         #endregion      
  19.      
  20.         /**//// ﹤summary﹥     
  21.         ///       
  22.         /// ﹤/summary﹥     
  23.         /// ﹤param name="obj">﹤/param﹥     
  24.         public static void Configure (object obj)      
  25.         {      
  26.             _mapper = null;      
  27.         }      
  28.      
  29.         /**//// ﹤summary﹥     
  30.         /// Init the 'default' SqlMapper defined by the SqlMap.Config file.      
  31.         /// ﹤/summary﹥     
  32.         public static void InitMapper()      
  33.         {      
  34.             ConfigureHandler handler = new ConfigureHandler (Configure);      
  35.             DomSqlMapBuilder builder = new DomSqlMapBuilder();      
  36.             _mapper = builder.ConfigureAndWatch ("AnthorMap.config",handler);      }      
  37.      
  38.         /**//// ﹤summary﹥     
  39.         /// Get the instance of the SqlMapper defined by the SqlMap.Config file.      
  40.         /// ﹤/summary﹥     
  41.         /// ﹤returns>A SqlMapper initalized via the SqlMap.Config file.﹤/returns﹥     
  42.         public static ISqlMapper Instance()      
  43.         {      
  44.             if (_mapper == null)      
  45.             {      
  46.                 lock (typeof (SqlMapper))      
  47.                 {      
  48.                     if (_mapper == null// double-check      
  49.                     {         
  50.                         InitMapper();      
  51.                     }      
  52.                 }      
  53.             }      
  54.             return _mapper;      
  55.         }      
  56.               
  57.         /**//// ﹤summary﹥     
  58.         /// Get the instance of the SqlMapper defined by the SqlMap.Config file. (Convenience form of Instance method.)      
  59.         /// ﹤/summary﹥     
  60.         /// ﹤returns>A SqlMapper initalized via the SqlMap.Config file.﹤/returns﹥     
  61.         public static ISqlMapper Get()      
  62.         {      
  63.             return Instance();      
  64.         }  
  65.     }  
  66. }  

以上代碼只是修改了iBATIS.NET中的Mapper的代碼,將_mapper = builder.ConfigureAndWatch (handler);修改為_mapper = builder.ConfigureAndWatch ("AnthorMap.config",handler),就是根據(jù)另一個AnthorMap.config文件來生成SqlMapper。

AnthorMap.config和默認的SqlMap.config一樣,只是根據(jù)你的數(shù)據(jù)不同設置不同而已,測試AnthorMap.config如下如下:

  1. ﹤?xml version="1.0" encoding="utf-8"?﹥    
  2. ﹤sqlMapConfig       
  3.   xmlns="http://ibatis.apache.org/dataMapper"       
  4.   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"﹥    
  5.      
  6.   ﹤settings﹥    
  7.         ﹤setting useStatementNamespaces="true"/﹥    
  8.     ﹤/settings﹥    
  9.      
  10.   ﹤providers resource="ServerConfig/providers.config"/﹥    
  11.      
  12.   ﹤!-- Database connection information --﹥    
  13.   ﹤database﹥    
  14.     ﹤provider name="sqlServer2.0"/﹥    
  15.     ﹤dataSource name="CrmSystem" connectionString="server=.;database=TestDB;uid=sa;pwd="/﹥    
  16.   ﹤/database﹥    
  17.      
  18.     ﹤sqlMaps﹥    
  19.     ﹤sqlMap embedded="Test.Domain.Weather.xml,Test.Domain" /﹥    
  20.           
  21.      
  22.   ﹤/sqlMaps﹥    
  23.           
  24. ﹤/sqlMapConfig﹥ 

iBATIS.NET多數(shù)據(jù)庫支持之使用AntherMapper來創(chuàng)建ISqlMapper了。如下:

  1. public IList﹤Weather﹥GetWeather()      
  2. {      
  3.      ISqlMapper map = AnthorMapper.Instance();      
  4.      
  5.      return map.QueryForList﹤Weather>("Weather.Select"null);      
  6. }  

那么iBATIS.NET多數(shù)據(jù)庫支持就介紹到這里,希望這樣的介紹對你有幫助。

【編輯推薦】

  1. 動態(tài)Mapped Statement在iBATIS中應用
  2. iBATIS中添加DAO的配置淺析
  3. iBATIS DAO framework初體驗
  4. iBATIS教程之快速入門淺析
  5. iBATIS教程之like語句的寫法淺析
責任編輯:仲衡 來源: CSDN博客
相關推薦

2009-07-20 09:51:19

iBATIS.net數(shù)據(jù)庫緩存

2009-07-20 15:14:44

iBATIS.NET連

2009-07-22 09:07:01

iBATIS.NET

2009-07-20 13:22:47

iBATIS.Net日

2009-07-20 10:06:07

iBATIS.net查詢方式

2009-07-20 14:56:18

iBATIS.NET動態(tài)選擇DAO

2009-07-21 13:50:00

iBATIS.NET調(diào)

2009-07-20 13:47:08

iBATIS.NET字

2009-07-21 16:30:15

iBATIS.NET與單元測試

2009-07-16 13:50:31

ibatisResultMap

2009-07-21 17:06:35

iBATIS.NET執(zhí)

2009-07-22 14:28:52

iBATIS.NET配

2009-07-20 09:27:42

IBATIS.netDAO

2009-07-22 14:11:09

配置ibatis.neiBatis.net配

2009-07-17 17:57:20

NPetShop iBATIS.Net

2011-03-15 13:30:27

IBatis.netMySQL

2009-07-21 14:15:00

iBATIS.NET多

2009-07-20 15:27:22

Castle.DynaiBATIS.NET

2009-07-21 16:17:28

iBATIS.NET

2009-07-31 09:57:47

ASP.NET數(shù)據(jù)庫緩
點贊
收藏

51CTO技術棧公眾號