class RunSQLComponent extends CommandComponentSparkFlow implements Serializable {

    @Override
    public void execute() {
        Properties properties = new Properties();
        Connection conn = null;
        Reader reader = null;

        if (((null != runSqlEntity.getDatabaseConnectionName()) && !(runSqlEntity.getDatabaseConnectionName().trim().isEmpty()))
                && ((null != runSqlEntity.getQueryCommand()) && !(runSqlEntity.getQueryCommand().trim().isEmpty()))) {
            if (runSqlEntity.getDatabaseConnectionName().equalsIgnoreCase("MYSQL")) {
                log.debug("Request received test connection " + runSqlEntity.getDatabaseConnectionName());
                try {
                    properties.setProperty("className", "com.mysql.jdbc.Driver");
                    conn = DriverManager.getConnection("jdbc:mysql://" + runSqlEntity.getServerName() + ":" + runSqlEntity.getPortNumber() + "/" + runSqlEntity.getDatabaseName() + "?allowMultiQueries=true", runSqlEntity.getDbUserName(), runSqlEntity.getDbPwd());
                    conn.setAutoCommit(false);
                    scriptBuilder(runSqlEntity.getQueryCommand());
                    ScriptRunner sr = new ScriptRunner(conn, false, true);
                    reader = new BufferedReader(new FileReader(tempFile));
                    sr.runScript(reader);
                } catch (SQLException | IOException | ClassNotFoundException e) {
                    log.debug("Failed to Execute" + runSqlEntity.getQueryCommand() + " The error is " + e.getMessage());
                    throw new RuntimeException(e);
                } finally {
                    Exception ex = null;
                    try {
                        SafeResourceClose.safeReaderClose(reader);
                    } catch (IOException e) {
                        log.debug("Failed to Execute" + runSqlEntity.getQueryCommand() + " The error is " + e.getMessage());
                        ex = e;
                    }
                    try {
                        tempFile.deleteOnExit();
                    } catch (Exception e) {
                        log.debug("Failed to Execute" + runSqlEntity.getQueryCommand() + " The error is " + e.getMessage());
                        ex = e;
                    }
                    try {
                        SafeResourceClose.safeConnectionClose(conn);
                    } catch (SQLException e) {
                        log.debug("Failed to Execute" + runSqlEntity.getQueryCommand() + " The error is " + e.getMessage());
                        ex = e;
                    }

                    if(ex != null) {
                        throw new RuntimeException(ex);
                    }
                }
            } else if (runSqlEntity.getDatabaseConnectionName().equalsIgnoreCase("Oracle")) {
                log.debug("Request received test connection " + runSqlEntity.getDatabaseConnectionName());
                try {
                    properties.setProperty("className", "oracle.jdbc.driver.OracleDriver");
                    conn = DriverManager.getConnection("jdbc:oracle:thin://@" + runSqlEntity.getServerName() + ":" + runSqlEntity.getPortNumber() + "/" + runSqlEntity.getDatabaseName(), runSqlEntity.getDbUserName(), runSqlEntity.getDbPwd());
                    conn.setAutoCommit(false);
                    scriptBuilder(runSqlEntity.getQueryCommand());
                    ScriptRunner sr = new ScriptRunner(conn, false, true);
                    reader = new BufferedReader(new FileReader(tempFile));
                    sr.runScript(reader);
                } catch (SQLException | IOException | ClassNotFoundException e) {
                    log.debug("Failed to Execute" + runSqlEntity.getQueryCommand() + " The error is " + e.getMessage());
                    throw new RuntimeException(e);
                } finally {
                    Exception ex = null;
                    try {
                        SafeResourceClose.safeReaderClose(reader);
                    } catch (IOException e) {
                        log.debug("Failed to Execute" + runSqlEntity.getQueryCommand() + " The error is " + e.getMessage());
                        ex = e;
                    }
                    try {
                        tempFile.deleteOnExit();
                    } catch (Exception e) {
                        log.debug("Failed to Execute" + runSqlEntity.getQueryCommand() + " The error is " + e.getMessage());
                        ex = e;
                    }
                    try {
                        SafeResourceClose.safeConnectionClose(conn);
                    } catch (SQLException e) {
                        log.debug("Failed to Execute" + runSqlEntity.getQueryCommand() + " The error is " + e.getMessage());
                        ex = e;
                    }

                    if(ex != null) {
                        throw new RuntimeException(ex);
                    }
                }
            } else if (runSqlEntity.getDatabaseConnectionName().equalsIgnoreCase("Teradata")) {
                log.debug("Request received test connection " + runSqlEntity.getDatabaseConnectionName());
                try {
                    properties.setProperty("className", "com.teradata.jdbc.TeraDriver");
                    conn = DriverManager.getConnection("jdbc:teradata://" + runSqlEntity.getServerName() + "/DATABASE=" + runSqlEntity.getDatabaseName() + ",USER=" + runSqlEntity.getDbUserName() + ", " + Constants.TERADATA_PWD + "=" + runSqlEntity.getDbPwd() + ",TMODE=ANSI,CHARSET=UTF8");
                    conn.setAutoCommit(false);
                    scriptBuilder(runSqlEntity.getQueryCommand());
                    ScriptRunner sr = new ScriptRunner(conn, false, true);
                    reader = new BufferedReader(new FileReader(tempFile));
                    sr.runScript(reader);
                } catch (SQLException | IOException | ClassNotFoundException e) {
                    log.debug("Failed to Execute" + runSqlEntity.getQueryCommand() + " The error is " + e.getMessage());
                    throw new RuntimeException(e);
                } finally {
                    Exception ex = null;
                    try {
                        SafeResourceClose.safeReaderClose(reader);
                    } catch (IOException e) {
                        log.debug("Failed to Execute" + runSqlEntity.getQueryCommand() + " The error is " + e.getMessage());
                        ex = e;
                    }
                    try {
                        tempFile.deleteOnExit();
                    } catch (Exception e) {
                        log.debug("Failed to Execute" + runSqlEntity.getQueryCommand() + " The error is " + e.getMessage());
                        ex = e;
                    }
                    try {
                        SafeResourceClose.safeConnectionClose(conn);
                    } catch (SQLException e) {
                        log.debug("Failed to Execute" + runSqlEntity.getQueryCommand() + " The error is " + e.getMessage());
                        ex = e;
                    }

                    if(ex != null) {
                        throw new RuntimeException(ex);
                    }
                }
            } else if (runSqlEntity.getDatabaseConnectionName().equalsIgnoreCase("Redshift")) {
                log.debug("Request received test connection " + runSqlEntity.getDatabaseConnectionName());
                try {
                    properties.setProperty("className", "com.amazon.redshift.jdbc42.Driver");
                    conn = DriverManager.getConnection("jdbc:redshift://" + runSqlEntity.getServerName() + ":" + runSqlEntity.getPortNumber() + "/" + runSqlEntity.getDatabaseName(), runSqlEntity.getDbUserName(), runSqlEntity.getDbPwd());
                    conn.setAutoCommit(false);
                    scriptBuilder(runSqlEntity.getQueryCommand());
                    ScriptRunner sr = new ScriptRunner(conn, false, true);
                    reader = new BufferedReader(new FileReader(tempFile));
                    sr.runScript(reader);
                } catch (SQLException | IOException | ClassNotFoundException e) {
                    log.debug("Failed to Execute" + runSqlEntity.getQueryCommand() + " The error is " + e.getMessage());
                    throw new RuntimeException(e);
                } finally {
                    try {
                        SafeResourceClose.safeReaderClose(reader);
                    } catch (IOException e) {
                        log.debug("Failed to Execute" + runSqlEntity.getQueryCommand() + " The error is " + e.getMessage());
                    }
                    try {
                        tempFile.deleteOnExit();
                    } catch (Exception e) {
                        log.debug("Failed to Execute" + runSqlEntity.getQueryCommand() + " The error is " + e.getMessage());
                    }
                    try {
                        SafeResourceClose.safeConnectionClose(conn);
                    } catch (SQLException e) {
                        log.debug("Failed to Execute" + runSqlEntity.getQueryCommand() + " The error is " + e.getMessage());
                    }
                }
            }
        } else {
            log.debug("Failed to Execute" + runSqlEntity.getQueryCommand() + "Required field is empty.");
            throw new DatabaseConnectionException("Required field is empty.",null);
        }
    }

    public  RunSQLComponent(AssemblyEntityBase assemblyEntityBase);

}