Skip to content

Commit 81f3eca

Browse files
committed
NH-4008 - Split out drivers into own projects.
1 parent 0c7e383 commit 81f3eca

File tree

100 files changed

+1785
-290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+1785
-290
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using NHibernate.Driver;
2+
3+
namespace NHibernate.Cfg.Loquacious
4+
{
5+
public static class ConnectionConfigurationExtensionReflectionBased
6+
{
7+
public static IConnectionConfiguration ByReflectionDriver<TDriver>(this IConnectionConfiguration cfg) where TDriver : ReflectionBasedDriver
8+
{
9+
return cfg.By<TDriver>();
10+
}
11+
}
12+
}

src/NHibernate/Driver/SqlServerCeDriver.cs renamed to src/NHibernate.Driver.AdoNet/Driver/SqlServerCeDriver.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
using System;
21
using System.Collections.Generic;
32
using System.Data;
43
using System.Data.Common;
54
using System.Reflection;
5+
using NHibernate.Cfg;
66
using NHibernate.SqlTypes;
77
using NHibernate.Util;
8-
using Environment = NHibernate.Cfg.Environment;
98

109
namespace NHibernate.Driver
1110
{
@@ -104,8 +103,8 @@ protected override void InitializeParameter(DbParameter dbParam, string name, Sq
104103
AdjustDbParamTypeForLargeObjects(dbParam, sqlType);
105104
if (prepareSql)
106105
{
107-
SqlClientDriver.SetVariableLengthParameterSize(dbParam, sqlType);
108-
}
106+
SqlClientParameterHelper.SetVariableLengthParameterSize(dbParam, sqlType);
107+
}
109108
}
110109

111110
private static SqlType AdjustSqlType(SqlType sqlType)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{AED62C8C-4391-479E-AFD5-E41DD860D23E}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>NHibernate</RootNamespace>
11+
<AssemblyName>NHibernate.Driver.AdoNet</AssemblyName>
12+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
<NoWarn>1591</NoWarn>
24+
<DocumentationFile>bin\Debug\NHibernate.Driver.AdoNet.xml</DocumentationFile>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
<NoWarn>1591</NoWarn>
34+
<DocumentationFile>bin\Release\NHibernate.Driver.AdoNet.xml</DocumentationFile>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<Reference Include="System" />
38+
<Reference Include="System.Core" />
39+
<Reference Include="System.Data.DataSetExtensions" />
40+
<Reference Include="System.Data" />
41+
<Reference Include="System.Xml" />
42+
</ItemGroup>
43+
<ItemGroup>
44+
<Compile Include="..\SharedAssemblyInfo.cs">
45+
<Link>Properties\SharedAssemblyInfo.cs</Link>
46+
</Compile>
47+
<Compile Include="Cfg\Loquacious\ConnectionConfigurationExtensionReflectionBased.cs" />
48+
<Compile Include="Driver\CsharpSqliteDriver.cs" />
49+
<Compile Include="Driver\DB2400Driver.cs" />
50+
<Compile Include="Driver\DB2Driver.cs" />
51+
<Compile Include="Driver\DotConnectMySqlDriver.cs" />
52+
<Compile Include="Driver\FirebirdClientDriver.cs" />
53+
<Compile Include="Driver\IfxDriver.cs" />
54+
<Compile Include="Driver\IngresDriver.cs" />
55+
<Compile Include="Driver\MySqlDataDriver.cs" />
56+
<Compile Include="Driver\NpgsqlDriver.cs" />
57+
<Compile Include="Driver\OracleClientDriver.cs" />
58+
<Compile Include="Driver\OracleDataClientDriver.cs" />
59+
<Compile Include="Driver\OracleLiteDataClientDriver.cs" />
60+
<Compile Include="Driver\OracleManagedDataClientDriver.cs" />
61+
<Compile Include="Driver\ReflectionBasedDriver.cs" />
62+
<Compile Include="Driver\SQLite20Driver.cs" />
63+
<Compile Include="Driver\SqlServerCeDriver.cs" />
64+
<Compile Include="Driver\SybaseAsaClientDriver.cs" />
65+
<Compile Include="Driver\SybaseAseClientDriver.cs" />
66+
<Compile Include="Driver\SybaseSQLAnywhereDotNet4Driver.cs" />
67+
<Compile Include="Driver\SybaseSQLAnywhereDriver.cs" />
68+
<Compile Include="Properties\AssemblyInfo.cs" />
69+
</ItemGroup>
70+
<ItemGroup>
71+
<ProjectReference Include="..\NHibernate\NHibernate.csproj">
72+
<Project>{5909bfe7-93cf-4e5f-be22-6293368af01d}</Project>
73+
<Name>NHibernate</Name>
74+
</ProjectReference>
75+
</ItemGroup>
76+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
77+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Reflection;
3+
using System.Security;
4+
5+
[assembly: CLSCompliantAttribute(true)]
6+
[assembly: AssemblyTitleAttribute("NHibernate.Driver.ReflectionBased")]
7+
[assembly: AssemblyDescriptionAttribute("An object persistence library for relational databases.")]
8+
[assembly: AssemblyCompanyAttribute("NHibernate.info")]
9+
[assembly: AssemblyProductAttribute("NHibernate.Driver.ReflectionBased")]
10+
[assembly: AssemblyCopyrightAttribute("Licensed under LGPL.")]
11+
[assembly: AssemblyDelaySignAttribute(false)]
12+
[assembly: AllowPartiallyTrustedCallersAttribute()]
13+
[assembly: SecurityRulesAttribute(SecurityRuleSet.Level1)]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using NHibernate.Driver;
2+
3+
namespace NHibernate.Cfg.Loquacious
4+
{
5+
public static class ConnectionConfigurationExtensionFirebirdClient
6+
{
7+
public static IConnectionConfiguration ByFirebirdClientDriver(this IConnectionConfiguration cfg)
8+
{
9+
return cfg.By<FirebirdClientDriver>();
10+
}
11+
}
12+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using System.Collections.Generic;
2+
using System.Data;
3+
using System.Data.Common;
4+
using System.Linq;
5+
using System.Text.RegularExpressions;
6+
using NHibernate.Dialect;
7+
using NHibernate.SqlCommand;
8+
using NHibernate.SqlTypes;
9+
using NHibernate.Util;
10+
11+
namespace NHibernate.Driver
12+
{
13+
public class FirebirdClientDriver : DriverBase
14+
{
15+
private const string SELECT_CLAUSE_EXP = @"(?<=\bselect|\bwhere).*";
16+
private const string CAST_PARAMS_EXP = @"(?<![=<>]\s?|first\s?|skip\s?|between\s|between\s@\bp\w+\b\sand\s)@\bp\w+\b(?!\s?[=<>])";
17+
private readonly Regex _statementRegEx = new Regex(SELECT_CLAUSE_EXP, RegexOptions.IgnoreCase);
18+
private readonly Regex _castCandidateRegEx = new Regex(CAST_PARAMS_EXP, RegexOptions.IgnoreCase);
19+
private readonly FirebirdDialect _fbDialect = new FirebirdDialect();
20+
21+
public override bool UseNamedPrefixInSql => true;
22+
23+
public override bool UseNamedPrefixInParameter => true;
24+
25+
public override string NamedPrefix => "@";
26+
27+
public override DbConnection CreateConnection()
28+
{
29+
return new FirebirdSql.Data.FirebirdClient.FbConnection();
30+
}
31+
32+
public override DbCommand CreateCommand()
33+
{
34+
return new FirebirdSql.Data.FirebirdClient.FbCommand();
35+
}
36+
37+
public override DbCommand GenerateCommand(CommandType type, SqlString sqlString, SqlType[] parameterTypes)
38+
{
39+
var command = base.GenerateCommand(type, sqlString, parameterTypes);
40+
41+
var expWithParams = GetStatementsWithCastCandidates(command.CommandText);
42+
if (!string.IsNullOrWhiteSpace(expWithParams))
43+
{
44+
var candidates = GetCastCandidates(expWithParams);
45+
var castParams = from DbParameter p in command.Parameters
46+
where candidates.Contains(p.ParameterName)
47+
select p;
48+
foreach (var param in castParams)
49+
{
50+
TypeCastParam(param, command);
51+
}
52+
}
53+
54+
return command;
55+
}
56+
57+
protected override void InitializeParameter(DbParameter dbParam, string name, SqlType sqlType)
58+
{
59+
var convertedSqlType = sqlType;
60+
if (convertedSqlType.DbType == DbType.Currency)
61+
convertedSqlType = new SqlType(DbType.Decimal);
62+
63+
base.InitializeParameter(dbParam, name, convertedSqlType);
64+
}
65+
66+
private string GetStatementsWithCastCandidates(string commandText)
67+
{
68+
return _statementRegEx.Match(commandText).Value;
69+
}
70+
71+
private HashSet<string> GetCastCandidates(string statement)
72+
{
73+
var candidates =
74+
_castCandidateRegEx
75+
.Matches(statement)
76+
.Cast<Match>()
77+
.Select(match => match.Value);
78+
return new HashSet<string>(candidates);
79+
}
80+
81+
private void TypeCastParam(DbParameter param, DbCommand command)
82+
{
83+
var castType = GetFbTypeFromDbType(param.DbType);
84+
command.CommandText = command.CommandText.ReplaceWholeWord(param.ParameterName, string.Format("cast({0} as {1})", param.ParameterName, castType));
85+
}
86+
87+
private string GetFbTypeFromDbType(DbType dbType)
88+
{
89+
return _fbDialect.GetCastTypeName(new SqlType(dbType));
90+
}
91+
}
92+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{DADD54C1-3679-4672-9774-9362428EB9E0}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>NHibernate</RootNamespace>
11+
<AssemblyName>NHibernate.Driver.FirebirdClient</AssemblyName>
12+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
<DocumentationFile>bin\Debug\NHibernate.Driver.FirebirdClient.xml</DocumentationFile>
24+
<NoWarn>1591</NoWarn>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
<DocumentationFile>bin\Release\NHibernate.Driver.FirebirdClient.xml</DocumentationFile>
34+
<NoWarn>1591</NoWarn>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<Reference Include="FirebirdSql.Data.FirebirdClient, Version=5.9.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c, processorArchitecture=MSIL">
38+
<HintPath>..\packages\FirebirdSql.Data.FirebirdClient.5.9.0.1\lib\net452\FirebirdSql.Data.FirebirdClient.dll</HintPath>
39+
</Reference>
40+
<Reference Include="System" />
41+
<Reference Include="System.Core" />
42+
<Reference Include="System.Data.DataSetExtensions" />
43+
<Reference Include="System.Data" />
44+
<Reference Include="System.Xml" />
45+
</ItemGroup>
46+
<ItemGroup>
47+
<Compile Include="..\SharedAssemblyInfo.cs">
48+
<Link>Properties\SharedAssemblyInfo.cs</Link>
49+
</Compile>
50+
<Compile Include="Cfg\Loquacious\ConnectionConfigurationExtensionFirebirdClient.cs" />
51+
<Compile Include="Driver\FirebirdClientDriver.cs" />
52+
<Compile Include="Properties\AssemblyInfo.cs" />
53+
</ItemGroup>
54+
<ItemGroup>
55+
<ProjectReference Include="..\NHibernate\NHibernate.csproj">
56+
<Project>{5909bfe7-93cf-4e5f-be22-6293368af01d}</Project>
57+
<Name>NHibernate</Name>
58+
</ProjectReference>
59+
</ItemGroup>
60+
<ItemGroup>
61+
<None Include="app.config" />
62+
<None Include="packages.config" />
63+
</ItemGroup>
64+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
65+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Reflection;
3+
using System.Security;
4+
5+
[assembly: CLSCompliantAttribute(true)]
6+
[assembly: AssemblyTitleAttribute("NHibernate.Driver.FirebirdClient")]
7+
[assembly: AssemblyDescriptionAttribute("An object persistence library for relational databases.")]
8+
[assembly: AssemblyCompanyAttribute("NHibernate.info")]
9+
[assembly: AssemblyProductAttribute("NHibernate.Driver.FirebirdClient")]
10+
[assembly: AssemblyCopyrightAttribute("Licensed under LGPL.")]
11+
[assembly: AssemblyDelaySignAttribute(false)]
12+
[assembly: AllowPartiallyTrustedCallersAttribute()]
13+
[assembly: SecurityRulesAttribute(SecurityRuleSet.Level1)]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<system.data>
4+
<DbProviderFactories>
5+
<remove invariant="FirebirdSql.Data.FirebirdClient" />
6+
<add name="FirebirdClient Data Provider" invariant="FirebirdSql.Data.FirebirdClient" description=".NET Framework Data Provider for Firebird" type="FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient" />
7+
</DbProviderFactories>
8+
</system.data>
9+
</configuration>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="FirebirdSql.Data.FirebirdClient" version="5.9.0.1" targetFramework="net461" />
4+
</packages>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using NHibernate.Driver;
2+
3+
namespace NHibernate.Cfg.Loquacious
4+
{
5+
public static class ConnectionConfigurationExtensionMySql
6+
{
7+
public static IConnectionConfiguration ByMySqlDataDriver(this IConnectionConfiguration cfg)
8+
{
9+
return cfg.By<MySqlDataDriver>();
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)