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);
}
}
Aggregations