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

现在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. SDWebImageInfo

    SDWebImage 简介 iOS中著名的牛逼的网络图片处理框架 包含的功能:图片下载.图片缓存.下载进度监听.gif处理等等 用法极其简单,功能十分强大,大大提高了网络图片的处理效率 国内超过90% ...

  2. JDK13环境变量配置

    第一步:下载JDK(开发工具包) JDK分为OracleJDK和OpenJDK下面简要说明 OracleJDK 部分代码闭源.商业收费 OpenJDK 开放源码.商业免费 两者大部分代码是共用的(除闭 ...

  3. 一、Git是什么?

    Git是什么? Git 是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目. Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控 ...

  4. Java中toCharArray()方法

    Java中 toCharArray() 方法详解 <Thinking in Java>Chapter11中存在下列代码 package holding; import java.util. ...

  5. lombok使用(给自己看的,只为不要忘记自己用过的技术)

    如何使用? 一.1)eclipse使用方法 1. 从项目首页下载lombok.jar 2. 双击lombok.jar, 将其安装到eclipse中(该项目需要jdk1.6+的环境) 2)idea使用方 ...

  6. idea开启Run DashBoard

    0-前言 IDEA中,run dashboard是一个直观.方便好用的面板,谁用谁知道: 但是它不是默认开启的,开启有两种方式: 方式一: 1.新项目中,有时会弹出面板让我们点击开启,点击一下就能开启 ...

  7. 20190531模拟赛总结&反思

    T1: 来源:Codeforces -  Classroom Watch Describe: 给出一个正整数 n,现在问存在多少个 x,使得  x在十进制下的每一位之和加上 x 等于 n. Solut ...

  8. C#中WebBrowser获取页面标签class值

    由于class是JavaScript的保留关键字 所以在C#中使用GetAttribute("className")来获取hmtlElement的class值 而不是GetAttr ...

  9. [ERROR] Aborting

    where? mysql 5.7 启动时候,报错 [ERROR] Aborting why? /etc/my.cnf 中有错误的配置参数 way? 检查参数是否出错,通过一行一行注释排错

  10. Java 常用类-程序员头大的日期时间API

    第二节.日期时间API 一.JDK8之前日期时间API 1.1 java.lang.System类 System类提供的public static long currentTimeMillis()用来 ...