Search in sources :

Example 6 with VisitException

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;
    }
}
Also used : ResultSetIterator(org.whole.lang.sql.iterators.ResultSetIterator) IVisitor(org.whole.lang.visitors.IVisitor) IEntity(org.whole.lang.model.IEntity) VisitException(org.whole.lang.visitors.VisitException) PrettyPrinterOperation.toPrettyPrintString(org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString) VisitException(org.whole.lang.visitors.VisitException)

Example 7 with VisitException

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);
    }
}
Also used : VisitException(org.whole.lang.visitors.VisitException) IBindingManager(org.whole.lang.bindings.IBindingManager) VisitException(org.whole.lang.visitors.VisitException)

Example 8 with VisitException

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;
    }
}
Also used : VisitException(org.whole.lang.visitors.VisitException) VisitException(org.whole.lang.visitors.VisitException)

Example 9 with VisitException

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);
}
Also used : ITaskDialogFactory(org.whole.lang.workflows.ui.dialogs.ITaskDialogFactory) Variable(org.whole.lang.workflows.model.Variable) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) VisitException(org.whole.lang.visitors.VisitException) Assignments(org.whole.lang.workflows.model.Assignments)

Example 10 with VisitException

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);
    }
}
Also used : VisitException(org.whole.lang.visitors.VisitException) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Aggregations

VisitException (org.whole.lang.visitors.VisitException)35 IEntity (org.whole.lang.model.IEntity)25 IBindingManager (org.whole.lang.bindings.IBindingManager)6 File (java.io.File)4 AbstractVisitor (org.whole.lang.visitors.AbstractVisitor)4 HashSet (java.util.HashSet)3 GenericIdentityVisitor (org.whole.lang.visitors.GenericIdentityVisitor)3 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 PrettyPrinterOperation.toPrettyPrintString (org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString)2 GenericTraversalFactory (org.whole.lang.visitors.GenericTraversalFactory)2 IVisitor (org.whole.lang.visitors.IVisitor)2 EvalError (bsh.EvalError)1 Interpreter (bsh.Interpreter)1 BufferedReader (java.io.BufferedReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 Writer (java.io.Writer)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1