Author: shawkins
Date: 2012-09-28 08:02:37 -0400 (Fri, 28 Sep 2012)
New Revision: 4484
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/TriggerActionPlanner.java
trunk/engine/src/test/java/org/teiid/query/processor/TestTriggerActions.java
Log:
TEIID-2222 additional fix for dynamic sql in a trigger action
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/TriggerActionPlanner.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/optimizer/TriggerActionPlanner.java 2012-09-27
19:55:13 UTC (rev 4483)
+++
trunk/engine/src/main/java/org/teiid/query/optimizer/TriggerActionPlanner.java 2012-09-28
12:02:37 UTC (rev 4484)
@@ -51,7 +51,7 @@
import org.teiid.query.sql.proc.TriggerAction;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
-import org.teiid.query.sql.symbol.Symbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.util.CommandContext;
@@ -109,18 +109,22 @@
TriggerAction ta, QueryMetadataInterface metadata,
Map<ElementSymbol, Expression> params)
throws QueryMetadataException, TeiidComponentException {
- QueryCommand query;
- ArrayList<Expression> selectSymbols = new ArrayList<Expression>();
List<ElementSymbol> allSymbols =
ResolverUtil.resolveElementsInGroup(ta.getView(), metadata);
+ GroupSymbol old = new GroupSymbol(SQLConstants.Reserved.OLD);
+ GroupSymbol newGroup = new GroupSymbol(SQLConstants.Reserved.NEW);
for (ElementSymbol elementSymbol : allSymbols) {
- params.put(new ElementSymbol(SQLConstants.Reserved.OLD + Symbol.SEPARATOR +
elementSymbol.getShortName()), elementSymbol);
+ ElementSymbol es = elementSymbol.clone();
+ es.setGroupSymbol(old);
+ params.put(es, elementSymbol);
if (userCommand instanceof Update) {
//default to old
- params.put(new ElementSymbol(SQLConstants.Reserved.NEW + Symbol.SEPARATOR +
elementSymbol.getShortName()), elementSymbol);
+ es = elementSymbol.clone();
+ es.setGroupSymbol(newGroup);
+ params.put(es, elementSymbol);
}
}
- selectSymbols.addAll(LanguageObject.Util.deepClone(allSymbols, ElementSymbol.class));
- query = new Query(new Select(selectSymbols), new From(Arrays.asList(new
UnaryFromClause(ta.getView()))),
((TranslatableProcedureContainer)userCommand).getCriteria(), null, null);
+ ArrayList<Expression> selectSymbols = new
ArrayList<Expression>(LanguageObject.Util.deepClone(allSymbols,
ElementSymbol.class));
+ QueryCommand query = new Query(new Select(selectSymbols), new From(Arrays.asList(new
UnaryFromClause(ta.getView()))),
((TranslatableProcedureContainer)userCommand).getCriteria(), null, null);
return query;
}
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestTriggerActions.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/processor/TestTriggerActions.java 2012-09-27
19:55:13 UTC (rev 4483)
+++
trunk/engine/src/test/java/org/teiid/query/processor/TestTriggerActions.java 2012-09-28
12:02:37 UTC (rev 4484)
@@ -103,6 +103,25 @@
helpProcess(plan, context, dm, expected);
}
+ @Test public void testDynamicUpdate() throws Exception {
+ TransformationMetadata metadata = TestUpdateValidator.example1();
+ TestUpdateValidator.createView("select '1' as x, 2 as y", metadata,
GX);
+ Table t = metadata.getMetadataStore().getSchemas().get(VM1).getTables().get(GX);
+ t.setDeletePlan("");
+ t.setUpdatePlan("FOR EACH ROW BEGIN execute immediate 'update pm1.g1 set e1 =
new.x where e2 = new.y'; END");
+ t.setInsertPlan("");
+
+ String sql = "update gx set x = 1 where y = 2";
+
+ HardcodedDataManager dm = new HardcodedDataManager();
+ dm.addData("UPDATE pm1.g1 SET e1 = '1' WHERE e2 = 2", new List[]
{Arrays.asList(1)});
+ CommandContext context = createCommandContext();
+ BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+ ProcessorPlan plan = TestProcessor.helpGetPlan(TestResolver.helpResolve(sql,
metadata), metadata, new DefaultCapabilitiesFinder(caps), context);
+ List<?>[] expected = new List[] {Arrays.asList(1)};
+ helpProcess(plan, context, dm, expected);
+ }
+
@Test public void testDynamicRecursion() throws Exception {
TransformationMetadata metadata = TestUpdateValidator.example1();
TestUpdateValidator.createView("select 'a' as x, 2 as y", metadata,
GX);
Show replies by date