mirror of
https://github.com/apache/sqoop.git
synced 2025-05-04 20:30:06 +08:00
SQOOP-1320. Sqoop2: Log entire SQLExceptions chain in GenericJdbcExecutor
(Jaroslav Cecho via Hari Shreedharan)
This commit is contained in:
parent
dccaf0b258
commit
0756d13662
@ -48,8 +48,8 @@ public GenericJdbcExecutor(String driver, String url,
|
|||||||
GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0000, driver, e);
|
GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0000, driver, e);
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new SqoopException(
|
logSQLException(e);
|
||||||
GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0001, e);
|
throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0001, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,8 +60,8 @@ public ResultSet executeQuery(String sql) {
|
|||||||
return statement.executeQuery(sql);
|
return statement.executeQuery(sql);
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new SqoopException(
|
logSQLException(e);
|
||||||
GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
|
throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,6 +69,7 @@ public void setAutoCommit(boolean autoCommit) {
|
|||||||
try {
|
try {
|
||||||
connection.setAutoCommit(autoCommit);
|
connection.setAutoCommit(autoCommit);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
logSQLException(e);
|
||||||
throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
|
throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,23 +105,21 @@ public void migrateData(String fromTable, String toTable) {
|
|||||||
GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0018);
|
GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0018);
|
||||||
}
|
}
|
||||||
} catch(SQLException e) {
|
} catch(SQLException e) {
|
||||||
LOG.error("Got SQLException while migrating data from: " + fromTable +
|
logSQLException(e, "Got SQLException while migrating data from: " + fromTable + " to: " + toTable);
|
||||||
" to: " + toTable, e);
|
throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0018, e);
|
||||||
throw new SqoopException(
|
|
||||||
GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0018, e);
|
|
||||||
} finally {
|
} finally {
|
||||||
if(stmt != null) {
|
if(stmt != null) {
|
||||||
try {
|
try {
|
||||||
stmt.close();
|
stmt.close();
|
||||||
} catch(SQLException e) {
|
} 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) {
|
if(oldAutoCommit != null) {
|
||||||
try {
|
try {
|
||||||
connection.setAutoCommit(oldAutoCommit);
|
connection.setAutoCommit(oldAutoCommit);
|
||||||
} catch(SQLException e) {
|
} 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 long getTableRowCount(String tableName) {
|
|||||||
if(resultSet != null)
|
if(resultSet != null)
|
||||||
resultSet.close();
|
resultSet.close();
|
||||||
} catch(SQLException e) {
|
} catch(SQLException e) {
|
||||||
LOG.warn("Got SQLException while closing resultset.", e);
|
logSQLException(e, "Got SQLException while closing resultset.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,8 +150,8 @@ public void executeUpdate(String sql) {
|
|||||||
statement.executeUpdate(sql);
|
statement.executeUpdate(sql);
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new SqoopException(
|
logSQLException(e);
|
||||||
GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
|
throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,8 +161,8 @@ public void beginBatch(String sql) {
|
|||||||
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new SqoopException(
|
logSQLException(e);
|
||||||
GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
|
throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,8 +173,8 @@ public void addBatch(Object[] array) {
|
|||||||
}
|
}
|
||||||
preparedStatement.addBatch();
|
preparedStatement.addBatch();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new SqoopException(
|
logSQLException(e);
|
||||||
GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
|
throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,8 +185,8 @@ public void executeBatch(boolean commit) {
|
|||||||
connection.commit();
|
connection.commit();
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new SqoopException(
|
logSQLException(e);
|
||||||
GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
|
throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,8 +196,8 @@ public void endBatch() {
|
|||||||
preparedStatement.close();
|
preparedStatement.close();
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new SqoopException(
|
logSQLException(e);
|
||||||
GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
|
throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0002, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,8 +215,8 @@ public String getPrimaryKey(String table) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new SqoopException(
|
logSQLException(e);
|
||||||
GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0003, e);
|
throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0003, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,8 +236,8 @@ public String[] getQueryColumns(String query) {
|
|||||||
return columns;
|
return columns;
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new SqoopException(
|
logSQLException(e);
|
||||||
GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0003, e);
|
throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0003, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,8 +255,8 @@ public boolean existTable(String table) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new SqoopException(
|
logSQLException(e);
|
||||||
GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0003, e);
|
throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0003, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,8 +295,18 @@ public void close() {
|
|||||||
connection.close();
|
connection.close();
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} 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:");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user