• Ibatis.Net各类的作用说明(三)


    一、SqlMapper类

      Ibatis中,加载、分析配置以及映射文件是在创建SqlMapper实例的时候进行的,另外对数据库的操作,也是在SqlMapper实例上调用方法来完成。在IBatis外部的程序中,创建SqlMapper的实例的方式是:

    ISqlMapper mapper = Mapper.Instance();

      在第一次调用Mapper.Instance()的时候,由DomSqlMapBuilder对象解析SqlMap.config(默认路径和命名)文件来创建SqlMapper实例,然后会缓存该mapper对象,如果程序运行过程中,修改了映射文件,那么再调用Mapper.Instance()创建SqlMapper实例时,SqlMapper会被重新加载创建。相当于一个文件缓存依赖,这个文件缓存依赖由DomSqlMapBuilder.ConfigureAndWatch方法来实现。

    如果你不希望修改了配置文件就重新加载,可以通过

    ISqlMapper mapper = builder.Configure();

    来创建实例。具体的位置写法,可以第二篇。

      IBatis.net的这个东西有个地方不好,默认是使用HttpContext作为xxx容器的。

      当非Web请求线程调用时,如Timer调用时会报如下错误:

    ibatis.net:WebSessionStore: Could not obtain reference to HttpContext

      这个问题可以在创建SQLMapper的时候指定

    SqlMapper.SessionStore = new HybridWebThreadSessionStore(sqlMapper.Id);
    
    /// <summary>
    /// 初始化
    /// </summary>
    /// <param name="sqlMapperPath"></param>
    public void InitMapper(string sqlMapperPath)
    {
      ConfigureHandler handler = new ConfigureHandler(Configure);
      DomSqlMapBuilder builder = new DomSqlMapBuilder();
      _mapper = builder.ConfigureAndWatch(sqlMapperPath, handler);
      _mapper.SessionStore = new IBatisNet.DataMapper.SessionStore.HybridWebThreadSessionStore(_mapper.Id);
    }
      就可以解决问题。
      详细解释见:http://www.iloveher.cn/ibatis/hybridwebthreadsessionstore.html
  • 相关阅读:
    微信小程序用setData修改数组或对象中的一个属性值,超好用,最简单的实现方法,不容错过!大神们 都 在 看 的方法!!!
    pythonchallenge1
    pythonchallenge4
    pythonchallenge7
    pythonchallenge9
    pythonchallenge8
    pythonchallenge2
    pythonchallenge0
    递归排序
    pythonchallenge3
  • 原文地址:https://www.cnblogs.com/kissdodog/p/3294549.html
Copyright © 2020-2023  润新知