forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManagedProviderConnectionHelper.cs
42 lines (37 loc) · 1.03 KB
/
ManagedProviderConnectionHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System.Collections.Generic;
using System.Data.Common;
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 partial class ManagedProviderConnectionHelper : IConnectionHelper
{
private readonly IDictionary<string, string> cfgProperties;
private IConnectionProvider connectionProvider;
private DbConnection connection;
public ManagedProviderConnectionHelper(IDictionary<string, string> cfgProperties)
{
this.cfgProperties = cfgProperties;
}
public void Prepare()
{
connectionProvider = ConnectionProviderFactory.NewConnectionProvider(cfgProperties);
connection = connectionProvider.GetConnection();
}
public DbConnection Connection
{
get { return connection; }
}
public void Release()
{
if (connection != null)
{
connectionProvider.CloseConnection(connection);
}
connection = null;
}
}
}