Search in sources :

Example 6 with BeConnectionProfile

use of com.developmentontheedge.be5.metadata.model.BeConnectionProfile in project be5 by DevelopmentOnTheEdge.

the class AppTools method execute.

@Override
public void execute() throws MojoFailureException {
    init();
    BeConnectionProfile prof = be5Project.getConnectionProfile();
    if (prof == null) {
        throw new MojoFailureException("Connection profile is required for SQL console");
    }
    try {
        getLog().info("Welcome to FTL/SQL console!");
        BeSqlExecutor sql = new BeSqlExecutor(connector) {

            @Override
            public void executeSingle(String statement) throws ExtendedSqlException {
                ResultSet rs = null;
                try {
                    rs = connector.executeQuery(statement);
                    format(rs, System.err, 20);
                } catch (SQLException e) {
                    throw new ExtendedSqlException(connector, statement, e);
                } finally {
                    connector.close(rs);
                }
            }
        };
        FreemarkerScript fs = new FreemarkerScript("SQL", be5Project.getApplication().getFreemarkerScripts());
        DataElementUtils.save(fs);
        ProcessController log = new NullLogger();
        while (true) {
            getLog().info("Enter FTL/SQL (use 'quit' to exit):");
            String line = new BufferedReader(new InputStreamReader(inputStream)).readLine();
            if (line == null) {
                break;
            }
            line = line.trim();
            if (line.equals("quit")) {
                break;
            }
            fs.setSource(line);
            ParseResult result = fs.getResult();
            if (result.getResult() != null) {
                getLog().info("SQL> " + result.getResult());
            } else {
                getLog().info("ERROR> " + result.getError());
                continue;
            }
            try {
                sql.executeScript(fs, log);
            } catch (Exception e) {
                getLog().info("ERROR> " + e.getMessage());
            }
        }
    } catch (Exception e) {
        throw new MojoFailureException("Console error: " + e.getMessage(), e);
    }
}
Also used : ParseResult(com.developmentontheedge.be5.metadata.model.ParseResult) SQLException(java.sql.SQLException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ExtendedSqlException(com.developmentontheedge.dbms.ExtendedSqlException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) SQLException(java.sql.SQLException) ExtendedSqlException(com.developmentontheedge.dbms.ExtendedSqlException) BeSqlExecutor(com.developmentontheedge.be5.metadata.sql.BeSqlExecutor) NullLogger(com.developmentontheedge.be5.metadata.util.NullLogger) BeConnectionProfile(com.developmentontheedge.be5.metadata.model.BeConnectionProfile) ProcessController(com.developmentontheedge.be5.metadata.util.ProcessController) ResultSet(java.sql.ResultSet) FreemarkerScript(com.developmentontheedge.be5.metadata.model.FreemarkerScript)

Aggregations

BeConnectionProfile (com.developmentontheedge.be5.metadata.model.BeConnectionProfile)5 LinkedHashMap (java.util.LinkedHashMap)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 Yaml (org.yaml.snakeyaml.Yaml)2 ProjectLoadException (com.developmentontheedge.be5.metadata.exception.ProjectLoadException)1 FreemarkerScript (com.developmentontheedge.be5.metadata.model.FreemarkerScript)1 ParseResult (com.developmentontheedge.be5.metadata.model.ParseResult)1 Project (com.developmentontheedge.be5.metadata.model.Project)1 BeModelElement (com.developmentontheedge.be5.metadata.model.base.BeModelElement)1 LoadContext (com.developmentontheedge.be5.metadata.serialization.LoadContext)1 BeSqlExecutor (com.developmentontheedge.be5.metadata.sql.BeSqlExecutor)1 NullLogger (com.developmentontheedge.be5.metadata.util.NullLogger)1 ProcessController (com.developmentontheedge.be5.metadata.util.ProcessController)1 ExtendedSqlException (com.developmentontheedge.dbms.ExtendedSqlException)1 SimpleConnector (com.developmentontheedge.dbms.SimpleConnector)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1