using IBatisNet.Common.Exceptions;

using IBatisNet.DataAccess;
using IBatisNet.DataAccess.DaoSessionHandlers;
using IBatisNet.DataAccess.Interfaces; using IBatisNet.DataMapper;
using IBatisNet.DataMapper.Commands;
using IBatisNet.DataMapper.Configuration.ParameterMapping;
using IBatisNet.DataMapper.MappedStatements;
using IBatisNet.DataMapper.Scope; using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.Text; namespace YTO.WeiXin.Core
{
public class IbatisDaoExceptionHelper
{
// Methods
public IbatisDaoExceptionHelper()
{ }
public static string GetStatementDetail(ISqlMapper sqlMap, string statementName, object parameterObject)
{
try
{
StringBuilder builder = new StringBuilder();
StringBuilder builder2 = new StringBuilder();
MappedStatement mappedStatement = (MappedStatement)sqlMap.MappedStatements[statementName];
ISqlMapSession localSession = sqlMap.LocalSession;
RequestScope request = mappedStatement.Statement.Sql.GetRequestScope(mappedStatement, parameterObject, localSession);
IDbCommand command = new DbCommandDecorator(localSession.CreateCommand(mappedStatement.Statement.CommandType), request);
string preparedSql = request.PreparedStatement.PreparedSql;
StringCollection dbParametersName = request.PreparedStatement.DbParametersName;
IDbDataParameter[] dbParameters = request.PreparedStatement.DbParameters;
int count = dbParametersName.Count;
for (int i = ; i < count; i++)
{
IDbDataParameter parameter = dbParameters[i];
ParameterProperty mapping = request.ParameterMap.GetProperty(i);
builder.Append(parameter.ParameterName);
builder.Append("=[");
builder2.Append(parameter.ParameterName);
builder2.Append("=[");
builder.Append(mapping.PropertyName);
builder.Append(",");
IDbDataParameter dataParameter = command.CreateParameter();
request.ParameterMap.SetParameter(mapping, dataParameter, parameterObject);
if (dataParameter.Value == DBNull.Value)
{
builder.Append("null");
builder.Append("], ");
builder2.Append("System.DBNull, null");
builder2.Append("], ");
}
else
{
builder.Append(dataParameter.Value.ToString());
builder.Append("], ");
builder2.Append(dataParameter.DbType.ToString());
builder2.Append(", ");
builder2.Append(dataParameter.Value.GetType().ToString());
builder2.Append("], ");
}
}
string str2 = "Statement Id: [" + mappedStatement.Statement.Id + "] Parameters: [0]";
string str3 = "";
if (builder2.Length != )
{
str2 = "Statement Id: [" + mappedStatement.Statement.Id + "] Parameters: [" + builder.ToString(, builder.Length - ) + "]";
str3 = "Statement Id: [" + mappedStatement.Statement.Id + "] Types: [" + builder2.ToString(, builder2.Length - ) + "]";
}
return (preparedSql + Environment.NewLine + str2 + (!string.IsNullOrEmpty(str3) ? (Environment.NewLine + str3) : ""));
}
catch
{
}
return "can't get the sql error info";
} }
[Serializable]//可序列化
public class BaseSqlMapDao1 : IDao
{
protected const int PAGE_SIZE = ; protected string sqlMapNamespace; public BaseSqlMapDao1()
{ } protected string WrapStatementName(string statementName)
{
return (this.sqlMapNamespace + "." + statementName);
}
protected ISqlMapper GetLocalSqlMap()
{
SqlMapDaoSession localDaoSession = (SqlMapDaoSession)this.DaoManager.LocalDaoSession;
return localDaoSession.SqlMap;
} public IDaoManager DaoManager { get; set; }
protected object ExecuteDelete(string statementName, object parameterObject)
{
object obj2;
ISqlMapper localSqlMap = this.GetLocalSqlMap();
try
{
obj2 = localSqlMap.Delete(statementName, parameterObject);
}
catch (Exception exception)
{
string str = IbatisDaoExceptionHelper.GetStatementDetail(localSqlMap, statementName, parameterObject);
IBatisNetException exception2 = new IBatisNetException("Error executing delete '" + statementName + "'. Cause: " + exception.Message, exception);
exception2.Data.Add("sqlTrace", str);
throw exception2;
}
return obj2;
} protected object ExecuteInsert(string statementName, object parameterObject)
{
object obj2;
ISqlMapper localSqlMap = this.GetLocalSqlMap();
try
{
obj2 = localSqlMap.Insert(statementName, parameterObject);
}
catch (Exception exception)
{
string str = IbatisDaoExceptionHelper.GetStatementDetail(localSqlMap, statementName, parameterObject);
IBatisNetException exception2 = new IBatisNetException("Error executing insert '" + statementName + "'. Cause: " + exception.Message, exception);
exception2.Data.Add("sqlTrace", str);
throw exception2;
}
return obj2;
} protected int ExecuteUpdate(string statementName, object parameterObject)
{
int num;
ISqlMapper localSqlMap = this.GetLocalSqlMap();
try
{
num = localSqlMap.Update(statementName, parameterObject);
}
catch (Exception exception)
{
string str = IbatisDaoExceptionHelper.GetStatementDetail(localSqlMap, statementName, parameterObject);
IBatisNetException exception2 = new IBatisNetException("Error update '" + statementName + "'. Cause: " + exception.Message, exception);
exception2.Data.Add("sqlTrace", str);
throw exception2;
}
return num;
} protected int ExecuteUpdate(string statementName, object parameterObject)
{
int num;
ISqlMapper localSqlMap = this.GetLocalSqlMap();
try
{
num = localSqlMap.Update(statementName, parameterObject);
}
catch (Exception exception)
{
string str = IbatisDaoExceptionHelper.GetStatementDetail(localSqlMap, statementName, parameterObject);
IBatisNetException exception2 = new IBatisNetException("Error update '" + statementName + "'. Cause: " + exception.Message, exception);
exception2.Data.Add("sqlTrace", str);
throw exception2;
}
return num;
} protected IList<T> ExecuteQueryForList<T>(string statementName, object parameterObject)
{
IList<T> list;
ISqlMapper localSqlMap = this.GetLocalSqlMap();
try
{
list = localSqlMap.QueryForList<T>(statementName, parameterObject);
}
catch (Exception exception)
{
string str = IbatisDaoExceptionHelper.GetStatementDetail(localSqlMap, statementName, parameterObject);
IBatisNetException exception2 = new IBatisNetException("Error executing query '" + statementName + "' for list. Cause: " + exception.Message, exception);
exception2.Data.Add("sqlTrace", str);
throw exception2;
}
return list;
}
}
}

后台代码对iBatis配置文件中具体的sql语句的调用实现(被封装的增删改查)的更多相关文章

  1. 我来讲讲在c#中怎么进行xml文件操作吧,主要是讲解增删改查!

    我把我写的四种方法代码贴上来吧,照着写没啥问题. 注: <bookstore> <book> <Id>1</Id> <tate>2010-1 ...

  2. “造轮运动”之 ORM框架系列(一)~谈谈我在实际业务中的增删改查

    想想毕业已经快一年了,也就是大约两年以前,怀着满腔的热血正式跨入程序员的世界,那时候的自己想象着所热爱的技术生涯会是多么的丰富多彩,每天可以与大佬们坐在一起讨论解决各种牛逼的技术问题,喝着咖啡,翘着二 ...

  3. java程序设计课期中考试——数据库的增删改查和简单的js界面

    首先是设计思路,对于数据库的增删改查,我们借助Ecilipse来进行前端和后端的编写.Ecilipse是可以进行java web项目的操作的. 前端,我们选择用使用jsp,所谓的jsp就是可以嵌入其他 ...

  4. IOS9中联系人对象的使用及增删改查操作的函数封装

    之前克服重重困难把IOS9中新的类联系人搞明白了,现在把增删改查封装成了函数,如下: // // ViewController.m // IOS9中联系人CNContact的使用 // // Crea ...

  5. SQLite中的增删改查

    虽然android提供了sql查询的封装方法,但是理解起来还是麻烦,所以我这里用sql语句来完成工作. 首先是建立一个类,继承SQLiteOpenHelper 这里面会建立一个数据库,并且初始化一个表 ...

  6. [译]聊聊C#中的泛型的使用(新手勿入) Seaching TreeVIew WPF 可编辑树Ztree的使用(包括对后台数据库的增删改查) 字段和属性的区别 C# 遍历Dictionary并修改其中的Value 学习笔记——异步 程序员常说的「哈希表」是个什么鬼?

    [译]聊聊C#中的泛型的使用(新手勿入)   写在前面 今天忙里偷闲在浏览外文的时候看到一篇讲C#中泛型的使用的文章,因此加上本人的理解以及四级没过的英语水平斗胆给大伙进行了翻译,当然在翻译的过程中发 ...

  7. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(5)-EF增删改查by糟糕的代码

    原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(5)-EF增删改查by糟糕的代码 上一讲我们创建了一系列的解决方案,我们通过一个例子来看看层与层之间的关系 ...

  8. PHP程序中使用PDO对象实现对数据库的增删改查操作的示例代码

    PHP程序中使用PDO对象实现对数据库的增删改查操作(PHP+smarty) dbconn.php <?php //------------------------使用PDO方式连接数据库文件- ...

  9. Mybatis框架基于映射文件和配置文件的方式,实现增删改查,可以打印日志信息

    首先在lib下导入: 与打印日志信息有关的架包 log4j-1.2.16.jar mybatis架包:mybatis-3.1.1.jar 连接数据库的架包:mysql-connector-java-5 ...

随机推荐

  1. ECC中的CRM UI端摆弄

    前段时间想搞CRM了,可是公司没有环境,就去ECC直接试试事务码,结果竟然可以打开网页...兴奋之余又去看了一下CRM里的一些CLASS,结果很多都是没有的.沮丧! 后来想想,只能用UI的框架,挂WD ...

  2. A-Apple Catching(POJ 2385)

    Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8759   Accepted: 4264 De ...

  3. 一些git命令

    git push --set-upstream origin release  强制将add的数据提交到  release分支.

  4. linux 查看僵尸进程

    top -b -i -n 1 查看僵死进程命令 ps -A -o stat,ppid,pid,cmd | grep -e '^[Zz]' 查看apache 当前进程数 ps -ef | grep ht ...

  5. ORACLE 建库过程总结

    1,忘记sys密码 打开CMD命令窗口,执行以下操作: ,SQLPLUS /NOLOG; , ,CONNECT / AS SYSDBA , ,ALTER USER SYS IDENTIFIED BY ...

  6. UVALive 7297 Hounded by Indecision BFS

    题目链接:Hounded by Indecision 题意:map中给出小偷的位置,警察的位置.警察有一只狗,开始的时候警察和狗一起行动,也就是看做一个格子,当警察遇见小偷走过的格子时,狗就会嗅到它的 ...

  7. 面向对象编程(OOP)基础之UML基础

    在我们学习OOP过程中,难免会见到一些结构图~各种小框框.各种箭头.今天小猪就来简单介绍一下这些框框箭头的意思——UML. UML定义的关系主要有:泛化(继承).实现.依赖.关联.聚合.组合,这六种关 ...

  8. Android的SwipeToDismiss第三方开源框架模拟QQ对话列表侧滑删除,置顶,将头像图片圆形化处理。

      <Android SwipeToDismiss:左右滑动删除ListView条目Item> Android的SwipeToDismiss是github上一个第三方开源框架(github ...

  9. Google十大惊人产品

    国外资讯网站BusinessInsider刊文细数了谷歌惊世骇俗的十大产品,范围从无人驾驶汽车到太空电梯再到高空风力发电,每一项都令人无限神往,充满未来感. 以下是谷歌十大惊人产品: 众所周知,谷歌并 ...

  10. 主机无法访问虚拟机上的elasticsearch服务器

    问题: es在linux上搭建好,通过curl -XGET ip:port可以获得服务器信息展示,但是主机在浏览器上无法访问. 原因: 主机通过telnet访问linux的80端口,发现是不通的.可以 ...