数据库

位置:IT落伍者 >> 数据库 >> 浏览文章

数据库连接池Data Connection Framework


发布日期:2019年06月08日
 
数据库连接池Data Connection Framework

数据库连接池Data Connection Framework具备Connection pooling机制能管理不同的 Connection并通过池对象工厂去PoolObjectFactory去创建数据连接池(可参考对象工厂创建 Singleton ObjectSingleCall ObjectPool Object )

连接池企业应用组件图如下

主要文件代码

/// <summary>

/// 连接池上下文

/// </summary>

public sealed class ConnectionPoolContext : IDisposable

{

/// <summary>

/// 池对象工厂

/// </summary>

private PoolObjectFactory _factory;

/// <summary>

/// 默认连接字符

/// </summary>

private string _defaultConnectionString;

/// <summary>

/// 工厂名称

/// </summary>

private string _factoryName;

/// <summary>

/// 类型

/// </summary>

private Type _factoryType;

/// <summary>

/// SQL状态仓库

/// </summary>

private SqlStatementRepository _statementRepository;

/// <summary>

/// 连接池

/// </summary>

private static Dictionary<string ConnectionPoolContext> _instances = new Dictionary<string ConnectionPoolContext>();

/// <summary>

/// 默认连接字符属性

/// </summary>

public string DefaultConnectionString

{

get

{

return _defaultConnectionString;

}

set

{

_defaultConnectionString = value;

}

}

/// <summary>

/// 工厂名

/// </summary>

public string FactoryName

{

get

{

return _factoryName;

}

set

{

_factoryName = value;

}

}

/// <summary>

/// SQL状态仓库属性

/// </summary>

public SqlStatementRepository StatementRepository

{

get

{

if (_statementRepository == null)

_statementRepository = new SqlStatementRepository();

return _statementRepository;

}

}

/// <summary>

/// 对象工厂模式

/// </summary>

internal PoolObjectFactory Factory

{

get

{

return _factory;

}

set

{

_factory = value;

}

}

/// <summary>

/// 实例化一个连接池

/// </summary>

/// <param name=id></param>

/// <returns></returns>

public static ConnectionPoolContext Instance(string id)

{

上一篇:网购系统——通用数据库访问函数

下一篇:WinCE下对数据库的操作方法实例