zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    cf 535 A. Tavas and Nafas
    codeforces 534 A. Exam
    hust新人赛模拟 20150407 H
    hust新人赛模拟20150407 F
    hust新人赛模拟20150407 C
    hust新人赛模拟20150407 A
    [dp专题]hdu 1160 FatMouse's Speed
    [dp专题]hdu 1260 tickets
    [dp专题]G免费馅饼
    迷宫问题(bfs+记录路径)
  • 原文地址:https://www.cnblogs.com/kissdodog/p/3294549.html
Copyright © 2011-2022 走看看