Search in sources :

Example 1 with ParseResult

use of com.developmentontheedge.be5.metadata.model.ParseResult 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)

Example 2 with ParseResult

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

the class Project method mergeTemplate.

public ParseResult mergeTemplate(TemplateElement element) {
    boolean besql = element instanceof Query && ((Query) element).getEntity().isBesql() && ((Query) element).isSqlQuery();
    try {
        sqlMacros.clear();
        if (" ".equals(element.getTemplateCode()))
            return new ParseResult(" ");
        final DataElementPath path = element.getCompletePath();
        final String merged = FreemarkerUtils.mergeTemplateByPath(path.toString(), getContext(element), getConfiguration());
        if (besql)
            enterSQL();
        return new ParseResult(besql ? translateSQL(merged) : merged);
    } catch (ProjectElementException e) {
        return new ParseResult(e);
    } catch (Throwable e) {
        return new ParseResult(new ProjectElementException(getCompletePath(), "source", e));
    } finally {
        beSQL = 0;
        sqlMacros.clear();
    }
}
Also used : ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException) DataElementPath(com.developmentontheedge.be5.metadata.model.base.DataElementPath)

Aggregations

ProjectElementException (com.developmentontheedge.be5.metadata.exception.ProjectElementException)1 BeConnectionProfile (com.developmentontheedge.be5.metadata.model.BeConnectionProfile)1 FreemarkerScript (com.developmentontheedge.be5.metadata.model.FreemarkerScript)1 ParseResult (com.developmentontheedge.be5.metadata.model.ParseResult)1 DataElementPath (com.developmentontheedge.be5.metadata.model.base.DataElementPath)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 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1