sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hshreedha...@apache.org
Subject git commit: SQOOP-1320. Sqoop2: Log entire SQLExceptions chain in GenericJdbcExecutor
Date Mon, 12 May 2014 19:24:35 GMT
Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 dccaf0b25 -> 0756d1366


SQOOP-1320. Sqoop2: Log entire SQLExceptions chain in GenericJdbcExecutor

(Jaroslav Cecho via Hari Shreedharan)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/0756d136
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/0756d136
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/0756d136

Branch: refs/heads/sqoop2
Commit: 0756d13662913a7c2df1a0a4d23cd50175dc42f4
Parents: dccaf0b
Author: Hari Shreedharan <hshreedharan@apache.org>
Authored: Mon May 12 12:23:12 2014 -0700
Committer: Hari Shreedharan <hshreedharan@apache.org>
Committed: Mon May 12 12:23:12 2014 -0700

----------------------------------------------------------------------
 .../connector/jdbc/GenericJdbcExecutor.java     | 65 +++++++++++---------
 1 file changed, 37 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/0756d136/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcExecutor.java
----------------------------------------------------------------------
diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcExecutor.java
b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcExecutor.java
index 9fd2e4f..5dc3c0b 100644
--- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcExecutor.java
+++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcExecutor.java
@@ -48,8 +48,8 @@ public class GenericJdbcExecutor {
           GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0000, driver, e);
 
     } catch (SQLException e) {
-      throw new SqoopException(
-          GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0001, e);
+      logSQLException(e);
+      throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0001, e);
     }
   }
 
@@ -60,8 +60,8 @@ public class GenericJdbcExecutor {
       return statement.executeQuery(sql);
 
     } catch (SQLException e) {
-      throw new SqoopException(
-          GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
+      logSQLException(e);
+      throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
     }
   }
 
@@ -69,6 +69,7 @@ public class GenericJdbcExecutor {
     try {
       connection.setAutoCommit(autoCommit);
     } catch (SQLException e) {
+      logSQLException(e);
       throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
     }
   }
@@ -104,23 +105,21 @@ public class GenericJdbcExecutor {
           GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0018);
       }
     } catch(SQLException e) {
-      LOG.error("Got SQLException while migrating data from: " + fromTable +
-        " to: " + toTable, e);
-      throw new SqoopException(
-        GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0018, e);
+      logSQLException(e, "Got SQLException while migrating data from: " + fromTable + " to:
" + toTable);
+      throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0018, e);
     } finally {
       if(stmt != null) {
         try {
           stmt.close();
         } catch(SQLException e) {
-          LOG.warn("Got SQLException at the time of closing statement.", e);
+          logSQLException(e, "Got SQLException at the time of closing statement.");
         }
       }
       if(oldAutoCommit != null) {
         try {
           connection.setAutoCommit(oldAutoCommit);
         } catch(SQLException e) {
-          LOG.warn("Got SQLException while setting autoCommit mode.", e);
+          logSQLException(e, "Got SQLException while setting autoCommit mode.");
         }
       }
     }
@@ -139,7 +138,7 @@ public class GenericJdbcExecutor {
         if(resultSet != null)
           resultSet.close();
       } catch(SQLException e) {
-        LOG.warn("Got SQLException while closing resultset.", e);
+        logSQLException(e, "Got SQLException while closing resultset.");
       }
     }
   }
@@ -151,8 +150,8 @@ public class GenericJdbcExecutor {
       statement.executeUpdate(sql);
 
     } catch (SQLException e) {
-      throw new SqoopException(
-          GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
+      logSQLException(e);
+      throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
     }
   }
 
@@ -162,8 +161,8 @@ public class GenericJdbcExecutor {
           ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
 
     } catch (SQLException e) {
-      throw new SqoopException(
-          GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
+      logSQLException(e);
+      throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
     }
   }
 
@@ -174,8 +173,8 @@ public class GenericJdbcExecutor {
       }
       preparedStatement.addBatch();
     } catch (SQLException e) {
-      throw new SqoopException(
-          GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
+      logSQLException(e);
+      throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
     }
   }
 
@@ -186,8 +185,8 @@ public class GenericJdbcExecutor {
         connection.commit();
       }
     } catch (SQLException e) {
-      throw new SqoopException(
-          GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
+      logSQLException(e);
+      throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
     }
   }
 
@@ -197,8 +196,8 @@ public class GenericJdbcExecutor {
         preparedStatement.close();
       }
     } catch (SQLException e) {
-      throw new SqoopException(
-          GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
+      logSQLException(e);
+      throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
     }
   }
 
@@ -216,8 +215,8 @@ public class GenericJdbcExecutor {
       }
 
     } catch (SQLException e) {
-      throw new SqoopException(
-          GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0003, e);
+      logSQLException(e);
+      throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0003, e);
     }
   }
 
@@ -237,8 +236,8 @@ public class GenericJdbcExecutor {
       return columns;
 
     } catch (SQLException e) {
-      throw new SqoopException(
-          GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0003, e);
+      logSQLException(e);
+      throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0003, e);
     }
   }
 
@@ -256,8 +255,8 @@ public class GenericJdbcExecutor {
       }
 
     } catch (SQLException e) {
-      throw new SqoopException(
-          GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0003, e);
+      logSQLException(e);
+      throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0003, e);
     }
   }
 
@@ -296,8 +295,18 @@ public class GenericJdbcExecutor {
       connection.close();
 
     } catch (SQLException e) {
-      // TODO: Log the exception
+      logSQLException(e);
     }
   }
 
+  private void logSQLException(SQLException e) {
+    logSQLException(e, "Caught SQLException:");
+  }
+
+  private void logSQLException(SQLException e, String message) {
+    LOG.error(message, e);
+    if(e.getNextException() != null) {
+      logSQLException(e.getNextException(), "Caused by:");
+    }
+  }
 }


Mime
View raw message