Get the App
SLTechnology News&Howtos  ›  Development  › 

How to parse iBATIS.NET multi-database support

Shulou Source: shulou.com Published: 2022-06-02 22:28:31 09月24日 Update

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:

< 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.

Tags: Data database support help code documentation different content just just more good interest example guy partner file article method introduction Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia MariaDB Apple OPPO Reno Microsoft