public static final CreateProcedureCommand sample3() { return new CreateProcedureCommand(TestBlock.sample1()); }
public static final CreateProcedureCommand sample1() { return new CreateProcedureCommand(TestBlock.sample1()); }
public static final CreateProcedureCommand sample2() { return new CreateProcedureCommand(TestBlock.sample2()); }
/** * Test cloning obj with mostly null state, test for NPE */ public void testCloneMethod3() { CreateProcedureCommand s1 = new CreateProcedureCommand(); CreateProcedureCommand s2 = (CreateProcedureCommand)s1.clone(); UnitTestUtil.helpTestEquivalence(0, s1, s2); }
final public CreateProcedureCommand createProcedure(ParseInfo info) throws ParseException { CreateProcedureCommand procCmd = new CreateProcedureCommand(); Statement stmt = null; jj_consume_token(CREATE); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case VIRTUAL: jj_consume_token(VIRTUAL); break; default: jj_la1[53] = jj_gen; ; } jj_consume_token(PROCEDURE); stmt = statement(info); procCmd.setBlock(asBlock(stmt)); {if (true) return procCmd;} throw new Error("Missing return statement in function"); }
final public CreateProcedureCommand createProcedure(ParseInfo info) throws ParseException { CreateProcedureCommand procCmd = new CreateProcedureCommand(); Statement stmt = null; jj_consume_token(CREATE); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case VIRTUAL: jj_consume_token(VIRTUAL); break; default: jj_la1[54] = jj_gen; ; } jj_consume_token(PROCEDURE); stmt = statement(info); procCmd.setBlock(asBlock(stmt)); {if (true) return procCmd;} throw new Error("Missing return statement in function"); }
final public CreateProcedureCommand createProcedure(ParseInfo info) throws ParseException { CreateProcedureCommand procCmd = new CreateProcedureCommand(); Statement stmt = null; jj_consume_token(CREATE); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case VIRTUAL: jj_consume_token(VIRTUAL); break; default: jj_la1[53] = jj_gen; ; } jj_consume_token(PROCEDURE); stmt = statement(info); procCmd.setBlock(asBlock(stmt)); {if (true) return procCmd;} throw new Error("Missing return statement in function"); }
final public CreateProcedureCommand procedureBodyCommand(ParseInfo info) throws ParseException { CreateProcedureCommand procCmd = new CreateProcedureCommand(); Statement stmt = null; if (jj_2_12(2)) { jj_consume_token(CREATE); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case VIRTUAL: jj_consume_token(VIRTUAL); break; default: jj_la1[55] = jj_gen; ; } jj_consume_token(PROCEDURE); } else { ; } stmt = statement(info); procCmd.setBlock(asBlock(stmt)); {if (true) return procCmd;} throw new Error("Missing return statement in function"); }
final public CreateProcedureCommand procedureBodyCommand(ParseInfo info) throws ParseException { CreateProcedureCommand procCmd = new CreateProcedureCommand(); Statement stmt = null; if (jj_2_11(2)) { jj_consume_token(CREATE); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case VIRTUAL: jj_consume_token(VIRTUAL); break; default: jj_la1[54] = jj_gen; ; } jj_consume_token(PROCEDURE); } else { ; } stmt = statement(info); procCmd.setBlock(asBlock(stmt)); {if (true) return procCmd;} throw new Error("Missing return statement in function"); }
final public CreateProcedureCommand procedureBodyCommand(ParseInfo info) throws ParseException { CreateProcedureCommand procCmd = new CreateProcedureCommand(); Statement stmt = null; if (jj_2_11(2)) { jj_consume_token(CREATE); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case VIRTUAL: jj_consume_token(VIRTUAL); break; default: jj_la1[54] = jj_gen; ; } jj_consume_token(PROCEDURE); } else { ; } stmt = statement(info); procCmd.setBlock(asBlock(stmt)); {if (true) return procCmd;} throw new Error("Missing return statement in function"); }
/** * Deep clone statement to produce a new identical statement. * @return Deep clone */ public Object clone() { CreateProcedureCommand copy = new CreateProcedureCommand(); //Clone this class state if (this.block != null) { copy.setBlock(this.block.clone()); } if (this.projectedSymbols != null) { copy.projectedSymbols = LanguageObject.Util.deepClone(this.projectedSymbols, Expression.class); } if (this.resultSetColumns != null) { copy.resultSetColumns = LanguageObject.Util.deepClone(this.resultSetColumns, Expression.class); } if (this.virtualGroup != null) { copy.virtualGroup = this.virtualGroup.clone(); } if (this.returnVariable != null) { copy.returnVariable = this.returnVariable; } copy.updateType = this.updateType; this.copyMetadataState(copy); return copy; }
/** * Deep clone statement to produce a new identical statement. * @return Deep clone */ public Object clone() { CreateProcedureCommand copy = new CreateProcedureCommand(); //Clone this class state if (this.block != null) { copy.setBlock(this.block.clone()); } if (this.projectedSymbols != null) { copy.projectedSymbols = LanguageObject.Util.deepClone(this.projectedSymbols, Expression.class); } if (this.resultSetColumns != null) { copy.resultSetColumns = LanguageObject.Util.deepClone(this.resultSetColumns, Expression.class); } if (this.virtualGroup != null) { copy.virtualGroup = this.virtualGroup.clone(); } if (this.returnVariable != null) { copy.returnVariable = this.returnVariable; } copy.updateType = this.updateType; this.copyMetadataState(copy); return copy; }
/** * @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command, TempMetadataAdapter, boolean) */ public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals) throws QueryMetadataException, QueryResolverException, TeiidComponentException { //by creating a new group context here it means that variables will resolve with a higher precedence than input/changing GroupContext externalGroups = command.getExternalGroupContexts(); List<ElementSymbol> symbols = new LinkedList<ElementSymbol>(); String countVar = ProcedureReservedWords.VARIABLES + Symbol.SEPARATOR + ProcedureReservedWords.ROWCOUNT; ElementSymbol updateCount = new ElementSymbol(countVar); updateCount.setType(DataTypeManager.DefaultDataClasses.INTEGER); symbols.add(updateCount); ProcedureContainerResolver.addScalarGroup(ProcedureReservedWords.VARIABLES, metadata.getMetadataStore(), externalGroups, symbols); if (command instanceof TriggerAction) { TriggerAction ta = (TriggerAction)command; CreateProcedureCommand cmd = new CreateProcedureCommand(ta.getBlock()); cmd.setVirtualGroup(ta.getView()); //TODO: this is not generally correct - we should update the api to set the appropriate type cmd.setUpdateType(Command.TYPE_INSERT); resolveBlock(cmd, ta.getBlock(), ta.getExternalGroupContexts(), metadata); return; } CreateProcedureCommand procCommand = (CreateProcedureCommand) command; resolveBlock(procCommand, procCommand.getBlock(), externalGroups, metadata); }
/** * @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command, TempMetadataAdapter, boolean) */ public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals) throws QueryMetadataException, QueryResolverException, TeiidComponentException { //by creating a new group context here it means that variables will resolve with a higher precedence than input/changing GroupContext externalGroups = command.getExternalGroupContexts(); List<ElementSymbol> symbols = new LinkedList<ElementSymbol>(); String countVar = ProcedureReservedWords.VARIABLES + Symbol.SEPARATOR + ProcedureReservedWords.ROWCOUNT; ElementSymbol updateCount = new ElementSymbol(countVar); updateCount.setType(DataTypeManager.DefaultDataClasses.INTEGER); symbols.add(updateCount); ProcedureContainerResolver.addScalarGroup(ProcedureReservedWords.VARIABLES, metadata.getMetadataStore(), externalGroups, symbols); if (command instanceof TriggerAction) { TriggerAction ta = (TriggerAction)command; CreateProcedureCommand cmd = new CreateProcedureCommand(ta.getBlock()); cmd.setVirtualGroup(ta.getView()); //TODO: this is not generally correct - we should update the api to set the appropriate type cmd.setUpdateType(Command.TYPE_INSERT); resolveBlock(cmd, ta.getBlock(), ta.getExternalGroupContexts(), metadata); return; } CreateProcedureCommand procCommand = (CreateProcedureCommand) command; resolveBlock(procCommand, procCommand.getBlock(), externalGroups, metadata); }
/** * @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command, TempMetadataAdapter, boolean) */ public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals) throws QueryMetadataException, QueryResolverException, TeiidComponentException { //by creating a new group context here it means that variables will resolve with a higher precedence than input/changing GroupContext externalGroups = command.getExternalGroupContexts(); List<ElementSymbol> symbols = new LinkedList<ElementSymbol>(); String countVar = ProcedureReservedWords.VARIABLES + Symbol.SEPARATOR + ProcedureReservedWords.ROWCOUNT; ElementSymbol updateCount = new ElementSymbol(countVar); updateCount.setType(DataTypeManager.DefaultDataClasses.INTEGER); symbols.add(updateCount); ProcedureContainerResolver.addScalarGroup(ProcedureReservedWords.VARIABLES, metadata.getMetadataStore(), externalGroups, symbols); if (command instanceof TriggerAction) { TriggerAction ta = (TriggerAction)command; CreateProcedureCommand cmd = new CreateProcedureCommand(ta.getBlock()); cmd.setVirtualGroup(ta.getView()); //TODO: this is not generally correct - we should update the api to set the appropriate type cmd.setUpdateType(Command.TYPE_INSERT); resolveBlock(cmd, ta.getBlock(), ta.getExternalGroupContexts(), metadata); return; } CreateProcedureCommand procCommand = (CreateProcedureCommand) command; resolveBlock(procCommand, procCommand.getBlock(), externalGroups, metadata); }
@Test public void testCacheProc() { String sql = "/*+ cache */ CREATE VIRTUAL PROCEDURE BEGIN END"; //$NON-NLS-1$ CreateProcedureCommand command = new CreateProcedureCommand(new Block()); command.setCacheHint(new CacheHint()); TestParser.helpTest(sql, "/*+ cache */ BEGIN\nEND", command); //$NON-NLS-1$ }
@Test public void testCreateUpdateProcedure1() { Delete d1 = new Delete(); d1.setGroup(new GroupSymbol("g")); //$NON-NLS-1$ CommandStatement cmdStmt = new CommandStatement(d1); 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.addStatement(cmdStmt); b.addStatement(assigStmt); b.addStatement(errStmt); CreateProcedureCommand cup = new CreateProcedureCommand(b); helpTest(cup, "BEGIN\nDELETE FROM g;\na = 1;\nRAISE 'My Error';\nEND"); //$NON-NLS-1$ }
@Test public void testCreateUpdateProcedure3() { Delete d1 = new Delete(); d1.setGroup(new GroupSymbol("g")); //$NON-NLS-1$ CommandStatement cmdStmt = new CommandStatement(d1); 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.addStatement(cmdStmt); b.addStatement(assigStmt); b.addStatement(errStmt); CreateProcedureCommand cup = new CreateProcedureCommand(b); helpTest(cup, "BEGIN\nDELETE FROM g;\na = 1;\nRAISE 'My Error';\nEND"); //$NON-NLS-1$ }
@Test public void testCreateUpdateProcedure2() { Delete d1 = new Delete(); d1.setGroup(new GroupSymbol("g")); //$NON-NLS-1$ CommandStatement cmdStmt = new CommandStatement(d1); 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.addStatement(cmdStmt); b.addStatement(assigStmt); b.addStatement(errStmt); CreateProcedureCommand cup = new CreateProcedureCommand(b); helpTest(cup, "BEGIN\nDELETE FROM g;\na = 1;\nRAISE 'My Error';\nEND"); //$NON-NLS-1$ }
@Test public void testIfElseWithoutBeginEnd() { String sql = "CREATE VIRTUAL PROCEDURE BEGIN IF (x > 1) select 1; IF (x > 1) select 1; ELSE select 1; END"; //$NON-NLS-1$ String expected = "BEGIN\nIF(x > 1)\nBEGIN\nSELECT 1;\nEND\nIF(x > 1)\nBEGIN\nSELECT 1;\nEND\nELSE\nBEGIN\nSELECT 1;\nEND\nEND"; //$NON-NLS-1$ Query query = new Query(); query.setSelect(new Select(Arrays.asList(new Constant(1)))); //$NON-NLS-1$ CommandStatement commandStmt = new CommandStatement(query); CompareCriteria criteria = new CompareCriteria(new ElementSymbol("x"), CompareCriteria.GT, new Constant(1)); //$NON-NLS-1$ Block block = new Block(); block.addStatement(commandStmt); IfStatement ifStmt = new IfStatement(criteria, block); IfStatement ifStmt1 = (IfStatement)ifStmt.clone(); Block block2 = new Block(); block2.addStatement(commandStmt); ifStmt1.setElseBlock(block2); Block block3 = new Block(); block3.addStatement(ifStmt); block3.addStatement(ifStmt1); CreateProcedureCommand command = new CreateProcedureCommand(block3); helpTest(sql, expected, command); }