Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Data/Data/Support
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv7705/Support
Modified Files:
ErrorCodeExceptionTranslator.cs
Log Message:
SPRNET-756 - Add protected method to ErrorCodeExceptionTranslator to allow for a subclass to first attempt exception translation.
Add additional code documentation
Index: ErrorCodeExceptionTranslator.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Data/Data/Support/ErrorCodeExceptionTranslator.cs,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** ErrorCodeExceptionTranslator.cs 1 Jan 2007 22:22:50 -0000 1.9
--- ErrorCodeExceptionTranslator.cs 30 Oct 2007 15:24:44 -0000 1.10
***************
*** 63,74 ****
#region Constructor (s)
!
public ErrorCodeExceptionTranslator(IDbProvider provider)
{
DbProvider = provider;
}
!
!
!
public ErrorCodeExceptionTranslator(IDbProvider provider, ErrorCodes ec)
{
--- 63,83 ----
#region Constructor (s)
!
! /// <summary>
! /// Initializes a new instance of the <see cref="ErrorCodeExceptionTranslator"/> class.
! /// </summary>
! /// <param name="provider">The data provider.</param>
public ErrorCodeExceptionTranslator(IDbProvider provider)
{
DbProvider = provider;
}
!
!
!
! /// <summary>
! /// Initializes a new instance of the <see cref="ErrorCodeExceptionTranslator"/> class.
! /// </summary>
! /// <param name="provider">The data provider.</param>
! /// <param name="ec">The error code collection.</param>
public ErrorCodeExceptionTranslator(IDbProvider provider, ErrorCodes ec)
{
***************
*** 83,86 ****
--- 92,99 ----
#region Properties
+ /// <summary>
+ /// Sets the db provider.
+ /// </summary>
+ /// <value>The db provider.</value>
public IDbProvider DbProvider
{
***************
*** 94,110 ****
}
! /*
! public string ProductName
! {
! set
! {
! //TODO would need a DbProvider registry or group together
! //error code with dbprovider definition in order to
! //configure this class based on product name
! errorCodes = ErrorCodesFactory.Instance.GetErrorCodes(value);
! }
! }
! */
!
public ErrorCodes ErrorCodes
{
--- 107,114 ----
}
! /// <summary>
! /// Gets the error codes for the provider
! /// </summary>
! /// <value>The error codes.</value>
public ErrorCodes ErrorCodes
{
***************
*** 116,120 ****
#endregion
!
public IAdoExceptionTranslator FallbackTranslator
{
--- 120,129 ----
#endregion
!
! /// <summary>
! /// Gets or sets the fallback translator to use in case error code based translation
! /// fails.
! /// </summary>
! /// <value>The fallback translator.</value>
public IAdoExceptionTranslator FallbackTranslator
{
***************
*** 146,150 ****
/// <paramref name="exception"/>.
/// </returns>
! public DataAccessException Translate(string task, string sql, Exception exception)
{
if (task == null)
--- 155,159 ----
/// <paramref name="exception"/>.
/// </returns>
! public virtual DataAccessException Translate(string task, string sql, Exception exception)
{
if (task == null)
***************
*** 157,161 ****
}
string errorCode = ExtractErrorCode(exception);
! if (this.errorCodes != null)
{
--- 166,179 ----
}
string errorCode = ExtractErrorCode(exception);
!
! // First, try custom translation from overridden method.
! DataAccessException dex = TranslateException(task, sql, errorCode, exception);
! if (dex != null)
! {
! return dex;
! }
!
!
! if (errorCodes != null)
{
***************
*** 208,224 ****
log.Debug("Unable to translate exception eith errorCode '" + errorCode + "', will use the fallback translator");
}
! return this.fallbackTranslator.Translate(task, sql, exception);
}
! public bool IsValidDataAccessException(Exception e)
{
! return dbProvider.IsDataAccessException(e);
! }
! private string BuildMessage(string task, string sql, Exception exception)
{
return task + "; SQL [" + sql + "]; " + exception.Message;
}
private void LogTranslation(string task, string sql, string errorCode, Exception exception, bool b)
{
--- 226,285 ----
log.Debug("Unable to translate exception eith errorCode '" + errorCode + "', will use the fallback translator");
}
! return fallbackTranslator.Translate(task, sql, exception);
}
! /// <summary>
! /// Subclasses can override this method to attempt a custom mapping from a data access Exception
! /// to DataAccessException.
! /// </summary>
! /// <param name="task">Readable text describing the task being attempted.</param>
! /// <param name="sql">SQL query or update that caused the problem. May be <code>null</code>.</param>
! /// <param name="errorCode">The error code extracted from the generic data access exception for
! /// a particular provider.</param>
! /// <param name="exception">The exception thrown from a data access operation.</param>
! /// <returns>
! /// null if no custom translation was possible, otherwise a DataAccessException
! /// resulting from custom translation. This exception should include the exception parameter
! /// as a nested root cause. This implementation always returns null, meaning that
! /// the translator always falls back to the default error codes.
! /// </returns>
! protected virtual DataAccessException TranslateException(string task, string sql, string errorCode, Exception exception)
{
! return null;
! }
!
! /// <summary>
! /// Builds the message.
! /// </summary>
! /// <param name="task">The task.</param>
! /// <param name="sql">The SQL.</param>
! /// <param name="exception">The exception.</param>
! /// <returns></returns>
! protected virtual string BuildMessage(string task, string sql, Exception exception)
{
return task + "; SQL [" + sql + "]; " + exception.Message;
}
+ /// <summary>
+ /// Determines whether the specified exception is valid data access exception.
+ /// </summary>
+ /// <param name="e">The exception.</param>
+ /// <returns>
+ /// <c>true</c> if is valid data access exception; otherwise, <c>false</c>.
+ /// </returns>
+ public bool IsValidDataAccessException(Exception e)
+ {
+ return dbProvider.IsDataAccessException(e);
+ }
+
+ /// <summary>
+ /// Logs the translation.
+ /// </summary>
+ /// <param name="task">The task.</param>
+ /// <param name="sql">The SQL.</param>
+ /// <param name="errorCode">The error code.</param>
+ /// <param name="exception">The exception.</param>
+ /// <param name="b">if set to <c>true</c> [b].</param>
private void LogTranslation(string task, string sql, string errorCode, Exception exception, bool b)
{
|