挤出时间看了一些代码,做一些笔记,备忘!!!

现在ORM随处可见,为什么不要已有的ORM而要手动写SQL呢?这肯定是有因为滴,存在必合理嘛!

自认为关于性能、维护、Maybe还有其他的,欢迎大家拍砖!

当然SQL是不会写在代码中,而存在于配置文件(想起了iBatis),便于统一管理和维护,不会污染代码。

以下就是关于此内容:

思路很简单,大家应该都明白,说白了就是从XML文件(以XML形式存在,当然其他任何文件形式都可)

里读取SQL到内存,然后组织DbCommand进行DB操作。但是还是有很多细节需要处理。

必竟理论与实践还是有区别的。

SQL语句在XML文件里,肯定会有对XML配置文件的相关操作(这里主要是读取的监视)和配置文件的格式定义

配置文件包含:1.Database.config(数据库连接字符串的配置文件)

       2.DbCommandFiles.config(SQL语句文件的集合(有哪些SQL配置文件需要注册到此文件))

       3.****.config(具体SQL语句配置文件)

Database.config格式:

<?xml version="1.0"?>
<databaseList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://***.com/DatabaseList">
<database name="**Service">
<connectionString>Hn3t+SQCaz3ZRQDdawhd6njUqoNX1BXcfMvvUaOvBtRi9O/9fPPZEuPSYvzs</connectionString>
</database> <database name="**Service">
    <connectionString>Hn3t+SQCaz3ZRQDdawh</connectionString>
</database>
<database name="MailService"> </databaseList>

Database.config 对应实体

[XmlRoot("databaseList", Namespace = "http://***.com/DatabaseList")]
public class DatabaseList
{
[XmlElement("database")]
public DatabaseInstance[] DatabaseInstances
{
get;
set;
}
} [XmlRoot("database")]
public class DatabaseInstance
{
[XmlAttribute("name")]
public string Name
{
get;
set;
} [XmlAttribute("type")]
public string Type
{
get;
set;
} [XmlElement("connectionString")]
public string ConnectionString
{
get;
set;
}
}

***.config

<?xml version="1.0" encoding="utf-8" ?>
<dataOperations xmlns="http://***.com/DataOperation">
<dataCommand name="GetAreaList" database="NCService" commandType="Text">
<commandText>
<![CDATA[
SELECT * FROM DDD.DBO.DDD WITH(NOLOCK) WHERE SYSNO = @SysNo
]]>
</commandText>
<parameters>
<param name="@SysNo" dbType="Int32"/>
</parameters>
</dataCommand>
</dataOperations>
 [XmlRoot("dataOperations", Namespace = "http://****.com/DataOperation")]
public partial class DataOperations
{
[XmlElement("dataCommand")]
public DataCommandConfig[] DataCommand
{
get;
set;
}
} [XmlRoot("dataCommand")]
public partial class DataCommandConfig
{
private CommandType m_CommandType = CommandType.Text;
private int m_TimeOut = 300; [XmlElement("commandText")]
public string CommandText
{
get;
set;
} [XmlElement("parameters")]
public Parameters Parameters
{
get;
set;
} [XmlAttribute("name")]
public string Name
{
get;
set;
} [XmlAttributeAttribute("database")]
public string Database
{
get;
set;
} [XmlAttributeAttribute("commandType")]
[DefaultValueAttribute(CommandType.Text)]
public CommandType CommandType
{
get
{
return this.m_CommandType;
}
set
{
this.m_CommandType = value;
}
} [XmlAttributeAttribute("timeOut")]
[DefaultValueAttribute(300)]
public int TimeOut
{
get
{
return this.m_TimeOut;
}
set
{
this.m_TimeOut = value;
}
} public DataCommandConfig Clone()
{
DataCommandConfig config = new DataCommandConfig();
config.CommandText = this.CommandText;
config.CommandType = this.CommandType;
config.Database = this.Database;
config.Name = this.Name;
config.Parameters = this.Parameters == null ? null : this.Parameters.Clone();
config.TimeOut = this.TimeOut;
return config;
}
} [XmlRoot("parameters")]
public partial class Parameters
{
[XmlElement("param")]
public Param[] Param
{
get;
set;
} public Parameters Clone()
{
Parameters p = new Parameters();
if (this.Param != null)
{
p.Param = new Param[this.Param.Length];
for (int i = 0; i < this.Param.Length; i++)
{
p.Param[i] = this.Param[i].Clone();
}
}
return p;
}
} [XmlRoot("param")]
public partial class Param
{
private ParameterDirection m_Direction = ParameterDirection.Input;
private int m_Size = -1;
private byte m_Scale = 0;
private byte m_Precision = 0; public Param Clone()
{
Param p = new Param();
p.DbType = this.DbType;
p.Direction = this.Direction;
p.Name = this.Name;
p.Precision = this.Precision;
p.Property = this.Property;
p.Scale = this.Scale;
p.Size = this.Size;
return p;
} [XmlAttribute("name")]
public string Name
{
get;
set;
} [XmlAttribute("dbType")]
public DbType DbType
{
get;
set;
} [XmlAttribute("direction")]
[DefaultValue(ParameterDirection.Input)]
public ParameterDirection Direction
{
get
{
return this.m_Direction;
}
set
{
this.m_Direction = value;
}
} [XmlAttribute("size")]
[DefaultValue(-1)]
public int Size
{
get
{
return this.m_Size;
}
set
{
this.m_Size = value;
}
} [XmlAttribute("scale")]
[DefaultValue(0)]
public byte Scale
{
get
{
return this.m_Scale;
}
set
{
this.m_Scale = value;
}
} [XmlAttribute("precision")]
[DefaultValue(0)]
public byte Precision
{
get
{
return this.m_Precision;
}
set
{
this.m_Precision = value;
}
} [XmlAttribute("property")]
public string Property
{
get;
set;
}
}

XML文件与Class的对应关系,当然可以定义你喜欢的任何格式,只要满足相关规范。

当前我们会用一个ConfigManager来对配置文件的管理。

笔记之Utility.DataAccess的更多相关文章

  1. CodeGenerator.cs

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CiCe ...

  2. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed(在64位模式下运行安装了32位的Oracle客户端组件时,会发生此问题)

    部署win服务时出现下面的问题: 在事件查看器中看到如下错误: 日志名称: Application来源: ***调度服务日期: 2014/5/21 12:53:21事件 ID: 0任务类别: 无级别: ...

  3. amazeui学习笔记--css(布局相关3)--辅助类Utility

    amazeui学习笔记--css(布局相关3)--辅助类Utility 一.总结 1.元素清除浮动: 添加 am-cf 这个 class 即可 2.水平滚动: .am-scrollable-horiz ...

  4. Effective Java笔记一 创建和销毁对象

    Effective Java笔记一 创建和销毁对象 第1条 考虑用静态工厂方法代替构造器 第2条 遇到多个构造器参数时要考虑用构建器 第3条 用私有构造器或者枚举类型强化Singleton属性 第4条 ...

  5. 《C#本质论》读书笔记(18)多线程处理

    .NET Framework 4.0 看(本质论第3版) .NET Framework 4.5 看(本质论第4版) .NET 4.0为多线程引入了两组新API:TPL(Task Parallel Li ...

  6. UE4 中Struct Emum 类型的定义方式 笔记

    UE4 基础,但是不经常用总是忘记,做个笔记加深记忆: 图方便就随便贴一个项目中的STRUCT和 Enum 的.h 文件 Note:虽然USTRUCT可以定义函数,但是不能加UFUNCTION 标签喔 ...

  7. 机器学习&数据挖掘笔记_22(PGM练习六:制定决策)

    前言: 本次实验是将一些简单的决策理论和PGM推理结合,实验内容相对前面的图模型推理要简单些.决策理论采用的是influence diagrams,和常见图模型本质一样, 其中的决策节点也可以用CPD ...

  8. django笔记-模型数据模板呈现过程记录(多对多关系)

    首先,推荐一个网址:http://www.tuicool.com/articles/BfqYz2F,因为这里的比我的要有条理,更有利于各位的理解. 以下仅为为个人一次不完整的笔记: 环境:ubuntu ...

  9. Linq_Lambda GroupBy使用笔记

    今天看MVC遇到了GroupBY的Lambda表达式..有兴趣详细的看下去..得此笔记..记录之... 不罗嗦..上代码... //得到List<GroupEmail>对象 数据源 var ...

随机推荐

  1. Python爬虫实战练习:爬取美团旅游景点评论数据

    前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理. 今年的国庆节还有半个月就要来了,相信很多的小伙伴还是非常期待这个小长假的.国庆节是一年中的小 ...

  2. 一篇文章说清楚TDengine的FQDN

    TDengine2.0以后需要使用FQDN来进行访问.小朋友,你是否有很多小问号:什么是FQDN,为什么要配置FQDN,如何配置FQDN.我们今天来简单讲一下.心急的小伙伴,可以直接跳转到配置章节. ...

  3. 剑指offer 59-II 队列的最大值

    题目描述 请定义一个队列并实现函数 max_value 得到队列里的最大值,要求函数max_value.push_back 和 pop_front 的均摊时间复杂度都是O(1). 若队列为空,pop_ ...

  4. docker之windows安装&centOS安装

    按这个安装  没什么毛病 https://blog.csdn.net/vitaair/article/details/80894890 https://www.runoob.com/docker/ce ...

  5. 自己实现一个 DFA 串模式识别器(二)

    正规表达式的实现原理 ​ 上文讨论了串的模式的表达,即正规表达式.那么这一小节将讨论我们实现一个正规表达式的方法和原理.因为我们知道,一个正规表达式对应着一个串模式,而一个串模式又对应着一些列符合该模 ...

  6. Kafka实战宝典:Kafka的控制器controller详解

    一.控制器简介 控制器组件(Controller),是 Apache Kafka 的核心组件.它的主要作用是在 Apache ZooKeeper 的帮助下管理和协调整个 Kafka 集群.集群中任意一 ...

  7. VUE3.0发布,自己搞个文档网站

    9月19日,尤大神发表了VUE3.0版本的演说,强大且震撼,这两天一直在找网站文档,可能还未被百度收录,未找到文档网站.后来在github上面找到了中文代码. 地址为:https://github.c ...

  8. Urule开源版系列5——RuleSetParser解析过程

    接上期Urule开源版系列4--Core包核心接口之规则解析过程 之前源码到了Parser,这期详细解析下RuleSetParser的解析过程 1.主流程 特殊处理一个属性 循环处理元素 当元素名称是 ...

  9. Appium 用途和特点

    Appium 是一个移动 App (手机应用)自动化工具. 手机APP 自动化有什么用? 自动化完成一些重复性的任务 比如微信客服机器人 爬虫 就是通过手机自动化爬取信息. 为什么不通过网页.HTTP ...

  10. org.springframework.dao.InvalidDataAccessApiUsageException: The given id must not be null!; nested exception is java.lang.IllegalArgumentException: The given id must not be null

    通过这个简单的案例,手把手教给你分析异常信息(适合初学者看) org.springframework.dao.InvalidDataAccessApiUsageException: The given ...