/** * Deep clone statement to produce a new identical statement. * @return Deep clone */ public Object clone() { if (getExpression() == null) { return new DeclareStatement(this.getVariable().clone(), this.varType); } return new DeclareStatement(this.getVariable().clone(), this.varType, (Expression)getExpression().clone()); }
/** * Deep clone statement to produce a new identical statement. * @return Deep clone */ public Object clone() { if (getValue() == null) { return new DeclareStatement(this.getVariable().clone(), this.varType); } return new DeclareStatement(this.getVariable().clone(), this.varType, (Expression)getValue().clone()); }
/** * Deep clone statement to produce a new identical statement. * @return Deep clone */ public Object clone() { if (getExpression() == null) { return new DeclareStatement(this.getVariable().clone(), this.varType); } return new DeclareStatement(this.getVariable().clone(), this.varType, (Expression)getExpression().clone()); }
@Test public void testStatement() throws Exception { ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$ String type = new String("short"); //$NON-NLS-1$ DeclareStatement declStmt = new DeclareStatement(a, type); Statement stmt = declStmt; helpStmtTest("DECLARE short a;", "DECLARE short a;", //$NON-NLS-1$ //$NON-NLS-2$ stmt); }
public static final DeclareStatement sample1() { return new DeclareStatement(new ElementSymbol("a"), "String"); //$NON-NLS-1$ //$NON-NLS-2$ }
public static final DeclareStatement sample2() { return new DeclareStatement(new ElementSymbol("b"), "Integer"); //$NON-NLS-1$ //$NON-NLS-2$ }
@Test public void testDeclareStatement() throws Exception { ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$ String type = new String("short"); //$NON-NLS-1$ DeclareStatement stmt = new DeclareStatement(a, type); helpStmtTest("DECLARE short a;","DECLARE short a;", stmt); //$NON-NLS-1$ //$NON-NLS-2$ }
@Test public void testBlock() throws Exception { ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$ String type = new String("short"); //$NON-NLS-1$ DeclareStatement declStmt = new DeclareStatement(a, type); Statement stmt = declStmt; Block block = new Block(stmt); helpBlockTest("BEGIN DECLARE short a; END", "BEGIN"+"\n"+"DECLARE short a;"+"\n"+"END", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ block); }
@Test public void testDeclareStatementWithAssignment() throws Exception { ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$ String type = new String("short"); //$NON-NLS-1$ DeclareStatement stmt = new DeclareStatement(a, type, new Constant(null)); helpStmtTest("DECLARE short a = null;","DECLARE short a = null;", stmt); //$NON-NLS-1$ //$NON-NLS-2$ }
{if (true) return new DeclareStatement(variableID, type.type, (Expression)value);} {if (true) return new DeclareStatement(variableID, type.type, new ScalarSubquery((QueryCommand)value));} {if (true) return new DeclareStatement(variableID, type.type, (Command)value);} throw new Error("Missing return statement in function");
{if (true) return new DeclareStatement(variableID, type.type, (Expression)value);} {if (true) return new DeclareStatement(variableID, type.type, new ScalarSubquery((QueryCommand)value));} {if (true) return new DeclareStatement(variableID, type.type, (Command)value);} throw new Error("Missing return statement in function");
@Test public void testDeclareStatement() { DeclareStatement dclStmt = new DeclareStatement(new ElementSymbol("a"), "String"); //$NON-NLS-1$ //$NON-NLS-2$ helpTest(dclStmt, "DECLARE String a;"); //$NON-NLS-1$ }
@Test public void testDeclareStatementWithAssignment1() throws Exception { ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$ String type = new String("string"); //$NON-NLS-1$ DeclareStatement stmt = new DeclareStatement(a, type, new ScalarSubquery(sampleQuery())); helpStmtTest("DECLARE string a = SELECT a1 FROM g WHERE a2 = 5;","DECLARE string a = (SELECT a1 FROM g WHERE a2 = 5);", stmt); //$NON-NLS-1$ //$NON-NLS-2$ }
@Test public void testIfStatement() throws Exception { ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$ String shortType = new String("short"); //$NON-NLS-1$ Statement ifStmt = new DeclareStatement(a, shortType); ElementSymbol b = new ElementSymbol("b"); //$NON-NLS-1$ Statement elseStmt = new DeclareStatement(b, shortType); Block ifBlock = new Block(); ifBlock.addStatement(ifStmt); Block elseBlock = new Block(); elseBlock.addStatement(elseStmt); ElementSymbol c = new ElementSymbol("c"); //$NON-NLS-1$ Criteria crit = new CompareCriteria(c, CompareCriteria.EQ, new Constant(new Integer(5))); IfStatement stmt = new IfStatement(crit, ifBlock, elseBlock); helpStmtTest("IF(c = 5) BEGIN DECLARE short a; END ELSE BEGIN DECLARE short b; END", //$NON-NLS-1$ "IF(c = 5)"+"\n"+ "BEGIN"+"\n"+"DECLARE short a;"+"\n"+"END"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ "ELSE"+"\n"+"BEGIN"+"\n"+"DECLARE short b;"+"\n"+"END", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ stmt); }
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); }
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);
@Test public void testLoopStatement() throws Exception { GroupSymbol g = new GroupSymbol("m.g"); //$NON-NLS-1$ From from = new From(); from.addGroup(g); Select select = new Select(); ElementSymbol c1 = new ElementSymbol("c1", false); //$NON-NLS-1$ select.addSymbol(c1); select.addSymbol(new ElementSymbol("c2", false)); //$NON-NLS-1$ Query query = new Query(); query.setSelect(select); query.setFrom(from); ElementSymbol x = new ElementSymbol("x"); //$NON-NLS-1$ String intType = new String("integer"); //$NON-NLS-1$ Statement dStmt = new DeclareStatement(x, intType); c1 = new ElementSymbol("mycursor.c1", true); //$NON-NLS-1$ Statement assignmentStmt = new AssignmentStatement(x, c1); Block block = new Block(); block.addStatement(dStmt); block.addStatement(assignmentStmt); String cursor = "mycursor"; //$NON-NLS-1$ LoopStatement loopStmt = new LoopStatement(block, query, cursor); helpStmtTest("LOOP ON (SELECT c1, c2 FROM m.g) AS mycursor BEGIN DECLARE integer x; x=mycursor.c1; END", //$NON-NLS-1$ "LOOP ON (SELECT c1, c2 FROM m.g) AS mycursor"+"\n"+ "BEGIN"+"\n"+"DECLARE integer x;"+"\n"+"x = mycursor.c1;" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ +"\n"+"END", loopStmt); //$NON-NLS-1$ //$NON-NLS-2$ }
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);
@Test public void testVirtualProcedure(){ ElementSymbol x = new ElementSymbol("x"); //$NON-NLS-1$ String intType = new String("integer"); //$NON-NLS-1$ Statement dStmt = new DeclareStatement(x, intType);
Statement dStmt = new DeclareStatement(x, intType); c1 = new ElementSymbol("mycursor.c1", true); //$NON-NLS-1$ Statement assignmentStmt = new AssignmentStatement(x, c1);