Example #1
0
 @Override
 public void prepare() throws IOException {
   LOG.debug(
       "Preparing JDBC resource source (resource={}, table={})",
       profile.getResourceName(),
       script.getTableName());
   try {
     this.resultSet = prepareResultSet();
   } catch (SQLException e) {
     for (SQLException ex = e; ex != null; ex = ex.getNextException()) {
       WGLOG.error(
           ex,
           "E03001",
           profile.getResourceName(),
           script.getName(),
           script.getTableName(),
           script.getColumnNames());
     }
     throw new IOException(
         MessageFormat.format(
             "Failed to prepare JDBC source (resource={0}, table={1}, columns={2})",
             profile.getResourceName(), script.getTableName(), script.getColumnNames()),
         e);
   }
   LOG.debug(
       "Creating ResultSet support {} for {}",
       script.getSupport().getClass().getName(),
       script.getColumnNames());
   support = script.getSupport().createResultSetSupport(resultSet, script.getColumnNames());
 }
Example #2
0
 private String createSql() {
   assert script.getColumnNames().isEmpty() == false;
   if (script.getCondition() != null) {
     assert script.getCondition().isEmpty() == false;
     return MessageFormat.format(
         "SELECT {1} FROM {0} WHERE {2}",
         script.getTableName(),
         JdbcResourceUtil.join(script.getColumnNames()),
         script.getCondition());
   } else {
     return MessageFormat.format(
         "SELECT {1} FROM {0}",
         script.getTableName(), JdbcResourceUtil.join(script.getColumnNames()));
   }
 }
Example #3
0
 private ResultSet prepareResultSet() throws SQLException {
   String sql = createSql();
   statement = connection.createStatement();
   boolean succeed = false;
   try {
     WGLOG.info(
         "I03001",
         profile.getResourceName(),
         script.getName(),
         script.getTableName(),
         script.getColumnNames());
     if (profile.getBatchGetUnit() != 0) {
       statement.setFetchSize(profile.getBatchGetUnit());
     }
     LOG.debug("Executing SQL: {}", sql);
     ResultSet result = statement.executeQuery(sql);
     LOG.debug("Executed SQL: {}", sql);
     WGLOG.info(
         "I03002",
         profile.getResourceName(),
         script.getName(),
         script.getTableName(),
         script.getColumnNames());
     succeed = true;
     return result;
   } finally {
     if (succeed == false) {
       try {
         statement.close();
       } catch (SQLException e) {
         for (SQLException ex = e; ex != null; ex = ex.getNextException()) {
           WGLOG.warn(
               ex,
               "W03001",
               profile.getResourceName(),
               script.getName(),
               script.getTableName(),
               script.getColumnNames());
         }
       }
     }
   }
 }
Example #4
0
 @Override
 public boolean next() throws IOException {
   try {
     sawNext = support.next(object);
     return sawNext;
   } catch (SQLException e) {
     sawNext = false;
     for (SQLException ex = e; ex != null; ex = ex.getNextException()) {
       WGLOG.error(
           ex,
           "E03001",
           profile.getResourceName(),
           script.getName(),
           script.getTableName(),
           script.getColumnNames());
     }
     throw new IOException(
         MessageFormat.format(
             "Failed to fetch next object from JDBC source (resource={0}, table={1})",
             profile.getResourceName(), script.getTableName()),
         e);
   }
 }
Example #5
0
 @Override
 public void close() throws IOException {
   LOG.debug(
       "Closing JDBC resource source (resource={}, table={})",
       profile.getResourceName(),
       script.getTableName());
   sawNext = false;
   if (resultSet != null) {
     try {
       resultSet.close();
       resultSet = null;
       support = null;
     } catch (SQLException e) {
       for (SQLException ex = e; ex != null; ex = ex.getNextException()) {
         WGLOG.warn(
             ex,
             "W03001",
             profile.getResourceName(),
             script.getName(),
             script.getTableName(),
             script.getColumnNames());
       }
     }
     try {
       if (statement != null) {
         statement.close();
       }
     } catch (SQLException e) {
       for (SQLException ex = e; ex != null; ex = ex.getNextException()) {
         WGLOG.warn(
             ex,
             "W03001",
             profile.getResourceName(),
             script.getName(),
             script.getTableName(),
             script.getColumnNames());
       }
     }
   }
   try {
     connection.close();
   } catch (SQLException e) {
     for (SQLException ex = e; ex != null; ex = ex.getNextException()) {
       WGLOG.warn(ex, "W02001", profile.getResourceName(), script.getName());
     }
   }
 }