Coverage Report - org.mule.transport.jdbc.SQLExceptionReader
 
Classes in this File Line Coverage Branch Coverage Complexity
SQLExceptionReader
0%
0/16
0%
0/8
0
 
 1  
 /*
 2  
  * $Id: SQLExceptionReader.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.transport.jdbc;
 12  
 
 13  
 import org.mule.api.config.ExceptionReader;
 14  
 import org.mule.util.StringUtils;
 15  
 
 16  
 import java.sql.SQLException;
 17  
 import java.util.HashMap;
 18  
 import java.util.Map;
 19  
 
 20  
 /**
 21  
  * Surfaces information about SQLExceptions such as the code and sql state. Also uses
 22  
  * the NextException to find the cause
 23  
  */
 24  0
 public class SQLExceptionReader implements ExceptionReader
 25  
 {
 26  
     public String getMessage(Throwable t)
 27  
     {
 28  0
         SQLException e = (SQLException) t;
 29  0
         return e.getMessage() + "(SQL Code: " + e.getErrorCode() + ", SQL State: + " + e.getSQLState() + ")";
 30  
     }
 31  
 
 32  
     public Throwable getCause(Throwable t)
 33  
     {
 34  0
         SQLException e = (SQLException) t;
 35  0
         Throwable cause = e.getNextException();
 36  0
         if (cause == null)
 37  
         {
 38  0
             cause = e.getCause();
 39  
         }
 40  0
         return cause;
 41  
     }
 42  
 
 43  
     public Class<?> getExceptionType()
 44  
     {
 45  0
         return SQLException.class;
 46  
     }
 47  
 
 48  
     /**
 49  
      * Returns a map of the non-stanard information stored on the exception
 50  
      * 
 51  
      * @param t the exception to extract the information from
 52  
      * @return a map of the non-stanard information stored on the exception
 53  
      */
 54  
     public Map<?, ?> getInfo(Throwable t)
 55  
     {
 56  0
         SQLException e = (SQLException) t;
 57  
         
 58  0
         Map<String, Object> info = new HashMap<String, Object>();
 59  0
         if (e.getErrorCode() != 0)
 60  
         {
 61  0
             info.put("SQL Code", String.valueOf(e.getErrorCode()));
 62  
         }
 63  0
         if (e.getSQLState() != null && !e.getSQLState().equals(StringUtils.EMPTY))
 64  
         {
 65  0
             info.put("SQL State", e.getSQLState());
 66  
         }
 67  0
         return info;
 68  
     }
 69  
 }