Author: shawkins
Date: 2009-07-14 16:23:53 -0400 (Tue, 14 Jul 2009)
New Revision: 1128
Added:
trunk/engine/src/main/java/com/metamatrix/query/sql/lang/TranslatableProcedureContainer.java
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/proc/ProcedurePlanner.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java
trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Delete.java
trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Update.java
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CriteriaTranslatorVisitor.java
trunk/engine/src/test/java/com/metamatrix/query/processor/FakeDataManager.java
trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataFactory.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java
Log:
TEIID-718 fix for translate criteria introducing variables from the parent scope. added
the notion of implicit parameters to set the value for references of this type.
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/proc/ProcedurePlanner.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/optimizer/proc/ProcedurePlanner.java 2009-07-14
17:38:11 UTC (rev 1127)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/proc/ProcedurePlanner.java 2009-07-14
20:23:53 UTC (rev 1128)
@@ -55,6 +55,7 @@
import com.metamatrix.query.sql.lang.Into;
import com.metamatrix.query.sql.lang.ProcedureContainer;
import com.metamatrix.query.sql.lang.Query;
+import com.metamatrix.query.sql.lang.TranslatableProcedureContainer;
import com.metamatrix.query.sql.proc.AssignmentStatement;
import com.metamatrix.query.sql.proc.Block;
import com.metamatrix.query.sql.proc.CommandStatement;
@@ -139,6 +140,9 @@
Map params = container.getProcedureParameters();
plan.setParams(params);
plan.setMetadata(metadata);
+ if (container instanceof TranslatableProcedureContainer) {
+
plan.setImplicitParams(((TranslatableProcedureContainer)container).getImplicitParams());
+ }
}
plan.setUpdateProcedure(((CreateUpdateProcedureCommand)procCommand).isUpdateProcedure());
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java 2009-07-14
17:38:11 UTC (rev 1127)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java 2009-07-14
20:23:53 UTC (rev 1128)
@@ -64,6 +64,7 @@
import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
+import com.metamatrix.query.sql.symbol.Reference;
import com.metamatrix.query.sql.util.VariableContext;
import com.metamatrix.query.tempdata.TempTableStore;
import com.metamatrix.query.tempdata.TempTableStoreImpl;
@@ -90,6 +91,7 @@
private List batchRows;
private boolean lastBatch = false;
private Map<ElementSymbol, Expression> params;
+ private Map<ElementSymbol, Reference> implicitParams;
private QueryMetadataInterface metadata;
private Map tupleSourceMap = new HashMap(); // rsName -> TupleSource
@@ -197,20 +199,29 @@
}
public void open() throws MetaMatrixProcessingException, MetaMatrixComponentException
{
- if (this.params != null && !this.evaluatedParams) {
- for (Map.Entry<ElementSymbol, Expression> entry : this.params.entrySet())
{
- ElementSymbol param = entry.getKey();
- Expression expr = entry.getValue();
-
- VariableContext context = getCurrentVariableContext();
- Object value = this.evaluateExpression(expr);
-
- //check constraint
- if (value == null &&
!metadata.elementSupports(param.getMetadataID(), SupportConstants.Element.NULL)) {
- throw new
QueryValidatorException(QueryExecPlugin.Util.getString("ProcedurePlan.nonNullableParam",
expr)); //$NON-NLS-1$
- }
- context.setValue(param, value);
- }
+ if (!this.evaluatedParams) {
+ if (this.params != null) {
+ for (Map.Entry<ElementSymbol, Expression> entry : this.params.entrySet())
{
+ ElementSymbol param = entry.getKey();
+ Expression expr = entry.getValue();
+
+ VariableContext context = getCurrentVariableContext();
+ Object value = this.evaluateExpression(expr);
+
+ //check constraint
+ if (value == null &&
!metadata.elementSupports(param.getMetadataID(), SupportConstants.Element.NULL)) {
+ throw new
QueryValidatorException(QueryExecPlugin.Util.getString("ProcedurePlan.nonNullableParam",
expr)); //$NON-NLS-1$
+ }
+ context.setValue(param, value);
+ }
+ }
+ if (this.implicitParams != null) {
+ for (Map.Entry<ElementSymbol, Reference> entry :
this.implicitParams.entrySet()) {
+ VariableContext context = getCurrentVariableContext();
+ Object value = this.evaluateExpression(entry.getValue());
+ context.setValue(entry.getKey(), value);
+ }
+ }
}
this.evaluatedParams = true;
}
@@ -362,6 +373,7 @@
plan.setUpdateProcedure(this.isUpdateProcedure());
plan.setOutputElements(this.getOutputElements());
plan.setParams(params);
+ plan.setImplicitParams(implicitParams);
plan.setMetadata(metadata);
return plan;
}
@@ -423,6 +435,10 @@
public void setParams( Map<ElementSymbol, Expression> params ) {
this.params = params;
}
+
+ public void setImplicitParams(Map<ElementSymbol, Reference> implicitParams) {
+ this.implicitParams = implicitParams;
+ }
private void createVariableContext() {
this.currentVarContext = new VariableContext(true);
Modified: trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java 2009-07-14
17:38:11 UTC (rev 1127)
+++ trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java 2009-07-14
20:23:53 UTC (rev 1128)
@@ -108,6 +108,7 @@
import com.metamatrix.query.sql.lang.SubqueryContainer;
import com.metamatrix.query.sql.lang.SubqueryFromClause;
import com.metamatrix.query.sql.lang.SubquerySetCriteria;
+import com.metamatrix.query.sql.lang.TranslatableProcedureContainer;
import com.metamatrix.query.sql.lang.UnaryFromClause;
import com.metamatrix.query.sql.lang.Update;
import com.metamatrix.query.sql.navigator.PostOrderNavigator;
@@ -610,22 +611,12 @@
// get the user's command from the procedure
Command userCmd = procCommand.getUserCommand();
- // check if there is a criteria on user's command, else return
- // a false criteria
- int cmdType = userCmd.getType();
-
- Criteria userCriteria = null;
- switch(cmdType) {
- case Command.TYPE_DELETE:
- userCriteria = ((Delete)userCmd).getCriteria();
- break;
- case Command.TYPE_UPDATE:
- userCriteria = ((Update)userCmd).getCriteria();
- break;
- default:
- return FALSE_CRITERIA;
+ if (!(userCmd instanceof TranslatableProcedureContainer)) {
+ return FALSE_CRITERIA;
}
+ Criteria userCriteria = ((TranslatableProcedureContainer)userCmd).getCriteria();
+
if(userCriteria == null) {
return FALSE_CRITERIA;
}
@@ -660,7 +651,8 @@
// translated criteria
translatedCriteria = translateVisitor.getTranslatedCriteria();
-
+ ((TranslatableProcedureContainer)userCmd).addImplicitParameters(translateVisitor.getImplicitParams());
+
translatedCriteria = rewriteCriteria(translatedCriteria, null, context, metadata);
// apply any implicit conversions
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Delete.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Delete.java 2009-07-14
17:38:11 UTC (rev 1127)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Delete.java 2009-07-14
20:23:53 UTC (rev 1128)
@@ -37,7 +37,7 @@
* "DELETE FROM <group> [WHERE <criteria>]".
* Implements Command interface.
*/
-public class Delete extends ProcedureContainer {
+public class Delete extends TranslatableProcedureContainer {
/** Identifies the group to delete data from. */
private GroupSymbol group;
Added:
trunk/engine/src/main/java/com/metamatrix/query/sql/lang/TranslatableProcedureContainer.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/sql/lang/TranslatableProcedureContainer.java
(rev 0)
+++
trunk/engine/src/main/java/com/metamatrix/query/sql/lang/TranslatableProcedureContainer.java 2009-07-14
20:23:53 UTC (rev 1128)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.query.sql.lang;
+
+import java.util.Map;
+
+import com.metamatrix.query.sql.symbol.ElementSymbol;
+import com.metamatrix.query.sql.symbol.Reference;
+
+public abstract class TranslatableProcedureContainer extends ProcedureContainer {
+
+ private Map<ElementSymbol, Reference> implicitParams;
+
+ public void addImplicitParameters(Map<ElementSymbol, Reference> parameters) {
+ if (parameters == null) {
+ return;
+ }
+ if (implicitParams == null) {
+ this.implicitParams = parameters;
+ }
+ this.implicitParams.putAll(parameters);
+ }
+
+ /**
+ * Get the implicit parameters (if any) created by translate criteria
+ * @return
+ */
+ public Map<ElementSymbol, Reference> getImplicitParams() {
+ return implicitParams;
+ }
+
+ public abstract Criteria getCriteria();
+}
Property changes on:
trunk/engine/src/main/java/com/metamatrix/query/sql/lang/TranslatableProcedureContainer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Update.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Update.java 2009-07-14
17:38:11 UTC (rev 1127)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Update.java 2009-07-14
20:23:53 UTC (rev 1128)
@@ -41,9 +41,9 @@
* Represents a SQL Update statement of the form:
* "UPDATE <group> SET <element> = <expression>, ... [WHERE
<criteria>]".
*/
-public class Update extends ProcedureContainer {
+public class Update extends TranslatableProcedureContainer {
- /** Identifies the group to be udpdated. */
+ /** Identifies the group to be updated. */
private GroupSymbol group;
private SetClauseList changeList = new SetClauseList();
Modified:
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CriteriaTranslatorVisitor.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CriteriaTranslatorVisitor.java 2009-07-14
17:38:11 UTC (rev 1127)
+++
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CriteriaTranslatorVisitor.java 2009-07-14
20:23:53 UTC (rev 1128)
@@ -55,13 +55,13 @@
// criteria selector specified on the TranslateCriteria obj
private CriteriaSelector selector;
- // traslation in for of CompareCriteria objs on the TranslateCriteria obj
+ // translation in for of CompareCriteria objs on the TranslateCriteria obj
private Collection translations;
// list of translated criteria
private List<Criteria> translatedCriteria = new ArrayList<Criteria>();
- private Map<Reference, Reference> impliedParameters = new HashMap<Reference,
Reference>();
+ private Map<ElementSymbol, Reference> implicitParams = new
HashMap<ElementSymbol, Reference>();
/**
* <p> This constructor initialises the visitor</p>
@@ -71,7 +71,7 @@
}
/**
- * <p> This constructor initialises this object by setting the
symbolMap.</p>
+ * <p> This constructor initializes this object by setting the
symbolMap.</p>
* @param symbolMap A map of virtual elements to their counterparts in transform
* defining the virtual group
*/
@@ -203,7 +203,7 @@
return false;
} else if(selector.hasElements()) {
Iterator selectElmnIter = selector.getElements().iterator();
- Collection critElmnts = ElementCollectorVisitor.getElements(criteria, true);
+ Collection<ElementSymbol> critElmnts =
ElementCollectorVisitor.getElements(criteria, true);
while(selectElmnIter.hasNext()) {
ElementSymbol selectElmnt = (ElementSymbol) selectElmnIter.next();
if(critElmnts.contains(selectElmnt)) {
@@ -221,14 +221,30 @@
Iterator transIter = this.translations.iterator();
while(transIter.hasNext()) {
CompareCriteria compCrit = (CompareCriteria) transIter.next();
- Collection leftElmnts =
ElementCollectorVisitor.getElements(compCrit.getLeftExpression(), true);
+ Collection<ElementSymbol> leftElmnts =
ElementCollectorVisitor.getElements(compCrit.getLeftExpression(), true);
// there is always only one element
- ElementSymbol element = (ElementSymbol)leftElmnts.iterator().next();
+ ElementSymbol element = leftElmnts.iterator().next();
if(obj.equals(element)) {
return compCrit.getRightExpression();
}
}
}
+ /*
+ * Special handling for references in translated criteria.
+ * We need to create a locally valid reference name.
+ */
+ if (obj instanceof Reference) {
+ Reference implicit = (Reference)obj;
+ ElementSymbol key = null;
+ if (implicit.isPositional()) {
+ key = new ElementSymbol("$INPUT." + implicit.getContextSymbol());
//$NON-NLS-1$
+ } else {
+ key = new ElementSymbol("$INPUT." + implicit.getExpression().getName());
//$NON-NLS-1$
+ }
+ key.setType(implicit.getType());
+ this.implicitParams.put(key, implicit);
+ return new Reference(key);
+ }
return super.replaceExpression(obj);
}
@@ -243,11 +259,15 @@
public Criteria getTranslatedCriteria() {
if(translatedCriteria.size() > 0) {
if(translatedCriteria.size() == 1) {
- return (Criteria) translatedCriteria.get(0);
+ return translatedCriteria.get(0);
}
return new CompoundCriteria(CompoundCriteria.AND, translatedCriteria);
}
return null;
}
-
+
+ public Map<ElementSymbol, Reference> getImplicitParams() {
+ return implicitParams;
+ }
+
}
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/FakeDataManager.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/processor/FakeDataManager.java 2009-07-14
17:38:11 UTC (rev 1127)
+++
trunk/engine/src/test/java/com/metamatrix/query/processor/FakeDataManager.java 2009-07-14
20:23:53 UTC (rev 1128)
@@ -42,6 +42,7 @@
import com.metamatrix.query.sql.lang.ProcedureContainer;
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.SetQuery;
+import com.metamatrix.query.sql.lang.TranslatableProcedureContainer;
import com.metamatrix.query.sql.lang.Update;
import com.metamatrix.query.sql.symbol.AliasSymbol;
import com.metamatrix.query.sql.symbol.ElementSymbol;
@@ -145,7 +146,7 @@
* either came from a BatchedUpdateCommand or a signle
* command from an Update command.
*/
- List<Update> updateCommands = new ArrayList<Update>();
+ List<TranslatableProcedureContainer> updateCommands = new
ArrayList<TranslatableProcedureContainer>();
// Apply query criteria to tuples
if(command instanceof Query){
@@ -176,15 +177,15 @@
tuples = new List[filteredTuples.size()];
filteredTuples.toArray(tuples);
}
- } else if ( command instanceof Update ) {
+ } else if ( command instanceof TranslatableProcedureContainer ) {
// add single update command to a list to be executed
- updateCommands.add((Update)command);
+ updateCommands.add((TranslatableProcedureContainer)command);
} else if ( command instanceof BatchedUpdateCommand ) {
if ( ((CommandContainer) command).getContainedCommands() != null &&
((CommandContainer) command).getContainedCommands().size() > 0 )
// add all update commands to a list to be executed
for ( int i = 0; i < ((CommandContainer)
command).getContainedCommands().size(); i++ )
- if ( ((CommandContainer) command).getContainedCommands().get(i) instanceof
Update ) {
- updateCommands.add(((Update) ((CommandContainer)
command).getContainedCommands().get(i)));
+ if ( ((CommandContainer) command).getContainedCommands().get(i) instanceof
TranslatableProcedureContainer ) {
+ updateCommands.add(((TranslatableProcedureContainer) ((CommandContainer)
command).getContainedCommands().get(i)));
}
}
@@ -192,7 +193,7 @@
if ( updateCommands.size() > 0 ) {
List<List<Integer>> filteredTuples = new
ArrayList<List<Integer>>();
for ( int c = 0; c < updateCommands.size(); c++ ) {
- Update update = (Update)updateCommands.get(c);
+ TranslatableProcedureContainer update = updateCommands.get(c);
if ( update.getCriteria() != null ) {
// Build lookupMap from BOTH all the elements and the projected symbols - both
may be needed here
Map<Object, Integer> lookupMap = new HashMap<Object,
Integer>();
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java 2009-07-14
17:38:11 UTC (rev 1127)
+++
trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java 2009-07-14
20:23:53 UTC (rev 1128)
@@ -444,7 +444,7 @@
}
}
- static void sampleData2b(FakeDataManager dataMgr) {
+ public static void sampleData2b(FakeDataManager dataMgr) {
FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
try {
Modified:
trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataFactory.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataFactory.java 2009-07-14
17:38:11 UTC (rev 1127)
+++
trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataFactory.java 2009-07-14
20:23:53 UTC (rev 1128)
@@ -890,7 +890,7 @@
vm1g1.putProperty(FakeMetadataObject.Props.INSERT_PROCEDURE, "CREATE
PROCEDURE BEGIN ROWS_UPDATED = INSERT INTO pm1.g1(e2) values(INPUT.e2); END");
//$NON-NLS-1$
vm1g1.putProperty(FakeMetadataObject.Props.UPDATE_PROCEDURE, "CREATE
PROCEDURE BEGIN ROWS_UPDATED = UPDATE pm1.g1 SET e2 = INPUT.e2; END"); //$NON-NLS-1$
vm1g37.putProperty(FakeMetadataObject.Props.INSERT_PROCEDURE, "CREATE
PROCEDURE BEGIN ROWS_UPDATED = INSERT INTO pm4.g1(e1, e2, e3, e4) values(INPUT.e1,
INPUT.e2, INPUT.e3, INPUT.e4); END"); //$NON-NLS-1$
- vm1g37.putProperty(FakeMetadataObject.Props.DELETE_PROCEDURE, "CREATE
PROCEDURE BEGIN ROWS_UPDATED = DELETE FROM pm1.g1 where translate criteria; END");
//$NON-NLS-1$
+ vm1g37.putProperty(FakeMetadataObject.Props.DELETE_PROCEDURE, "CREATE
PROCEDURE BEGIN ROWS_UPDATED = DELETE FROM pm4.g1 where translate criteria; END");
//$NON-NLS-1$
QueryNode vspqn37 = new QueryNode("vsp37", "CREATE VIRTUAL
PROCEDURE BEGIN DECLARE integer x; VARIABLES.x=5; INSERT INTO vm1.g1(e2)
values(VARIABLES.x); END"); //$NON-NLS-1$ //$NON-NLS-2$
FakeMetadataObject vsp37 = createVirtualProcedure("pm1.vsp37", pm1,
Arrays.asList(new FakeMetadataObject[] { vspp1 }), vspqn37); //$NON-NLS-1$
Modified:
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java 2009-07-14
17:38:11 UTC (rev 1127)
+++
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java 2009-07-14
20:23:53 UTC (rev 1128)
@@ -22,13 +22,14 @@
package org.teiid.dqp.internal.process;
+import static org.junit.Assert.*;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
-import junit.framework.TestCase;
-
+import org.junit.Test;
import org.teiid.dqp.internal.process.TestRequest.FakeApplicationEnvironment;
import com.metamatrix.api.exception.MetaMatrixComponentException;
@@ -54,7 +55,7 @@
import com.metamatrix.query.unittest.FakeMetadataFacade;
import com.metamatrix.query.unittest.FakeMetadataFactory;
-public class TestPreparedStatement extends TestCase{
+public class TestPreparedStatement {
private static final int SESSION_ID = 6;
@@ -75,10 +76,6 @@
}
- public TestPreparedStatement(String name) {
- super(name);
- }
-
static void helpTestProcessing(String preparedSql, List values, List[] expected,
ProcessorDataManager dataManager, QueryMetadataInterface metadata, boolean
callableStatement) throws Exception {
helpTestProcessing(preparedSql, values, expected, dataManager, metadata,
callableStatement, false);
}
@@ -146,7 +143,7 @@
assertEquals(exHitCount, pPlanCache.hitCount);
}
- public void testWhere() throws Exception {
+ @Test public void testWhere() throws Exception {
// Create query
String preparedSql = "SELECT pm1.g1.e1, e2, pm1.g1.e3 as a, e4 as b FROM
pm1.g1 WHERE e2=?"; //$NON-NLS-1$
@@ -163,7 +160,7 @@
helpTestProcessing(preparedSql, values, expected, dataManager,
FakeMetadataFactory.example1Cached(), false);
}
- public void testSessionSpecificFunction() throws Exception {
+ @Test public void testSessionSpecificFunction() throws Exception {
// Create query
String preparedSql = "SELECT user(), e2, pm1.g1.e3 as a, e4 as b FROM pm1.g1
WHERE e2=?"; //$NON-NLS-1$
@@ -180,7 +177,7 @@
helpTestProcessing(preparedSql, values, expected, dataManager,
FakeMetadataFactory.example1Cached(), false, true);
}
- public void testFunctionWithReferencePushDown() throws Exception {
+ @Test public void testFunctionWithReferencePushDown() throws Exception {
// Create query
String preparedSql = "SELECT pm1.g1.e1 FROM pm1.g1, pm1.g2 WHERE pm1.g1.e1 =
pm1.g2.e1 and pm1.g1.e2+2=?"; //$NON-NLS-1$
@@ -203,8 +200,7 @@
FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
- List values = new ArrayList();
- values.add(new Integer(0));
+ List values = Arrays.asList(0);
PreparedStatementRequest plan = helpGetProcessorPlan(preparedSql, values,
capFinder, metadata, new PreparedPlanCache(), SESSION_ID, false, false);
@@ -266,7 +262,7 @@
return serverRequest;
}
- public void testValidateCorrectValues() throws Exception {
+ @Test public void testValidateCorrectValues() throws Exception {
// Create query
String preparedSql = "SELECT pm1.g1.e1, e2, pm1.g1.e3 as a, e4 as b FROM
pm1.g1 WHERE pm1.g1.e1=?"; //$NON-NLS-1$
@@ -278,32 +274,29 @@
}
/** SELECT pm1.g1.e1 FROM pm1.g1 WHERE pm1.g1.e2 IN (SELECT pm1.g2.e2 FROM pm1.g2 WHERE
pm1.g2.e1 = ?)*/
- public void testWithSubquery() throws Exception {
+ @Test public void testWithSubquery() throws Exception {
// Create query
String preparedSql = "SELECT pm1.g1.e1 FROM pm1.g1 WHERE pm1.g1.e2 IN (SELECT
pm1.g2.e2 FROM pm1.g2 WHERE pm1.g2.e1 = ?)"; //$NON-NLS-1$
- List values = new ArrayList();
- values.add("a"); //$NON-NLS-1$
+ List values = Arrays.asList("a"); //$NON-NLS-1$
//Create plan
helpGetProcessorPlan(preparedSql, values, new PreparedPlanCache());
}
/** SELECT pm1.g1.e1 FROM pm1.g1 WHERE pm1.g1.e1 = ? AND pm1.g1.e2 IN (SELECT pm1.g2.e2
FROM pm1.g2 WHERE pm1.g2.e1 = ?) */
- public void testWithSubquery2() throws Exception {
+ @Test public void testWithSubquery2() throws Exception {
// Create query
String preparedSql = "SELECT pm1.g1.e1 FROM pm1.g1 WHERE pm1.g1.e1 = ? AND
pm1.g1.e2 IN (SELECT pm1.g2.e2 FROM pm1.g2 WHERE pm1.g2.e1 = ?)"; //$NON-NLS-1$
- List values = new ArrayList();
- values.add("d"); //$NON-NLS-1$
- values.add("c"); //$NON-NLS-1$
+ List values = Arrays.asList("d", "c"); //$NON-NLS-1$ //$NON-NLS-2$
//Create plan
helpGetProcessorPlan(preparedSql, values, new PreparedPlanCache());
}
/** SELECT X.e1 FROM (SELECT pm1.g2.e1 FROM pm1.g2 WHERE pm1.g2.e1 = ?) as X */
- public void testWithSubquery3() throws Exception {
+ @Test public void testWithSubquery3() throws Exception {
// Create query
String preparedSql = "SELECT X.e1 FROM (SELECT pm1.g2.e1 FROM pm1.g2 WHERE
pm1.g2.e1 = ?) as X"; //$NON-NLS-1$
@@ -315,7 +308,7 @@
helpGetProcessorPlan(preparedSql, values, new PreparedPlanCache());
}
- public void testValidateWrongValues() throws Exception {
+ @Test public void testValidateWrongValues() throws Exception {
// Create query
String preparedSql = "SELECT pm1.g1.e1, e2, pm1.g1.e3 as a, e4 as b FROM pm1.g1
WHERE pm1.g1.e2=?"; //$NON-NLS-1$
TestablePreparedPlanCache prepCache = new TestablePreparedPlanCache();
@@ -359,13 +352,11 @@
}
- public void testResolveParameterValues() throws Exception {
+ @Test public void testResolveParameterValues() throws Exception {
// Create query
String preparedSql = "SELECT pm1.g1.e1, e2, pm1.g1.e3 as a, e4 as b FROM
pm1.g1 WHERE pm1.g1.e2=?"; //$NON-NLS-1$
- List values = new ArrayList();
- //values.add("a");
- values.add("0"); //$NON-NLS-1$
+ List values = Arrays.asList("0"); //$NON-NLS-1$
helpGetProcessorPlan(preparedSql, values, new PreparedPlanCache());
}
@@ -373,12 +364,11 @@
/**
* TODO: there may be other ways of handling this situation in the future
*/
- public void testLimitNoCache() throws Exception {
+ @Test public void testLimitNoCache() throws Exception {
// Create query
String preparedSql = "SELECT pm1.g1.e1, e2, pm1.g1.e3 as a, e4 as b FROM
pm1.g1 WHERE pm1.g1.e2=?"; //$NON-NLS-1$
- List values = new ArrayList();
- values.add("0"); //$NON-NLS-1$
+ List values = Arrays.asList("0"); //$NON-NLS-1$
TestablePreparedPlanCache planCache = new TestablePreparedPlanCache();
@@ -388,5 +378,18 @@
//make sure the plan wasn't reused
assertEquals(0, planCache.hitCount);
}
+
+ @Test public void testUpdateProcedureCriteria() throws Exception {
+ String preparedSql = "delete from vm1.g37 where e1=?"; //$NON-NLS-1$
+
+ List[] expected = new List[] {
+ Arrays.asList(1),
+ };
+
+ List values = Arrays.asList("aa "); //$NON-NLS-1$
+ FakeDataManager dataManager = new FakeDataManager();
+ TestProcessor.sampleData2b(dataManager);
+ helpTestProcessing(preparedSql, values, expected, dataManager,
FakeMetadataFactory.example1Cached(), false, false);
+ }
}