diff --git a/src/NHibernate.Test/ExceptionsTest/NullQueryTest.cs b/src/NHibernate.Test/ExceptionsTest/NullQueryTest.cs index 5c6d7ebe78e..4d2c668a22d 100644 --- a/src/NHibernate.Test/ExceptionsTest/NullQueryTest.cs +++ b/src/NHibernate.Test/ExceptionsTest/NullQueryTest.cs @@ -1,7 +1,9 @@ using System; using System.Collections; using System.Data; +using NHibernate.Engine; using NHibernate.Exceptions; +using NHibernate.Impl; using NUnit.Framework; namespace NHibernate.Test.ExceptionsTest @@ -35,7 +37,7 @@ public void BadGrammar() catch (Exception sqle) { Assert.DoesNotThrow( - () => ADOExceptionHelper.Convert(sessions.SQLExceptionConverter, sqle, "could not get or update next value", null)); + () => ADOExceptionHelper.Convert((ISessionImplementor)session, sessions.SQLExceptionConverter, sqle, "could not get or update next value", null)); } finally { diff --git a/src/NHibernate.Test/Insertordering/InsertOrderingFixture.cs b/src/NHibernate.Test/Insertordering/InsertOrderingFixture.cs index a65b6f59323..7d3824cd4a0 100644 --- a/src/NHibernate.Test/Insertordering/InsertOrderingFixture.cs +++ b/src/NHibernate.Test/Insertordering/InsertOrderingFixture.cs @@ -85,8 +85,8 @@ public class StatsBatcher : SqlClientBatchingBatcher private static IList batchSizes = new List(); private static int currentBatch = -1; - public StatsBatcher(ConnectionManager connectionManager, IInterceptor interceptor) - : base(connectionManager, interceptor) {} + public StatsBatcher(ConnectionManager connectionManager, IInterceptor interceptor, ISessionImplementor session) + : base(connectionManager, interceptor, session) {} public static IList BatchSizes { @@ -139,9 +139,9 @@ public class StatsBatcherFactory : IBatcherFactory { #region IBatcherFactory Members - public IBatcher CreateBatcher(ConnectionManager connectionManager, IInterceptor interceptor) + public IBatcher CreateBatcher(ConnectionManager connectionManager, IInterceptor interceptor, ISessionImplementor session) { - return new StatsBatcher(connectionManager, interceptor); + return new StatsBatcher(connectionManager, interceptor, session); } #endregion diff --git a/src/NHibernate.Test/Linq/QueryTimeoutTests.cs b/src/NHibernate.Test/Linq/QueryTimeoutTests.cs index 0140da5600c..403057a8299 100644 --- a/src/NHibernate.Test/Linq/QueryTimeoutTests.cs +++ b/src/NHibernate.Test/Linq/QueryTimeoutTests.cs @@ -77,8 +77,8 @@ public class TimeoutCatchingNonBatchingBatcher : NonBatchingBatcher public static int LastCommandTimeout; - public TimeoutCatchingNonBatchingBatcher(ConnectionManager connectionManager, IInterceptor interceptor) - : base(connectionManager, interceptor) + public TimeoutCatchingNonBatchingBatcher(ConnectionManager connectionManager, IInterceptor interceptor, ISessionImplementor session) + : base(connectionManager, interceptor, session) { } @@ -92,9 +92,9 @@ public override System.Data.IDataReader ExecuteReader(System.Data.IDbCommand cmd public class TimeoutCatchingNonBatchingBatcherFactory : IBatcherFactory { - public IBatcher CreateBatcher(ConnectionManager connectionManager, IInterceptor interceptor) + public IBatcher CreateBatcher(ConnectionManager connectionManager, IInterceptor interceptor, ISessionImplementor session) { - return new TimeoutCatchingNonBatchingBatcher(connectionManager, interceptor); + return new TimeoutCatchingNonBatchingBatcher(connectionManager, interceptor, session); } } } diff --git a/src/NHibernate/AdoNet/AbstractBatcher.cs b/src/NHibernate/AdoNet/AbstractBatcher.cs index 9a250398404..44287fce693 100644 --- a/src/NHibernate/AdoNet/AbstractBatcher.cs +++ b/src/NHibernate/AdoNet/AbstractBatcher.cs @@ -7,6 +7,7 @@ using NHibernate.Driver; using NHibernate.Engine; using NHibernate.Exceptions; +using NHibernate.Impl; using NHibernate.SqlCommand; using NHibernate.SqlTypes; using NHibernate.Util; @@ -27,8 +28,9 @@ public abstract class AbstractBatcher : IBatcher private readonly ConnectionManager _connectionManager; private readonly ISessionFactoryImplementor _factory; private readonly IInterceptor _interceptor; + private readonly ISessionImplementor _session; - // batchCommand used to be called batchUpdate - that name to me implied that updates + // batchCommand used to be called batchUpdate - that name to me implied that updates // were being sent - however this could be just INSERT/DELETE/SELECT SQL statement not // just update. However I haven't seen this being used with read statements... private IDbCommand _batchCommand; @@ -45,11 +47,12 @@ public abstract class AbstractBatcher : IBatcher /// /// The owning this batcher. /// - protected AbstractBatcher(ConnectionManager connectionManager, IInterceptor interceptor) + protected AbstractBatcher(ConnectionManager connectionManager, IInterceptor interceptor, ISessionImplementor session) { _connectionManager = connectionManager; _interceptor = interceptor; - _factory = connectionManager.Factory; + _session = session; + _factory = connectionManager.Factory; } protected IDriver Driver @@ -539,7 +542,7 @@ public bool HasOpenResources protected Exception Convert(Exception sqlException, string message) { - return ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, sqlException, message); + return ADOExceptionHelper.Convert(_session, Factory.SQLExceptionConverter, sqlException, message); } #region IDisposable Members diff --git a/src/NHibernate/AdoNet/ConnectionManager.cs b/src/NHibernate/AdoNet/ConnectionManager.cs index ce90eeaed7f..1ed144d7285 100644 --- a/src/NHibernate/AdoNet/ConnectionManager.cs +++ b/src/NHibernate/AdoNet/ConnectionManager.cs @@ -58,7 +58,7 @@ public ConnectionManager( this.connectionReleaseMode = connectionReleaseMode; this.interceptor = interceptor; - batcher = session.Factory.Settings.BatcherFactory.CreateBatcher(this, interceptor); + batcher = session.Factory.Settings.BatcherFactory.CreateBatcher(this, interceptor, session); ownConnection = suppliedConnection == null; } @@ -312,7 +312,7 @@ public void GetObjectData(SerializationInfo info, StreamingContext context) void IDeserializationCallback.OnDeserialization(object sender) { - batcher = session.Factory.Settings.BatcherFactory.CreateBatcher(this, interceptor); + batcher = session.Factory.Settings.BatcherFactory.CreateBatcher(this, interceptor, session); } #endregion diff --git a/src/NHibernate/AdoNet/IBatcherFactory.cs b/src/NHibernate/AdoNet/IBatcherFactory.cs index 477d9ef58d6..7d48e26ed06 100644 --- a/src/NHibernate/AdoNet/IBatcherFactory.cs +++ b/src/NHibernate/AdoNet/IBatcherFactory.cs @@ -5,6 +5,6 @@ namespace NHibernate.AdoNet /// Factory for instances. public interface IBatcherFactory { - IBatcher CreateBatcher(ConnectionManager connectionManager, IInterceptor interceptor); + IBatcher CreateBatcher(ConnectionManager connectionManager, IInterceptor interceptor, ISessionImplementor session); } } \ No newline at end of file diff --git a/src/NHibernate/AdoNet/MySqlClientBatchingBatcher.cs b/src/NHibernate/AdoNet/MySqlClientBatchingBatcher.cs index bec94cea973..d6a7a925871 100644 --- a/src/NHibernate/AdoNet/MySqlClientBatchingBatcher.cs +++ b/src/NHibernate/AdoNet/MySqlClientBatchingBatcher.cs @@ -2,21 +2,25 @@ using System.Data.Common; using System.Text; using NHibernate.AdoNet.Util; +using NHibernate.Engine; using NHibernate.Exceptions; +using NHibernate.Impl; namespace NHibernate.AdoNet { public class MySqlClientBatchingBatcher : AbstractBatcher { - private int batchSize; + private readonly ISessionImplementor _session; + private int batchSize; private int totalExpectedRowsAffected; private MySqlClientSqlCommandSet currentBatch; private StringBuilder currentBatchCommandsLog; - public MySqlClientBatchingBatcher(ConnectionManager connectionManager, IInterceptor interceptor) - : base(connectionManager, interceptor) + public MySqlClientBatchingBatcher(ConnectionManager connectionManager, IInterceptor interceptor, ISessionImplementor session) + : base(connectionManager, interceptor, session) { - batchSize = Factory.Settings.AdoBatchSize; + _session = session; + batchSize = Factory.Settings.AdoBatchSize; currentBatch = CreateConfiguredBatch(); //we always create this, because we need to deal with a scenario in which @@ -84,7 +88,7 @@ protected override void DoExecuteBatch(IDbCommand ps) } catch (DbException e) { - throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, e, "could not execute batch command."); + throw ADOExceptionHelper.Convert(_session, Factory.SQLExceptionConverter, e, "could not execute batch command."); } Expectations.VerifyOutcomeBatched(totalExpectedRowsAffected, rowsAffected); diff --git a/src/NHibernate/AdoNet/MySqlClientBatchingBatcherFactory.cs b/src/NHibernate/AdoNet/MySqlClientBatchingBatcherFactory.cs index 8470c6579fd..93b7a4ebc60 100644 --- a/src/NHibernate/AdoNet/MySqlClientBatchingBatcherFactory.cs +++ b/src/NHibernate/AdoNet/MySqlClientBatchingBatcherFactory.cs @@ -4,9 +4,9 @@ namespace NHibernate.AdoNet { public class MySqlClientBatchingBatcherFactory : IBatcherFactory { - public virtual IBatcher CreateBatcher(ConnectionManager connectionManager, IInterceptor interceptor) + public virtual IBatcher CreateBatcher(ConnectionManager connectionManager, IInterceptor interceptor, ISessionImplementor session) { - return new MySqlClientBatchingBatcher(connectionManager, interceptor); + return new MySqlClientBatchingBatcher(connectionManager, interceptor, session); } } } \ No newline at end of file diff --git a/src/NHibernate/AdoNet/NonBatchingBatcher.cs b/src/NHibernate/AdoNet/NonBatchingBatcher.cs index 2fb3a7ad37a..4f2c65bb8b7 100644 --- a/src/NHibernate/AdoNet/NonBatchingBatcher.cs +++ b/src/NHibernate/AdoNet/NonBatchingBatcher.cs @@ -15,9 +15,9 @@ public class NonBatchingBatcher : AbstractBatcher /// Initializes a new instance of the class. /// /// The for this batcher. - /// - public NonBatchingBatcher(ConnectionManager connectionManager, IInterceptor interceptor) - : base(connectionManager, interceptor) + /// + public NonBatchingBatcher(ConnectionManager connectionManager, IInterceptor interceptor, ISessionImplementor session) + : base(connectionManager, interceptor, session) { } diff --git a/src/NHibernate/AdoNet/NonBatchingBatcherFactory.cs b/src/NHibernate/AdoNet/NonBatchingBatcherFactory.cs index 544348831b4..0385a7c2b27 100644 --- a/src/NHibernate/AdoNet/NonBatchingBatcherFactory.cs +++ b/src/NHibernate/AdoNet/NonBatchingBatcherFactory.cs @@ -8,9 +8,9 @@ namespace NHibernate.AdoNet /// public class NonBatchingBatcherFactory : IBatcherFactory { - public virtual IBatcher CreateBatcher(ConnectionManager connectionManager, IInterceptor interceptor) + public virtual IBatcher CreateBatcher(ConnectionManager connectionManager, IInterceptor interceptor, ISessionImplementor session) { - return new NonBatchingBatcher(connectionManager, interceptor); + return new NonBatchingBatcher(connectionManager, interceptor, session); } } } diff --git a/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs b/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs index 7e1d92ec908..7964e179ceb 100644 --- a/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs +++ b/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs @@ -5,7 +5,9 @@ using System.Reflection; using System.Text; using NHibernate.AdoNet.Util; +using NHibernate.Engine; using NHibernate.Exceptions; +using NHibernate.Impl; namespace NHibernate.AdoNet { @@ -15,7 +17,8 @@ namespace NHibernate.AdoNet /// public class OracleDataClientBatchingBatcher : AbstractBatcher { - private int _batchSize; + private readonly ISessionImplementor _session; + private int _batchSize; private int _countOfCommands = 0; private int _totalExpectedRowsAffected; private IDbCommand _currentBatch; @@ -23,10 +26,11 @@ public class OracleDataClientBatchingBatcher : AbstractBatcher private IDictionary _parameterIsAllNullsHashTable; private StringBuilder _currentBatchCommandsLog; - public OracleDataClientBatchingBatcher(ConnectionManager connectionManager, IInterceptor interceptor) - : base(connectionManager, interceptor) + public OracleDataClientBatchingBatcher(ConnectionManager connectionManager, IInterceptor interceptor, ISessionImplementor session) + : base(connectionManager, interceptor, session) { - _batchSize = Factory.Settings.AdoBatchSize; + _session = session; + _batchSize = Factory.Settings.AdoBatchSize; //we always create this, because we need to deal with a scenario in which //the user change the logging configuration at runtime. Trying to put this //behind an if(log.IsDebugEnabled) will cause a null reference exception @@ -133,7 +137,7 @@ protected override void DoExecuteBatch(IDbCommand ps) } catch (DbException e) { - throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, e, "could not execute batch command."); + throw ADOExceptionHelper.Convert(_session, Factory.SQLExceptionConverter, e, "could not execute batch command."); } Expectations.VerifyOutcomeBatched(_totalExpectedRowsAffected, rowsAffected); diff --git a/src/NHibernate/AdoNet/OracleDataClientBatchingBatcherFactory.cs b/src/NHibernate/AdoNet/OracleDataClientBatchingBatcherFactory.cs index b5bfa091e66..74606df0885 100644 --- a/src/NHibernate/AdoNet/OracleDataClientBatchingBatcherFactory.cs +++ b/src/NHibernate/AdoNet/OracleDataClientBatchingBatcherFactory.cs @@ -4,9 +4,9 @@ namespace NHibernate.AdoNet { public class OracleDataClientBatchingBatcherFactory : IBatcherFactory { - public virtual IBatcher CreateBatcher(ConnectionManager connectionManager, IInterceptor interceptor) + public virtual IBatcher CreateBatcher(ConnectionManager connectionManager, IInterceptor interceptor, ISessionImplementor session) { - return new OracleDataClientBatchingBatcher(connectionManager, interceptor); + return new OracleDataClientBatchingBatcher(connectionManager, interceptor, session); } } } \ No newline at end of file diff --git a/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs b/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs index 1926b1bc539..6595b6351a4 100644 --- a/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs +++ b/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs @@ -3,23 +3,27 @@ using System.Data.Common; using System.Text; using NHibernate.AdoNet.Util; +using NHibernate.Engine; using NHibernate.Exceptions; +using NHibernate.Impl; using NHibernate.Util; namespace NHibernate.AdoNet { public class SqlClientBatchingBatcher : AbstractBatcher { - private int _batchSize; + private readonly ISessionImplementor _session; + private int _batchSize; private int _totalExpectedRowsAffected; private SqlClientSqlCommandSet _currentBatch; private StringBuilder _currentBatchCommandsLog; private readonly int _defaultTimeout; - public SqlClientBatchingBatcher(ConnectionManager connectionManager, IInterceptor interceptor) - : base(connectionManager, interceptor) + public SqlClientBatchingBatcher(ConnectionManager connectionManager, IInterceptor interceptor, ISessionImplementor session) + : base(connectionManager, interceptor, session) { - _batchSize = Factory.Settings.AdoBatchSize; + _session = session; + _batchSize = Factory.Settings.AdoBatchSize; _defaultTimeout = PropertiesHelper.GetInt32(Cfg.Environment.CommandTimeout, Cfg.Environment.Properties, -1); _currentBatch = CreateConfiguredBatch(); @@ -88,7 +92,7 @@ protected override void DoExecuteBatch(IDbCommand ps) } catch (DbException e) { - throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, e, "could not execute batch command."); + throw ADOExceptionHelper.Convert(_session, Factory.SQLExceptionConverter, e, "could not execute batch command."); } Expectations.VerifyOutcomeBatched(_totalExpectedRowsAffected, rowsAffected); diff --git a/src/NHibernate/AdoNet/SqlClientBatchingBatcherFactory.cs b/src/NHibernate/AdoNet/SqlClientBatchingBatcherFactory.cs index 4cd6052bb78..7c98c6bf805 100644 --- a/src/NHibernate/AdoNet/SqlClientBatchingBatcherFactory.cs +++ b/src/NHibernate/AdoNet/SqlClientBatchingBatcherFactory.cs @@ -4,9 +4,9 @@ namespace NHibernate.AdoNet { public class SqlClientBatchingBatcherFactory : IBatcherFactory { - public virtual IBatcher CreateBatcher(ConnectionManager connectionManager, IInterceptor interceptor) + public virtual IBatcher CreateBatcher(ConnectionManager connectionManager, IInterceptor interceptor, ISessionImplementor session) { - return new SqlClientBatchingBatcher(connectionManager, interceptor); + return new SqlClientBatchingBatcher(connectionManager, interceptor, session); } } } \ No newline at end of file diff --git a/src/NHibernate/Dialect/Lock/SelectLockingStrategy.cs b/src/NHibernate/Dialect/Lock/SelectLockingStrategy.cs index fcd9f66392c..c07bcb62e47 100644 --- a/src/NHibernate/Dialect/Lock/SelectLockingStrategy.cs +++ b/src/NHibernate/Dialect/Lock/SelectLockingStrategy.cs @@ -101,7 +101,8 @@ public void Lock(object id, object version, object obj, ISessionImplementor sess Message = "could not lock: " + MessageHelper.InfoString(lockable, id, factory), Sql = sql.ToString(), EntityName = lockable.EntityName, - EntityId = id + EntityId = id, + Session = session }; throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, exceptionContext); } diff --git a/src/NHibernate/Dialect/Lock/UpdateLockingStrategy.cs b/src/NHibernate/Dialect/Lock/UpdateLockingStrategy.cs index 16c9d4982fc..7b6ee634b04 100644 --- a/src/NHibernate/Dialect/Lock/UpdateLockingStrategy.cs +++ b/src/NHibernate/Dialect/Lock/UpdateLockingStrategy.cs @@ -113,7 +113,8 @@ public void Lock(object id, object version, object obj, ISessionImplementor sess Message = "could not lock: " + MessageHelper.InfoString(lockable, id, factory), Sql = sql.ToString(), EntityName = lockable.EntityName, - EntityId = id + EntityId = id, + Session = session }; throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, exceptionContext); } diff --git a/src/NHibernate/Engine/Query/NativeSQLQueryPlan.cs b/src/NHibernate/Engine/Query/NativeSQLQueryPlan.cs index d99f46dbca4..866371135c5 100644 --- a/src/NHibernate/Engine/Query/NativeSQLQueryPlan.cs +++ b/src/NHibernate/Engine/Query/NativeSQLQueryPlan.cs @@ -109,7 +109,7 @@ public int PerformExecuteUpdate(QueryParameters queryParameters, ISessionImpleme } catch (Exception sqle) { - throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle, + throw ADOExceptionHelper.Convert(session, session.Factory.SQLExceptionConverter, sqle, "could not execute native bulk manipulation query:" + sourceQuery); } diff --git a/src/NHibernate/Engine/TransactionHelper.cs b/src/NHibernate/Engine/TransactionHelper.cs index d819143e410..fa8bcae5ec3 100644 --- a/src/NHibernate/Engine/TransactionHelper.cs +++ b/src/NHibernate/Engine/TransactionHelper.cs @@ -2,6 +2,7 @@ using System.Data.Common; using NHibernate.Engine.Transaction; using NHibernate.Exceptions; +using NHibernate.Impl; namespace NHibernate.Engine { @@ -33,7 +34,7 @@ public void DoWork(IDbConnection connection, IDbTransaction transaction) } catch (DbException sqle) { - throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle, "could not get or update next value", null); + throw ADOExceptionHelper.Convert(session, session.Factory.SQLExceptionConverter, sqle, "could not get or update next value", null); } } diff --git a/src/NHibernate/Exceptions/ADOExceptionHelper.cs b/src/NHibernate/Exceptions/ADOExceptionHelper.cs index 8138dacc454..1ea865fef75 100644 --- a/src/NHibernate/Exceptions/ADOExceptionHelper.cs +++ b/src/NHibernate/Exceptions/ADOExceptionHelper.cs @@ -3,6 +3,7 @@ using System.Data.Common; using System.Text; using NHibernate.Engine; +using NHibernate.Impl; using NHibernate.SqlCommand; using NHibernate.Util; @@ -33,35 +34,36 @@ public static Exception Convert(ISQLExceptionConverter converter, AdoExceptionCo /// An optional error message. /// The SQL executed. /// The converted . - public static Exception Convert(ISQLExceptionConverter converter, Exception sqlException, string message, + public static Exception Convert(ISessionImplementor session, ISQLExceptionConverter converter, Exception sqlException, string message, SqlString sql) { return Convert(converter, new AdoExceptionContextInfo - {SqlException = sqlException, Message = message, Sql = sql != null ? sql.ToString() : null}); + {SqlException = sqlException, Message = message, Sql = sql != null ? sql.ToString() : null, Session = session}); } - /// - /// Converts the given SQLException into Exception hierarchy, as well as performing - /// appropriate logging. - /// - /// The converter to use. - /// The exception to convert. - /// An optional error message. - /// The converted . - public static Exception Convert(ISQLExceptionConverter converter, Exception sqlException, string message) + /// + /// Converts the given SQLException into Exception hierarchy, as well as performing + /// appropriate logging. + /// + /// The current session. + /// The converter to use. + /// The exception to convert. + /// An optional error message. + /// The converted . + public static Exception Convert(ISessionImplementor session, ISQLExceptionConverter converter, Exception sqlException, string message) { var sql = TryGetActualSqlQuery(sqlException, SQLNotAvailable); - return Convert(converter, new AdoExceptionContextInfo {SqlException = sqlException, Message = message, Sql = sql}); + return Convert(converter, new AdoExceptionContextInfo {SqlException = sqlException, Message = message, Sql = sql, Session = session }); } - public static Exception Convert(ISQLExceptionConverter converter, Exception sqle, string message, SqlString sql, + public static Exception Convert(ISessionImplementor session, ISQLExceptionConverter converter, Exception sqle, string message, SqlString sql, object[] parameterValues, IDictionary namedParameters) { sql = TryGetActualSqlQuery(sqle, sql); string extendMessage = ExtendMessage(message, sql != null ? sql.ToString() : null, parameterValues, namedParameters); ADOExceptionReporter.LogExceptions(sqle, extendMessage); - return Convert(converter, sqle, extendMessage, sql); + return Convert(session, converter, sqle, extendMessage, sql); } /// For the given , locates the . diff --git a/src/NHibernate/Exceptions/AdoExceptionContextInfo.cs b/src/NHibernate/Exceptions/AdoExceptionContextInfo.cs index 5a57cfd2639..c0ff0c71a1c 100644 --- a/src/NHibernate/Exceptions/AdoExceptionContextInfo.cs +++ b/src/NHibernate/Exceptions/AdoExceptionContextInfo.cs @@ -1,4 +1,6 @@ using System; +using NHibernate.Engine; +using NHibernate.Impl; namespace NHibernate.Exceptions { @@ -36,5 +38,10 @@ public class AdoExceptionContextInfo /// Optional EntityId where available in the original exception context. /// public object EntityId { get; set; } + + /// + /// Session from which the exception was thrown. + /// + public ISessionImplementor Session { get; set; } } } \ No newline at end of file diff --git a/src/NHibernate/Hql/Ast/ANTLR/Exec/BasicExecutor.cs b/src/NHibernate/Hql/Ast/ANTLR/Exec/BasicExecutor.cs index c096d6bca73..97dd816fa61 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/Exec/BasicExecutor.cs +++ b/src/NHibernate/Hql/Ast/ANTLR/Exec/BasicExecutor.cs @@ -9,6 +9,7 @@ using NHibernate.Engine; using NHibernate.Exceptions; using NHibernate.Hql.Ast.ANTLR.Tree; +using NHibernate.Impl; using NHibernate.Param; using NHibernate.SqlCommand; using NHibernate.SqlTypes; @@ -89,7 +90,7 @@ public override int Execute(QueryParameters parameters, ISessionImplementor sess } catch (DbException sqle) { - throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle, + throw ADOExceptionHelper.Convert(session, session.Factory.SQLExceptionConverter, sqle, "could not execute update query", sql); } } diff --git a/src/NHibernate/Hql/Ast/ANTLR/Exec/MultiTableDeleteExecutor.cs b/src/NHibernate/Hql/Ast/ANTLR/Exec/MultiTableDeleteExecutor.cs index 96bb2853f56..fdb090aec1f 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/Exec/MultiTableDeleteExecutor.cs +++ b/src/NHibernate/Hql/Ast/ANTLR/Exec/MultiTableDeleteExecutor.cs @@ -5,6 +5,7 @@ using NHibernate.Engine; using NHibernate.Exceptions; using NHibernate.Hql.Ast.ANTLR.Tree; +using NHibernate.Impl; using NHibernate.Param; using NHibernate.SqlCommand; using NHibernate.SqlTypes; @@ -103,7 +104,7 @@ public override int Execute(QueryParameters parameters, ISessionImplementor sess } catch (DbException e) { - throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, e, "could not insert/select ids for bulk delete", idInsertSelect); + throw ADOExceptionHelper.Convert(session, Factory.SQLExceptionConverter, e, "could not insert/select ids for bulk delete", idInsertSelect); } // Start performing the deletes @@ -126,7 +127,7 @@ public override int Execute(QueryParameters parameters, ISessionImplementor sess } catch (DbException e) { - throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, e, "error performing bulk delete", deletes[i]); + throw ADOExceptionHelper.Convert(session, Factory.SQLExceptionConverter, e, "error performing bulk delete", deletes[i]); } } diff --git a/src/NHibernate/Hql/Ast/ANTLR/Exec/MultiTableUpdateExecutor.cs b/src/NHibernate/Hql/Ast/ANTLR/Exec/MultiTableUpdateExecutor.cs index f6257951253..46579947a08 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/Exec/MultiTableUpdateExecutor.cs +++ b/src/NHibernate/Hql/Ast/ANTLR/Exec/MultiTableUpdateExecutor.cs @@ -6,6 +6,7 @@ using NHibernate.Engine; using NHibernate.Exceptions; using NHibernate.Hql.Ast.ANTLR.Tree; +using NHibernate.Impl; using NHibernate.Param; using NHibernate.Persister.Entity; using NHibernate.SqlCommand; @@ -131,7 +132,7 @@ public override int Execute(QueryParameters parameters, ISessionImplementor sess } catch (DbException e) { - throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, e, "could not insert/select ids for bulk update", + throw ADOExceptionHelper.Convert(session, Factory.SQLExceptionConverter, e, "could not insert/select ids for bulk update", idInsertSelect); } @@ -168,7 +169,7 @@ public override int Execute(QueryParameters parameters, ISessionImplementor sess } catch (DbException e) { - throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, e, "error performing bulk update", updates[i]); + throw ADOExceptionHelper.Convert(session, Factory.SQLExceptionConverter, e, "error performing bulk update", updates[i]); } } diff --git a/src/NHibernate/Id/Enhanced/SequenceStructure.cs b/src/NHibernate/Id/Enhanced/SequenceStructure.cs index 42e05167a32..bfe3a0545e7 100644 --- a/src/NHibernate/Id/Enhanced/SequenceStructure.cs +++ b/src/NHibernate/Id/Enhanced/SequenceStructure.cs @@ -4,6 +4,7 @@ using NHibernate.Engine; using NHibernate.Exceptions; +using NHibernate.Impl; using NHibernate.SqlCommand; using NHibernate.SqlTypes; @@ -132,7 +133,7 @@ public virtual long GetNextValue() } catch (DbException sqle) { - throw ADOExceptionHelper.Convert(_session.Factory.SQLExceptionConverter, sqle, "could not get next sequence value", _owner._sql); + throw ADOExceptionHelper.Convert(_session, _session.Factory.SQLExceptionConverter, sqle, "could not get next sequence value", _owner._sql); } } diff --git a/src/NHibernate/Id/IncrementGenerator.cs b/src/NHibernate/Id/IncrementGenerator.cs index 834c92c6d72..4abf676a832 100644 --- a/src/NHibernate/Id/IncrementGenerator.cs +++ b/src/NHibernate/Id/IncrementGenerator.cs @@ -6,6 +6,7 @@ using NHibernate.Engine; using NHibernate.Exceptions; +using NHibernate.Impl; using NHibernate.Type; using NHibernate.Util; using System.Data.Common; @@ -130,7 +131,7 @@ private void GetNext(ISessionImplementor session) catch (DbException sqle) { log.Error("could not get increment value", sqle); - throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle, + throw ADOExceptionHelper.Convert(session, session.Factory.SQLExceptionConverter, sqle, "could not fetch initial value for increment generator"); } } diff --git a/src/NHibernate/Id/Insert/AbstractReturningDelegate.cs b/src/NHibernate/Id/Insert/AbstractReturningDelegate.cs index 0e6208b8e0e..62b8b27fb3a 100644 --- a/src/NHibernate/Id/Insert/AbstractReturningDelegate.cs +++ b/src/NHibernate/Id/Insert/AbstractReturningDelegate.cs @@ -2,6 +2,7 @@ using System.Data.Common; using NHibernate.Engine; using NHibernate.Exceptions; +using NHibernate.Impl; using NHibernate.SqlCommand; namespace NHibernate.Id.Insert @@ -48,7 +49,7 @@ public object PerformInsert(SqlCommandInfo insertSQL, ISessionImplementor sessio } catch (DbException sqle) { - throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle, + throw ADOExceptionHelper.Convert(session, session.Factory.SQLExceptionConverter, sqle, "could not insert: " + persister.GetInfoString(), insertSQL.Text); } } diff --git a/src/NHibernate/Id/Insert/AbstractSelectingDelegate.cs b/src/NHibernate/Id/Insert/AbstractSelectingDelegate.cs index 8776247ad66..edb659da027 100644 --- a/src/NHibernate/Id/Insert/AbstractSelectingDelegate.cs +++ b/src/NHibernate/Id/Insert/AbstractSelectingDelegate.cs @@ -44,7 +44,7 @@ public object PerformInsert(SqlCommandInfo insertSQL, ISessionImplementor sessio } catch (DbException sqle) { - throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle, + throw ADOExceptionHelper.Convert(session, session.Factory.SQLExceptionConverter, sqle, "could not insert: " + persister.GetInfoString(), insertSQL.Text); } @@ -74,7 +74,7 @@ public object PerformInsert(SqlCommandInfo insertSQL, ISessionImplementor sessio } catch (DbException sqle) { - throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle, + throw ADOExceptionHelper.Convert(session, session.Factory.SQLExceptionConverter, sqle, "could not retrieve generated id after insert: " + persister.GetInfoString(), insertSQL.Text); } diff --git a/src/NHibernate/Id/NativeGuidGenerator.cs b/src/NHibernate/Id/NativeGuidGenerator.cs index d79909f9a39..b0e1b03c739 100644 --- a/src/NHibernate/Id/NativeGuidGenerator.cs +++ b/src/NHibernate/Id/NativeGuidGenerator.cs @@ -3,6 +3,7 @@ using NHibernate.Engine; using NHibernate.Exceptions; +using NHibernate.Impl; using NHibernate.SqlCommand; using NHibernate.SqlTypes; using NHibernate.Type; @@ -49,7 +50,7 @@ public object Generate(ISessionImplementor session, object obj) } catch (Exception sqle) { - throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle, "could not retrieve GUID", sql); + throw ADOExceptionHelper.Convert(session, session.Factory.SQLExceptionConverter, sqle, "could not retrieve GUID", sql); } } diff --git a/src/NHibernate/Id/SequenceGenerator.cs b/src/NHibernate/Id/SequenceGenerator.cs index 3407487a69a..2b591f48320 100644 --- a/src/NHibernate/Id/SequenceGenerator.cs +++ b/src/NHibernate/Id/SequenceGenerator.cs @@ -4,6 +4,7 @@ using NHibernate.Engine; using NHibernate.Exceptions; +using NHibernate.Impl; using NHibernate.SqlCommand; using NHibernate.SqlTypes; using NHibernate.Type; @@ -141,7 +142,7 @@ public virtual object Generate(ISessionImplementor session, object obj) catch (DbException sqle) { log.Error("error generating sequence", sqle); - throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle, "could not get next sequence value"); + throw ADOExceptionHelper.Convert(session, session.Factory.SQLExceptionConverter, sqle, "could not get next sequence value"); } } diff --git a/src/NHibernate/Impl/AbstractSessionImpl.cs b/src/NHibernate/Impl/AbstractSessionImpl.cs index 217c5ff79fc..ca5386cc89e 100644 --- a/src/NHibernate/Impl/AbstractSessionImpl.cs +++ b/src/NHibernate/Impl/AbstractSessionImpl.cs @@ -425,7 +425,7 @@ protected Exception Convert(Exception sqlException, string message) { using (new SessionIdLoggingContext(SessionId)) { - return ADOExceptionHelper.Convert(factory.SQLExceptionConverter, sqlException, message); + return ADOExceptionHelper.Convert(this, factory.SQLExceptionConverter, sqlException, message); } } diff --git a/src/NHibernate/Impl/EnumerableImpl.cs b/src/NHibernate/Impl/EnumerableImpl.cs index b0dd3d1562e..d893537a093 100644 --- a/src/NHibernate/Impl/EnumerableImpl.cs +++ b/src/NHibernate/Impl/EnumerableImpl.cs @@ -119,7 +119,7 @@ public bool MoveNext() } catch (DbException e) { - throw ADOExceptionHelper.Convert(_session.Factory.SQLExceptionConverter, e, "Error executing Enumerable() query", + throw ADOExceptionHelper.Convert(_session, _session.Factory.SQLExceptionConverter, e, "Error executing Enumerable() query", new SqlString(_cmd.CommandText)); } PostMoveNext(readResult); @@ -144,7 +144,7 @@ private void PostNext() } catch (DbException e) { - throw ADOExceptionHelper.Convert(_session.Factory.SQLExceptionConverter, e, "Error executing Enumerable() query", + throw ADOExceptionHelper.Convert(_session, _session.Factory.SQLExceptionConverter, e, "Error executing Enumerable() query", new SqlString(_cmd.CommandText)); } } diff --git a/src/NHibernate/Impl/MultiCriteriaImpl.cs b/src/NHibernate/Impl/MultiCriteriaImpl.cs index 16802f43513..fe3ce5177f6 100644 --- a/src/NHibernate/Impl/MultiCriteriaImpl.cs +++ b/src/NHibernate/Impl/MultiCriteriaImpl.cs @@ -260,7 +260,7 @@ private void GetResultsFromDatabase(IList results) { var message = string.Format("Failed to execute multi criteria: [{0}]", resultSetsCommand.Sql); log.Error(message, sqle); - throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle, "Failed to execute multi criteria", resultSetsCommand.Sql); + throw ADOExceptionHelper.Convert(session, session.Factory.SQLExceptionConverter, sqle, "Failed to execute multi criteria", resultSetsCommand.Sql); } if (statsEnabled) { diff --git a/src/NHibernate/Impl/MultiQueryImpl.cs b/src/NHibernate/Impl/MultiQueryImpl.cs index 479a3560187..0cad566b999 100644 --- a/src/NHibernate/Impl/MultiQueryImpl.cs +++ b/src/NHibernate/Impl/MultiQueryImpl.cs @@ -605,7 +605,7 @@ protected List DoList() { var message = string.Format("Failed to execute multi query: [{0}]", resultSetsCommand.Sql); log.Error(message, sqle); - throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle, "Failed to execute multi query", resultSetsCommand.Sql); + throw ADOExceptionHelper.Convert(session, session.Factory.SQLExceptionConverter, sqle, "Failed to execute multi query", resultSetsCommand.Sql); } if (statsEnabled) diff --git a/src/NHibernate/Loader/Loader.cs b/src/NHibernate/Loader/Loader.cs index fbb468444e5..b09e61c91ca 100644 --- a/src/NHibernate/Loader/Loader.cs +++ b/src/NHibernate/Loader/Loader.cs @@ -287,7 +287,7 @@ protected object LoadSingleRow(IDataReader resultSet, ISessionImplementor sessio } catch (Exception sqle) { - throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, sqle, "could not read next row of results", + throw ADOExceptionHelper.Convert(session, Factory.SQLExceptionConverter, sqle, "could not read next row of results", SqlString, queryParameters.PositionalParameterValues, queryParameters.NamedParameters); } @@ -1285,7 +1285,7 @@ protected IList LoadEntity(ISessionImplementor session, object id, IType identif catch (Exception sqle) { ILoadable[] persisters = EntityPersisters; - throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, sqle, + throw ADOExceptionHelper.Convert(session, Factory.SQLExceptionConverter, sqle, "could not load an entity: " + MessageHelper.InfoString(persisters[persisters.Length - 1], id, identifierType, @@ -1312,7 +1312,7 @@ protected IList LoadEntity(ISessionImplementor session, object key, object index } catch (Exception sqle) { - throw ADOExceptionHelper.Convert(_factory.SQLExceptionConverter, sqle, "could not collection element by index", + throw ADOExceptionHelper.Convert(session, _factory.SQLExceptionConverter, sqle, "could not collection element by index", SqlString); } @@ -1349,7 +1349,7 @@ protected internal IList LoadEntityBatch(ISessionImplementor session, object[] i } catch (Exception sqle) { - throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, sqle, + throw ADOExceptionHelper.Convert(session, Factory.SQLExceptionConverter, sqle, "could not load an entity batch: " + MessageHelper.InfoString(persister, ids, Factory), SqlString); // NH: Hibernate3 passes EntityPersisters[0] instead of persister, I think it's wrong. @@ -1381,7 +1381,7 @@ public void LoadCollection(ISessionImplementor session, object id, IType type) } catch (Exception sqle) { - throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, sqle, + throw ADOExceptionHelper.Convert(session, Factory.SQLExceptionConverter, sqle, "could not initialize a collection: " + MessageHelper.InfoString(CollectionPersisters[0], id), SqlString); } @@ -1412,7 +1412,7 @@ public void LoadCollectionBatch(ISessionImplementor session, object[] ids, IType } catch (Exception sqle) { - throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, sqle, + throw ADOExceptionHelper.Convert(session, Factory.SQLExceptionConverter, sqle, "could not initialize a collection batch: " + MessageHelper.InfoString(CollectionPersisters[0], ids), SqlString); } @@ -1440,7 +1440,7 @@ protected void LoadCollectionSubselect(ISessionImplementor session, object[] ids } catch (Exception sqle) { - throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, sqle, + throw ADOExceptionHelper.Convert(session, Factory.SQLExceptionConverter, sqle, "could not load collection by subselect: " + MessageHelper.InfoString(CollectionPersisters[0], ids), SqlString, parameterValues, namedParameters); @@ -1570,7 +1570,7 @@ protected IList DoList(ISessionImplementor session, QueryParameters queryParamet } catch (Exception sqle) { - throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, sqle, "could not execute query", SqlString, + throw ADOExceptionHelper.Convert(session, Factory.SQLExceptionConverter, sqle, "could not execute query", SqlString, queryParameters.PositionalParameterValues, queryParameters.NamedParameters); } if (statsEnabled) diff --git a/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs b/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs index 892ae824de4..87a022eba14 100644 --- a/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs +++ b/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs @@ -853,8 +853,8 @@ private SqlString GenerateSelectSizeString(ISessionImplementor sessionImplemento protected virtual string GetCountSqlSelectClause() { // NH: too many "if" when each collection can have its persister - if (isCollectionIntegerIndex) return string.Format("coalesce(max({0}) + 1, 0)", IndexColumnNames[0]); // Do we need this "optimization"? - return string.Format("count({0})", HasIndex ? GetIndexCountExpression() : ElementColumnNames[0]); + if (isCollectionIntegerIndex) return string.Format("coalesce(max({0}) + 1, 0)", IndexColumnNames[0]); // Do we need this "optimization"? + return string.Format("count({0})", HasIndex ? GetIndexCountExpression() : ElementColumnNames[0]); } private string GetIndexCountExpression() @@ -1062,7 +1062,7 @@ public void Remove(object id, ISessionImplementor session) } catch (DbException sqle) { - throw ADOExceptionHelper.Convert(sqlExceptionConverter, sqle, + throw ADOExceptionHelper.Convert(session, sqlExceptionConverter, sqle, "could not delete collection: " + MessageHelper.InfoString(this, id)); } } @@ -1126,7 +1126,7 @@ public void Recreate(IPersistentCollection collection, object id, ISessionImplem } catch (DbException sqle) { - throw ADOExceptionHelper.Convert(sqlExceptionConverter, sqle, + throw ADOExceptionHelper.Convert(session, sqlExceptionConverter, sqle, "could not insert collection: " + MessageHelper.InfoString(this, id)); } } @@ -1235,7 +1235,7 @@ public void DeleteRows(IPersistentCollection collection, object id, ISessionImpl } catch (DbException sqle) { - throw ADOExceptionHelper.Convert(sqlExceptionConverter, sqle, + throw ADOExceptionHelper.Convert(session, sqlExceptionConverter, sqle, "could not delete collection rows: " + MessageHelper.InfoString(this, id)); } } @@ -1288,7 +1288,7 @@ public void InsertRows(IPersistentCollection collection, object id, ISessionImpl } catch (DbException sqle) { - throw ADOExceptionHelper.Convert(sqlExceptionConverter, sqle, + throw ADOExceptionHelper.Convert(session, sqlExceptionConverter, sqle, "could not insert collection rows: " + MessageHelper.InfoString(this, id)); } } @@ -1532,7 +1532,7 @@ public int GetSize(object key, ISessionImplementor session) } catch (DbException sqle) { - throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, sqle, + throw ADOExceptionHelper.Convert(session, Factory.SQLExceptionConverter, sqle, "could not retrieve collection size: " + MessageHelper.InfoString(this, key, Factory), GenerateSelectSizeString(session)); } @@ -1583,7 +1583,7 @@ private bool Exists(object key, object indexOrElement, IType indexOrElementType, } catch (DbException sqle) { - throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, sqle, + throw ADOExceptionHelper.Convert(session, Factory.SQLExceptionConverter, sqle, "could not check row existence: " + MessageHelper.InfoString(this, key, Factory), GenerateSelectSizeString(session)); } @@ -1626,7 +1626,7 @@ public virtual object GetElementByIndex(object key, object index, ISessionImplem } catch (DbException sqle) { - throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, sqle, + throw ADOExceptionHelper.Convert(session, Factory.SQLExceptionConverter, sqle, "could not read row: " + MessageHelper.InfoString(this, key, Factory), GenerateSelectSizeString(session)); } diff --git a/src/NHibernate/Persister/Collection/BasicCollectionPersister.cs b/src/NHibernate/Persister/Collection/BasicCollectionPersister.cs index 5d06f9d5023..5c5f803c504 100644 --- a/src/NHibernate/Persister/Collection/BasicCollectionPersister.cs +++ b/src/NHibernate/Persister/Collection/BasicCollectionPersister.cs @@ -244,7 +244,7 @@ protected override int DoUpdateRows(object id, IPersistentCollection collection, } catch (DbException sqle) { - throw ADOExceptionHelper.Convert(SQLExceptionConverter, sqle, + throw ADOExceptionHelper.Convert(session, SQLExceptionConverter, sqle, "could not update collection rows: " + MessageHelper.InfoString(this, id), SqlUpdateRowString.Text); } diff --git a/src/NHibernate/Persister/Collection/OneToManyPersister.cs b/src/NHibernate/Persister/Collection/OneToManyPersister.cs index 2140869e248..8403ea59837 100644 --- a/src/NHibernate/Persister/Collection/OneToManyPersister.cs +++ b/src/NHibernate/Persister/Collection/OneToManyPersister.cs @@ -294,7 +294,7 @@ protected override int DoUpdateRows(object id, IPersistentCollection collection, } catch (DbException sqle) { - throw ADOExceptionHelper.Convert(SQLExceptionConverter, sqle, "could not update collection rows: " + MessageHelper.InfoString(this, id)); + throw ADOExceptionHelper.Convert(session, SQLExceptionConverter, sqle, "could not update collection rows: " + MessageHelper.InfoString(this, id)); } } diff --git a/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs b/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs index d34000ee673..45fee1566d5 100644 --- a/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs +++ b/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs @@ -1277,7 +1277,8 @@ private object InitializeLazyPropertiesFromDatastore(string fieldName, object en "could not initialize lazy properties: " + MessageHelper.InfoString(this, id, Factory), Sql = SQLLazySelectString.ToString(), EntityName = EntityName, - EntityId = id + EntityId = id, + Session = session }; throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, exceptionContext); } @@ -1449,7 +1450,8 @@ public object[] GetDatabaseSnapshot(object id, ISessionImplementor session) Message = "could not retrieve snapshot: " + MessageHelper.InfoString(this, id, Factory), Sql = SQLSnapshotSelectString.ToString(), EntityName = EntityName, - EntityId = id + EntityId = id, + Session = session }; throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, exceptionContext); } @@ -1632,7 +1634,8 @@ public object ForceVersionIncrement(object id, object currentVersion, ISessionIm Message = "could not retrieve version: " + MessageHelper.InfoString(this, id, Factory), Sql = VersionSelectString.ToString(), EntityName = EntityName, - EntityId = id + EntityId = id, + Session = session }; throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, exceptionContext); } @@ -1694,7 +1697,8 @@ public object GetCurrentVersion(object id, ISessionImplementor session) Message = "could not retrieve version: " + MessageHelper.InfoString(this, id, Factory), Sql = VersionSelectString.ToString(), EntityName = EntityName, - EntityId = id + EntityId = id, + Session = session }; throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, exceptionContext); } @@ -2669,7 +2673,8 @@ protected void Insert(object id, object[] fields, bool[] notNull, int j, Message = "could not insert: " + MessageHelper.InfoString(this, id), Sql = sql.ToString(), EntityName = EntityName, - EntityId = id + EntityId = id, + Session = session }; throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, exceptionContext); } @@ -2812,7 +2817,8 @@ protected bool Update(object id, object[] fields, object[] oldFields, object row Message = "could not update: " + MessageHelper.InfoString(this, id, Factory), Sql = sql.Text.ToString(), EntityName = EntityName, - EntityId = id + EntityId = id, + Session = session }; throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, exceptionContext); } @@ -2932,7 +2938,8 @@ public void Delete(object id, object version, int j, object obj, SqlCommandInfo Message = "could not delete: " + MessageHelper.InfoString(this, id, Factory), Sql = sql.Text.ToString(), EntityName = EntityName, - EntityId = id + EntityId = id, + Session = session }; throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, exceptionContext); } @@ -4020,7 +4027,8 @@ private void ProcessGeneratedProperties(object id, object entity, object[] state Message = "unable to select generated column values", Sql = selectionSQL.ToString(), EntityName = EntityName, - EntityId = id + EntityId = id, + Session = session }; throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, exceptionContext); } @@ -4111,7 +4119,8 @@ public virtual object[] GetNaturalIdentifierSnapshot(object id, ISessionImplemen Message = "could not retrieve snapshot: " + MessageHelper.InfoString(this, id, Factory), Sql = sql.ToString(), EntityName = EntityName, - EntityId = id + EntityId = id, + Session = session }; throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, exceptionContext); } diff --git a/src/NHibernate/Tool/hbm2ddl/DatabaseMetadata.cs b/src/NHibernate/Tool/hbm2ddl/DatabaseMetadata.cs index c51b607eb1b..66a663bc3eb 100644 --- a/src/NHibernate/Tool/hbm2ddl/DatabaseMetadata.cs +++ b/src/NHibernate/Tool/hbm2ddl/DatabaseMetadata.cs @@ -6,6 +6,7 @@ using NHibernate.Dialect.Schema; using NHibernate.Exceptions; +using NHibernate.Impl; using NHibernate.Mapping; using NHibernate.Util; @@ -94,7 +95,7 @@ public ITableMetadata GetTableMetadata(string name, string schema, string catalo } catch (DbException sqle) { - throw ADOExceptionHelper.Convert(sqlExceptionConverter, sqle, "could not get table metadata: " + name); + throw ADOExceptionHelper.Convert(null, sqlExceptionConverter, sqle, "could not get table metadata: " + name); } } diff --git a/src/NHibernate/Transaction/AdoNetTransactionFactory.cs b/src/NHibernate/Transaction/AdoNetTransactionFactory.cs index 1f8e0410b67..c19c8ae6b5b 100644 --- a/src/NHibernate/Transaction/AdoNetTransactionFactory.cs +++ b/src/NHibernate/Transaction/AdoNetTransactionFactory.cs @@ -85,7 +85,7 @@ public void ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork wo } else if (t is DbException) { - throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, t, + throw ADOExceptionHelper.Convert(session, session.Factory.SQLExceptionConverter, t, "error performing isolated work"); } else diff --git a/src/NHibernate/Type/DbTimestampType.cs b/src/NHibernate/Type/DbTimestampType.cs index 9f33ea2c8e2..59a44c4dc7d 100644 --- a/src/NHibernate/Type/DbTimestampType.cs +++ b/src/NHibernate/Type/DbTimestampType.cs @@ -74,7 +74,7 @@ protected virtual object UsePreparedStatement(string timestampSelectString, ISes } catch (DbException sqle) { - throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle, + throw ADOExceptionHelper.Convert(session, session.Factory.SQLExceptionConverter, sqle, "could not select current db timestamp", tsSelect); } finally diff --git a/src/NHibernate/Type/EntityType.cs b/src/NHibernate/Type/EntityType.cs index b2488cc33ae..8b609f15fea 100644 --- a/src/NHibernate/Type/EntityType.cs +++ b/src/NHibernate/Type/EntityType.cs @@ -5,6 +5,7 @@ using System.Xml; using NHibernate.Engine; using NHibernate.Exceptions; +using NHibernate.Impl; using NHibernate.Persister.Entity; using NHibernate.Proxy; using NHibernate.Util; @@ -572,7 +573,7 @@ public object LoadByUniqueKey(string entityName, string uniqueKeyPropertyName, o } catch (Exception sqle) { - throw ADOExceptionHelper.Convert(factory.SQLExceptionConverter, sqle, "Error performing LoadByUniqueKey"); + throw ADOExceptionHelper.Convert(session, factory.SQLExceptionConverter, sqle, "Error performing LoadByUniqueKey"); } }