1 24 25 package org.objectweb.cjdbc.common.exceptions; 26 27 import java.sql.SQLException ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 31 37 public class SQLExceptionFactory 38 { 39 40 47 public static SQLException getSQLException(SQLException sqlEx, 48 String cjdbcMessage) 49 { 50 SQLException newException = new SQLException (cjdbcMessage, sqlEx 51 .getSQLState(), sqlEx.getErrorCode()); 52 newException.setNextException(sqlEx); 57 return newException; 58 } 59 60 69 public static SQLException getSQLException(List exceptions, 70 String cjdbcMessage) 71 { 72 String sqlState = null; 73 int errorCode = 0; 74 for (int i = 0; i < exceptions.size(); i++) 75 { 76 SQLException ex = (SQLException ) exceptions.get(i); 77 cjdbcMessage += ex.getMessage() + "\n"; 78 if (i == 0) 79 { 80 sqlState = ex.getSQLState(); 82 errorCode = ex.getErrorCode(); 83 } 84 else 85 { 86 if (sqlState != null && !sqlState.equals(ex.getSQLState())) 88 sqlState = null; 89 if (errorCode != ex.getErrorCode()) 91 errorCode = 0; 92 } 93 } 94 SQLException newHead = new SQLException (cjdbcMessage, sqlState, errorCode); 95 Iterator exIter = exceptions.iterator(); 96 97 while (exIter.hasNext()) 100 newHead.setNextException((SQLException )exIter.next()); 101 102 return newHead; 103 } 104 105 } 106 | Popular Tags |