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