/** * Deep clone statement to produce a new identical statement. * @return Deep clone */ public Object clone() { AssignmentStatement clone = new AssignmentStatement(this.variable.clone(), (Expression) this.value.clone()); return clone; }
/** * Compare two AssignmentStatements for equality. They will only evaluate to equal if * they are IDENTICAL: variable and its value which could be a command or an expression * objects are equal. * @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 AssignmentStatement)) { return false; } AssignmentStatement other = (AssignmentStatement) obj; return // Compare the variables EquivalenceUtil.areEqual(this.getVariable(), other.getVariable()) && // Compare the values EquivalenceUtil.areEqual(this.getExpression(), other.getExpression()); // Compare the values }
public boolean equals(Object obj) { // Quick same object test if(this == obj) { return true; } // Quick fail tests if(!(obj instanceof ReturnStatement)) { return false; } ReturnStatement other = (ReturnStatement) obj; return super.equals(other); }
/** * @see org.teiid.query.sql.LanguageVisitor#visit(org.teiid.query.sql.proc.AssignmentStatement) * @since 5.0 */ public void visit(AssignmentStatement obj) { obj.setExpression(replaceExpression(obj.getExpression())); }
public void addStatement(Statement statement, boolean exception) { if (statement instanceof AssignmentStatement) { AssignmentStatement stmt = (AssignmentStatement)statement; Command cmd = stmt.getCommand(); if (cmd != null) { internalAddStatement(new CommandStatement(cmd), exception); stmt.setCommand(null); stmt.setExpression(null); if (stmt.getVariable().getShortName().equalsIgnoreCase(ProcedureReservedWords.ROWCOUNT) && stmt.getVariable().getGroupSymbol() != null && stmt.getVariable().getGroupSymbol().getName().equalsIgnoreCase(ProcedureReservedWords.VARIABLES)) { return; } String fullName = ProcedureReservedWords.VARIABLES+Symbol.SEPARATOR+ProcedureReservedWords.ROWCOUNT; stmt.setExpression(new ElementSymbol(fullName)); } } internalAddStatement(statement, exception); }
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 void testGetVariable() { AssignmentStatement s1 = sample1(); assertEquals("Didn't get the same parts ", s1.getVariable(), new ElementSymbol("a")); //$NON-NLS-1$ //$NON-NLS-2$ }
public void testGetExpression() { AssignmentStatement s1 = sample1(); assertEquals("Didn't get the same parts ", s1.getExpression(), new Constant("1")); //$NON-NLS-1$ //$NON-NLS-2$ }
/** * Get hashcode for TableAssignmentStatement. WARNING: This hash code relies on the hash codes of the * statements present in the block. If statements are added to the block or if * statements on the block change the hash code will change. Hash code is only valid * after the block has been completely constructed. * @return Hash code */ public int hashCode() { // This hash code relies on the variable and its value for this statement // and criteria clauses, not on the from, order by, or option clauses int myHash = super.hashCode(); myHash = HashCodeUtil.hashCode(myHash, this.getVariableType()); return myHash; }
public void addStatement(Statement statement, boolean exception) { if (statement instanceof AssignmentStatement) { AssignmentStatement stmt = (AssignmentStatement)statement; Command cmd = stmt.getCommand(); if (cmd != null) { internalAddStatement(new CommandStatement(cmd), exception); stmt.setCommand(null); stmt.setExpression(null); if (stmt.getVariable().getShortName().equalsIgnoreCase(ProcedureReservedWords.ROWCOUNT) && stmt.getVariable().getGroupSymbol() != null && stmt.getVariable().getGroupSymbol().getName().equalsIgnoreCase(ProcedureReservedWords.VARIABLES)) { return; } String fullName = ProcedureReservedWords.VARIABLES+Symbol.SEPARATOR+ProcedureReservedWords.ROWCOUNT; stmt.setExpression(new ElementSymbol(fullName)); } } internalAddStatement(statement, exception); }
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();
/** * @see org.teiid.query.sql.LanguageVisitor#visit(org.teiid.query.sql.proc.AssignmentStatement) * @since 5.0 */ public void visit(AssignmentStatement obj) { obj.setExpression(replaceExpression(obj.getExpression())); }
case Statement.TYPE_ASSIGNMENT: AssignmentStatement assStmt = (AssignmentStatement)statement; ResolverVisitor.resolveLanguageObject(assStmt.getVariable(), null, externalGroups, metadata); if (!metadata.elementSupports(assStmt.getVariable().getMetadataID(), SupportConstants.Element.UPDATE)) { throw new QueryResolverException(QueryPlugin.Event.TEIID30121, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30121, assStmt.getVariable())); assStmt.getVariable().setIsExternalReference(false); break; case Statement.TYPE_RETURN:
public void testGetCommand() throws Exception { AssignmentStatement s2 = sample2(); Query query = (Query) QueryParser.getQueryParser().parseCommand("Select x from y"); //$NON-NLS-1$ assertEquals("Didn't get the same parts ", ((ScalarSubquery)s2.getExpression()).getCommand(), query); //$NON-NLS-1$ }
/** * Get hashcode for TableAssignmentStatement. WARNING: This hash code relies on the hash codes of the * statements present in the block. If statements are added to the block or if * statements on the block change the hash code will change. Hash code is only valid * after the block has been completely constructed. * @return Hash code */ public int hashCode() { // This hash code relies on the variable and its value for this statement // and criteria clauses, not on the from, order by, or option clauses int myHash = super.hashCode(); myHash = HashCodeUtil.hashCode(myHash, this.getVariableType()); return myHash; }
/** * Compare two AssignmentStatements for equality. They will only evaluate to equal if * they are IDENTICAL: variable and its value which could be a command or an expression * objects are equal. * @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 AssignmentStatement)) { return false; } AssignmentStatement other = (AssignmentStatement) obj; return // Compare the variables EquivalenceUtil.areEqual(this.getVariable(), other.getVariable()) && // Compare the values EquivalenceUtil.areEqual(this.getExpression(), other.getExpression()); // Compare the values }
public void addStatement(Statement statement, boolean exception) { if (statement instanceof AssignmentStatement) { AssignmentStatement stmt = (AssignmentStatement)statement; Command cmd = stmt.getCommand(); if (cmd != null) { internalAddStatement(new CommandStatement(cmd), exception); stmt.setCommand(null); stmt.setExpression(null); if (stmt.getVariable().getShortName().equalsIgnoreCase(ProcedureReservedWords.ROWCOUNT) && stmt.getVariable().getGroupSymbol() != null && stmt.getVariable().getGroupSymbol().getName().equalsIgnoreCase(ProcedureReservedWords.VARIABLES)) { return; } String fullName = ProcedureReservedWords.VARIABLES+Symbol.SEPARATOR+ProcedureReservedWords.ROWCOUNT; stmt.setExpression(new ElementSymbol(fullName)); } } internalAddStatement(statement, exception); }
/** * Deep clone statement to produce a new identical statement. * @return Deep clone */ public Object clone() { AssignmentStatement clone = new AssignmentStatement(this.variable.clone(), (Expression) this.value.clone()); return clone; }
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();
/** * @see org.teiid.query.sql.LanguageVisitor#visit(org.teiid.query.sql.proc.AssignmentStatement) * @since 5.0 */ public void visit(AssignmentStatement obj) { obj.setExpression(replaceExpression(obj.getExpression())); }