Spring.Data.NHibernate.SessionFactoryUtils.ConvertAdoAccessException C# (CSharp) Method

ConvertAdoAccessException() public static method

Converts a Hibernate ADOException to a Spring DataAccessExcption, extracting the underlying error code from ADO.NET. Will extract the ADOException Message and SqlString properties and pass them to the translate method of the provided IAdoExceptionTranslator.
public static ConvertAdoAccessException ( IAdoExceptionTranslator translator, ADOException ex ) : Spring.Dao.DataAccessException
translator IAdoExceptionTranslator The IAdoExceptionTranslator, may be a user provided implementation as configured on /// HibernateTemplate. ///
ex NHibernate.ADOException The ADOException throw
return Spring.Dao.DataAccessException
        public static DataAccessException ConvertAdoAccessException(IAdoExceptionTranslator translator, ADOException ex)
        {
            try
            {
                string sqlString = (ex.SqlString != null)
                                       ? ex.SqlString.ToString()
                                       : string.Empty;
                return translator.Translate(
                    "Hibernate operation: " + ex.Message, sqlString, ex.InnerException);
            } catch (Exception e)
            {
                log.Error("Exception thrown during exception translation. Message = [" + e.Message + "]", e);
                log.Error("Exception that was attempted to be translated was [" + ex.Message + "]", ex);                
                if (ex.InnerException != null)
                {
                    log.Error("  Inner Exception was [" + ex.InnerException.Message + "]", ex.InnerException);
                }
                throw new UncategorizedAdoException(e.Message, "", "", e);
            }
        }

Usage Example

示例#1
0
 /// <summary>
 /// Converts the ADO.NET access exception to an appropriate exception from the
 /// <code>org.springframework.dao</code> hierarchy. Can be overridden in subclasses.
 /// </summary>
 /// <param name="ex">ADOException that occured, wrapping underlying ADO.NET exception.</param>
 /// <returns>
 /// the corresponding DataAccessException instance
 /// </returns>
 protected virtual DataAccessException ConvertAdoAccessException(ADOException ex)
 {
     return(SessionFactoryUtils.ConvertAdoAccessException(AdoExceptionTranslator, ex));
 }