@Override public Object clone() { SetClauseList copy = new SetClauseList(); for (SetClause clause : this.setClauses) { copy.addClause((SetClause)clause.clone()); } return copy; }
List<org.teiid.language.SetClause> translate(SetClauseList setClauseList) { List<org.teiid.language.SetClause> clauses = new ArrayList<org.teiid.language.SetClause>(setClauseList.getClauses().size()); for (SetClause setClause : setClauseList.getClauses()) { clauses.add(translate(setClause)); } return clauses; }
private boolean canChangePrimaryKey(final SetClauseList update) { if (rowId == null) { Set<ElementSymbol> affectedColumns = new HashSet<ElementSymbol>(update.getClauseMap().keySet()); affectedColumns.retainAll(columns.subList(0, tree.getKeyLength())); if (!affectedColumns.isEmpty()) { return true; } } return false; }
/** * @param procEnv * @param localContext * @throws TeiidComponentException * @throws TeiidComponentException * @throws TeiidProcessingException */ private void updateContextWithUsingValues(ProcedurePlan procEnv, VariableContext localContext) throws TeiidComponentException, TeiidProcessingException { if (dynamicCommand.getUsing() != null && !dynamicCommand.getUsing().isEmpty()) { for (SetClause setClause : dynamicCommand.getUsing().getClauses()) { Object assignment = procEnv.evaluateExpression(setClause.getValue()); LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, new Object[] { this, " The using variable ", //$NON-NLS-1$ setClause.getSymbol(), " has value :", assignment }); //$NON-NLS-1$ localContext.setValue(setClause.getSymbol(), assignment); ElementSymbol es = setClause.getSymbol().clone(); es.getGroupSymbol().setShortName(Reserved.USING); localContext.setValue(es, assignment); } } }
Update update = (Update)container; boolean constraintApplicable = false; for (SetClause clause : update.getChangeList().getClauses()) { if (!elems.contains(clause.getSymbol())) { continue; Collection<ElementSymbol> elems = ElementCollectorVisitor.getElements(filter, true); Update update = (Update)container; if (!Collections.disjoint(elems, update.getChangeList().getClauseMap().keySet())) { validateAndPlanSubqueries(filter, container.getGroup(), planner); update.setConstraint(filter);
TeiidComponentException, QueryResolverException, TeiidProcessingException { UpdateMapping mapping = info.findUpdateMapping(update.getChangeList().getClauseMap().keySet(), false); if (mapping == null) { throw new QueryValidatorException(QueryPlugin.Event.TEIID30376, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30376, update.getChangeList().getClauseMap().keySet())); if (fullMapping != null) { update.setGroup(mapping.getGroup().clone()); for (SetClause clause : update.getChangeList().getClauses()) { clause.setSymbol(symbolMap.get(clause.getSymbol())); query.setOrderBy(null); SymbolMap expressionMapping = SymbolMap.createSymbolMap(update.getGroup(), query.getProjectedSymbols(), metadata); SetClauseList setClauseList = (SetClauseList) update.getChangeList().clone(); GroupSymbol varGroup = getVarGroup(update); ArrayList<Expression> selectSymbols = mapChangeList(setClauseList, symbolMap, varGroup);
crit = (Criteria) crit.clone(); SetClauseList setClauseList = (SetClauseList) update.getChangeList().clone(); GroupSymbol varGroup = getVarGroup(update); ArrayList<Expression> selectSymbols = rewriter.mapChangeList(setClauseList, null, varGroup); Map<ElementSymbol, Expression> map = null; Collection<ElementSymbol> elems = ElementCollectorVisitor.getElements(update.getConstraint(), true); Set<ElementSymbol> existing = setClauseList.getClauseMap().keySet(); for (ElementSymbol es : elems) { if (existing.contains(es)) {
&& !dynamicCommand.getUsing().isEmpty()) { metadataStore.addTempGroup(Reserved.USING, new LinkedList<ElementSymbol>(dynamicCommand.getUsing().getClauseMap().keySet())); GroupSymbol using = new GroupSymbol(Reserved.USING); using.setMetadataID(metadataStore.getTempGroupID(Reserved.USING)); command.addExternalGroupToContext(using); metadataStore.addTempGroup(ProcedureReservedWords.DVARS, new LinkedList<ElementSymbol>(dynamicCommand.getUsing().getClauseMap().keySet())); using = new GroupSymbol(ProcedureReservedWords.DVARS); using.setMetadataID(metadataStore.getTempGroupID(ProcedureReservedWords.DVARS));
if (update.getChangeList().isEmpty()) { return;
/** * Add change to change list - a change is represented by a CompareCriteria * internally but can be added here as an element and an expression * @param id Element to be changed * @param value Expression, often a value, being set */ public void addChange(ElementSymbol id, Expression value) { changeList.addClause(id, value); }
/** * Return a copy of this Update. * @return Deep clone */ public Object clone() { Update copy = new Update(); if(group != null) { copy.setGroup(group.clone()); } copy.setChangeList((SetClauseList)this.changeList.clone()); if(criteria != null) { copy.setCriteria((Criteria) criteria.clone()); } this.copyMetadataState(copy); if (this.constraint != null) { copy.constraint = (Criteria) this.constraint.clone(); } return copy; }
@Test public void testShouldExecuteUpdate() throws Exception { Update update = new Update(); update.setGroup(new GroupSymbol("test")); //$NON-NLS-1$ update.addChange(new ElementSymbol("e1"), new Constant("1")); //$NON-NLS-1$ //$NON-NLS-2$ assertTrue(RelationalNodeUtil.shouldExecute(update, false)); update.setChangeList(new SetClauseList()); assertFalse(RelationalNodeUtil.shouldExecute(update, false)); }
/** * Compare two update commands for equality. Will only evaluate to equal if * they are IDENTICAL: group is equal, changeList contains same compareCriteria, criteria are in * the same exact structure. * @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 Update)) { return false; } Update other = (Update) obj; return EquivalenceUtil.areEqual(getGroup(), other.getGroup()) && getChangeList().equals(other.getChangeList()) && sameOptionAndHint(other) && EquivalenceUtil.areEqual(getCriteria(), other.getCriteria()); }
/** * @param procEnv * @param localContext * @throws TeiidComponentException * @throws TeiidComponentException * @throws TeiidProcessingException */ private void updateContextWithUsingValues(ProcedurePlan procEnv, VariableContext localContext) throws TeiidComponentException, TeiidProcessingException { if (dynamicCommand.getUsing() != null && !dynamicCommand.getUsing().isEmpty()) { for (SetClause setClause : dynamicCommand.getUsing().getClauses()) { Object assignment = procEnv.evaluateExpression(setClause.getValue()); LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, new Object[] { this, " The using variable ", //$NON-NLS-1$ setClause.getSymbol(), " has value :", assignment }); //$NON-NLS-1$ localContext.setValue(setClause.getSymbol(), assignment); ElementSymbol es = setClause.getSymbol().clone(); es.getGroupSymbol().setShortName(Reserved.USING); localContext.setValue(es, assignment); } } }
Update update = (Update)container; boolean constraintApplicable = false; for (SetClause clause : update.getChangeList().getClauses()) { if (!elems.contains(clause.getSymbol())) { continue; Collection<ElementSymbol> elems = ElementCollectorVisitor.getElements(filter, true); Update update = (Update)container; if (!Collections.disjoint(elems, update.getChangeList().getClauseMap().keySet())) { validateAndPlanSubqueries(filter, container.getGroup(), planner); update.setConstraint(filter);
TeiidComponentException, QueryResolverException, TeiidProcessingException { UpdateMapping mapping = info.findUpdateMapping(update.getChangeList().getClauseMap().keySet(), false); if (mapping == null) { throw new QueryValidatorException(QueryPlugin.Event.TEIID30376, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30376, update.getChangeList().getClauseMap().keySet())); if (fullMapping != null) { update.setGroup(mapping.getGroup().clone()); for (SetClause clause : update.getChangeList().getClauses()) { clause.setSymbol(symbolMap.get(clause.getSymbol())); query.setOrderBy(null); SymbolMap expressionMapping = SymbolMap.createSymbolMap(update.getGroup(), query.getProjectedSymbols(), metadata); SetClauseList setClauseList = (SetClauseList) update.getChangeList().clone(); GroupSymbol varGroup = getVarGroup(update); ArrayList<Expression> selectSymbols = mapChangeList(setClauseList, symbolMap, varGroup);
crit = (Criteria) crit.clone(); SetClauseList setClauseList = (SetClauseList) update.getChangeList().clone(); GroupSymbol varGroup = getVarGroup(update); ArrayList<Expression> selectSymbols = rewriter.mapChangeList(setClauseList, null, varGroup); Map<ElementSymbol, Expression> map = null; Collection<ElementSymbol> elems = ElementCollectorVisitor.getElements(update.getConstraint(), true); Set<ElementSymbol> existing = setClauseList.getClauseMap().keySet(); for (ElementSymbol es : elems) { if (existing.contains(es)) {
&& !dynamicCommand.getUsing().isEmpty()) { metadataStore.addTempGroup(Reserved.USING, new LinkedList<ElementSymbol>(dynamicCommand.getUsing().getClauseMap().keySet())); GroupSymbol using = new GroupSymbol(Reserved.USING); using.setMetadataID(metadataStore.getTempGroupID(Reserved.USING)); command.addExternalGroupToContext(using); metadataStore.addTempGroup(ProcedureReservedWords.DVARS, new LinkedList<ElementSymbol>(dynamicCommand.getUsing().getClauseMap().keySet())); using = new GroupSymbol(ProcedureReservedWords.DVARS); using.setMetadataID(metadataStore.getTempGroupID(ProcedureReservedWords.DVARS));
if (update.getChangeList().isEmpty()) { return;
/** * Add change to change list - a change is represented by a CompareCriteria * internally but can be added here as an element and an expression * @param id Element to be changed * @param value Expression, often a value, being set */ public void addChange(ElementSymbol id, Expression value) { changeList.addClause(id, value); }