wrapped static method calls to GetConnectionTxPair and DisposeConnection within overridable member methods
This commit is contained in:
@@ -34,6 +34,8 @@ namespace Spring.Data.Core
|
||||
/// <author>Juergen Hoeller</author>
|
||||
public abstract class AdoAccessor : IInitializingObject
|
||||
{
|
||||
protected object AdoUtils;
|
||||
|
||||
protected int commandTimeout;
|
||||
|
||||
#region Properties
|
||||
@@ -110,10 +112,29 @@ namespace Spring.Data.Core
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
protected virtual void ApplyCommandSettings(IDbCommand command)
|
||||
{
|
||||
ConnectionUtils.ApplyTransactionTimeout(command, DbProvider, CommandTimeout );
|
||||
{
|
||||
Support.ConnectionUtils.ApplyTransactionTimeout(command, DbProvider, CommandTimeout);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose the command, if any
|
||||
/// </summary>
|
||||
protected virtual void DisposeCommand(IDbCommand command)
|
||||
{
|
||||
Support.AdoUtils.DisposeCommand(command);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose the command, if any
|
||||
/// </summary>
|
||||
protected virtual void DisposeDataAdapterCommands(IDbDataAdapter adapter)
|
||||
{
|
||||
Support.AdoUtils.DisposeDataAdapterCommands(adapter);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extract the command text from the given <see cref="ICommandTextProvider"/>, if any.
|
||||
/// </summary>
|
||||
protected virtual string GetCommandText(object cmdTextProvider)
|
||||
{
|
||||
ICommandTextProvider commandTextProvider = cmdTextProvider as ICommandTextProvider;
|
||||
@@ -125,8 +146,20 @@ namespace Spring.Data.Core
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Obtain a connection/transaction pair
|
||||
/// </summary>
|
||||
protected virtual ConnectionTxPair GetConnectionTxPair(IDbProvider provider)
|
||||
{
|
||||
return Support.ConnectionUtils.GetConnectionTxPair(provider);
|
||||
}
|
||||
|
||||
protected virtual void DisposeConnection(IDbConnection connection, IDbProvider provider)
|
||||
{
|
||||
Support.ConnectionUtils.DisposeConnection(connection, provider);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked by an <see cref="Spring.Objects.Factory.IObjectFactory"/>
|
||||
|
||||
@@ -219,7 +219,7 @@ namespace Spring.Data.Core
|
||||
/// <returns>object returned from callback</returns>
|
||||
public object Execute(ICommandCallback action)
|
||||
{
|
||||
ConnectionTxPair connectionTxPairToUse = ConnectionUtils.GetConnectionTxPair(DbProvider);
|
||||
ConnectionTxPair connectionTxPairToUse = GetConnectionTxPair(DbProvider);
|
||||
|
||||
IDbCommand command = null;
|
||||
try
|
||||
@@ -237,9 +237,9 @@ namespace Spring.Data.Core
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
AdoUtils.DisposeCommand(command);
|
||||
DisposeCommand(command);
|
||||
command = null;
|
||||
ConnectionUtils.DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
connectionTxPairToUse.Connection = null;
|
||||
if (DbProvider.IsDataAccessException(e))
|
||||
{
|
||||
@@ -254,8 +254,8 @@ namespace Spring.Data.Core
|
||||
}
|
||||
finally
|
||||
{
|
||||
AdoUtils.DisposeCommand(command);
|
||||
ConnectionUtils.DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
DisposeCommand(command);
|
||||
DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -272,7 +272,7 @@ namespace Spring.Data.Core
|
||||
AssertUtils.ArgumentNotNull(commandCreator, "commandCreator", "IDbCommandCreator must not be null");
|
||||
AssertUtils.ArgumentNotNull(action, "action", "Callback object must not be null");
|
||||
|
||||
ConnectionTxPair connectionTxPairToUse = ConnectionUtils.GetConnectionTxPair(DbProvider);
|
||||
ConnectionTxPair connectionTxPairToUse = GetConnectionTxPair(DbProvider);
|
||||
|
||||
|
||||
IDbCommand command = null;
|
||||
@@ -294,9 +294,9 @@ namespace Spring.Data.Core
|
||||
catch (Exception e)
|
||||
{
|
||||
commandCreator = null;
|
||||
AdoUtils.DisposeCommand(command);
|
||||
DisposeCommand(command);
|
||||
command = null;
|
||||
ConnectionUtils.DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
connectionTxPairToUse.Connection = null;
|
||||
if (DbProvider.IsDataAccessException(e))
|
||||
{
|
||||
@@ -309,8 +309,8 @@ namespace Spring.Data.Core
|
||||
}
|
||||
finally
|
||||
{
|
||||
AdoUtils.DisposeCommand(command);
|
||||
ConnectionUtils.DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
DisposeCommand(command);
|
||||
DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -325,7 +325,7 @@ namespace Spring.Data.Core
|
||||
/// <returns>A result object returned by the callback or null</returns>
|
||||
public object Execute(IDataAdapterCallback dataAdapterCallback)
|
||||
{
|
||||
ConnectionTxPair connectionTxPairToUse = ConnectionUtils.GetConnectionTxPair(DbProvider);
|
||||
ConnectionTxPair connectionTxPairToUse = GetConnectionTxPair(DbProvider);
|
||||
IDbDataAdapter dataAdapter = null;
|
||||
try
|
||||
{
|
||||
@@ -342,17 +342,17 @@ namespace Spring.Data.Core
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
AdoUtils.DisposeDataAdapterCommands(dataAdapter);
|
||||
DisposeDataAdapterCommands(dataAdapter);
|
||||
//TODO set dataAdapter command's = null; ?
|
||||
//TODO exception translation? different hierarchy for data set operations.
|
||||
ConnectionUtils.DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
connectionTxPairToUse.Connection = null;
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
AdoUtils.DisposeDataAdapterCommands(dataAdapter);
|
||||
ConnectionUtils.DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
DisposeDataAdapterCommands(dataAdapter);
|
||||
DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
}
|
||||
|
||||
|
||||
@@ -2586,7 +2586,7 @@ namespace Spring.Data.Core
|
||||
}
|
||||
finally
|
||||
{
|
||||
AdoUtils.CloseReader(reader);
|
||||
Support.AdoUtils.CloseReader(reader);
|
||||
}
|
||||
ParameterUtils.ExtractOutputParameters(returnedResults, command);
|
||||
return returnedResults;
|
||||
@@ -2662,7 +2662,7 @@ namespace Spring.Data.Core
|
||||
}
|
||||
finally
|
||||
{
|
||||
AdoUtils.CloseReader(reader);
|
||||
Support.AdoUtils.CloseReader(reader);
|
||||
}
|
||||
ParameterUtils.ExtractOutputParameters(returnedParameters, command);
|
||||
return null;
|
||||
@@ -2693,7 +2693,7 @@ namespace Spring.Data.Core
|
||||
}
|
||||
finally
|
||||
{
|
||||
AdoUtils.CloseReader(reader);
|
||||
Support.AdoUtils.CloseReader(reader);
|
||||
}
|
||||
ParameterUtils.ExtractOutputParameters(returnedParameters, command);
|
||||
return returnVal;
|
||||
@@ -2729,7 +2729,7 @@ namespace Spring.Data.Core
|
||||
}
|
||||
finally
|
||||
{
|
||||
AdoUtils.CloseReader(reader);
|
||||
Support.AdoUtils.CloseReader(reader);
|
||||
}
|
||||
ParameterUtils.ExtractOutputParameters(returnedParameters, command);
|
||||
return objectList;
|
||||
@@ -2958,7 +2958,7 @@ namespace Spring.Data.Core
|
||||
}
|
||||
finally
|
||||
{
|
||||
AdoUtils.CloseReader(reader);
|
||||
Support.AdoUtils.CloseReader(reader);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3019,7 +3019,7 @@ namespace Spring.Data.Core
|
||||
}
|
||||
finally
|
||||
{
|
||||
AdoUtils.CloseReader(reader);
|
||||
Support.AdoUtils.CloseReader(reader);
|
||||
ParameterUtils.CopyParameters(parameters, command);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ namespace Spring.Data.Generic
|
||||
/// <returns>object returned from callback</returns>
|
||||
public T Execute<T>(ICommandCallback<T> action)
|
||||
{
|
||||
ConnectionTxPair connectionTxPairToUse = ConnectionUtils.GetConnectionTxPair(DbProvider);
|
||||
ConnectionTxPair connectionTxPairToUse = GetConnectionTxPair(DbProvider);
|
||||
|
||||
IDbCommand command = null;
|
||||
try
|
||||
@@ -223,9 +223,9 @@ namespace Spring.Data.Generic
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
AdoUtils.DisposeCommand(command);
|
||||
DisposeCommand(command);
|
||||
command = null;
|
||||
ConnectionUtils.DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
connectionTxPairToUse.Connection = null;
|
||||
if (DbProvider.IsDataAccessException(e))
|
||||
{
|
||||
@@ -240,8 +240,8 @@ namespace Spring.Data.Generic
|
||||
}
|
||||
finally
|
||||
{
|
||||
AdoUtils.DisposeCommand(command);
|
||||
ConnectionUtils.DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
DisposeCommand(command);
|
||||
DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ namespace Spring.Data.Generic
|
||||
/// <returns>A result object returned by the action or null</returns>
|
||||
public T Execute<T>(CommandDelegate<T> del)
|
||||
{
|
||||
ConnectionTxPair connectionTxPairToUse = ConnectionUtils.GetConnectionTxPair(DbProvider);
|
||||
ConnectionTxPair connectionTxPairToUse = GetConnectionTxPair(DbProvider);
|
||||
|
||||
IDbCommand command = null;
|
||||
try
|
||||
@@ -282,9 +282,9 @@ namespace Spring.Data.Generic
|
||||
catch (Exception e)
|
||||
{
|
||||
string commandText = command.CommandText;
|
||||
AdoUtils.DisposeCommand(command);
|
||||
DisposeCommand(command);
|
||||
command = null;
|
||||
ConnectionUtils.DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
connectionTxPairToUse.Connection = null;
|
||||
if (DbProvider.IsDataAccessException(e))
|
||||
{
|
||||
@@ -299,8 +299,8 @@ namespace Spring.Data.Generic
|
||||
}
|
||||
finally
|
||||
{
|
||||
AdoUtils.DisposeCommand(command);
|
||||
ConnectionUtils.DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
DisposeCommand(command);
|
||||
DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ namespace Spring.Data.Generic
|
||||
/// <returns>object returned from callback</returns>
|
||||
public T Execute<T>(IDbCommandCallback<T> action)
|
||||
{
|
||||
ConnectionTxPair connectionTxPairToUse = ConnectionUtils.GetConnectionTxPair(DbProvider);
|
||||
ConnectionTxPair connectionTxPairToUse = GetConnectionTxPair(DbProvider);
|
||||
|
||||
IDbCommand command = null;
|
||||
try
|
||||
@@ -330,9 +330,9 @@ namespace Spring.Data.Generic
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
AdoUtils.DisposeCommand(command);
|
||||
DisposeCommand(command);
|
||||
command = null;
|
||||
ConnectionUtils.DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
connectionTxPairToUse.Connection = null;
|
||||
if (DbProvider.IsDataAccessException(e))
|
||||
{
|
||||
@@ -347,8 +347,8 @@ namespace Spring.Data.Generic
|
||||
}
|
||||
finally
|
||||
{
|
||||
AdoUtils.DisposeCommand(command);
|
||||
ConnectionUtils.DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
DisposeCommand(command);
|
||||
DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,7 +361,7 @@ namespace Spring.Data.Generic
|
||||
/// <returns>A result object returned by the action or null</returns>
|
||||
public T Execute<T>(IDbCommandDelegate<T> del)
|
||||
{
|
||||
ConnectionTxPair connectionTxPairToUse = ConnectionUtils.GetConnectionTxPair(DbProvider);
|
||||
ConnectionTxPair connectionTxPairToUse = GetConnectionTxPair(DbProvider);
|
||||
|
||||
IDbCommand command = null;
|
||||
try
|
||||
@@ -380,9 +380,9 @@ namespace Spring.Data.Generic
|
||||
catch (Exception e)
|
||||
{
|
||||
string commandText = command.CommandText;
|
||||
AdoUtils.DisposeCommand(command);
|
||||
DisposeCommand(command);
|
||||
command = null;
|
||||
ConnectionUtils.DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
connectionTxPairToUse.Connection = null;
|
||||
if (DbProvider.IsDataAccessException(e))
|
||||
{
|
||||
@@ -397,8 +397,8 @@ namespace Spring.Data.Generic
|
||||
}
|
||||
finally
|
||||
{
|
||||
AdoUtils.DisposeCommand(command);
|
||||
ConnectionUtils.DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
DisposeCommand(command);
|
||||
DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,7 +417,7 @@ namespace Spring.Data.Generic
|
||||
{
|
||||
AssertUtils.ArgumentNotNull(commandCreator, "commandCreator", "IDbCommandCreator must not be null");
|
||||
AssertUtils.ArgumentNotNull(action, "action", "Callback object must not be null");
|
||||
ConnectionTxPair connectionTxPairToUse = ConnectionUtils.GetConnectionTxPair(DbProvider);
|
||||
ConnectionTxPair connectionTxPairToUse = GetConnectionTxPair(DbProvider);
|
||||
|
||||
IDbCommand command = null;
|
||||
try
|
||||
@@ -435,9 +435,9 @@ namespace Spring.Data.Generic
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
AdoUtils.DisposeCommand(command);
|
||||
DisposeCommand(command);
|
||||
command = null;
|
||||
ConnectionUtils.DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
connectionTxPairToUse.Connection = null;
|
||||
if (DbProvider.IsDataAccessException(e))
|
||||
{
|
||||
@@ -452,8 +452,8 @@ namespace Spring.Data.Generic
|
||||
}
|
||||
finally
|
||||
{
|
||||
AdoUtils.DisposeCommand(command);
|
||||
ConnectionUtils.DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
DisposeCommand(command);
|
||||
DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -471,7 +471,7 @@ namespace Spring.Data.Generic
|
||||
/// </remarks>
|
||||
public T Execute<T>(IDataAdapterCallback<T> dataAdapterCallback)
|
||||
{
|
||||
ConnectionTxPair connectionTxPairToUse = ConnectionUtils.GetConnectionTxPair(DbProvider);
|
||||
ConnectionTxPair connectionTxPairToUse = GetConnectionTxPair(DbProvider);
|
||||
IDbDataAdapter dataAdapter = null;
|
||||
try
|
||||
{
|
||||
@@ -487,17 +487,17 @@ namespace Spring.Data.Generic
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
AdoUtils.DisposeDataAdapterCommands(dataAdapter);
|
||||
DisposeDataAdapterCommands(dataAdapter);
|
||||
//TODO set dataAdapter command's = null; ?
|
||||
//TODO exception translation? different hierarchy for data set operations.
|
||||
ConnectionUtils.DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
connectionTxPairToUse.Connection = null;
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
AdoUtils.DisposeDataAdapterCommands(dataAdapter);
|
||||
ConnectionUtils.DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
DisposeDataAdapterCommands(dataAdapter);
|
||||
DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
}
|
||||
|
||||
|
||||
@@ -514,7 +514,7 @@ namespace Spring.Data.Generic
|
||||
/// <returns>A result object returned by the callback or null</returns>
|
||||
public T Execute<T>(DataAdapterDelegate<T> dataAdapterCallback)
|
||||
{
|
||||
ConnectionTxPair connectionTxPairToUse = ConnectionUtils.GetConnectionTxPair(DbProvider);
|
||||
ConnectionTxPair connectionTxPairToUse = GetConnectionTxPair(DbProvider);
|
||||
IDbDataAdapter dataAdapter = null;
|
||||
try
|
||||
{
|
||||
@@ -531,17 +531,17 @@ namespace Spring.Data.Generic
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
AdoUtils.DisposeDataAdapterCommands(dataAdapter);
|
||||
DisposeDataAdapterCommands(dataAdapter);
|
||||
//TODO set dataAdapter command's = null; ?
|
||||
//TODO exception translation? different hierarchy for data set operations.
|
||||
ConnectionUtils.DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
connectionTxPairToUse.Connection = null;
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
AdoUtils.DisposeDataAdapterCommands(dataAdapter);
|
||||
ConnectionUtils.DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
DisposeDataAdapterCommands(dataAdapter);
|
||||
DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1201,7 +1201,7 @@ namespace Spring.Data.Generic
|
||||
}
|
||||
finally
|
||||
{
|
||||
AdoUtils.CloseReader(reader);
|
||||
Support.AdoUtils.CloseReader(reader);
|
||||
ParameterUtils.CopyParameters(parameters, command);
|
||||
}
|
||||
}
|
||||
@@ -1273,7 +1273,7 @@ namespace Spring.Data.Generic
|
||||
}
|
||||
finally
|
||||
{
|
||||
AdoUtils.CloseReader(reader);
|
||||
Support.AdoUtils.CloseReader(reader);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1343,7 +1343,7 @@ namespace Spring.Data.Generic
|
||||
}
|
||||
finally
|
||||
{
|
||||
AdoUtils.CloseReader(reader);
|
||||
Support.AdoUtils.CloseReader(reader);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1376,7 +1376,7 @@ namespace Spring.Data.Generic
|
||||
}
|
||||
finally
|
||||
{
|
||||
AdoUtils.CloseReader(reader);
|
||||
Support.AdoUtils.CloseReader(reader);
|
||||
}
|
||||
ParameterUtils.ExtractOutputParameters(returnedParameters, command);
|
||||
return objectList;
|
||||
@@ -1408,7 +1408,7 @@ namespace Spring.Data.Generic
|
||||
}
|
||||
finally
|
||||
{
|
||||
AdoUtils.CloseReader(reader);
|
||||
Support.AdoUtils.CloseReader(reader);
|
||||
}
|
||||
ParameterUtils.ExtractOutputParameters(returnedParameters, command);
|
||||
return returnVal;
|
||||
@@ -1555,7 +1555,7 @@ namespace Spring.Data.Generic
|
||||
}
|
||||
finally
|
||||
{
|
||||
AdoUtils.CloseReader(reader);
|
||||
Support.AdoUtils.CloseReader(reader);
|
||||
}
|
||||
ParameterUtils.ExtractOutputParameters(returnedResults, command);
|
||||
return returnedResults;
|
||||
@@ -1691,7 +1691,7 @@ namespace Spring.Data.Generic
|
||||
}
|
||||
finally
|
||||
{
|
||||
AdoUtils.CloseReader(reader);
|
||||
Support.AdoUtils.CloseReader(reader);
|
||||
}
|
||||
ParameterUtils.ExtractOutputParameters(returnedResults, command);
|
||||
return returnedResults;
|
||||
|
||||
Reference in New Issue
Block a user