笔记之Utility.DataAccess
挤出时间看了一些代码,做一些笔记,备忘!!!
现在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的更多相关文章
- CodeGenerator.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CiCe ...
- 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任务类别: 无级别: ...
- amazeui学习笔记--css(布局相关3)--辅助类Utility
amazeui学习笔记--css(布局相关3)--辅助类Utility 一.总结 1.元素清除浮动: 添加 am-cf 这个 class 即可 2.水平滚动: .am-scrollable-horiz ...
- Effective Java笔记一 创建和销毁对象
Effective Java笔记一 创建和销毁对象 第1条 考虑用静态工厂方法代替构造器 第2条 遇到多个构造器参数时要考虑用构建器 第3条 用私有构造器或者枚举类型强化Singleton属性 第4条 ...
- 《C#本质论》读书笔记(18)多线程处理
.NET Framework 4.0 看(本质论第3版) .NET Framework 4.5 看(本质论第4版) .NET 4.0为多线程引入了两组新API:TPL(Task Parallel Li ...
- UE4 中Struct Emum 类型的定义方式 笔记
UE4 基础,但是不经常用总是忘记,做个笔记加深记忆: 图方便就随便贴一个项目中的STRUCT和 Enum 的.h 文件 Note:虽然USTRUCT可以定义函数,但是不能加UFUNCTION 标签喔 ...
- 机器学习&数据挖掘笔记_22(PGM练习六:制定决策)
前言: 本次实验是将一些简单的决策理论和PGM推理结合,实验内容相对前面的图模型推理要简单些.决策理论采用的是influence diagrams,和常见图模型本质一样, 其中的决策节点也可以用CPD ...
- django笔记-模型数据模板呈现过程记录(多对多关系)
首先,推荐一个网址:http://www.tuicool.com/articles/BfqYz2F,因为这里的比我的要有条理,更有利于各位的理解. 以下仅为为个人一次不完整的笔记: 环境:ubuntu ...
- Linq_Lambda GroupBy使用笔记
今天看MVC遇到了GroupBY的Lambda表达式..有兴趣详细的看下去..得此笔记..记录之... 不罗嗦..上代码... //得到List<GroupEmail>对象 数据源 var ...
随机推荐
- [Binder深入学习二]Binder驱动——基础数据结构二
Userspace和KernelSpace进行交互时,大部分命令是通过 ioctl 实现的,在这个过程中,最重要的一个便是 BINDER_WRITE_READ 命令了. #define BINDER_ ...
- vue项目Windows Server服务器部署IIS设置Url重写
1.将vue项目使用npm run build命令打包后将dist文件夹内的文件全部拷贝到服务器. 2.IIS添加应用程序池,.NET CLR版本选择无托管代码 3.添加网站,应用程序池选择刚刚添加的 ...
- JVM_02 类加载子系统
JVM细节版架构图 本文针对Class Loader SubSystem这一块展开讲解类加载子系统的工作流程 类加载子系统作用 1.类加载子系统负责从文件系统或者网络中加载class文件,class文 ...
- 被喷了!聊聊我开源的RPC框架那些事
前段时间利用业余时间写了一个简单的 RPC 框架,花费了不少精力.开源出来之后,少部分不太友好的技术人站在上帝视角说了风凉话.就很难受,兄弟,谁还没有一个玻璃心. 简单吐槽一波,给大家聊聊关于 gui ...
- Java线程阻塞方法sleep()和wait()精炼详解
版权声明:因为个人水平有限,文章中可能会出现错误,如果你觉得有描述不当.代码错误等内容或者有更好的实现方式,欢迎在评论区告诉我,即刻回复!最后,欢迎关注博主!谢谢 https://blog.csdn. ...
- 最全总结 | 聊聊 Python 数据处理全家桶(Sqlite篇)
1. 前言 上篇文章 聊到 Python 处理 Mysql 数据库最常见的两种方式,本篇文章继续说另外一种比较常用的数据库:Sqlite Sqlite 是一种 嵌入式数据库,数据库就是一个文件,体积很 ...
- SpringBoot框架:通过AOP和自定义注解完成druid连接池的动态数据源切换(三)
一.引入依赖 引入数据库连接池的依赖--druid和面向切面编程的依赖--aop,如下所示: <!-- druid --> <dependency> <groupId&g ...
- ASP.NET Web API 2系列(四):基于JWT的token身份认证方案
1.引言 通过前边的系列教程,我们可以掌握WebAPI的初步运用,但是此时的API接口任何人都可以访问,这显然不是我们想要的,这时就需要控制对它的访问,也就是WebAPI的权限验证.验证方式非常多,本 ...
- CountDownLatch、CyclicBarrier
CountDownLatch CountDownLatch类位于java.util.concurrent包下,利用它可以实现类似计数器的功能.比如有一个任务A,它要等待其他4个任务执行完毕之后才能执行 ...
- echarts中折线图切换为数据视图(表格布局)表头无法对齐解决方法
dataView: { show: true, readOnly: true, option ...