Skip to content

Makes the session available to ISQLExceptionConverter. #217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/NHibernate.Test/ExceptionsTest/NullQueryTest.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be session.GetSessionImplementor()

}
finally
{
Expand Down
8 changes: 4 additions & 4 deletions src/NHibernate.Test/Insertordering/InsertOrderingFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public class StatsBatcher : SqlClientBatchingBatcher
private static IList<int> batchSizes = new List<int>();
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<int> BatchSizes
{
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/NHibernate.Test/Linq/QueryTimeoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand All @@ -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);
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/NHibernate/AdoNet/AbstractBatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -45,11 +47,12 @@ public abstract class AbstractBatcher : IBatcher
/// </summary>
/// <param name="connectionManager">The <see cref="ConnectionManager"/> owning this batcher.</param>
/// <param name="interceptor"></param>
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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/NHibernate/AdoNet/ConnectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/AdoNet/IBatcherFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace NHibernate.AdoNet
/// <summary> Factory for <see cref="IBatcher"/> instances.</summary>
public interface IBatcherFactory
{
IBatcher CreateBatcher(ConnectionManager connectionManager, IInterceptor interceptor);
IBatcher CreateBatcher(ConnectionManager connectionManager, IInterceptor interceptor, ISessionImplementor session);
}
}
14 changes: 9 additions & 5 deletions src/NHibernate/AdoNet/MySqlClientBatchingBatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/NHibernate/AdoNet/MySqlClientBatchingBatcherFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
6 changes: 3 additions & 3 deletions src/NHibernate/AdoNet/NonBatchingBatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public class NonBatchingBatcher : AbstractBatcher
/// Initializes a new instance of the <see cref="NonBatchingBatcher"/> class.
/// </summary>
/// <param name="connectionManager">The <see cref="ConnectionManager"/> for this batcher.</param>
/// <param name="interceptor"></param>
public NonBatchingBatcher(ConnectionManager connectionManager, IInterceptor interceptor)
: base(connectionManager, interceptor)
/// <param name="interceptor"></param>
public NonBatchingBatcher(ConnectionManager connectionManager, IInterceptor interceptor, ISessionImplementor session)
: base(connectionManager, interceptor, session)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/NHibernate/AdoNet/NonBatchingBatcherFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace NHibernate.AdoNet
/// </summary>
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);
}
}
}
14 changes: 9 additions & 5 deletions src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -15,18 +17,20 @@ namespace NHibernate.AdoNet
/// </summary>
public class OracleDataClientBatchingBatcher : AbstractBatcher
{
private int _batchSize;
private readonly ISessionImplementor _session;
private int _batchSize;
private int _countOfCommands = 0;
private int _totalExpectedRowsAffected;
private IDbCommand _currentBatch;
private IDictionary<string, List<object>> _parameterValueListHashTable;
private IDictionary<string, bool> _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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
14 changes: 9 additions & 5 deletions src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/NHibernate/AdoNet/SqlClientBatchingBatcherFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
3 changes: 2 additions & 1 deletion src/NHibernate/Dialect/Lock/SelectLockingStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/NHibernate/Dialect/Lock/UpdateLockingStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Engine/Query/NativeSQLQueryPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
3 changes: 2 additions & 1 deletion src/NHibernate/Engine/TransactionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Data.Common;
using NHibernate.Engine.Transaction;
using NHibernate.Exceptions;
using NHibernate.Impl;

namespace NHibernate.Engine
{
Expand Down Expand Up @@ -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);
}
}

Expand Down
Loading