Skip to content

Commit

Permalink
Workaround for issue chucknorris#37
Browse files Browse the repository at this point in the history
This is a workaround for a problem with NHibernate in combination with
the Microsoft Oracle driver. See
http://thebasilet.blogspot.be/2009/07/nhibernate-oracle-clobs.html for
details
  • Loading branch information
Lodewijk Sioen authored and Buthrakaur committed Jun 19, 2013
1 parent 8554ddd commit e697175
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
29 changes: 29 additions & 0 deletions product/roundhouse.databases.oracle/RoundhousEOracleDriver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Data.OracleClient;
using NHibernate.Driver;
using NHibernate.SqlTypes;
using roundhouse.infrastructure.logging;

namespace roundhouse.databases.oracle
{
public class RoundhousEOracleDriver : OracleClientDriver
{
protected override void InitializeParameter(System.Data.IDbDataParameter dbParam, string name, SqlType sqlType)
{
base.InitializeParameter(dbParam, name, sqlType);

//http://thebasilet.blogspot.be/2009/07/nhibernate-oracle-clobs.html
//System.Data.OracleClient.dll driver generates an exception
//we set the IDbDataParameter.Value = (string whose length: 4000 > length > 2000 )
//when we set the IDbDataParameter.DbType = DbType.String
//when DB Column is of type NCLOB/CLOB
//The Above is the default behavior for NHibernate.OracleClientDriver
//So we use the built-in StringClobSqlType to tell the driver to use the NClob Oracle type
//This will work for both NCLOB/CLOBs without issues.
//Mapping file will need to be update to use StringClob as the property type
if ((sqlType is StringClobSqlType))
{
((OracleParameter)dbParam).OracleType = OracleType.NClob;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace roundhouse.databases.oracle.orm
using NHibernate.SqlTypes;

namespace roundhouse.databases.oracle.orm
{
using System;
using FluentNHibernate.Mapping;
Expand All @@ -20,9 +22,9 @@ public ScriptsRunErrorMapping()
Map(x => x.repository_path);
Map(x => x.version).Length(50);
Map(x => x.script_name);
Map(x => x.text_of_script).CustomSqlType("Clob");
Map(x => x.erroneous_part_of_script).CustomSqlType("Clob");
Map(x => x.error_message).CustomSqlType("Clob");
Map(x => x.text_of_script).CustomSqlType("Clob").CustomType<StringClobSqlType>();
Map(x => x.erroneous_part_of_script).CustomSqlType("Clob").CustomType<StringClobSqlType>();
Map(x => x.error_message).CustomSqlType("Clob").CustomType<StringClobSqlType>();

//audit
Map(x => x.entry_date);
Expand Down
4 changes: 3 additions & 1 deletion product/roundhouse.databases.oracle/orm/ScriptsRunMapping.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using NHibernate.SqlTypes;

namespace roundhouse.databases.oracle.orm
{
using System;
Expand All @@ -19,7 +21,7 @@ public ScriptsRunMapping()
Id(x => x.id).Column("id").GeneratedBy.Sequence(ApplicationParameters.CurrentMappings.roundhouse_schema_name + "_" + ApplicationParameters.CurrentMappings.scripts_run_table_name + "id").UnsavedValue(0);
Map(x => x.version_id);
Map(x => x.script_name);
Map(x => x.text_of_script).CustomSqlType("Clob");
Map(x => x.text_of_script).CustomSqlType("Clob").CustomType<StringClobSqlType>();
Map(x => x.text_hash).Length(512);
Map(x => x.one_time_script);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<Compile Include="orm\VersionMapping.cs" />
<Compile Include="PLSQLSpecific.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RoundhousEOracleDriver.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\roundhouse\roundhouse.csproj">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public NHibernateSessionFactoryBuilder(ConfigurationPropertyHolder config)
func_dictionary.Add("roundhouse.databases.mysql.MySqlDatabase, roundhouse.databases.mysql",
() => MySQLConfiguration.Standard.ConnectionString(configuration_holder.ConnectionString));
func_dictionary.Add("roundhouse.databases.oracle.OracleDatabase, roundhouse.databases.oracle",
() => OracleClientConfiguration.Oracle9.ConnectionString(configuration_holder.ConnectionString));
() => OracleClientConfiguration.Oracle9.ConnectionString(configuration_holder.ConnectionString)
.Driver("roundhouse.databases.oracle.RoundhousEOracleDriver, roundhouse.databases.oracle"));
func_dictionary.Add("roundhouse.databases.access.AccessDatabase, roundhouse.databases.access",
() => JetDriverConfiguration.Standard.ConnectionString(configuration_holder.ConnectionString));
func_dictionary.Add("roundhouse.databases.sqlite.SqliteDatabase, roundhouse.databases.sqlite",
Expand All @@ -46,7 +47,8 @@ public NHibernateSessionFactoryBuilder(ConfigurationPropertyHolder config)
func_dictionary.Add("roundhouse.databases.mysql.MySqlDatabase, " + merged_assembly_name,
() => MySQLConfiguration.Standard.ConnectionString(configuration_holder.ConnectionString));
func_dictionary.Add("roundhouse.databases.oracle.OracleDatabase, " + merged_assembly_name,
() => OracleClientConfiguration.Oracle9.ConnectionString(configuration_holder.ConnectionString));
() => OracleClientConfiguration.Oracle9.ConnectionString(configuration_holder.ConnectionString)
.Driver("roundhouse.databases.oracle.RoundhousEOracleDriver, " + merged_assembly_name));
func_dictionary.Add("roundhouse.databases.access.AccessDatabase, " + merged_assembly_name,
() => JetDriverConfiguration.Standard.ConnectionString(configuration_holder.ConnectionString));
func_dictionary.Add("roundhouse.databases.sqlite.SqliteDatabase, " + merged_assembly_name,
Expand Down

0 comments on commit e697175

Please sign in to comment.