Skip to content

Commit

Permalink
Fixed blob driver to work correctly with Oracle NHibernate dialects.
Browse files Browse the repository at this point in the history
  • Loading branch information
bittercoder committed Jul 30, 2011
1 parent bcfbbb1 commit c364184
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 122 deletions.
48 changes: 24 additions & 24 deletions Src/GlobalAssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyCompany("http://www.devdefined.com/")]
[assembly: AssemblyCopyright("(C) 20011-2012 DevDefined Ltd")]
[assembly: AssemblyTrademark("Lob for .Net")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]


//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.225
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyCompany("http://www.devdefined.com/")]
[assembly: AssemblyCopyright("(C) 20011-2012 DevDefined Ltd")]
[assembly: AssemblyTrademark("Lob for .Net")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]

1 change: 1 addition & 0 deletions Src/Lob.NHibernate.Tests/StubDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Data;
using NHibernate.Driver;
using NHibernate.Engine;
using NHibernate.SqlCommand;
using NHibernate.SqlTypes;

Expand Down
199 changes: 102 additions & 97 deletions Src/Lob.NHibernate/Wrappers/ExternalBlobDbCommandWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,98 +1,103 @@
using System.Data;
using System.Data.Common;

namespace Lob.NHibernate.Wrappers
{
public class ExternalBlobDbCommandWrapper : DbCommand
{
readonly DbCommand _cmd;
DbConnection _conn;

public ExternalBlobDbCommandWrapper(DbConnection conn, DbCommand cmd)
{
_cmd = cmd;
_conn = conn;
}

public override string CommandText
{
get { return _cmd.CommandText; }
set { _cmd.CommandText = value; }
}

public override int CommandTimeout
{
get { return _cmd.CommandTimeout; }
set { _cmd.CommandTimeout = value; }
}

public override CommandType CommandType
{
get { return _cmd.CommandType; }
set { _cmd.CommandType = value; }
}

protected override DbConnection DbConnection
{
get { return _conn; }
set
{
_conn = value;
_cmd.Connection = ((ExternalBlobDbConnectionWrapper) value)._db as DbConnection;
}
}

protected override DbParameterCollection DbParameterCollection
{
get { return _cmd.Parameters; }
}

protected override DbTransaction DbTransaction
{
get { return _cmd.Transaction; }
set { _cmd.Transaction = value; }
}

public override bool DesignTimeVisible
{
get { return false; }
set { }
}

public override UpdateRowSource UpdatedRowSource
{
get { return _cmd.UpdatedRowSource; }
set { _cmd.UpdatedRowSource = value; }
}

public override void Cancel()
{
_cmd.Cancel();
}

protected override DbParameter CreateDbParameter()
{
return _cmd.CreateParameter();
}

protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
{
return _cmd.ExecuteReader(behavior);
}

public override int ExecuteNonQuery()
{
return _cmd.ExecuteNonQuery();
}

public override object ExecuteScalar()
{
return _cmd.ExecuteScalar();
}

public override void Prepare()
{
_cmd.Prepare();
}
}
using System.Data;
using System.Data.Common;

namespace Lob.NHibernate.Wrappers
{
public class ExternalBlobDbCommandWrapper : DbCommand
{
readonly DbCommand _cmd;
DbConnection _conn;

public ExternalBlobDbCommandWrapper(DbConnection conn, DbCommand cmd)
{
_cmd = cmd;
_conn = conn;
}

public virtual DbCommand UnderlyingCommand
{
get { return _cmd; }
}

public override string CommandText
{
get { return _cmd.CommandText; }
set { _cmd.CommandText = value; }
}

public override int CommandTimeout
{
get { return _cmd.CommandTimeout; }
set { _cmd.CommandTimeout = value; }
}

public override CommandType CommandType
{
get { return _cmd.CommandType; }
set { _cmd.CommandType = value; }
}

protected override DbConnection DbConnection
{
get { return _conn; }
set
{
_conn = value;
_cmd.Connection = ((ExternalBlobDbConnectionWrapper) value)._db as DbConnection;
}
}

protected override DbParameterCollection DbParameterCollection
{
get { return _cmd.Parameters; }
}

protected override DbTransaction DbTransaction
{
get { return _cmd.Transaction; }
set { _cmd.Transaction = value; }
}

public override bool DesignTimeVisible
{
get { return false; }
set { }
}

public override UpdateRowSource UpdatedRowSource
{
get { return _cmd.UpdatedRowSource; }
set { _cmd.UpdatedRowSource = value; }
}

public override void Cancel()
{
_cmd.Cancel();
}

protected override DbParameter CreateDbParameter()
{
return _cmd.CreateParameter();
}

protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
{
return _cmd.ExecuteReader(behavior);
}

public override int ExecuteNonQuery()
{
return _cmd.ExecuteNonQuery();
}

public override object ExecuteScalar()
{
return _cmd.ExecuteScalar();
}

public override void Prepare()
{
_cmd.Prepare();
}
}
}
11 changes: 10 additions & 1 deletion Src/Lob.NHibernate/Wrappers/ExternalBlobDriverWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Data;
using System.Data.Common;
using NHibernate.Driver;
using NHibernate.Engine;
using NHibernate.SqlCommand;
using NHibernate.SqlTypes;

Expand Down Expand Up @@ -39,7 +40,15 @@ public IDbCommand GenerateCommand(CommandType type, SqlString sqlString, SqlType

public void PrepareCommand(IDbCommand command)
{
_base.PrepareCommand(command);
// we must unwrap command before preparing it, as the OracleDriver and OracleClientDriver
// make use of PrepareCommand and reflection to tweak some settings of the command which are not
// part of the DbCommand base class (so fails if invoked on our DB Command wrapper)

var wrapper = command as ExternalBlobDbCommandWrapper;

var unwrappedCommand = (wrapper != null) ? wrapper.UnderlyingCommand : command;

_base.PrepareCommand(unwrappedCommand);
}

public void ExpandQueryParameters(IDbCommand cmd, SqlString sqlString)
Expand Down

0 comments on commit c364184

Please sign in to comment.