use of org.whole.lang.visitors.VisitException in project whole by wholeplatform.
the class SQLInterpreterVisitor method visit.
@Override
public void visit(SQLStatement entity) {
try {
IVisitor ov = getOperation().setVisitor(entity, 0, getOperation().getVisitor(entity, 1));
getOperation().stagedVisit(entity);
getOperation().setVisitor(entity, 0, ov);
entity = (SQLStatement) getResult();
String sql = toPrettyPrintString(entity);
if (batchMode)
statement.addBatch(sql);
else {
String[] names;
if (entity.wGetEntityDescriptor().equals(SQLEntityDescriptorEnum.Select)) {
IEntity columnExprs = entity.wGet(SQLFeatureDescriptorEnum.columnExprs);
int size = columnExprs.wSize();
names = new String[size];
for (int i = 0; i < size; i++) {
IEntity columnExpr = columnExprs.wGet(i);
if (Matcher.matchImpl(SQLEntityDescriptorEnum.ColumnExpression, columnExpr)) {
IEntity alias = columnExpr.wGet(SQLFeatureDescriptorEnum.alias);
if (DataTypeUtils.getDataKind(alias).isString())
names[i] = alias.wStringValue();
else {
IEntity expr = columnExpr.wGet(SQLFeatureDescriptorEnum.expression);
if (Matcher.matchImpl(SQLEntityDescriptorEnum.ColumnName, expr))
names[i] = expr.wStringValue();
}
}
}
} else
names = new String[0];
if (statement.execute(sql))
setResultIterator(new ResultSetIterator(statement.getResultSet(), names));
else {
setResult(null);
statement.close();
}
}
} catch (Exception e) {
try {
statement.close();
} catch (Exception e1) {
}
throw new VisitException(SQL_INTERPRETER_ERROR_MESSAGE, e);
} finally {
if (!batchMode)
statement = null;
}
}
use of org.whole.lang.visitors.VisitException in project whole by wholeplatform.
the class SQLInterpreterVisitor method visit.
@Override
public void visit(ISQLEntity entity) {
if (statement != null)
return;
try {
if (!Matcher.isAssignableAsIsFrom(SQLEntityDescriptorEnum.SQLStatement, entity) && !Matcher.match(SQLEntityDescriptorEnum.SQLStatements, entity))
throw new IllegalArgumentException("cannot interpret.");
IBindingManager env = getBindings();
if (!env.wIsSet("connection"))
throw new IllegalArgumentException("database connection undefined.");
connection = (Connection) env.wGetValue("connection");
statement = connection.createStatement();
} catch (Exception e) {
throw new VisitException(SQL_INTERPRETER_ERROR_MESSAGE, e);
}
}
use of org.whole.lang.visitors.VisitException in project whole by wholeplatform.
the class SQLInterpreterVisitor method visit.
@Override
public void visit(SQLStatements entity) {
try {
batchMode = true;
int size = entity.wSize();
for (int i = 0; i < size; i++) ((ISQLEntity) entity.wGet(i)).accept(this);
statement.executeBatch();
} catch (Exception e) {
throw new VisitException(SQL_INTERPRETER_ERROR_MESSAGE, e);
} finally {
try {
statement.close();
} catch (Exception e) {
}
statement = null;
}
}
use of org.whole.lang.visitors.VisitException in project whole by wholeplatform.
the class WorkflowsIDEInterpreterVisitor method visit.
@Override
public void visit(Task entity) {
entity.getLabel().accept(this);
String title = PrettyPrinterOperation.toPrettyPrintString(getResult());
entity.getDescription().accept(this);
String description = PrettyPrinterOperation.toPrettyPrintString(getResult());
Assignments assignments = EntityUtils.clone(entity.getAssignments());
Variable factoryVariable = entity.getFactory();
ITaskDialogFactory factory;
if (EntityUtils.isNotResolver(factoryVariable)) {
factoryVariable.accept(this);
factory = (ITaskDialogFactory) getResultValue();
} else if (EntityUtils.isNotResolver(assignments)) {
factory = AssignmentsDialogFactory.instance();
} else
factory = ConfirmationDialogFactory.instance();
if (EntityUtils.isNotResolver(assignments)) {
stagedVisit(assignments, 1);
assignments = (Assignments) getResult();
}
if (!TaskDialogHelper.showTaskDialog(factory, title, description, assignments, getBindings()))
throw new OperationCanceledException(new VisitException("task not completed: " + description));
assignments.accept(this);
}
use of org.whole.lang.visitors.VisitException in project whole by wholeplatform.
the class WorkflowsInterpreterVisitor method visit.
public void visit(Task entity) {
entity.getAssignments().accept(this);
entity.getDescription().accept(this);
String description = PrettyPrinterOperation.toPrettyPrintString(getResult());
Reader reader = getOperation().getReader();
try {
if (!reader.ready()) {
PrintWriter printWriter = getOperation().getPrintWriter();
printWriter.println(description);
printWriter.println("Confirm task completion[Yes/no]: ");
printWriter.flush();
}
BufferedReader bufferedReader = new BufferedReader(reader);
if (bufferedReader.readLine().equalsIgnoreCase("no"))
throw new VisitException("task not completed: " + description);
} catch (IOException e) {
throw new VisitException(e);
}
}
Aggregations