Skip to content

Commit d03d88f

Browse files
author
Mike Doerfler
committed
Minor modification to how certain Connection & Command classes
are instantiated. More code moved to DriverBase. Added Oracle DataProvider to project. Thanks to feilng for the contribution. SVN: trunk@523
1 parent 116e8b6 commit d03d88f

8 files changed

+107
-10
lines changed

src/NHibernate/Driver/ByteFXDataDriver.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ public ByteFXDataDriver()
3333
commandType = System.Type.GetType("ByteFX.Data.MySqlClient.MySqlCommand, ByteFX.Data");
3434
}
3535

36-
public override IDbConnection CreateConnection()
36+
public override System.Type CommandType
3737
{
38-
return (IDbConnection) Activator.CreateInstance(connectionType);
38+
get { return commandType; }
3939
}
4040

41-
public override IDbCommand CreateCommand()
41+
public override System.Type ConnectionType
4242
{
43-
return (IDbCommand) Activator.CreateInstance(commandType);
43+
get { return connectionType; }
4444
}
4545

4646
public override bool UseNamedPrefixInSql

src/NHibernate/Driver/DriverBase.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,18 @@ public DriverBase()
1616

1717
#region IDriver Members
1818

19-
public abstract IDbConnection CreateConnection();
19+
public abstract System.Type CommandType {get; }
20+
public abstract System.Type ConnectionType {get; }
2021

21-
public abstract IDbCommand CreateCommand();
22+
public virtual IDbConnection CreateConnection()
23+
{
24+
return (IDbConnection) Activator.CreateInstance(ConnectionType);
25+
}
26+
27+
public virtual IDbCommand CreateCommand()
28+
{
29+
return (IDbCommand) Activator.CreateInstance(CommandType);
30+
}
2231

2332
public abstract bool UseNamedPrefixInSql {get;}
2433

src/NHibernate/Driver/FirebirdDriver.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ public FirebirdDriver()
1818
commandType = System.Type.GetType("FirebirdSql.Data.Firebird.FbCommand, FirebirdSql.Data.Firebird");
1919
}
2020

21-
public override IDbConnection CreateConnection()
21+
public override System.Type CommandType
2222
{
23-
return (IDbConnection) Activator.CreateInstance(connectionType);
23+
get { return commandType; }
2424
}
2525

26-
public override IDbCommand CreateCommand()
26+
public override System.Type ConnectionType
2727
{
28-
return (IDbCommand) Activator.CreateInstance(commandType);
28+
get { return connectionType; }
2929
}
3030

3131
public override bool UseNamedPrefixInSql

src/NHibernate/Driver/IDriver.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ namespace NHibernate.Driver
3636
public interface IDriver
3737
{
3838

39+
/// <summary>
40+
/// The Type used to create an IDbConnection
41+
/// </summary>
42+
System.Type ConnectionType { get; }
43+
44+
/// <summary>
45+
/// The Type used to create an IDbCommand
46+
/// </summary>
47+
System.Type CommandType { get; }
48+
3949
/// <summary>
4050
/// Creates an uninitialized IDbConnection object for the specific Driver
4151
/// </summary>

src/NHibernate/Driver/OdbcDriver.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ public OdbcDriver()
1515
{
1616
}
1717

18+
public override System.Type CommandType
19+
{
20+
get { return typeof(System.Data.Odbc.OdbcCommand); }
21+
}
22+
23+
public override System.Type ConnectionType
24+
{
25+
get { return typeof(System.Data.Odbc.OdbcConnection); }
26+
}
27+
1828
public override IDbConnection CreateConnection()
1929
{
2030
return new System.Data.Odbc.OdbcConnection();

src/NHibernate/Driver/OleDbDriver.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ public OleDbDriver()
1515
{
1616
}
1717

18+
public override System.Type CommandType
19+
{
20+
get { return typeof(System.Data.OleDb.OleDbCommand); }
21+
}
22+
23+
public override System.Type ConnectionType
24+
{
25+
get { return typeof(System.Data.OleDb.OleDbConnection); }
26+
}
27+
1828
public override IDbConnection CreateConnection()
1929
{
2030
return new System.Data.OleDb.OleDbConnection();
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Data;
3+
using System.Reflection;
4+
5+
namespace NHibernate.Driver
6+
{
7+
/// <summary>
8+
/// A NHibernate Driver for using the Oracle DataProvider
9+
/// <see cref="System.Data.OracleClient.OracleConnection"/>.
10+
/// </summary>
11+
public class OracleClientDriver: DriverBase
12+
{
13+
private System.Type connectionType;
14+
private System.Type commandType;
15+
16+
public OracleClientDriver()
17+
{
18+
connectionType = System.Type.GetType("System.Data.OracleClient.OracleConnection, System.Data.OracleClient, version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
19+
commandType = System.Type.GetType("System.Data.OracleClient.OracleCommand, System.Data.OracleClient, version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
20+
}
21+
22+
public override System.Type CommandType
23+
{
24+
get { return commandType; }
25+
}
26+
27+
public override System.Type ConnectionType
28+
{
29+
get { return connectionType; }
30+
}
31+
32+
public override bool UseNamedPrefixInSql
33+
{
34+
get {return true;}
35+
}
36+
37+
public override bool UseNamedPrefixInParameter
38+
{
39+
get {return true;}
40+
}
41+
42+
public override string NamedPrefix
43+
{
44+
get {return ":";}
45+
}
46+
}
47+
}
48+

src/NHibernate/Driver/SqlClientDriver.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ public SqlClientDriver()
1212
{
1313
}
1414

15+
public override System.Type CommandType
16+
{
17+
get { return typeof(System.Data.SqlClient.SqlCommand); }
18+
}
19+
20+
public override System.Type ConnectionType
21+
{
22+
get { return typeof(System.Data.SqlClient.SqlConnection); }
23+
}
24+
1525
public override IDbConnection CreateConnection()
1626
{
1727
return new System.Data.SqlClient.SqlConnection();

0 commit comments

Comments
 (0)