Review Board 1.7.22


SQOOP-933 Properly log SQLExceptions using getNextException() method for chaining exceptions

Review Request #9803 - Created March 7, 2013 and submitted

Jarek Cecho
SQOOP-933
Reviewers
Sqoop
sqoop-trunk
I've used following command to change all error exception logging to call method that properly resolves "getNextException":

grep "(SQLException" src/java -R -A 2 -n | grep "LOG.error"
Unit tests are passing.
src/java/org/apache/sqoop/manager/CatalogQueryManager.java
Revision fa7661e38e5cf0fd9ad202d3953e7b64f8a4bf8c New Change
[20] 26 lines
[+20]
27

    
   
27

   
28
import org.apache.commons.logging.Log;
28
import org.apache.commons.logging.Log;
29
import org.apache.commons.logging.LogFactory;
29
import org.apache.commons.logging.LogFactory;
30

    
   
30

   
31
import com.cloudera.sqoop.SqoopOptions;
31
import com.cloudera.sqoop.SqoopOptions;

    
   
32
import org.apache.sqoop.util.LoggingUtils;
32

    
   
33

   
33
/**
34
/**
34
 * Database manager that queries catalog tables directly
35
 * Database manager that queries catalog tables directly
35
 * (instead of metadata calls) to retrieve information.
36
 * (instead of metadata calls) to retrieve information.
36
 */
37
 */
[+20] [20] 27 lines
[+20] [+] public String[] listDatabases() {
64
      try {
65
      try {
65
        if (c != null) {
66
        if (c != null) {
66
          c.rollback();
67
          c.rollback();
67
        }
68
        }
68
      } catch (SQLException ce) {
69
      } catch (SQLException ce) {
69
        LOG.error("Failed to rollback transaction", ce);
70
        LoggingUtils.logAll(LOG, "Failed to rollback transaction", ce);
70
      }
71
      }
71
      LOG.error("Failed to list databases", sqle);
72
      LoggingUtils.logAll(LOG, "Failed to list databases", sqle);
72
      throw new RuntimeException(sqle);
73
      throw new RuntimeException(sqle);
73
    } finally {
74
    } finally {
74
      if (rs != null) {
75
      if (rs != null) {
75
        try {
76
        try {
76
          rs.close();
77
          rs.close();
77
        } catch (SQLException re) {
78
        } catch (SQLException re) {
78
          LOG.error("Failed to close resultset", re);
79
          LoggingUtils.logAll(LOG, "Failed to close resultset", re);
79
        }
80
        }
80
      }
81
      }
81
      if (s != null) {
82
      if (s != null) {
82
        try {
83
        try {
83
          s.close();
84
          s.close();
84
        } catch (SQLException se) {
85
        } catch (SQLException se) {
85
          LOG.error("Failed to close statement", se);
86
          LoggingUtils.logAll(LOG, "Failed to close statement", se);
86
        }
87
        }
87
      }
88
      }
88
    }
89
    }
89

    
   
90

   
90
    return databases.toArray(new String[databases.size()]);
91
    return databases.toArray(new String[databases.size()]);
[+20] [20] 18 lines
[+20] [+] public String[] listTables() {
109
      try {
110
      try {
110
        if (c != null) {
111
        if (c != null) {
111
          c.rollback();
112
          c.rollback();
112
        }
113
        }
113
      } catch (SQLException ce) {
114
      } catch (SQLException ce) {
114
        LOG.error("Failed to rollback transaction", ce);
115
        LoggingUtils.logAll(LOG, "Failed to rollback transaction", ce);
115
      }
116
      }
116
      LOG.error("Failed to list tables", sqle);
117
      LoggingUtils.logAll(LOG, "Failed to list tables", sqle);
117
      throw new RuntimeException(sqle);
118
      throw new RuntimeException(sqle);
118
    } finally {
119
    } finally {
119
      if (rs != null) {
120
      if (rs != null) {
120
        try {
121
        try {
121
          rs.close();
122
          rs.close();
122
        } catch (SQLException re) {
123
        } catch (SQLException re) {
123
          LOG.error("Failed to close resultset", re);
124
          LoggingUtils.logAll(LOG, "Failed to close resultset", re);
124
        }
125
        }
125
      }
126
      }
126
      if (s != null) {
127
      if (s != null) {
127
        try {
128
        try {
128
          s.close();
129
          s.close();
129
        } catch (SQLException se) {
130
        } catch (SQLException se) {
130
          LOG.error("Failed to close statement", se);
131
          LoggingUtils.logAll(LOG, "Failed to close statement", se);
131
        }
132
        }
132
      }
133
      }
133
    }
134
    }
134

    
   
135

   
135
    return tables.toArray(new String[tables.size()]);
136
    return tables.toArray(new String[tables.size()]);
[+20] [20] 19 lines
[+20] [+] public String[] getColumnNames(String tableName) {
155
      try {
156
      try {
156
        if (c != null) {
157
        if (c != null) {
157
          c.rollback();
158
          c.rollback();
158
        }
159
        }
159
      } catch (SQLException ce) {
160
      } catch (SQLException ce) {
160
        LOG.error("Failed to rollback transaction", ce);
161
        LoggingUtils.logAll(LOG, "Failed to rollback transaction", ce);
161
      }
162
      }
162
      LOG.error("Failed to list columns from query: " + listColumnsQuery, sqle);
163
      LoggingUtils.logAll(LOG, "Failed to list columns from query: "

    
   
164
        + listColumnsQuery, sqle);
163
      throw new RuntimeException(sqle);
165
      throw new RuntimeException(sqle);
164
    } finally {
166
    } finally {
165
      if (rs != null) {
167
      if (rs != null) {
166
        try {
168
        try {
167
          rs.close();
169
          rs.close();
168
        } catch (SQLException re) {
170
        } catch (SQLException re) {
169
          LOG.error("Failed to close resultset", re);
171
          LoggingUtils.logAll(LOG, "Failed to close resultset", re);
170
        }
172
        }
171
      }
173
      }
172
      if (s != null) {
174
      if (s != null) {
173
        try {
175
        try {
174
          s.close();
176
          s.close();
175
        } catch (SQLException se) {
177
        } catch (SQLException se) {
176
          LOG.error("Failed to close statement", se);
178
          LoggingUtils.logAll(LOG, "Failed to close statement", se);
177
        }
179
        }
178
      }
180
      }
179
    }
181
    }
180

    
   
182

   
181
    return columns.toArray(new String[columns.size()]);
183
    return columns.toArray(new String[columns.size()]);
[+20] [20] 22 lines
[+20] [+] public String getPrimaryKey(String tableName) {
204
      try {
206
      try {
205
        if (c != null) {
207
        if (c != null) {
206
          c.rollback();
208
          c.rollback();
207
        }
209
        }
208
      } catch (SQLException ce) {
210
      } catch (SQLException ce) {
209
        LOG.error("Failed to rollback transaction", ce);
211
        LoggingUtils.logAll(LOG, "Failed to rollback transaction", ce);
210
      }
212
      }
211
      LOG.error("Failed to list primary key", sqle);
213
      LoggingUtils.logAll(LOG, "Failed to list primary key", sqle);
212
      throw new RuntimeException(sqle);
214
      throw new RuntimeException(sqle);
213
    } finally {
215
    } finally {
214
      if (rs != null) {
216
      if (rs != null) {
215
        try {
217
        try {
216
          rs.close();
218
          rs.close();
217
        } catch (SQLException re) {
219
        } catch (SQLException re) {
218
          LOG.error("Failed to close resultset", re);
220
          LoggingUtils.logAll(LOG, "Failed to close resultset", re);
219
        }
221
        }
220
      }
222
      }
221
      if (s != null) {
223
      if (s != null) {
222
        try {
224
        try {
223
          s.close();
225
          s.close();
224
        } catch (SQLException se) {
226
        } catch (SQLException se) {
225
          LOG.error("Failed to close statement", se);
227
          LoggingUtils.logAll(LOG, "Failed to close statement", se);
226
        }
228
        }
227
      }
229
      }
228
    }
230
    }
229

    
   
231

   
230
    if (columns.size() == 0) {
232
    if (columns.size() == 0) {
[+20] [20] 15 lines
src/java/org/apache/sqoop/manager/Db2Manager.java
Revision a84b4dcd2b7101f0eb7bb4ea30e104c7aad6d677 New Change
 
src/java/org/apache/sqoop/manager/MySQLManager.java
Revision b79c92664462e80bb6e1028cf14d569e805f0bbf New Change
 
src/java/org/apache/sqoop/manager/OracleManager.java
Revision 56244c741d9221b01cab27454bb18be4937ff639 New Change
 
src/java/org/apache/sqoop/manager/SqlManager.java
Revision f0a920df4d423ec0caa4efb34cd7678a8b8f54b9 New Change
 
src/java/org/apache/sqoop/mapreduce/ExportJobBase.java
Revision 5261671bdc3461f57fa3171d12447aeba2079444 New Change
 
src/java/org/apache/sqoop/mapreduce/PGBulkloadExportMapper.java
Revision 6c8d8068e73bc844b309f62726ec4fb9543abc67 New Change
 
src/java/org/apache/sqoop/mapreduce/PGBulkloadExportReducer.java
Revision 63c52c7bedfdea6fb3d85642dc8f9cb78b1a1e07 New Change
 
src/java/org/apache/sqoop/mapreduce/db/DBOutputFormat.java
Revision cd37a25e1a06dc34c8066370c53df0161796a093 New Change
 
src/java/org/apache/sqoop/mapreduce/db/DBRecordReader.java
Revision ab8bf1894149e50e4233113b112832ef87c0fe06 New Change
 
src/java/org/apache/sqoop/mapreduce/db/DataDrivenDBInputFormat.java
Revision 81677d7133f91acec5961ca4d91dd8f1575b6395 New Change
 
src/java/org/apache/sqoop/util/LoggingUtils.java
Revision cb74401be65cf181fc0000e7cef45982b99eeae2 New Change
 
src/java/org/apache/sqoop/util/ResultSetPrinter.java
Revision c6ec09df70c8643e1b8b5d26e4248cefcacded59 New Change
 
  1. src/java/org/apache/sqoop/manager/CatalogQueryManager.java: Loading...
  2. src/java/org/apache/sqoop/manager/Db2Manager.java: Loading...
  3. src/java/org/apache/sqoop/manager/MySQLManager.java: Loading...
  4. src/java/org/apache/sqoop/manager/OracleManager.java: Loading...
  5. src/java/org/apache/sqoop/manager/SqlManager.java: Loading...
  6. src/java/org/apache/sqoop/mapreduce/ExportJobBase.java: Loading...
  7. src/java/org/apache/sqoop/mapreduce/PGBulkloadExportMapper.java: Loading...
  8. src/java/org/apache/sqoop/mapreduce/PGBulkloadExportReducer.java: Loading...
  9. src/java/org/apache/sqoop/mapreduce/db/DBOutputFormat.java: Loading...
  10. src/java/org/apache/sqoop/mapreduce/db/DBRecordReader.java: Loading...
  11. src/java/org/apache/sqoop/mapreduce/db/DataDrivenDBInputFormat.java: Loading...
  12. src/java/org/apache/sqoop/util/LoggingUtils.java: Loading...
  13. src/java/org/apache/sqoop/util/ResultSetPrinter.java: Loading...