/** * <p> This method updates the <code>Insert</code> object it receives as an * argument by replacing the virtual groups/elements with their physical * counterparts.</p> * @param obj The Insert object to be updated with physical groups/elements */ public void visit(Insert obj) { List physicalElements = new ArrayList(); // get the GroupSymbol on the insert GroupSymbol virtualGroup = obj.getGroup(); obj.setGroup(getMappedGroup(virtualGroup)); // get all virtual columns present on the Insert and replace them with // physical elements if(obj.getVariables() != null) { Iterator elementIter = obj.getVariables().iterator(); while(elementIter.hasNext()) { ElementSymbol virtualElement = (ElementSymbol) elementIter.next(); physicalElements.add(getMappedElement(virtualElement)); } obj.setVariables(physicalElements); } }
/** * <p> This method updates the <code>Insert</code> object it receives as an * argument by replacing the virtual groups/elements with their physical * counterparts.</p> * @param obj The Insert object to be updated with physical groups/elements */ public void visit(Insert obj) { List physicalElements = new ArrayList(); // get the GroupSymbol on the insert GroupSymbol virtualGroup = obj.getGroup(); obj.setGroup(getMappedGroup(virtualGroup)); // get all virtual columns present on the Insert and replace them with // physical elements if(obj.getVariables() != null) { Iterator elementIter = obj.getVariables().iterator(); while(elementIter.hasNext()) { ElementSymbol virtualElement = (ElementSymbol) elementIter.next(); physicalElements.add(getMappedElement(virtualElement)); } obj.setVariables(physicalElements); } }
/** * <p> This method updates the <code>Insert</code> object it receives as an * argument by replacing the virtual groups/elements with their physical * counterparts.</p> * @param obj The Insert object to be updated with physical groups/elements */ public void visit(Insert obj) { List physicalElements = new ArrayList(); // get the GroupSymbol on the insert GroupSymbol virtualGroup = obj.getGroup(); obj.setGroup(getMappedGroup(virtualGroup)); // get all virtual columns present on the Insert and replace them with // physical elements if(obj.getVariables() != null) { Iterator elementIter = obj.getVariables().iterator(); while(elementIter.hasNext()) { ElementSymbol virtualElement = (ElementSymbol) elementIter.next(); physicalElements.add(getMappedElement(virtualElement)); } obj.setVariables(physicalElements); } }
private Insert correctDatatypes(Insert insert) { boolean needsView = false; for (int i = 0; !needsView && i < insert.getVariables().size(); i++) { Expression ses = insert.getVariables().get(i); if (ses.getType() != insert.getQueryExpression().getProjectedSymbols().get(i).getType()) { needsView = true; } } if (needsView) { try { insert.setQueryExpression(createInlineViewQuery(new GroupSymbol("X"), insert.getQueryExpression(), metadata, insert.getVariables())); //$NON-NLS-1$ } catch (TeiidException err) { throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30371, err); } } return insert; }
private Insert correctDatatypes(Insert insert) { boolean needsView = false; for (int i = 0; !needsView && i < insert.getVariables().size(); i++) { Expression ses = insert.getVariables().get(i); if (ses.getType() != insert.getQueryExpression().getProjectedSymbols().get(i).getType()) { needsView = true; } } if (needsView) { try { insert.setQueryExpression(createInlineViewQuery(new GroupSymbol("X"), insert.getQueryExpression(), metadata, insert.getVariables())); //$NON-NLS-1$ } catch (TeiidException err) { throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30371, err); } } return insert; }
/** * Validate insert/merge entitlements */ protected void validateEntitlements(Insert obj) { List<LanguageObject> insert = new LinkedList<LanguageObject>(); insert.add(obj.getGroup()); insert.addAll(obj.getVariables()); validateEntitlements( insert, DataPolicy.PermissionType.CREATE, Context.INSERT); if (obj.isUpsert()) { validateEntitlements( insert, DataPolicy.PermissionType.UPDATE, Context.MERGE); } }
/** * Validate insert/merge entitlements */ protected void validateEntitlements(Insert obj) { List<LanguageObject> insert = new LinkedList<LanguageObject>(); insert.add(obj.getGroup()); insert.addAll(obj.getVariables()); validateEntitlements( insert, DataPolicy.PermissionType.CREATE, Context.INSERT); if (obj.isUpsert()) { validateEntitlements( insert, DataPolicy.PermissionType.UPDATE, Context.MERGE); } }
/** * Validate insert/merge entitlements */ protected void validateEntitlements(Insert obj) { List<LanguageObject> insert = new LinkedList<LanguageObject>(); insert.add(obj.getGroup()); insert.addAll(obj.getVariables()); validateEntitlements( insert, DataPolicy.PermissionType.CREATE, Context.INSERT); if (obj.isUpsert()) { validateEntitlements( insert, DataPolicy.PermissionType.UPDATE, Context.MERGE); } }
private Insert correctDatatypes(Insert insert) { boolean needsView = false; for (int i = 0; !needsView && i < insert.getVariables().size(); i++) { Expression ses = insert.getVariables().get(i); if (ses.getType() != insert.getQueryExpression().getProjectedSymbols().get(i).getType()) { needsView = true; } } if (needsView) { try { insert.setQueryExpression(createInlineViewQuery(new GroupSymbol("X"), insert.getQueryExpression(), metadata, insert.getVariables())); //$NON-NLS-1$ } catch (TeiidException err) { throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30371, err); } } return insert; }
private void resolveVariables(TempMetadataAdapter metadata, Insert insert, Set<GroupSymbol> groups) throws TeiidComponentException, QueryResolverException { try { resolveList(insert.getVariables(), metadata, null, groups); } catch (QueryResolverException e) { throw new QueryResolverException(QueryPlugin.Event.TEIID30126, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30126, insert.getGroup(), e.getUnresolvedSymbols())); } }
private void resolveVariables(TempMetadataAdapter metadata, Insert insert, Set<GroupSymbol> groups) throws TeiidComponentException, QueryResolverException { try { resolveList(insert.getVariables(), metadata, null, groups); } catch (QueryResolverException e) { throw new QueryResolverException(QueryPlugin.Event.TEIID30126, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30126, insert.getGroup(), e.getUnresolvedSymbols())); } }
private void resolveVariables(TempMetadataAdapter metadata, Insert insert, Set<GroupSymbol> groups) throws TeiidComponentException, QueryResolverException { try { resolveList(insert.getVariables(), metadata, null, groups); } catch (QueryResolverException e) { throw new QueryResolverException(QueryPlugin.Event.TEIID30126, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30126, insert.getGroup(), e.getUnresolvedSymbols())); } }
@Test public void testInsertWithoutColumnsUndefinedTemp() { String sql = "Insert into #temp values (1, 2)"; //$NON-NLS-1$ Insert command = (Insert)helpResolve(sql); assertEquals(2, command.getVariables().size()); }
@Test public void testInsertWithoutColumnsPasses() { String sql = "Insert into pm1.g1 values (1, 2, true, 4)"; //$NON-NLS-1$ helpResolve(sql); Insert command = (Insert)helpResolve(sql); assertEquals(4, command.getVariables().size()); }
/** * Compare two Insert commands for equality. Will only evaluate to equal if * they are IDENTICAL: group is equal, value is equal and variables 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 Insert)) { return false; } Insert other = (Insert) obj; return EquivalenceUtil.areEqual(getGroup(), other.getGroup()) && EquivalenceUtil.areEqual(getValues(), other.getValues()) && EquivalenceUtil.areEqual(getVariables(), other.getVariables()) && sameOptionAndHint(other) && EquivalenceUtil.areEqual(getQueryExpression(), other.getQueryExpression()) && this.upsert == other.upsert; }
/** * Compare two Insert commands for equality. Will only evaluate to equal if * they are IDENTICAL: group is equal, value is equal and variables 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 Insert)) { return false; } Insert other = (Insert) obj; return EquivalenceUtil.areEqual(getGroup(), other.getGroup()) && EquivalenceUtil.areEqual(getValues(), other.getValues()) && EquivalenceUtil.areEqual(getVariables(), other.getVariables()) && sameOptionAndHint(other) && EquivalenceUtil.areEqual(getQueryExpression(), other.getQueryExpression()) && this.upsert == other.upsert; }
public void visit(Insert obj) { preVisitVisitor(obj); visitNode(obj.getGroup()); visitNodes(obj.getVariables()); visitNodes(obj.getValues()); if(deep && obj.getQueryExpression()!=null) { visitNode(obj.getQueryExpression()); } visitNode(obj.getOption()); postVisitVisitor(obj); } public void visit(Create obj) {
public void visit(Insert obj) { preVisitVisitor(obj); visitNode(obj.getGroup()); visitNodes(obj.getVariables()); visitNodes(obj.getValues()); if(deep && obj.getQueryExpression()!=null) { visitNode(obj.getQueryExpression()); } visitNode(obj.getOption()); postVisitVisitor(obj); } public void visit(Create obj) {
public void visit(Insert obj) { preVisitVisitor(obj); visitNode(obj.getGroup()); visitNodes(obj.getVariables()); visitNodes(obj.getValues()); if(deep && obj.getQueryExpression()!=null) { visitNode(obj.getQueryExpression()); } visitNode(obj.getOption()); postVisitVisitor(obj); } public void visit(Create obj) {
/** * Return a deep copy of this Insert. * @return Deep copy of Insert */ public Object clone() { GroupSymbol copyGroup = null; if(group != null) { copyGroup = group.clone(); } List<ElementSymbol> copyVars = LanguageObject.Util.deepClone(getVariables(), ElementSymbol.class); List<Expression> copyVals = null; if ( getValues() != null) { copyVals = LanguageObject.Util.deepClone(getValues(), Expression.class); } Insert copy = new Insert(copyGroup, copyVars, copyVals); if (this.queryExpression != null) { copy.setQueryExpression((QueryCommand)this.queryExpression.clone()); } this.copyMetadataState(copy); if (this.constraint != null) { copy.constraint = (Criteria) this.constraint.clone(); } copy.upsert = this.upsert; return copy; }