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. 133. Clone Graph 138. Copy List with Random Pointer 拷贝图和链表

    133. Clone Graph Clone an undirected graph. Each node in the graph contains a label and a list of it ...

  2. 自定义头文件 No such file or directory

    my_file.h为你的头文件名 要用#include"my_file.h",而不能是#include<my_file.h>. 如果头文件名在尖括号<>里, ...

  3. c++实现之 -- 文章TF-IDF值的计算

    首先,是关键词的选取: 好吧这个我这模型实在是太简单了,但还是讲一讲比较好呢... 我们现在手头有的是一堆百度百科词条w的DF(w, c)值,c是整个百科词条...原因是...方便嘛~(而且人家现成的 ...

  4. jQuery修改后代、兄弟样式

    <div> <div >1</div> <div class="one"> 2 <div>2_1 <div> ...

  5. C#入门篇6-7:字符串操作 看看字符串的特殊之处 值类型与引用类型的区别

    //看看字符串的特殊之处值类型与引用类型的区别 public static void CompareString(string stra, string strb, int i) { #region ...

  6. wordpress 中禁止更新提示

    前言: 在此之前每每打开blog的时候总是有那么个数字在那边显示,如果是很重要的更新显示在那也就算了,有时候就算一个破主题他还一直在那边,很是让小猪纠结.最关键的是要是更新了主题,那么之前所有自定义的 ...

  7. L1 - 运行机制

    var name = 'kl'; function person(){ alert(name); var name = 'ko'; } person(); 这段代码输出 ‘undefined’,这种现 ...

  8. 浅谈C++源码的过国内杀软的免杀

    以下只是简单的思路和定位.也许有人秒过,但是不要笑话我写的笨方法.定位永远是过期不了的. 其实这里废话一下 , 本人并不是大牛 ,今天跟大家分享下 .所以写出这篇文章.(大牛飘过) 只是个人实战的经验 ...

  9. 北邮新生排位赛1解题报告d-e

    话说cdsn要是前面插入源代码又什么都不放就会出现奇怪的源代码?不知道是哪个网页的 407. BLOCKS 时间限制 1000 ms 内存限制 65536 KB 题目描述 给定一个N∗M的矩阵,求问里 ...

  10. 火车安排问题(dp好题)

    火车站内往往设有一些主干线分叉出去的铁路支路,供火车停靠,以便上下客或装载货物.铁路 支路有一定长度:火车也有一定的长度,且每列火车的长度相等. 假设某东西向的铁路上,有一小站.该站只有一条铁路支路可 ...