forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnectionProviderFactory.cs
49 lines (46 loc) · 1.51 KB
/
ConnectionProviderFactory.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
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
using NHibernate.Util;
using Environment=NHibernate.Cfg.Environment;
namespace NHibernate.Connection
{
/// <summary>
/// Instantiates a connection provider given configuration properties.
/// </summary>
public static class ConnectionProviderFactory
{
private static readonly INHibernateLogger log = NHibernateLogger.For(typeof(ConnectionProviderFactory));
// cannot be instantiated
public static IConnectionProvider NewConnectionProvider(IDictionary<string, string> settings)
{
IConnectionProvider connections;
string providerClass;
if (settings.TryGetValue(Environment.ConnectionProvider, out providerClass))
{
try
{
log.Info("Initializing connection provider: {0}", providerClass);
connections =
(IConnectionProvider)
Environment.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(providerClass));
}
catch (Exception e)
{
log.Fatal(e, "Could not instantiate connection provider");
throw new HibernateException("Could not instantiate connection provider: " + providerClass, e);
}
}
else if (settings.ContainsKey(Environment.ConnectionString) || settings.ContainsKey(Environment.ConnectionStringName))
{
connections = new DriverConnectionProvider();
}
else
{
log.Info("No connection provider specified, UserSuppliedConnectionProvider will be used.");
connections = new UserSuppliedConnectionProvider();
}
connections.Configure(settings);
return connections;
}
}
}