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