managedproviderconnectionhelper.cs

来自「NHibernate NET开发者所需的」· CS 代码 · 共 43 行

CS
43
字号
using System.Collections.Generic;
using System.Data;
using NHibernate.Connection;

namespace NHibernate.Tool.hbm2ddl
{
	/// <summary>
	/// A <seealso cref="IConnectionHelper"/> implementation based on an internally
	///  built and managed <seealso cref="ConnectionProvider"/>.
	/// </summary>
	public class ManagedProviderConnectionHelper : IConnectionHelper
	{
		private readonly IDictionary<string, string> cfgProperties;
		private IConnectionProvider connectionProvider;
		private IDbConnection connection;

		public ManagedProviderConnectionHelper(IDictionary<string, string> cfgProperties)
		{
			this.cfgProperties = cfgProperties;
		}

		public void Prepare()
		{
			connectionProvider = ConnectionProviderFactory.NewConnectionProvider(cfgProperties);
			connection = connectionProvider.GetConnection();
		}

		public IDbConnection GetConnection()
		{
			return connection;
		}

		public void Release()
		{
			if (connection != null)
			{
				connectionProvider.CloseConnection(connection);
			}
			connection = null;
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?