欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

开发自己的Data Access Application Block[下篇]

程序员文章站 2024-01-31 20:00:16
...

上接: [原创] 我的ORM: 开发自己的Data Access Application Block - Part I 4. Database 下面来介绍重中之重:Database,绝大部分的DataAccess 操作都集中在这个Abstract Database中。这是一个相对庞大的Class,所以不得不采用Partial Class的方式来编写。

上接:[原创] 我的ORM: 开发自己的Data Access Application Block - Part I
4. Database

下面来介绍重中之重:Database,绝大部分的Data Access 操作都集中在这个Abstract Database中。这是一个相对庞大的Class,所以不得不采用Partial Class的方式来编写。

Part I:Field 和Property

这些Field 和Property基本上对应我们前面的Configuraiton。此为我们定义了三个Field 和Property:DbDataAdapter,Connection,_transaction。考虑到垃圾回收,使Database实现IDisposable接口。值得说明一点的是,我们通过Database的DatabaseProviderFactory创建了泛型的DbDataAdapter,DbConnection和Transaction。

  • ConnectionString:string

  • DatabaseProviderFactory:DbProviderFactory

  • DefaultCommandType:CommandType

  • UseCommandBuilder:bool

  • DbParameterNameMapping:IDbParameterNameMapping

  • StoredProcedureNameMapping:IStoredProcedureNameMapping

  • DbDataAdapter:DbDataAdapter

  • Connection: DbConnection

  • Transaction: DbTransaction

开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]using System;
开发自己的Data Access Application Block[下篇]
using System.Collections.Generic;
开发自己的Data Access Application Block[下篇]
using System.Text;
开发自己的Data Access Application Block[下篇]
using System.Data;
开发自己的Data Access Application Block[下篇]
using System.Data.Common;
开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]
using Artech.ApplicationBlock.DataMapping;
开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]
namespace Artech.ApplicationBlock.DataAccess
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
/**////


开发自己的Data Access Application Block[下篇]
/// Database defines a series of database-based operations.
开发自己的Data Access Application Block[下篇]
///
开发自己的Data Access Application Block[下篇] public abstract partial class Database : IDisposable
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
private bool _isDisposed;
开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
The five private fields possess the corressponding pubic properties, and they are only allowed to be evaluated by Database Factory.#region The five private fields possess the corressponding pubic properties, and they are only allowed to be evaluated by Database Factory.
开发自己的Data Access Application Block[下篇]
private DbProviderFactory _dbProviderFactory;
开发自己的Data Access Application Block[下篇]
private string _connectionString;
开发自己的Data Access Application Block[下篇]
private CommandType _defaultCommandType;
开发自己的Data Access Application Block[下篇]
private bool _useCommandBuilder;
开发自己的Data Access Application Block[下篇]
private IDbParameterNameMapping _dbParameterNameMapping;
开发自己的Data Access Application Block[下篇]
private IStoredProcedureNameMapping _storedProcedureNameMapping;
开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
/**////
开发自己的Data Access Application Block[下篇]
/// Database connection string which is specified by the database factory.
开发自己的Data Access Application Block[下篇]
///

开发自己的Data Access Application Block[下篇] public string ConnectionString
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
get
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
return this._connectionString;
开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]
set
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
this._connectionString = value;
开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
/**////
开发自己的Data Access Application Block[下篇]
/// The concrete database specific provider factory.
开发自己的Data Access Application Block[下篇]
///

开发自己的Data Access Application Block[下篇] public DbProviderFactory DatabaseProviderFactory
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
get
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
return this._dbProviderFactory;
开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇]
set
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
this._dbProviderFactory = value;
开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
/**////
开发自己的Data Access Application Block[下篇]
/// The defaull command type to perform the database operations which do not specify the commanf type.
开发自己的Data Access Application Block[下篇]
///

开发自己的Data Access Application Block[下篇] public CommandType DefaultCommandType
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
get
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
return this._defaultCommandType;
开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇]
set
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
this._defaultCommandType = value;
开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
/**////
开发自己的Data Access Application Block[下篇]
///Determine whether to use command builder or mapped stored procedures to execute database operations.
开发自己的Data Access Application Block[下篇]
///

开发自己的Data Access Application Block[下篇] public bool UseCommandBuilder
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
get
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
return this._useCommandBuilder;
开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇]
set
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
this._useCommandBuilder = value;
开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
/**////
开发自己的Data Access Application Block[下篇]
/// A string which indicates the type to perform mapping between stored procedure parameter and source column.
开发自己的Data Access Application Block[下篇]
///

开发自己的Data Access Application Block[下篇] public IDbParameterNameMapping DbParameterNameMapping
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
get
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
return this._dbParameterNameMapping;
开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇]
set
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
this._dbParameterNameMapping = value;
开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
/**////
开发自己的Data Access Application Block[下篇]
/// A string which indicates the type to perform mapping between table name and the related stored procedure names.
开发自己的Data Access Application Block[下篇]
///

开发自己的Data Access Application Block[下篇] public IStoredProcedureNameMapping StoredProcedureNameMapping
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
get
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
return this._storedProcedureNameMapping;
开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇]
set
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
this._storedProcedureNameMapping = value;
开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇]
#endregion

开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
Connection & Database DataAdapter#region Connection & Database DataAdapter
开发自己的Data Access Application Block[下篇]
private DbDataAdapter _dbDataAdapter;
开发自己的Data Access Application Block[下篇]
private DbConnection _connection;
开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
/**////
开发自己的Data Access Application Block[下篇]
/// A generic database data adapter which is responsible for save the changed data into database.
开发自己的Data Access Application Block[下篇]
///

开发自己的Data Access Application Block[下篇] private DbDataAdapter DatabaseAdapter
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
get
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
if (this._dbDataAdapter == null)
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
this._dbDataAdapter = this._dbProviderFactory.CreateDataAdapter();
开发自己的Data Access Application Block[下篇]
this._dbDataAdapter.AcceptChangesDuringUpdate = false;
开发自己的Data Access Application Block[下篇]
this._dbDataAdapter.MissingSchemaAction = MissingSchemaAction.Add;
开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]
return this._dbDataAdapter;
开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
/**////
开发自己的Data Access Application Block[下篇]
/// The database connection.
开发自己的Data Access Application Block[下篇]
///

开发自己的Data Access Application Block[下篇] private DbConnection Connection
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
get
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
if (this._connection == null)
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]{
开发自己的Data Access Application Block[下篇]
this._connection = this._dbProviderFactory.CreateConnection();
开发自己的Data Access Application Block[下篇]
this._connection.ConnectionString = this._connectionString;
开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]
return this._connection;
开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇] }

开发自己的Data Access Application Block[下篇]
#endregion

开发自己的Data Access Application Block[下篇]
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇]
Constructor#region Constructor
开发自己的Data Access Application Block[下篇]
public Database()
开发自己的Data Access Application Block[下篇]开发自己的Data Access Application Block[下篇] &
开发自己的Data Access Application Block[下篇]

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。