zoukankan      html  css  js  c++  java
  • 关于在IBatis中返回DataSet

    在一个邮件列表的讨论中,了解了如何在IBatis.Net中返回DataSet以及一些相关的内容

            public static DataSet QueryForDataSet(string statementName, object paramObject)
            {
                DataSet ds 
    = new DataSet();
                ISqlMapper mapper 
    = GetMapper();
                IMappedStatement statement 
    = mapper.GetMappedStatement(statementName);
                
    if (!mapper.IsSessionStarted)
                {
                    mapper.OpenConnection();
                }
                RequestScope scope 
    = statement.Statement.Sql.GetRequestScope(statement, paramObject, mapper.LocalSession);
                statement.PreparedCommand.Create(scope, mapper.LocalSession, statement.Statement, paramObject);
                mapper.LocalSession.CreateDataAdapter(scope.IDbCommand).Fill(ds);

                
    return ds;
            }


    在这个过程中,我们还可以顺便得出获得SQL语句的方法

            public static string GetSql(string statementName, object paramObject)
            {
                ISqlMapper mapper 
    = GetMapper();
                IMappedStatement statement 
    = mapper.GetMappedStatement(statementName);
                
    if (!mapper.IsSessionStarted)
                {
                    mapper.OpenConnection();
                }
                RequestScope scope 
    = statement.Statement.Sql.GetRequestScope(statement, paramObject, mapper.LocalSession);

                
    return scope.PreparedStatement.PreparedSql;
            }

    下面是我对文中内容的理解

    并不是所有地方都要OO,IBatisJava.NET实现中都支持Dictionary类型的对象.DataTable因为有了DataView的支持而较IDictionary具有一些优势.如果我们需要对数据进行额外的排序或者过滤操作,那么DataTable会更方便一些.因此像这种返回DataSet的方法会使得IBatis更加易用.

    但同时感觉,这种方法将IBatis打开了一个缺口,似乎背离了IBatis的设计初衷——创建一个优秀的“Persistence Ignorance domain model。比如现在,我们进行一次查询,获得“Plain Old CLR Objects”,看起来输入是与数据持久化相关的,而输出则完全集中在了领域模型上。

    因此,返回DataSet的方法可能会导致不好的设计,从长远来看,也模糊了IBatis的初衷和意图。


  • 相关阅读:
    微信支付授权目录填写规则
    前后端分离之vue2.0+webpack2 实战项目 -- html模板拼接
    前后端分离之vue2.0+webpack2 实战项目 -- webpack介绍
    windows下nginx的安装及使用方法入门
    抛弃vue-resource拥抱axios
    Eslint检测出的问题如何自动修复
    用webpack2.0构建vue2.0单文件组件超级详细精简实例
    SQLAlchemy 教程 —— 基础入门篇
    Linux下python2.7安装pip
    python 创建虚拟环境(virtualenv)
  • 原文地址:https://www.cnblogs.com/anderslly/p/queryfordatasetinibatis.html
Copyright © 2011-2022 走看看