In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces you how to analyze iBATIS.NET multi-database support, the content is very detailed, interested friends can refer to, hope to be helpful to you.
When it comes to iBATIS.NET multi-database support, let's first take a look at its own help documentation, which introduces multi-database support in iBATIS.NET help documents, but did not write the full code, and later looked at its source code, combined with help documentation, found a solution, in fact, the truth is to achieve another Mapper.
IBATIS.NET supports multiple database instances such as AnthorMapper:
Apache Notice#region Apache Notice# endregion using IBatisNet.Common.Utilities; using IBatisNet.DataMapper; using IBatisNet.DataMapper.Configuration Namespace IBatisNet.DataMapper {/ * * / < summary > / A singleton class to access the default SqlMapper defined by the SqlMap.Config / < / summary > public sealed class AnthorMapper {Fields#region Fields private static volatile ISqlMapper _ mapper = null # endregion / * * / < summary > / < / summary > / / < param name= "obj" > < / param > public static void Configure (object obj) {_ mapper = null } / * * / < summary > / Init the 'default' SqlMapper defined by the SqlMap.Config file. / / < / summary > public static void InitMapper () {ConfigureHandler handler = new ConfigureHandler (Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder (); _ mapper = builder.ConfigureAndWatch ("AnthorMap.config", handler) } / * * / < summary > / Get the instance of the SqlMapper defined by the SqlMap.Config file. / / < / summary > / / < returns > A SqlMapper initalized via the SqlMap.Config file. < / returns > public static ISqlMapper Instance () {if (_ mapper = = null) {lock (typeof (SqlMapper)) { If (_ mapper = = null) / / double-check {InitMapper () } return _ mapper;} / * * / < summary > / Get the instance of the SqlMapper defined by the SqlMap.Config file. (Convenience form of Instance method.) / / < / summary > / / < returns > A SqlMapper initalized via the SqlMap.Config file. < / returns > public static ISqlMapper Get () {return Instance ();}
The above code simply modifies the code of Mapper in iBATIS.NET, changing _ mapper = builder.ConfigureAndWatch (handler) to _ mapper = builder.ConfigureAndWatch ("AnthorMap.config", handler), which is based on another AnthorMap.config file to generate SqlMapper.
AnthorMap.config is the same as the default SqlMap.config, except that the settings vary according to your data. The test AnthorMap.config is as follows:
xml version= "1.0" encoding= "utf-8"? > < sqlMapConfig xmlns= "http://ibatis.apache.org/dataMapper" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" > < settings > < setting useStatementNamespaces= "true" / > < / settings > < providers resource= "ServerConfig/providers.config" / > < !-- Database connection information-> < database > < provider name= "sqlServer2.0" / > < dataSource name= "CrmSystem" connectionString= "server=. Database=TestDB;uid=sa;pwd= "/ > < / database > < sqlMaps > < sqlMap embedded=" Test.Domain.Weather.xml,Test.Domain "/ > < / sqlMaps > < / sqlMapConfig >
IBATIS.NET multi-database support uses AntherMapper to create ISqlMapper. As follows:
Public IList < Weather > GetWeather () {ISqlMapper map = AnthorMapper.Instance (); return map.QueryForList < Weather > ("Weather.Select", null);}
So much for iBATIS.NET multi-database support.
On how to parse iBATIS.NET multi-database support to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.