/** * Execute SELECT statement. * * @param node the root node of the statement. * @return null. */ public Object execute(ICodeNode node) { // Is there already an entry for this SELECT node in the // jump table cache? If not, create a jump table entry. HashMap<Object, ICodeNode> jumpTable = jumpCache.get(node); if (jumpTable == null) { jumpTable = createJumpTable(node); jumpCache.put(node, jumpTable); } // Get the SELECT node's children. ArrayList<ICodeNode> selectChildren = node.getChildren(); ICodeNode exprNode = selectChildren.get(0); // Evaluate the SELECT expression. ExpressionExecutor expressionExecutor = new ExpressionExecutor(this); Object selectValue = expressionExecutor.execute(exprNode); // If there is a selection, execute the SELECT_BRANCH's statement. ICodeNode statementNode = jumpTable.get(selectValue); if (statementNode != null) { StatementExecutor statementExecutor = new StatementExecutor(this); statementExecutor.execute(statementNode); } ++executionCount; // count the SELECT statement itself return null; }
@Override public String toString() { final StringBuilder builder = new StringBuilder(); builder.append(executor.toString()); builder.append(" ["); String separator = ""; for (final int n : inputs) { builder.append(separator); builder.append(String.format("%d", n)); separator = ", "; } builder.append(']'); return builder.toString(); }