/** * Deep clone statement to produce a new identical block. * @return Deep clone */ public Block clone() { Block copy = new Block(); copy.setAtomic(atomic); copy.statements = LanguageObject.Util.deepClone(statements, Statement.class); if (exceptionStatements != null) { copy.exceptionStatements = LanguageObject.Util.deepClone(exceptionStatements, Statement.class); } copy.exceptionGroup = this.exceptionGroup; copy.setLabel(label); return copy; }
/** * Add a <code>Statement</code> to this block. * @param statement The <code>Statement</code> to be added to the block */ public void addStatement(Statement statement) { addStatement(statement, false); }
/** * Deep clone statement to produce a new identical statement. * @return Deep clone */ public Object clone() { Block otherIf = this.ifBlock.clone(); Criteria otherCrit = (Criteria) this.condition.clone(); Block otherElse = null; if(this.hasElseBlock()) { otherElse = this.elseBlock.clone(); } return new IfStatement(otherCrit, otherIf, otherElse); }
private Block rewriteBlock(Block block) throws TeiidComponentException { List<Statement> statements = block.getStatements(); List<Statement> newStmts = rewriteStatements(statements); block.setStatements(newStmts); if (block.getExceptionStatements() != null) { block.setExceptionStatements(rewriteStatements(block.getExceptionStatements())); } return block; }
Program programBlock = new Program(block.isAtomic()); programBlock.setLabel(block.getLabel()); planStatements(parentProcCommand, block.getStatements(), metadata, debug, idGenerator, capFinder, analysisRecord, context, programBlock); if (block.getExceptionGroup() != null) { programBlock.setExceptionGroup(block.getExceptionGroup()); if (block.getExceptionStatements() != null) { Program exceptionBlock = new Program(false); planStatements(parentProcCommand, block.getExceptionStatements(), metadata, debug, idGenerator, capFinder, analysisRecord, context, exceptionBlock); programBlock.setExceptionProgram(exceptionBlock);
private Command asLoopProcedure(GroupSymbol group, QueryCommand query, Statement s, GroupSymbol varGroup, int updateType) throws QueryResolverException, TeiidComponentException, TeiidProcessingException { Block b = new Block(); b.addStatement(s); CreateProcedureCommand cupc = new CreateProcedureCommand(); cupc.setUpdateType(updateType); Block parent = new Block(); parent.setAtomic(true); ElementSymbol rowsUpdated = new ElementSymbol(ProcedureReservedWords.VARIABLES+Symbol.SEPARATOR+"ROWS_UPDATED"); //$NON-NLS-1$ DeclareStatement ds = new DeclareStatement(rowsUpdated, DataTypeManager.DefaultDataTypes.INTEGER, new Constant(0)); parent.addStatement(ds); LoopStatement ls = new LoopStatement(b, query, varGroup.getName()); parent.addStatement(ls); AssignmentStatement as = new AssignmentStatement(); rowsUpdated.setType(DataTypeManager.DefaultDataClasses.INTEGER); as.setVariable(rowsUpdated); as.setExpression(new Function("+", new Expression[] {rowsUpdated, new Constant(1)})); //$NON-NLS-1$ b.addStatement(as); Query returnQuery = new Query(); returnQuery.setSelect(new Select(Arrays.asList(rowsUpdated.clone()))); parent.addStatement(new CommandStatement(returnQuery)); cupc.setBlock(parent); cupc.setVirtualGroup(group); QueryResolver.resolveCommand(cupc, metadata); return rewrite(cupc, metadata, context); }
public static final Block sample1() { Block block = new Block(); block.addStatement(TestAssignmentStatement.sample1()); block.addStatement(TestCommandStatement.sample1()); block.addStatement(TestRaiseErrorStatement.sample1()); block.addStatement(TestAssignmentStatement.sample1()); return block; }
final public Block compoundStatement(ParseInfo info) throws ParseException { Statement stmt = null; Block block = new Block(); Boolean atomic = null; String eId = null; block.addStatement(stmt, false); jj_consume_token(EXCEPTION); eId = id(Boolean.FALSE); block.setExceptionGroup(eId); label_4: while (true) { block.addStatement(stmt, true); block.setAtomic(atomic);
@Test public void testWhileStatement1() throws Exception { ElementSymbol x = new ElementSymbol("x", false); //$NON-NLS-1$ Function f = new Function("+", new Expression[] { x, new Constant(new Integer(1)) }); //$NON-NLS-1$ Statement assignmentStmt = new AssignmentStatement(x, f); Block block = new Block(); block.setAtomic(true); block.setLabel("1y"); block.addStatement(assignmentStmt); BranchingStatement bs = new BranchingStatement(BranchingMode.CONTINUE); bs.setLabel("1y"); block.addStatement(bs); Criteria crit = new CompareCriteria(x, CompareCriteria.LT, new Constant(new Integer(100))); WhileStatement whileStmt = new WhileStatement(crit, block); helpStmtTest("WHILE (x < 100) \"1y\": BEGIN ATOMIC x=x+1; CONTINUE \"1y\"; END", //$NON-NLS-1$ "WHILE(x < 100)"+"\n"+ "\"1y\" : BEGIN ATOMIC"+"\n"+"x = (x + 1);\nCONTINUE \"1y\";" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ +"\n"+"END", whileStmt); //$NON-NLS-1$ //$NON-NLS-2$ }
@Test public void testaddStatement1() { Block b1 = sample1().clone(); b1.addStatement(TestCommandStatement.sample2()); assertTrue("Incorrect number of statements in the Block", (b1.getStatements().size() == 5)); //$NON-NLS-1$ }
@Test public void testExceptionGroup() { Block b1 = sample1(); Block b2 = b1.clone(); b1.setExceptionGroup("x"); b2.setExceptionGroup("y"); assertFalse(b1.equals(b2)); }
for (Statement statement : block.getStatements()) { resolveStatement(command, statement, externalGroups, variables, metadata); if (block.getExceptionGroup() != null) { isValidGroup(metadata, block.getExceptionGroup()); if (block.getExceptionStatements() != null) { ProcedureContainerResolver.addScalarGroup(block.getExceptionGroup(), store, externalGroups, exceptionGroup, false); for (Statement statement : block.getExceptionStatements()) { resolveStatement(command, statement, externalGroups, variables, metadata);
@Test public void testBlockExceptionHandling() throws ParseException { CommandStatement cmdStmt = new CommandStatement(new Query(new Select(Arrays.asList(new MultipleElementSymbol())), new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("x")))), null, null, null)); AssignmentStatement assigStmt = new AssignmentStatement(new ElementSymbol("a"), new Constant(new Integer(1))); //$NON-NLS-1$ RaiseStatement errStmt = new RaiseStatement(new Constant("My Error")); //$NON-NLS-1$ Block b = new Block(); b.setExceptionGroup("e"); b.addStatement(cmdStmt); b.addStatement(assigStmt); b.addStatement(errStmt, true); helpStmtTest("BEGIN\nselect * from x;\na = 1;\nexception e\nERROR 'My Error';\nEND", "BEGIN\nSELECT * FROM x;\na = 1;\nEXCEPTION e\nRAISE SQLEXCEPTION 'My Error';\nEND", b); //$NON-NLS-1$ }
/** * Compare two queries for equality. Blocks will only evaluate to equal if * they are IDENTICAL: statements in the block are equal and are in the same order. * @param obj Other object * @return True if equal */ public boolean equals(Object obj) { // Quick same object test if(this == obj) { return true; } // Quick fail tests if(!(obj instanceof Block)) { return false; } Block other = (Block)obj; // Compare the statements on the block return this.atomic == other.atomic && StringUtil.equalsIgnoreCase(label, other.label) && EquivalenceUtil.areEqual(getStatements(), other.getStatements()) && EquivalenceUtil.areEqual(exceptionGroup, other.exceptionGroup) && EquivalenceUtil.areEqual(exceptionStatements, exceptionStatements); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof TriggerAction)) { return false; } TriggerAction other = (TriggerAction) obj; return block.equals(other.block); }
public void visit(Block obj) { preVisitVisitor(obj); visitNodes(obj.getStatements()); visitNodes(obj.getExceptionStatements()); postVisitVisitor(obj); } public void visit(BranchingStatement obj) {
static Block asBlock(Statement stmt) { if (stmt == null) { return null; } if (stmt instanceof Block) { return (Block)stmt; } return new Block(stmt); }
@Test public void testClone() { Block b1 = sample1(); Block b2 = b1.clone(); UnitTestUtil.helpTestEquivalence(0, b1, b2); assertNotSame(b1.getStatements().get(0), b2.getStatements().get(0)); }
public void setBlock(Block block) { block.setAtomic(true); this.block = block; }
private Command asLoopProcedure(GroupSymbol group, QueryCommand query, Statement s, GroupSymbol varGroup, int updateType) throws QueryResolverException, TeiidComponentException, TeiidProcessingException { Block b = new Block(); b.addStatement(s); CreateProcedureCommand cupc = new CreateProcedureCommand(); cupc.setUpdateType(updateType); Block parent = new Block(); parent.setAtomic(true); ElementSymbol rowsUpdated = new ElementSymbol(ProcedureReservedWords.VARIABLES+Symbol.SEPARATOR+"ROWS_UPDATED"); //$NON-NLS-1$ DeclareStatement ds = new DeclareStatement(rowsUpdated, DataTypeManager.DefaultDataTypes.INTEGER, new Constant(0)); parent.addStatement(ds); parent.addStatement(new CommandStatement(insert)); Query q = new Query(); q.setSelect(new Select()); q.setFrom(new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("#changes"))))); //$NON-NLS-1$ LoopStatement ls = new LoopStatement(b, q, varGroup.getName()); parent.addStatement(ls); AssignmentStatement as = new AssignmentStatement(); rowsUpdated.setType(DataTypeManager.DefaultDataClasses.INTEGER); as.setVariable(rowsUpdated); as.setExpression(new Function("+", new Expression[] {rowsUpdated, new Constant(1)})); //$NON-NLS-1$ b.addStatement(as); Query returnQuery = new Query(); returnQuery.setSelect(new Select(Arrays.asList(rowsUpdated.clone()))); parent.addStatement(new CommandStatement(returnQuery)); cupc.setBlock(parent); cupc.setVirtualGroup(group);