Example #1
0
  private void execute(
      boolean script, boolean export, Writer fileOutput, Statement statement, final String sql)
      throws IOException, SQLException {
    final SqlExceptionHelper sqlExceptionHelper = new SqlExceptionHelper();

    String formatted = formatter.format(sql);
    if (delimiter != null) formatted += delimiter;
    if (script) System.out.println(formatted);
    LOG.debug(formatted);
    if (outputFile != null) {
      fileOutput.write(formatted + "\n");
    }
    if (export) {

      statement.executeUpdate(sql);
      try {
        SQLWarning warnings = statement.getWarnings();
        if (warnings != null) {
          sqlExceptionHelper.logAndClearWarnings(connectionHelper.getConnection());
        }
      } catch (SQLException sqle) {
        LOG.unableToLogSqlWarnings(sqle);
      }
    }
  }
  @Override
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    if ("findColumn".equals(method.getName())) {
      return findColumn((String) args[0]);
    }

    if (isFirstArgColumnLabel(method, args)) {
      try {
        final Integer columnIndex = findColumn((String) args[0]);
        return invokeMethod(
            locateCorrespondingColumnIndexMethod(method),
            buildColumnIndexMethodArgs(args, columnIndex));
      } catch (SQLException ex) {
        final String msg =
            "Exception getting column index for column: ["
                + args[0]
                + "].\nReverting to using: ["
                + args[0]
                + "] as first argument for method: ["
                + method
                + "]";
        SQL_EXCEPTION_HELPER.logExceptions(ex, msg);
      } catch (NoSuchMethodException ex) {
        LOG.unableToSwitchToMethodUsingColumnIndex(method);
      }
    }
    return invokeMethod(method, args);
  }
Example #3
0
 @Override
 public void export(String string) throws Exception {
   statement.executeUpdate(string);
   try {
     SQLWarning warnings = statement.getWarnings();
     if (warnings != null) {
       sqlExceptionHelper.logAndClearWarnings(connection);
     }
   } catch (SQLException e) {
     LOG.unableToLogSqlWarnings(e);
   }
 }