teiid SVN: r3683 - in trunk: engine/src/main/java/org/teiid/query/optimizer and 21 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-11-22 07:55:13 -0500 (Tue, 22 Nov 2011)
New Revision: 3683
Added:
trunk/engine/src/main/java/org/teiid/query/sql/proc/CreateProcedureCommand.java
Removed:
trunk/engine/src/main/java/org/teiid/query/sql/proc/CreateUpdateProcedureCommand.java
Modified:
trunk/build/kits/jboss-container/teiid-releasenotes.html
trunk/engine/src/main/java/org/teiid/query/optimizer/ProcedurePlanner.java
trunk/engine/src/main/java/org/teiid/query/optimizer/QueryOptimizer.java
trunk/engine/src/main/java/org/teiid/query/optimizer/TriggerActionPlanner.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java
trunk/engine/src/main/java/org/teiid/query/processor/proc/ExecDynamicSqlInstruction.java
trunk/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java
trunk/engine/src/main/java/org/teiid/query/resolver/ProcedureContainerResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java
trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java
trunk/engine/src/main/java/org/teiid/query/sql/ProcedureReservedWords.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/AlterProcedure.java
trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
trunk/engine/src/test/java/org/teiid/query/optimizer/proc/TestProcedurePlanner.java
trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
trunk/engine/src/test/java/org/teiid/query/processor/TestInherintlyUpdatableViews.java
trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java
trunk/engine/src/test/java/org/teiid/query/resolver/TestProcedureResolving.java
trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java
trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCreateUpdateProcedureCommand.java
trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java
trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java
Log:
TEIID-1842 completely removing the concept of an update procedure
Modified: trunk/build/kits/jboss-container/teiid-releasenotes.html
===================================================================
--- trunk/build/kits/jboss-container/teiid-releasenotes.html 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/build/kits/jboss-container/teiid-releasenotes.html 2011-11-22 12:55:13 UTC (rev 3683)
@@ -37,7 +37,7 @@
<h4>from 7.6</h4>
<ul>
- <li>TRANSLATE/HAS CRITERIA has been removed. INSTEAD OF trigger actions should be used instead. INPUTS and INPUT are no longer procedure reserved words.
+ <li>TRANSLATE/HAS CRITERIA has been removed. INSTEAD OF trigger actions should be used instead. ROWS_UPDATED, INPUTS, and INPUT are no longer procedure reserved words.
</ul>
<h4>from 7.5</h4>
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/ProcedurePlanner.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/ProcedurePlanner.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/ProcedurePlanner.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -35,31 +35,12 @@
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
import org.teiid.query.processor.ProcessorPlan;
-import org.teiid.query.processor.proc.AssignmentInstruction;
-import org.teiid.query.processor.proc.BranchingInstruction;
-import org.teiid.query.processor.proc.CreateCursorResultSetInstruction;
-import org.teiid.query.processor.proc.ErrorInstruction;
-import org.teiid.query.processor.proc.ExecDynamicSqlInstruction;
-import org.teiid.query.processor.proc.IfInstruction;
-import org.teiid.query.processor.proc.LoopInstruction;
-import org.teiid.query.processor.proc.ProcedurePlan;
-import org.teiid.query.processor.proc.Program;
-import org.teiid.query.processor.proc.ProgramInstruction;
-import org.teiid.query.processor.proc.WhileInstruction;
+import org.teiid.query.processor.proc.*;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.DynamicCommand;
import org.teiid.query.sql.lang.SPParameter;
import org.teiid.query.sql.lang.StoredProcedure;
-import org.teiid.query.sql.proc.AssignmentStatement;
-import org.teiid.query.sql.proc.Block;
-import org.teiid.query.sql.proc.BranchingStatement;
-import org.teiid.query.sql.proc.CommandStatement;
-import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
-import org.teiid.query.sql.proc.IfStatement;
-import org.teiid.query.sql.proc.LoopStatement;
-import org.teiid.query.sql.proc.RaiseErrorStatement;
-import org.teiid.query.sql.proc.Statement;
-import org.teiid.query.sql.proc.WhileStatement;
+import org.teiid.query.sql.proc.*;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.Reference;
@@ -69,7 +50,7 @@
/**
* <p> This prepares an {@link org.teiid.query.processor.proc.ProcedurePlan ProcedurePlan} from
- * a CreateUpdateProcedureCommand {@link org.teiid.query.sql.proc.CreateUpdateProcedureCommand CreateUpdateProcedureCommand}.
+ * a CreateUpdateProcedureCommand {@link org.teiid.query.sql.proc.CreateProcedureCommand CreateUpdateProcedureCommand}.
* </p>
*/
public final class ProcedurePlanner implements CommandPlanner {
@@ -94,7 +75,7 @@
analysisRecord.println("PROCEDURE COMMAND: " + procCommand); //$NON-NLS-1$
}
- CreateUpdateProcedureCommand cupc = Assertion.isInstanceOf(procCommand, CreateUpdateProcedureCommand.class, "Wrong command type"); //$NON-NLS-1$
+ CreateProcedureCommand cupc = Assertion.isInstanceOf(procCommand, CreateProcedureCommand.class, "Wrong command type"); //$NON-NLS-1$
if(debug) {
analysisRecord.println("OPTIMIZING SUB-COMMANDS: "); //$NON-NLS-1$
@@ -117,7 +98,6 @@
// create plan from program and initialized environment
ProcedurePlan plan = new ProcedurePlan(programBlock);
- plan.setUpdateProcedure(cupc.isUpdateProcedure());
plan.setOutputElements(cupc.getProjectedSymbols());
if(debug) {
@@ -142,7 +122,7 @@
* @throws QueryMetadataException if there is an error accessing metadata
* @throws TeiidComponentException if unexpected error occurs
*/
- private Program planBlock(CreateUpdateProcedureCommand parentProcCommand, Block block, QueryMetadataInterface metadata, boolean debug, IDGenerator idGenerator, CapabilitiesFinder capFinder, AnalysisRecord analysisRecord, CommandContext context)
+ private Program planBlock(CreateProcedureCommand parentProcCommand, Block block, QueryMetadataInterface metadata, boolean debug, IDGenerator idGenerator, CapabilitiesFinder capFinder, AnalysisRecord analysisRecord, CommandContext context)
throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
// Generate program and add instructions
@@ -184,7 +164,7 @@
* @throws QueryMetadataException if there is an error accessing metadata
* @throws TeiidComponentException if unexpected error occurs
*/
- private Object planStatement(CreateUpdateProcedureCommand parentProcCommand, Statement statement, QueryMetadataInterface metadata, boolean debug, IDGenerator idGenerator, CapabilitiesFinder capFinder, AnalysisRecord analysisRecord, CommandContext context)
+ private Object planStatement(CreateProcedureCommand parentProcCommand, Statement statement, QueryMetadataInterface metadata, boolean debug, IDGenerator idGenerator, CapabilitiesFinder capFinder, AnalysisRecord analysisRecord, CommandContext context)
throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
int stmtType = statement.getType();
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/QueryOptimizer.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/QueryOptimizer.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/QueryOptimizer.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -53,7 +53,7 @@
import org.teiid.query.sql.lang.Query;
import org.teiid.query.sql.lang.SPParameter;
import org.teiid.query.sql.lang.StoredProcedure;
-import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.proc.CreateProcedureCommand;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.util.CommandContext;
@@ -106,8 +106,9 @@
switch (command.getType()) {
case Command.TYPE_UPDATE_PROCEDURE:
- CreateUpdateProcedureCommand cupc = (CreateUpdateProcedureCommand)command;
- if (cupc.isUpdateProcedure()) {
+ CreateProcedureCommand cupc = (CreateProcedureCommand)command;
+ if (cupc.getUserCommand() == null) {
+ //row update procedure
result = planProcedure(command, metadata, idGenerator, capFinder, analysisRecord, context);
} else {
StoredProcedure c = (StoredProcedure)cupc.getUserCommand();
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/TriggerActionPlanner.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/TriggerActionPlanner.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/TriggerActionPlanner.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -47,7 +47,7 @@
import org.teiid.query.rewriter.QueryRewriter;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.lang.*;
-import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.proc.CreateProcedureCommand;
import org.teiid.query.sql.proc.TriggerAction;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
@@ -99,7 +99,7 @@
ProcessorPlan queryPlan = QueryOptimizer.optimizePlan(query, metadata, idGenerator, capFinder, analysisRecord, context);
result.setQueryPlan(queryPlan);
result.setLookupMap(RelationalNode.createLookupMap(query.getProjectedSymbols()));
- ProcedurePlan rowProcedure = (ProcedurePlan)QueryOptimizer.optimizePlan(new CreateUpdateProcedureCommand(ta.getBlock()), metadata, idGenerator, capFinder, analysisRecord, context);
+ ProcedurePlan rowProcedure = (ProcedurePlan)QueryOptimizer.optimizePlan(new CreateProcedureCommand(ta.getBlock()), metadata, idGenerator, capFinder, analysisRecord, context);
result.setRowProcedure(rowProcedure);
return result;
}
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -73,7 +73,7 @@
import org.teiid.query.sql.LanguageObject.Util;
import org.teiid.query.sql.lang.*;
import org.teiid.query.sql.navigator.PreOrPostOrderNavigator;
-import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.proc.CreateProcedureCommand;
import org.teiid.query.sql.proc.TriggerAction;
import org.teiid.query.sql.symbol.*;
import org.teiid.query.sql.util.SymbolMap;
@@ -548,8 +548,8 @@
}
} else {
c = (Command)c.clone();
- if (c instanceof CreateUpdateProcedureCommand) {
- ((CreateUpdateProcedureCommand)c).setUserCommand(container);
+ if (c instanceof CreateProcedureCommand) {
+ ((CreateProcedureCommand)c).setUserCommand(container);
}
}
if (c != null) {
Modified: trunk/engine/src/main/java/org/teiid/query/processor/proc/ExecDynamicSqlInstruction.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/proc/ExecDynamicSqlInstruction.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/main/java/org/teiid/query/processor/proc/ExecDynamicSqlInstruction.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -60,7 +60,7 @@
import org.teiid.query.sql.lang.Insert;
import org.teiid.query.sql.lang.Query;
import org.teiid.query.sql.lang.SetClause;
-import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.proc.CreateProcedureCommand;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
@@ -94,12 +94,12 @@
private QueryMetadataInterface metadata;
// The parent command
- CreateUpdateProcedureCommand parentProcCommand;
+ CreateProcedureCommand parentProcCommand;
private Program dynamicProgram;
public ExecDynamicSqlInstruction(
- CreateUpdateProcedureCommand parentProcCommand,
+ CreateProcedureCommand parentProcCommand,
DynamicCommand command, QueryMetadataInterface metadata,
IDGenerator idGenerator, CapabilitiesFinder capFinder) {
this.parentProcCommand = parentProcCommand;
Modified: trunk/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -110,19 +110,14 @@
private Map<String, CursorState> cursorStates = new HashMap<String, CursorState>();
- private static ElementSymbol ROWS_UPDATED =
- new ElementSymbol(ProcedureReservedWords.VARIABLES+"."+ProcedureReservedWords.ROWS_UPDATED); //$NON-NLS-1$
-
static ElementSymbol ROWCOUNT =
new ElementSymbol(ProcedureReservedWords.VARIABLES+"."+ProcedureReservedWords.ROWCOUNT); //$NON-NLS-1$
static {
- ROWS_UPDATED.setType(DataTypeManager.DefaultDataClasses.INTEGER);
ROWCOUNT.setType(DataTypeManager.DefaultDataClasses.INTEGER);
}
private VariableContext currentVarContext;
- private boolean isUpdateProcedure = true;
private TupleSource lastTupleSource;
@@ -377,10 +372,6 @@
program.incrementProgramCounter();
}
- if(this.isUpdateProcedure){
- return this.getUpdateCountAsToupleSource();
- }
-
if(lastTupleSource == null){
return CollectionTupleSource.createNullTupleSource();
}
@@ -416,7 +407,6 @@
public ProcessorPlan clone(){
ProcedurePlan plan = new ProcedurePlan((Program)originalProgram.clone());
- plan.setUpdateProcedure(this.isUpdateProcedure());
plan.setOutputElements(this.getOutputElements());
plan.setParams(params);
plan.setOutParams(outParams);
@@ -486,18 +476,9 @@
private void createVariableContext() {
this.currentVarContext = new VariableContext(true);
- this.currentVarContext.setValue(ROWS_UPDATED, 0);
this.currentVarContext.setValue(ROWCOUNT, 0);
}
- private TupleSource getUpdateCountAsToupleSource() {
- Object rowCount = currentVarContext.getValue(ROWS_UPDATED);
- if(rowCount == null) {
- rowCount = 0;
- }
- return CollectionTupleSource.createUpdateCountTupleSource((Integer)rowCount);
- }
-
/**
* <p> Get the current <code>VariavleContext</code> on this environment.
* The VariableContext is updated with variables and their values by
@@ -714,20 +695,6 @@
return context;
}
- /**
- * @return
- */
- public boolean isUpdateProcedure() {
- return isUpdateProcedure;
- }
-
- /**
- * @param b
- */
- public void setUpdateProcedure(boolean b) {
- isUpdateProcedure = b;
- }
-
public List getOutputElements() {
return outputElements;
}
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/ProcedureContainerResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/ProcedureContainerResolver.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/ProcedureContainerResolver.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -49,7 +49,7 @@
import org.teiid.query.sql.lang.GroupContext;
import org.teiid.query.sql.lang.ProcedureContainer;
import org.teiid.query.sql.lang.SPParameter;
-import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.proc.CreateProcedureCommand;
import org.teiid.query.sql.proc.TriggerAction;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.GroupSymbol;
@@ -255,8 +255,8 @@
if (type == Command.TYPE_UPDATE || type == Command.TYPE_DELETE) {
ProcedureContainerResolver.addScalarGroup(SQLConstants.Reserved.OLD, tma.getMetadataStore(), externalGroups, viewElements, false);
}
- } else if (currentCommand instanceof CreateUpdateProcedureCommand) {
- CreateUpdateProcedureCommand cupc = (CreateUpdateProcedureCommand)currentCommand;
+ } else if (currentCommand instanceof CreateProcedureCommand) {
+ CreateProcedureCommand cupc = (CreateProcedureCommand)currentCommand;
cupc.setVirtualGroup(container);
if (type == Command.TYPE_STORED_PROCEDURE) {
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -61,7 +61,7 @@
import org.teiid.query.sql.lang.SubqueryContainer;
import org.teiid.query.sql.lang.UnaryFromClause;
import org.teiid.query.sql.navigator.DeepPostOrderNavigator;
-import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.proc.CreateProcedureCommand;
import org.teiid.query.sql.symbol.AliasSymbol;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
@@ -105,14 +105,12 @@
if (command == null) {
return null;
}
- if (command instanceof CreateUpdateProcedureCommand) {
- CreateUpdateProcedureCommand cupCommand = (CreateUpdateProcedureCommand)command;
+ if (command instanceof CreateProcedureCommand) {
+ CreateProcedureCommand cupCommand = (CreateProcedureCommand)command;
cupCommand.setUserCommand(proc);
//if the subcommand is virtual stored procedure, it must have the same
//projected symbol as its parent.
- if(!cupCommand.isUpdateProcedure()){
- cupCommand.setProjectedSymbols(proc.getProjectedSymbols());
- }
+ cupCommand.setProjectedSymbols(proc.getProjectedSymbols());
}
resolveCommand(command, proc.getGroup(), proc.getType(), metadata.getDesignTimeMetadata());
return command;
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -73,26 +73,17 @@
if (command instanceof TriggerAction) {
TriggerAction ta = (TriggerAction)command;
- resolveBlock(new CreateUpdateProcedureCommand(), ta.getBlock(), ta.getExternalGroupContexts(), metadata);
+ resolveBlock(new CreateProcedureCommand(), ta.getBlock(), ta.getExternalGroupContexts(), metadata);
return;
}
- CreateUpdateProcedureCommand procCommand = (CreateUpdateProcedureCommand) command;
+ CreateProcedureCommand procCommand = (CreateProcedureCommand) command;
//by creating a new group context here it means that variables will resolve with a higher precedence than input/changing
GroupContext externalGroups = command.getExternalGroupContexts();
List<ElementSymbol> symbols = new LinkedList<ElementSymbol>();
- // virtual group elements in HAS and TRANSLATE criteria have to be resolved
- if(procCommand.isUpdateProcedure()){
- //add the default variables
- String countVar = ProcedureReservedWords.VARIABLES + ElementSymbol.SEPARATOR + ProcedureReservedWords.ROWS_UPDATED;
- ElementSymbol updateCount = new ElementSymbol(countVar);
- updateCount.setType(DataTypeManager.DefaultDataClasses.INTEGER);
- symbols.add(updateCount);
- }
-
String countVar = ProcedureReservedWords.VARIABLES + ElementSymbol.SEPARATOR + ProcedureReservedWords.ROWCOUNT;
ElementSymbol updateCount = new ElementSymbol(countVar);
updateCount.setType(DataTypeManager.DefaultDataClasses.INTEGER);
@@ -102,7 +93,7 @@
resolveBlock(procCommand, procCommand.getBlock(), externalGroups, metadata);
}
- public void resolveBlock(CreateUpdateProcedureCommand command, Block block, GroupContext externalGroups,
+ public void resolveBlock(CreateProcedureCommand command, Block block, GroupContext externalGroups,
TempMetadataAdapter metadata)
throws QueryResolverException, QueryMetadataException, TeiidComponentException {
LogManager.logTrace(org.teiid.logging.LogConstants.CTX_QUERY_RESOLVER, new Object[]{"Resolving block", block}); //$NON-NLS-1$
@@ -120,7 +111,7 @@
}
}
- private void resolveStatement(CreateUpdateProcedureCommand command, Statement statement, GroupContext externalGroups, GroupSymbol variables, TempMetadataAdapter metadata)
+ private void resolveStatement(CreateProcedureCommand command, Statement statement, GroupContext externalGroups, GroupSymbol variables, TempMetadataAdapter metadata)
throws QueryResolverException, QueryMetadataException, TeiidComponentException {
LogManager.logTrace(org.teiid.logging.LogConstants.CTX_QUERY_RESOLVER, new Object[]{"Resolving statement", statement}); //$NON-NLS-1$
@@ -172,27 +163,25 @@
if (subCommand instanceof DynamicCommand) {
DynamicCommand dynCommand = (DynamicCommand)subCommand;
- if(dynCommand.getIntoGroup() == null && !command.isUpdateProcedure()
+ if(dynCommand.getIntoGroup() == null
&& !dynCommand.isAsClauseSet() && !command.getProjectedSymbols().isEmpty()) {
dynCommand.setAsColumns(command.getProjectedSymbols());
}
}
- if(!command.isUpdateProcedure()){
- //don't bother using the metadata when it doesn't matter
- if (command.getResultsCommand() != null && command.getResultsCommand().getType() == Command.TYPE_DYNAMIC) {
- DynamicCommand dynamicCommand = (DynamicCommand)command.getResultsCommand();
- if (!dynamicCommand.isAsClauseSet()) {
- dynamicCommand.setAsColumns(Collections.EMPTY_LIST);
- }
+ //don't bother using the metadata when it doesn't matter
+ if (command.getResultsCommand() != null && command.getResultsCommand().getType() == Command.TYPE_DYNAMIC) {
+ DynamicCommand dynamicCommand = (DynamicCommand)command.getResultsCommand();
+ if (!dynamicCommand.isAsClauseSet()) {
+ dynamicCommand.setAsColumns(Collections.EMPTY_LIST);
}
-
- if (subCommand.returnsResultSet()) {
- //this could be the last select statement, set the projected symbol
- //on the virtual procedure command
- command.setResultsCommand(subCommand);
- }
}
+
+ if (subCommand.returnsResultSet()) {
+ //this could be the last select statement, set the projected symbol
+ //on the virtual procedure command
+ command.setResultsCommand(subCommand);
+ }
break;
case Statement.TYPE_ERROR:
Modified: trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -197,7 +197,7 @@
command = rewriteDelete((Delete) command);
break;
case Command.TYPE_UPDATE_PROCEDURE:
- command = rewriteUpdateProcedure((CreateUpdateProcedureCommand) command);
+ command = rewriteUpdateProcedure((CreateProcedureCommand) command);
break;
case Command.TYPE_BATCHED_UPDATE:
List subCommands = ((BatchedUpdateCommand)command).getUpdateCommands();
@@ -218,7 +218,7 @@
return command;
}
- private Command rewriteUpdateProcedure(CreateUpdateProcedureCommand command)
+ private Command rewriteUpdateProcedure(CreateProcedureCommand command)
throws TeiidComponentException, TeiidProcessingException{
Block block = rewriteBlock(command.getBlock());
command.setBlock(block);
@@ -1872,7 +1872,7 @@
return criteria;
}
- public static Expression rewriteExpression(Expression expression, CreateUpdateProcedureCommand procCommand, CommandContext context, QueryMetadataInterface metadata) throws TeiidComponentException, TeiidProcessingException{
+ public static Expression rewriteExpression(Expression expression, CreateProcedureCommand procCommand, CommandContext context, QueryMetadataInterface metadata) throws TeiidComponentException, TeiidProcessingException{
return new QueryRewriter(metadata, context).rewriteExpressionDirect(expression);
}
@@ -2651,15 +2651,23 @@
TeiidComponentException, TeiidProcessingException {
Block b = new Block();
b.addStatement(new CommandStatement(newUpdate));
- CreateUpdateProcedureCommand cupc = new CreateUpdateProcedureCommand();
+ CreateProcedureCommand cupc = new CreateProcedureCommand();
+ cupc.setUpdateProcedure(false);
Block parent = new Block();
+ parent.setAtomic(true);
+ ElementSymbol rowsUpdated = new ElementSymbol(ProcedureReservedWords.VARIABLES+ElementSymbol.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, "X"); //$NON-NLS-1$
parent.addStatement(ls);
AssignmentStatement as = new AssignmentStatement();
- ElementSymbol rowsUpdate = new ElementSymbol(ProcedureReservedWords.VARIABLES+ElementSymbol.SEPARATOR+ProcedureReservedWords.ROWS_UPDATED);
- as.setVariable(rowsUpdate);
- as.setExpression(new Function("+", new Expression[] {rowsUpdate, new Constant(1)})); //$NON-NLS-1$
+ 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);
Modified: trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -70,7 +70,7 @@
import org.teiid.query.sql.proc.Block;
import org.teiid.query.sql.proc.BranchingStatement;
import org.teiid.query.sql.proc.CommandStatement;
-import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.proc.CreateProcedureCommand;
import org.teiid.query.sql.proc.DeclareStatement;
import org.teiid.query.sql.proc.IfStatement;
import org.teiid.query.sql.proc.LoopStatement;
@@ -181,7 +181,7 @@
public void visit(AssignmentStatement obj) {}
public void visit(Block obj) {}
public void visit(CommandStatement obj) {}
- public void visit(CreateUpdateProcedureCommand obj) {}
+ public void visit(CreateProcedureCommand obj) {}
public void visit(DeclareStatement obj) {
visit((AssignmentStatement)obj);
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/ProcedureReservedWords.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/ProcedureReservedWords.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/main/java/org/teiid/query/sql/ProcedureReservedWords.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -33,8 +33,6 @@
*/
public class ProcedureReservedWords {
- public static final String ROWS_UPDATED = "ROWS_UPDATED"; //$NON-NLS-1$
-
public static final String ROWCOUNT = "ROWCOUNT"; //$NON-NLS-1$
public static final String CHANGING = "CHANGING"; //$NON-NLS-1$
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/AlterProcedure.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/AlterProcedure.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/AlterProcedure.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -22,9 +22,9 @@
package org.teiid.query.sql.lang;
import org.teiid.query.sql.LanguageVisitor;
-import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.proc.CreateProcedureCommand;
-public class AlterProcedure extends Alter<CreateUpdateProcedureCommand> {
+public class AlterProcedure extends Alter<CreateProcedureCommand> {
@Override
public void acceptVisitor(LanguageVisitor visitor) {
Modified: trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -74,7 +74,7 @@
import org.teiid.query.sql.proc.Block;
import org.teiid.query.sql.proc.BranchingStatement;
import org.teiid.query.sql.proc.CommandStatement;
-import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.proc.CreateProcedureCommand;
import org.teiid.query.sql.proc.DeclareStatement;
import org.teiid.query.sql.proc.IfStatement;
import org.teiid.query.sql.proc.LoopStatement;
@@ -213,7 +213,7 @@
preVisitVisitor(obj);
postVisitVisitor(obj);
}
- public void visit(CreateUpdateProcedureCommand obj) {
+ public void visit(CreateProcedureCommand obj) {
preVisitVisitor(obj);
visitNode(obj.getBlock());
postVisitVisitor(obj);
Copied: trunk/engine/src/main/java/org/teiid/query/sql/proc/CreateProcedureCommand.java (from rev 3670, trunk/engine/src/main/java/org/teiid/query/sql/proc/CreateUpdateProcedureCommand.java)
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/proc/CreateProcedureCommand.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/query/sql/proc/CreateProcedureCommand.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -0,0 +1,267 @@
+/*
+ * 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 org.teiid.query.sql.proc;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.teiid.core.util.EquivalenceUtil;
+import org.teiid.core.util.HashCodeUtil;
+import org.teiid.query.sql.LanguageVisitor;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.StoredProcedure;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.symbol.SingleElementSymbol;
+import org.teiid.query.sql.visitor.SQLStringVisitor;
+
+
+/**
+ * <p> This class represents a update procedure in the storedprocedure language.
+ * It extends the <code>Command</code> and represents the command for Insert , Update
+ * and Delete procedures.</p>
+ */
+public class CreateProcedureCommand extends Command {
+
+ // top level block for the procedure
+ private Block block;
+
+ // the command the user submitted against the virtual group being updated
+ private Command userCommand;
+
+ //whether it is update procedure or virtual stored procedure, default to update procedure
+ private boolean isUpdateProcedure = true;
+
+ private List projectedSymbols;
+
+ private GroupSymbol virtualGroup;
+
+ //command that returns resultset. For virtual procedure only.
+ private Command resultsCommand;
+ /**
+ * Constructor for CreateUpdateProcedureCommand.
+ */
+ public CreateProcedureCommand() {
+ super();
+ }
+
+ /**
+ * Constructor for CreateUpdateProcedureCommand.
+ * @param block The block on this command
+ * @param type The procedure type
+ */
+ public CreateProcedureCommand(Block block) {
+ this.block = block;
+ }
+
+ /**
+ * Return type of command to make it easier to build switch statements by command type.
+ * @return The type of this command
+ */
+ public int getType() {
+ return Command.TYPE_UPDATE_PROCEDURE;
+ }
+
+ /**
+ * Get the block on this command.
+ * @return The <code>Block</code> on this command
+ */
+ public Block getBlock() {
+ return block;
+ }
+
+ /**
+ * Set the block on this command.
+ * @param block The <code>Block</code> on this command
+ */
+ public void setBlock(Block block) {
+ this.block = block;
+ }
+
+ /**
+ * Set the user's command to which this obj which is the subcommand
+ * @param command The user's command
+ */
+ public void setUserCommand(Command command) {
+ this.userCommand = command;
+ }
+
+ /**
+ * Get the user's command to which this obj which is the subcommand
+ * @return The user's command
+ */
+ public Command getUserCommand() {
+ return this.userCommand;
+ }
+
+ // =========================================================================
+ // P R O C E S S I N G M E T H O D S
+ // =========================================================================
+
+ public void acceptVisitor(LanguageVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ /**
+ * Deep clone statement to produce a new identical statement.
+ * @return Deep clone
+ */
+ public Object clone() {
+ CreateProcedureCommand copy = new CreateProcedureCommand();
+
+ //Clone this class state
+ if (this.block != null) {
+ copy.setBlock(this.block.clone());
+ }
+ if (this.projectedSymbols != null) {
+ copy.setProjectedSymbols(new ArrayList(this.projectedSymbols));
+ }
+ if (this.virtualGroup != null) {
+ copy.virtualGroup = this.virtualGroup.clone();
+ }
+ this.copyMetadataState(copy);
+ return copy;
+ }
+
+ /**
+ * Compare two CreateUpdateProcedureCommand for equality. They will only evaluate to equal if
+ * they are IDENTICAL: the commandTypes are same and the block 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 CreateProcedureCommand)) {
+ return false;
+ }
+
+ CreateProcedureCommand other = (CreateProcedureCommand)obj;
+
+ // Compare the block
+ return sameOptionAndHint(other) && EquivalenceUtil.areEqual(getBlock(), other.getBlock());
+ }
+
+ /**
+ * Get hashcode for CreateUpdateProcedureCommand. WARNING: This hash code relies
+ * on the hash codes of the block and the procedure type of this command. Hash code
+ * is only valid after the command has been completely constructed.
+ * @return Hash code
+ */
+ public int hashCode() {
+ // This hash code relies on the block and the procedure type for this command
+ int myHash = 0;
+ myHash = HashCodeUtil.hashCode(myHash, this.getBlock());
+ return myHash;
+ }
+
+ /**
+ * Returns a string representation of an instance of this class.
+ * @return String representation of object
+ */
+ public String toString() {
+ return SQLStringVisitor.getSQLString(this);
+ }
+
+ // ========================================
+ // Methods inherited from Command
+ // ========================================
+
+ /**
+ * Get the ordered list of all elements returned by this query. These elements
+ * may be ElementSymbols or ExpressionSymbols but in all cases each represents a
+ * single column.
+ * @return Ordered list of SingleElementSymbol
+ */
+ public List getProjectedSymbols(){
+ if(this.projectedSymbols != null){
+ return this.projectedSymbols;
+ }
+ if(!isUpdateProcedure){
+ if(this.resultsCommand == null){
+ //user may have not entered any query yet
+ return Collections.EMPTY_LIST;
+ }
+ List<? extends SingleElementSymbol> symbols = this.resultsCommand.getProjectedSymbols();
+ if (this.resultsCommand instanceof StoredProcedure) {
+ StoredProcedure sp = (StoredProcedure)this.resultsCommand;
+ if (sp.isCallableStatement()) {
+ symbols = sp.getResultSetColumns();
+ }
+ }
+ setProjectedSymbols(symbols);
+ return this.projectedSymbols;
+ }
+ this.projectedSymbols = Command.getUpdateCommandSymbol();
+ return this.projectedSymbols;
+ }
+
+ /**
+ * @param isUpdateProcedure
+ */
+ public void setUpdateProcedure(boolean isUpdateProcedure) {
+ this.isUpdateProcedure = isUpdateProcedure;
+ }
+
+ /**
+ * @param projSymbols
+ */
+ public void setProjectedSymbols(List projSymbols) {
+ projectedSymbols = projSymbols;
+ }
+
+ /**
+ * @return Command
+ */
+ public Command getResultsCommand() {
+ return resultsCommand;
+ }
+
+ /**
+ * @param command
+ */
+ public void setResultsCommand(Command command) {
+ resultsCommand = command;
+ }
+
+ /**
+ * @see org.teiid.query.sql.lang.Command#areResultsCachable()
+ */
+ public boolean areResultsCachable() {
+ return Query.areResultsCachable(getProjectedSymbols());
+ }
+
+ public GroupSymbol getVirtualGroup() {
+ return this.virtualGroup;
+ }
+
+ public void setVirtualGroup(GroupSymbol virtualGroup) {
+ this.virtualGroup = virtualGroup;
+ }
+
+} // END CLASS
Deleted: trunk/engine/src/main/java/org/teiid/query/sql/proc/CreateUpdateProcedureCommand.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/proc/CreateUpdateProcedureCommand.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/main/java/org/teiid/query/sql/proc/CreateUpdateProcedureCommand.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -1,305 +0,0 @@
-/*
- * 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 org.teiid.query.sql.proc;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.teiid.core.util.EquivalenceUtil;
-import org.teiid.core.util.HashCodeUtil;
-import org.teiid.query.sql.LanguageVisitor;
-import org.teiid.query.sql.lang.Command;
-import org.teiid.query.sql.lang.Query;
-import org.teiid.query.sql.lang.StoredProcedure;
-import org.teiid.query.sql.symbol.GroupSymbol;
-import org.teiid.query.sql.symbol.SingleElementSymbol;
-import org.teiid.query.sql.visitor.SQLStringVisitor;
-
-
-/**
- * <p> This class represents a update procedure in the storedprocedure language.
- * It extends the <code>Command</code> and represents the command for Insert , Update
- * and Delete procedures.</p>
- */
-public class CreateUpdateProcedureCommand extends Command {
-
- // top level block for the procedure
- private Block block;
-
- // map between elements on the virtual groups and the elements in the
- // transformation query that define it.
- private Map symbolMap;
-
- // the command the user submitted against the virtual group being updated
- private Command userCommand;
-
- //whether it is update procedure or virtual stored procedure, default to update procedure
- private boolean isUpdateProcedure = true;
-
- private List projectedSymbols;
-
- private GroupSymbol virtualGroup;
-
- //command that returns resultset. For virtual procedure only.
- private Command resultsCommand;
- /**
- * Constructor for CreateUpdateProcedureCommand.
- */
- public CreateUpdateProcedureCommand() {
- super();
- }
-
- /**
- * Constructor for CreateUpdateProcedureCommand.
- * @param block The block on this command
- * @param type The procedure type
- */
- public CreateUpdateProcedureCommand(Block block) {
- this.block = block;
- }
-
- /**
- * Return type of command to make it easier to build switch statements by command type.
- * @return The type of this command
- */
- public int getType() {
- return Command.TYPE_UPDATE_PROCEDURE;
- }
-
- /**
- * Get the block on this command.
- * @return The <code>Block</code> on this command
- */
- public Block getBlock() {
- return block;
- }
-
- /**
- * Set the block on this command.
- * @param block The <code>Block</code> on this command
- */
- public void setBlock(Block block) {
- this.block = block;
- }
-
- /**
- * Set the user's command to which this obj which is the subcommand
- * @param command The user's command
- */
- public void setUserCommand(Command command) {
- this.userCommand = command;
- }
-
- /**
- * Get the user's command to which this obj which is the subcommand
- * @return The user's command
- */
- public Command getUserCommand() {
- return this.userCommand;
- }
-
- /**
- * Set the symbol map between elements on the virtual group being updated and the
- * elements on the transformation query.
- * @param symbolMap Map of virtual group elements -> elements that define those
- */
- public void setSymbolMap(Map symbolMap) {
- this.symbolMap = symbolMap;
- }
-
- /**
- * Get the symbol map between elements on the virtual group being updated and the
- * elements on the transformation query.
- * @return Map of virtual group elements -> elements that define those
- */
- public Map getSymbolMap() {
- return this.symbolMap;
- }
-
- // =========================================================================
- // P R O C E S S I N G M E T H O D S
- // =========================================================================
-
- public void acceptVisitor(LanguageVisitor visitor) {
- visitor.visit(this);
- }
-
- /**
- * Deep clone statement to produce a new identical statement.
- * @return Deep clone
- */
- public Object clone() {
- CreateUpdateProcedureCommand copy = new CreateUpdateProcedureCommand();
-
- //Clone this class state
- if (this.block != null) {
- copy.setBlock(this.block.clone());
- }
- if (this.getSymbolMap() != null) {
- copy.setSymbolMap(new HashMap(this.getSymbolMap()));
- }
- copy.setUpdateProcedure(isUpdateProcedure());
- if (this.projectedSymbols != null) {
- copy.setProjectedSymbols(new ArrayList(this.projectedSymbols));
- }
- if (this.virtualGroup != null) {
- copy.virtualGroup = this.virtualGroup.clone();
- }
- this.copyMetadataState(copy);
- return copy;
- }
-
- /**
- * Compare two CreateUpdateProcedureCommand for equality. They will only evaluate to equal if
- * they are IDENTICAL: the commandTypes are same and the block 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 CreateUpdateProcedureCommand)) {
- return false;
- }
-
- CreateUpdateProcedureCommand other = (CreateUpdateProcedureCommand)obj;
-
- // Compare the block
- return sameOptionAndHint(other) && EquivalenceUtil.areEqual(getBlock(), other.getBlock());
- }
-
- /**
- * Get hashcode for CreateUpdateProcedureCommand. WARNING: This hash code relies
- * on the hash codes of the block and the procedure type of this command. Hash code
- * is only valid after the command has been completely constructed.
- * @return Hash code
- */
- public int hashCode() {
- // This hash code relies on the block and the procedure type for this command
- int myHash = 0;
- myHash = HashCodeUtil.hashCode(myHash, this.getBlock());
- return myHash;
- }
-
- /**
- * Returns a string representation of an instance of this class.
- * @return String representation of object
- */
- public String toString() {
- return SQLStringVisitor.getSQLString(this);
- }
-
- // ========================================
- // Methods inherited from Command
- // ========================================
-
- /**
- * Get the ordered list of all elements returned by this query. These elements
- * may be ElementSymbols or ExpressionSymbols but in all cases each represents a
- * single column.
- * @return Ordered list of SingleElementSymbol
- */
- public List getProjectedSymbols(){
- if(this.projectedSymbols != null){
- return this.projectedSymbols;
- }
- if(!isUpdateProcedure){
- if(this.resultsCommand == null){
- //user may have not entered any query yet
- return Collections.EMPTY_LIST;
- }
- List<? extends SingleElementSymbol> symbols = this.resultsCommand.getProjectedSymbols();
- if (this.resultsCommand instanceof StoredProcedure) {
- StoredProcedure sp = (StoredProcedure)this.resultsCommand;
- if (sp.isCallableStatement()) {
- symbols = sp.getResultSetColumns();
- }
- }
- setProjectedSymbols(symbols);
- return this.projectedSymbols;
- }
- this.projectedSymbols = Command.getUpdateCommandSymbol();
- return this.projectedSymbols;
- }
-
- /**
- * @return
- */
- public boolean isUpdateProcedure() {
- return isUpdateProcedure;
- }
-
- /**
- * @param isUpdateProcedure
- */
- public void setUpdateProcedure(boolean isUpdateProcedure) {
- this.isUpdateProcedure = isUpdateProcedure;
- }
-
- /**
- * @param projSymbols
- */
- public void setProjectedSymbols(List projSymbols) {
- projectedSymbols = projSymbols;
- }
-
- /**
- * @return Command
- */
- public Command getResultsCommand() {
- return resultsCommand;
- }
-
- /**
- * @param command
- */
- public void setResultsCommand(Command command) {
- resultsCommand = command;
- }
-
- /**
- * @see org.teiid.query.sql.lang.Command#areResultsCachable()
- */
- public boolean areResultsCachable() {
- if(isUpdateProcedure()){
- return false;
- }
- return Query.areResultsCachable(getProjectedSymbols());
- }
-
- public GroupSymbol getVirtualGroup() {
- return this.virtualGroup;
- }
-
- public void setVirtualGroup(GroupSymbol virtualGroup) {
- this.virtualGroup = virtualGroup;
- }
-
-} // END CLASS
Modified: trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -39,100 +39,14 @@
import org.teiid.metadata.BaseColumn.NullType;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.LanguageVisitor;
-import org.teiid.query.sql.lang.AlterProcedure;
-import org.teiid.query.sql.lang.AlterTrigger;
-import org.teiid.query.sql.lang.AlterView;
-import org.teiid.query.sql.lang.ArrayTable;
-import org.teiid.query.sql.lang.AtomicCriteria;
-import org.teiid.query.sql.lang.BetweenCriteria;
-import org.teiid.query.sql.lang.CacheHint;
-import org.teiid.query.sql.lang.CompareCriteria;
-import org.teiid.query.sql.lang.CompoundCriteria;
-import org.teiid.query.sql.lang.Create;
-import org.teiid.query.sql.lang.Criteria;
-import org.teiid.query.sql.lang.Delete;
-import org.teiid.query.sql.lang.DependentSetCriteria;
-import org.teiid.query.sql.lang.Drop;
-import org.teiid.query.sql.lang.DynamicCommand;
-import org.teiid.query.sql.lang.ExistsCriteria;
-import org.teiid.query.sql.lang.ExpressionCriteria;
-import org.teiid.query.sql.lang.From;
-import org.teiid.query.sql.lang.FromClause;
-import org.teiid.query.sql.lang.GroupBy;
-import org.teiid.query.sql.lang.Insert;
-import org.teiid.query.sql.lang.Into;
-import org.teiid.query.sql.lang.IsNullCriteria;
-import org.teiid.query.sql.lang.JoinPredicate;
-import org.teiid.query.sql.lang.JoinType;
-import org.teiid.query.sql.lang.Limit;
-import org.teiid.query.sql.lang.MatchCriteria;
-import org.teiid.query.sql.lang.NotCriteria;
-import org.teiid.query.sql.lang.Option;
-import org.teiid.query.sql.lang.OrderBy;
-import org.teiid.query.sql.lang.OrderByItem;
-import org.teiid.query.sql.lang.PredicateCriteria;
-import org.teiid.query.sql.lang.Query;
-import org.teiid.query.sql.lang.QueryCommand;
-import org.teiid.query.sql.lang.SPParameter;
-import org.teiid.query.sql.lang.Select;
-import org.teiid.query.sql.lang.SetClause;
-import org.teiid.query.sql.lang.SetClauseList;
-import org.teiid.query.sql.lang.SetCriteria;
-import org.teiid.query.sql.lang.SetQuery;
-import org.teiid.query.sql.lang.SourceHint;
-import org.teiid.query.sql.lang.StoredProcedure;
-import org.teiid.query.sql.lang.SubqueryCompareCriteria;
-import org.teiid.query.sql.lang.SubqueryFromClause;
-import org.teiid.query.sql.lang.SubquerySetCriteria;
-import org.teiid.query.sql.lang.TextTable;
-import org.teiid.query.sql.lang.UnaryFromClause;
-import org.teiid.query.sql.lang.Update;
-import org.teiid.query.sql.lang.WithQueryCommand;
-import org.teiid.query.sql.lang.XMLTable;
+import org.teiid.query.sql.lang.*;
import org.teiid.query.sql.lang.ExistsCriteria.SubqueryHint;
import org.teiid.query.sql.lang.TableFunctionReference.ProjectedColumn;
import org.teiid.query.sql.lang.TextTable.TextColumn;
import org.teiid.query.sql.lang.XMLTable.XMLColumn;
-import org.teiid.query.sql.proc.AssignmentStatement;
-import org.teiid.query.sql.proc.Block;
-import org.teiid.query.sql.proc.BranchingStatement;
-import org.teiid.query.sql.proc.CommandStatement;
-import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
-import org.teiid.query.sql.proc.DeclareStatement;
-import org.teiid.query.sql.proc.IfStatement;
-import org.teiid.query.sql.proc.LoopStatement;
-import org.teiid.query.sql.proc.RaiseErrorStatement;
-import org.teiid.query.sql.proc.Statement;
-import org.teiid.query.sql.proc.TriggerAction;
-import org.teiid.query.sql.proc.WhileStatement;
+import org.teiid.query.sql.proc.*;
import org.teiid.query.sql.proc.Statement.Labeled;
-import org.teiid.query.sql.symbol.AggregateSymbol;
-import org.teiid.query.sql.symbol.AliasSymbol;
-import org.teiid.query.sql.symbol.CaseExpression;
-import org.teiid.query.sql.symbol.Constant;
-import org.teiid.query.sql.symbol.DerivedColumn;
-import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.query.sql.symbol.Expression;
-import org.teiid.query.sql.symbol.ExpressionSymbol;
-import org.teiid.query.sql.symbol.Function;
-import org.teiid.query.sql.symbol.GroupSymbol;
-import org.teiid.query.sql.symbol.MultipleElementSymbol;
-import org.teiid.query.sql.symbol.QueryString;
-import org.teiid.query.sql.symbol.Reference;
-import org.teiid.query.sql.symbol.ScalarSubquery;
-import org.teiid.query.sql.symbol.SearchedCaseExpression;
-import org.teiid.query.sql.symbol.SelectSymbol;
-import org.teiid.query.sql.symbol.SingleElementSymbol;
-import org.teiid.query.sql.symbol.TextLine;
-import org.teiid.query.sql.symbol.WindowFunction;
-import org.teiid.query.sql.symbol.WindowSpecification;
-import org.teiid.query.sql.symbol.XMLAttributes;
-import org.teiid.query.sql.symbol.XMLElement;
-import org.teiid.query.sql.symbol.XMLForest;
-import org.teiid.query.sql.symbol.XMLNamespaces;
-import org.teiid.query.sql.symbol.XMLParse;
-import org.teiid.query.sql.symbol.XMLQuery;
-import org.teiid.query.sql.symbol.XMLSerialize;
+import org.teiid.query.sql.symbol.*;
import org.teiid.query.sql.symbol.AggregateSymbol.Type;
import org.teiid.query.sql.symbol.XMLNamespaces.NamespaceItem;
import org.teiid.translator.SourceSystemFunctions;
@@ -1459,13 +1373,11 @@
append(";"); //$NON-NLS-1$
}
- public void visit( CreateUpdateProcedureCommand obj ) {
+ public void visit( CreateProcedureCommand obj ) {
append(CREATE);
append(SPACE);
- if (!obj.isUpdateProcedure()) {
- append(VIRTUAL);
- append(SPACE);
- }
+ append(VIRTUAL);
+ append(SPACE);
append(PROCEDURE);
append("\n"); //$NON-NLS-1$
addTabs(0);
Modified: trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -60,7 +60,7 @@
import org.teiid.query.sql.navigator.PreOrderNavigator;
import org.teiid.query.sql.proc.Block;
import org.teiid.query.sql.proc.BranchingStatement;
-import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.proc.CreateProcedureCommand;
import org.teiid.query.sql.proc.LoopStatement;
import org.teiid.query.sql.proc.WhileStatement;
import org.teiid.query.sql.proc.BranchingStatement.BranchingMode;
@@ -367,15 +367,10 @@
}
}
- public void visit(CreateUpdateProcedureCommand obj) {
- if(!obj.isUpdateProcedure()){
-
- //check that the procedure does not contain references to itself
- if (GroupCollectorVisitor.getGroups(obj,true).contains(obj.getVirtualGroup())) {
- handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.Procedure_has_group_self_reference"),obj); //$NON-NLS-1$
- }
-
- return;
+ public void visit(CreateProcedureCommand obj) {
+ //check that the procedure does not contain references to itself
+ if (GroupCollectorVisitor.getGroups(obj,true).contains(obj.getVirtualGroup())) {
+ handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.Procedure_has_group_self_reference"),obj); //$NON-NLS-1$
}
}
Modified: trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
===================================================================
--- trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2011-11-22 12:55:13 UTC (rev 3683)
@@ -1066,10 +1066,7 @@
Statement stmt = null;
}
{
- <CREATE> [<VIRTUAL> {updateProcCmd.setUpdateProcedure(false);}]
- [<UPDATE>]
- <PROCEDURE>
-
+ <CREATE> [<VIRTUAL>] <PROCEDURE>
stmt = statement(info)
{
updateProcCmd.setBlock(asBlock(stmt));
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/proc/TestProcedurePlanner.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/proc/TestProcedurePlanner.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/proc/TestProcedurePlanner.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -40,7 +40,7 @@
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.rewriter.QueryRewriter;
import org.teiid.query.sql.lang.Command;
-import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.proc.CreateProcedureCommand;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.unittest.RealMetadataFactory;
import org.teiid.query.validator.Validator;
@@ -61,10 +61,10 @@
QueryParser parser = QueryParser.getQueryParser();
Command userCommand = userQuery != null ? parser.parseCommand(userQuery) : parser.parseCommand(procedure);
- if (userCommand instanceof CreateUpdateProcedureCommand) {
+ if (userCommand instanceof CreateProcedureCommand) {
GroupSymbol gs = new GroupSymbol("proc");
gs.setMetadataID(new TempMetadataID("proc", Collections.EMPTY_LIST));
- ((CreateUpdateProcedureCommand)userCommand).setVirtualGroup(gs);
+ ((CreateProcedureCommand)userCommand).setVirtualGroup(gs);
}
QueryResolver.resolveCommand(userCommand, metadata);
Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -3888,7 +3888,7 @@
CommandStatement cmdStmt = new CommandStatement(query);
block.addStatement(cmdStmt);
- CreateUpdateProcedureCommand virtualProcedureCommand = new CreateUpdateProcedureCommand();
+ CreateProcedureCommand virtualProcedureCommand = new CreateProcedureCommand();
virtualProcedureCommand.setBlock(block);
virtualProcedureCommand.setUpdateProcedure(false);
@@ -4913,8 +4913,8 @@
}
@Test public void testIfElseWithoutBeginEnd() {
- String sql = "CREATE PROCEDURE BEGIN IF (x > 1) select 1; IF (x > 1) select 1; ELSE select 1; END"; //$NON-NLS-1$
- String expected = "CREATE PROCEDURE\nBEGIN\nIF(x > 1)\nBEGIN\nSELECT 1;\nEND\nIF(x > 1)\nBEGIN\nSELECT 1;\nEND\nELSE\nBEGIN\nSELECT 1;\nEND\nEND"; //$NON-NLS-1$
+ String sql = "CREATE VIRTUAL PROCEDURE BEGIN IF (x > 1) select 1; IF (x > 1) select 1; ELSE select 1; END"; //$NON-NLS-1$
+ String expected = "CREATE VIRTUAL PROCEDURE\nBEGIN\nIF(x > 1)\nBEGIN\nSELECT 1;\nEND\nIF(x > 1)\nBEGIN\nSELECT 1;\nEND\nELSE\nBEGIN\nSELECT 1;\nEND\nEND"; //$NON-NLS-1$
Query query = new Query();
query.setSelect(new Select(Arrays.asList(new ExpressionSymbol("expr", new Constant(1))))); //$NON-NLS-1$
@@ -4930,7 +4930,7 @@
Block block3 = new Block();
block3.addStatement(ifStmt);
block3.addStatement(ifStmt1);
- CreateUpdateProcedureCommand command = new CreateUpdateProcedureCommand(block3);
+ CreateProcedureCommand command = new CreateProcedureCommand(block3);
helpTest(sql, expected, command);
}
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestInherintlyUpdatableViews.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestInherintlyUpdatableViews.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestInherintlyUpdatableViews.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -60,8 +60,8 @@
CommandContext context = createCommandContext();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setFunctionSupport(SourceSystemFunctions.CONVERT, true);
- ProcessorPlan plan = helpGetPlan(command, metadata, new DefaultCapabilitiesFinder(caps), context);
- List[] expected = new List[] {Arrays.asList(1)};
+ ProcessorPlan plan = helpGetPlan(helpParse(userSql), metadata, new DefaultCapabilitiesFinder(caps), context);
+ List<?>[] expected = new List[] {Arrays.asList(1)};
helpProcess(plan, context, dm, expected);
}
@@ -116,7 +116,7 @@
dm.addData("SELECT g_1.e2, g_1.e2 FROM pm1.g1 AS g_0, pm1.g2 AS g_1 WHERE (g_0.e1 = g_1.e1) AND (g_1.e3 IS NULL)", new List[] {Arrays.asList(1, 1)});
dm.addData("UPDATE pm1.g2 SET e1 = pm1.g2.e2 WHERE pm1.g2.e2 = 1", new List[] {Arrays.asList(1)});
- helpTest(userSql, viewSql, "CREATE PROCEDURE\nBEGIN\nLOOP ON (SELECT pm1.g2.e2 AS s_0, pm1.g2.e2 AS s_1 FROM pm1.g1 INNER JOIN pm1.g2 ON g1.e1 = g2.e1 WHERE pm1.g2.e3 IS NULL) AS X\nBEGIN\nUPDATE pm1.g2 SET e1 = pm1.g2.e2 WHERE pm1.g2.e2 = X.s_1;\nVARIABLES.ROWS_UPDATED = (VARIABLES.ROWS_UPDATED + 1);\nEND\nEND",
+ helpTest(userSql, viewSql, "CREATE VIRTUAL PROCEDURE\nBEGIN ATOMIC\nDECLARE integer VARIABLES.ROWS_UPDATED = 0;\nLOOP ON (SELECT pm1.g2.e2 AS s_0, pm1.g2.e2 AS s_1 FROM pm1.g1 INNER JOIN pm1.g2 ON g1.e1 = g2.e1 WHERE pm1.g2.e3 IS NULL) AS X\nBEGIN\nUPDATE pm1.g2 SET e1 = pm1.g2.e2 WHERE pm1.g2.e2 = X.s_1;\nVARIABLES.ROWS_UPDATED = (VARIABLES.ROWS_UPDATED + 1);\nEND\nSELECT VARIABLES.ROWS_UPDATED;\nEND",
dm);
}
@@ -128,7 +128,7 @@
dm.addData("SELECT g_1.e2 FROM pm1.g1 AS g_0, pm1.g2 AS g_1 WHERE (g_0.e1 = g_1.e1) AND (g_1.e2 < 10)", new List[] {Arrays.asList(2)});
dm.addData("DELETE FROM pm1.g2 WHERE pm1.g2.e2 = 2", new List[] {Arrays.asList(1)});
- helpTest(userSql, viewSql, "CREATE PROCEDURE\nBEGIN\nLOOP ON (SELECT pm1.g2.e2 AS s_0 FROM pm1.g1 INNER JOIN pm1.g2 ON g1.e1 = g2.e1 WHERE pm1.g2.e2 < 10) AS X\nBEGIN\nDELETE FROM pm1.g2 WHERE pm1.g2.e2 = X.s_0;\nVARIABLES.ROWS_UPDATED = (VARIABLES.ROWS_UPDATED + 1);\nEND\nEND",
+ helpTest(userSql, viewSql, "CREATE VIRTUAL PROCEDURE\nBEGIN ATOMIC\nDECLARE integer VARIABLES.ROWS_UPDATED = 0;\nLOOP ON (SELECT pm1.g2.e2 AS s_0 FROM pm1.g1 INNER JOIN pm1.g2 ON g1.e1 = g2.e1 WHERE pm1.g2.e2 < 10) AS X\nBEGIN\nDELETE FROM pm1.g2 WHERE pm1.g2.e2 = X.s_0;\nVARIABLES.ROWS_UPDATED = (VARIABLES.ROWS_UPDATED + 1);\nEND\nSELECT VARIABLES.ROWS_UPDATED;\nEND",
dm);
}
Modified: trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -44,7 +44,6 @@
import org.teiid.metadata.Procedure;
import org.teiid.metadata.ProcedureParameter;
import org.teiid.metadata.Schema;
-import org.teiid.metadata.Table;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.mapping.relational.QueryNode;
import org.teiid.query.metadata.QueryMetadataInterface;
@@ -124,10 +123,6 @@
}
}
- private void helpTestProcess(ProcessorPlan procPlan, int expectedRows, FakeDataManager dataMgr, QueryMetadataInterface metadata) throws Exception {
- helpTestProcess(procPlan, new List[] {Arrays.asList(expectedRows)}, dataMgr, metadata);
- }
-
private FakeDataManager exampleDataManager(QueryMetadataInterface metadata) throws TeiidException {
FakeDataManager dataMgr = new FakeDataManager();
@@ -202,147 +197,6 @@
return dataMgr;
}
- // procedure does nothing returns zero update count
- @Test public void testProcedureProcessor1() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1 = 0;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure);
-
- FakeDataManager dataMgr = exampleDataManager(metadata);
-
- ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
-
- helpTestProcess(plan, 0, dataMgr, metadata);
- }
-
- // testing if statement
- @Test public void testProcedureProcessor2() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "var1 = Select pm1.g1.e2 from pm1.g1 where e2=5;\n"; //$NON-NLS-1$
- procedure = procedure + "if(var1 = 5)\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure);
-
- FakeDataManager dataMgr = exampleDataManager(metadata);
-
- ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
-
- helpTestProcess(plan, 5, dataMgr, metadata);
- }
-
- // testing if statement
- @Test public void testProcedureProcessor2WithBlockedException() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "var1 = Select pm1.g1.e2 from pm1.g1 where e2=5;\n"; //$NON-NLS-1$
- procedure = procedure + "if(var1 = 5)\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure);
-
- FakeDataManager dataMgr = exampleDataManager(metadata);
- dataMgr.setBlockOnce();
-
- ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
-
- helpTestProcess(plan, 5, dataMgr, metadata);
- }
-
- // more rows than expected
- @Test public void testProcedureProcessor6() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = Select pm1.g1.e2 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure);
-
- FakeDataManager dataMgr = exampleDataManager(metadata);
-
- ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
-
- helpTestProcessFailure(plan, dataMgr, "Error Code:ERR.015.006.0058 Message:Unable to evaluate (SELECT pm1.g1.e2 FROM pm1.g1 LIMIT 2): Error Code:ERR.015.006.0058 Message:The command of this scalar subquery returned more than one value: SELECT pm1.g1.e2 FROM pm1.g1 LIMIT 2", metadata); //$NON-NLS-1$
- }
-
- // error statement
- @Test public void testProcedureProcessor7() throws Exception {
- String errorValue = "'MY ERROR'"; //$NON-NLS-1$
- helpTestErrorStatment(errorValue, "MY ERROR"); //$NON-NLS-1$
- }
-
- @Test public void testProcedureProcessor8() throws Exception {
- String errorValue = "var1"; //$NON-NLS-1$
- helpTestErrorStatment(errorValue, "5"); //$NON-NLS-1$
- }
-
- @Test public void testProcedureProcessor9() throws Exception {
- String errorValue = "var1||'MY ERROR'"; //$NON-NLS-1$
- helpTestErrorStatment(errorValue, "5MY ERROR"); //$NON-NLS-1$
- }
-
- @Test public void testProcedureProcessor10() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "loop on (Select pm1.g1.e2 from pm1.g1 where e2 = 5) as mycursor\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "ERROR (mycursor.e2||'MY ERROR');\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = 0;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure);
-
- FakeDataManager dataMgr = exampleDataManager(metadata);
-
- ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
-
- helpTestProcessFailure(plan, dataMgr, ErrorInstruction.ERROR_PREFIX + "5MY ERROR", metadata); //$NON-NLS-1$
- }
-
- private void helpTestErrorStatment(String errorValue, String expected) throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "var1 = 5;\n"; //$NON-NLS-1$
- procedure = procedure + "ERROR "+errorValue+";\n"; //$NON-NLS-1$ //$NON-NLS-2$
- procedure = procedure + "ROWS_UPDATED = 0;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure);
-
- FakeDataManager dataMgr = exampleDataManager(metadata);
-
- ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
-
- helpTestProcessFailure(plan, dataMgr, ErrorInstruction.ERROR_PREFIX + expected, metadata);
- }
-
@Test public void testVirtualProcedure() throws Exception {
String userUpdateStr = "EXEC pm1.vsp2()"; //$NON-NLS-1$
@@ -1891,58 +1745,6 @@
helpTestProcess(plan, expected, dataMgr, metadata);
}
- @Test public void testDefect8693() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "var1 = Select pm1.g1.e2 from pm1.g1 where e2 = 5;\n"; //$NON-NLS-1$
- procedure = procedure + "if (5 in (select 5 from pm1.g1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure);
- FakeDataManager dataMgr = exampleDataManager(metadata);
- ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
- helpTestProcess(plan, 5, dataMgr, metadata);
- }
-
- @Test public void testWhileWithSubquery() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1 = 2;\n"; //$NON-NLS-1$
- procedure = procedure + "WHILE (5 in (select var1 from pm1.g1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure);
- FakeDataManager dataMgr = exampleDataManager(metadata);
- ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
- helpTestProcess(plan, 0, dataMgr, metadata);
- }
-
- @Test public void testDefect18404() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1 = 5 + (select count(e2) from pm1.g1);\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure);
- FakeDataManager dataMgr = exampleDataManager(metadata);
- ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
- helpTestProcess(plan, 8, dataMgr, metadata);
- }
-
/**
* Test the use of a procedure variable in the criteria of a LEFT OUTER
* JOIN which will be optimized out as non-JOIN criteria.
Modified: trunk/engine/src/test/java/org/teiid/query/resolver/TestProcedureResolving.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/resolver/TestProcedureResolving.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/TestProcedureResolving.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -44,7 +44,7 @@
import org.teiid.query.sql.proc.AssignmentStatement;
import org.teiid.query.sql.proc.Block;
import org.teiid.query.sql.proc.CommandStatement;
-import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.proc.CreateProcedureCommand;
import org.teiid.query.sql.proc.LoopStatement;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
@@ -109,19 +109,19 @@
assertNull(tempIDs.get("LOOPCURSOR2")); //$NON-NLS-1$
}
- private CreateUpdateProcedureCommand helpResolveUpdateProcedure(String procedure, String userUpdateStr, Table.TriggerEvent procedureType) throws QueryParserException, QueryResolverException, TeiidComponentException {
+ private CreateProcedureCommand helpResolveUpdateProcedure(String procedure, String userUpdateStr, Table.TriggerEvent procedureType) throws QueryParserException, QueryResolverException, TeiidComponentException {
QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(procedureType, procedure);
return resolveProcedure(userUpdateStr, metadata);
}
- private CreateUpdateProcedureCommand resolveProcedure(String userUpdateStr,
+ private CreateProcedureCommand resolveProcedure(String userUpdateStr,
QueryMetadataInterface metadata) throws QueryParserException,
QueryResolverException, TeiidComponentException,
QueryMetadataException {
ProcedureContainer userCommand = (ProcedureContainer)QueryParser.getQueryParser().parseCommand(userUpdateStr);
QueryResolver.resolveCommand(userCommand, metadata);
metadata = new TempMetadataAdapter(metadata, new TempMetadataStore(userCommand.getTemporaryMetadata()));
- return (CreateUpdateProcedureCommand)QueryResolver.expandCommand(userCommand, metadata, null);
+ return (CreateProcedureCommand)QueryResolver.expandCommand(userCommand, metadata, null);
}
private void helpResolveException(String userUpdateStr, QueryMetadataInterface metadata, String msg) throws QueryParserException, TeiidComponentException {
@@ -133,7 +133,7 @@
}
}
- private CreateUpdateProcedureCommand helpResolve(String userUpdateStr, QueryMetadataInterface metadata) throws QueryParserException, QueryResolverException, TeiidComponentException {
+ private CreateProcedureCommand helpResolve(String userUpdateStr, QueryMetadataInterface metadata) throws QueryParserException, QueryResolverException, TeiidComponentException {
return resolveProcedure(userUpdateStr, metadata);
}
@@ -141,7 +141,7 @@
* Constants will now auto resolve if they are consistently representable in the target type
*/
@Test public void testDefect23257() throws Exception{
- CreateUpdateProcedureCommand command = helpResolve("EXEC pm6.vsp59()", RealMetadataFactory.example1Cached()); //$NON-NLS-1$
+ CreateProcedureCommand command = helpResolve("EXEC pm6.vsp59()", RealMetadataFactory.example1Cached()); //$NON-NLS-1$
CommandStatement cs = (CommandStatement)command.getBlock().getStatements().get(1);
@@ -165,7 +165,7 @@
String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
- CreateUpdateProcedureCommand command = helpResolveUpdateProcedure(proc.toString(), userUpdateStr,
+ CreateProcedureCommand command = helpResolveUpdateProcedure(proc.toString(), userUpdateStr,
Table.TriggerEvent.UPDATE);
Block block = command.getBlock();
@@ -494,7 +494,6 @@
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "DECLARE string var1;\n"; //$NON-NLS-1$
procedure = procedure + "var1 = 1+1;"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
@@ -503,22 +502,6 @@
Table.TriggerEvent.UPDATE);
}
- // resolving AssignmentStatement, variable type and assigned type
- // do not match, but implicit conversion available
- @Test public void testCreateUpdateProcedure55() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE string var1;\n"; //$NON-NLS-1$
- procedure = procedure + "var1 = 1+ROWS_UPDATED;"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpResolveUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
@Test public void testDefect14912_CreateUpdateProcedure57_FunctionWithElementParamInAssignmentStatement() {
// Tests that the function params are resolved before the function for assignment statements
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
@@ -538,7 +521,6 @@
@Test public void testCase4624() {
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "VARIABLES.ROWS_UPDATED = 0;\n"; //$NON-NLS-1$
procedure = procedure + "DECLARE boolean var1;\n"; //$NON-NLS-1$
procedure = procedure + "var1 = {b'false'};\n"; //$NON-NLS-1$
procedure = procedure + "IF(var1 = {b 'true'})\n"; //$NON-NLS-1$
@@ -617,7 +599,6 @@
.append("BEGIN\n") //$NON-NLS-1$
.append("execute string 'SELECT e1, e2, e3, e4 FROM pm1.g2' as e1 string, e2 string, e3 string, e4 string INTO #myTempTable;\n") //$NON-NLS-1$
.append("select e1 from #myTempTable;\n") //$NON-NLS-1$
- .append("ROWS_UPDATED =0;\n") //$NON-NLS-1$
.append("END\n"); //$NON-NLS-1$
helpResolveUpdateProcedure(procedure.toString(), userUpdateStr,
Table.TriggerEvent.UPDATE);
@@ -629,7 +610,6 @@
StringBuffer procedure = new StringBuffer("CREATE PROCEDURE ") //$NON-NLS-1$
.append("BEGIN\n") //$NON-NLS-1$
.append("execute string 'SELECT e1, e2, e3, e4 FROM pm1.g2';\n") //$NON-NLS-1$
- .append("ROWS_UPDATED =0;\n") //$NON-NLS-1$
.append("END\n"); //$NON-NLS-1$
helpResolveUpdateProcedure(procedure.toString(), userUpdateStr,
Table.TriggerEvent.UPDATE);
@@ -682,7 +662,6 @@
StringBuffer procedure = new StringBuffer("CREATE PROCEDURE ") //$NON-NLS-1$
.append("BEGIN\n") //$NON-NLS-1$
.append("SELECT e1, e2, e3, e4 INTO pm1.g1 FROM pm1.g2;\n") //$NON-NLS-1$
- .append("ROWS_UPDATED =0;\n") //$NON-NLS-1$
.append("END\n"); //$NON-NLS-1$
String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
@@ -693,7 +672,6 @@
procedure = new StringBuffer("CREATE PROCEDURE ") //$NON-NLS-1$
.append("BEGIN\n") //$NON-NLS-1$
.append("SELECT e1, e2, e3, e4 INTO #myTempTable FROM pm1.g2;\n") //$NON-NLS-1$
- .append("ROWS_UPDATED =0;\n") //$NON-NLS-1$
.append("END\n"); //$NON-NLS-1$
helpResolveUpdateProcedure(procedure.toString(), userUpdateStr,
Table.TriggerEvent.UPDATE);
@@ -703,7 +681,6 @@
StringBuffer procedure = new StringBuffer("CREATE PROCEDURE ") //$NON-NLS-1$
.append("BEGIN\n") //$NON-NLS-1$
.append("SELECT 'a', 19, {b'true'}, 13.999 INTO pm1.g1;\n") //$NON-NLS-1$
- .append("ROWS_UPDATED =0;\n") //$NON-NLS-1$
.append("END\n"); //$NON-NLS-1$
String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
@@ -714,56 +691,11 @@
procedure = new StringBuffer("CREATE PROCEDURE ") //$NON-NLS-1$
.append("BEGIN\n") //$NON-NLS-1$
.append("SELECT 'a', 19, {b'true'}, 13.999 INTO #myTempTable;\n") //$NON-NLS-1$
- .append("ROWS_UPDATED =0;\n") //$NON-NLS-1$
.append("END\n"); //$NON-NLS-1$
helpResolveUpdateProcedure(procedure.toString(), userUpdateStr,
Table.TriggerEvent.UPDATE);
}
- /*@Test public void testCommandUpdating3() throws Exception{
- StringBuffer procedure = new StringBuffer("CREATE PROCEDURE ") //$NON-NLS-1$
- .append("BEGIN\n") //$NON-NLS-1$
- .append("INSERT INTO pm1.g1 (e1) VALUES (INPUTS.e1);\n") //$NON-NLS-1$
- .append("ROWS_UPDATED = INSERT INTO pm1.g2 (e1) VALUES (INPUTS.e1);\n") //$NON-NLS-1$
- .append("END\n"); //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- Command command = helpResolveUpdateProcedure(procedure.toString(), userUpdateStr,
- Table.TriggerEvent.UPDATE);
- assertEquals(2, command.updatingModelCount(metadata));
- }*/
-
- /*@Test public void testCommandUpdatingCount6() throws Exception{
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "if(INPUTS.e1 = 10)\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "INSERT INTO pm1.g1 (e2) VALUES (INPUTS.e2);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "INSERT into vm1.g1 (e1) values('x')"; //$NON-NLS-1$
-
- Command command = helpResolveUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.INSERT);
- assertEquals(2, command.updatingModelCount(metadata));
- }*/
-
- // variable declared is of special type ROWS_RETURNED
- @Test public void testDeclareRowsUpdated() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer rows_updated;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpFailUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE, "Variable rows_updated was previously declared."); //$NON-NLS-1$
- }
-
// validating INPUT element assigned
@Test public void testAssignInput() {
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
@@ -796,7 +728,7 @@
// variables cannot be used among insert elements
@Test public void testVariableInInsert() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ String procedure = "CREATE VIRTUAL PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
procedure = procedure + "Insert into pm1.g1 (pm1.g1.e2, var1) values (1, 2);\n"; //$NON-NLS-1$
@@ -811,7 +743,7 @@
// variables cannot be used among insert elements
@Test public void testVariableInInsert2() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ String procedure = "CREATE VIRTUAL PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
procedure = procedure + "Insert into pm1.g1 (pm1.g1.e2, INPUTS.x) values (1, 2);\n"; //$NON-NLS-1$
@@ -826,11 +758,10 @@
//should resolve first to the table's column
@Test public void testVariableInInsert3() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ String procedure = "CREATE VIRTUAL PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "DECLARE integer e2;\n"; //$NON-NLS-1$
procedure = procedure + "Insert into pm1.g1 (e2) values (1);\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
String userQuery = "UPDATE vm1.g3 SET x='x' where e3= 1"; //$NON-NLS-1$
@@ -852,7 +783,7 @@
}
@Test public void testLoopRedefinition() {
- StringBuffer proc = new StringBuffer("CREATE PROCEDURE") //$NON-NLS-1$
+ StringBuffer proc = new StringBuffer("CREATE VIRTUAL PROCEDURE") //$NON-NLS-1$
.append("\nBEGIN") //$NON-NLS-1$
.append("\n declare string var1;") //$NON-NLS-1$
.append("\n LOOP ON (SELECT pm1.g1.e1 FROM pm1.g1) AS loopCursor") //$NON-NLS-1$
@@ -871,7 +802,7 @@
}
@Test public void testTempGroupElementShouldNotBeResolable() {
- StringBuffer proc = new StringBuffer("CREATE PROCEDURE") //$NON-NLS-1$
+ StringBuffer proc = new StringBuffer("CREATE VIRTUAL PROCEDURE") //$NON-NLS-1$
.append("\nBEGIN") //$NON-NLS-1$
.append("\n select 1 as a into #temp;") //$NON-NLS-1$
.append("\n select #temp.a from pm1.g1;") //$NON-NLS-1$
@@ -884,7 +815,7 @@
}
@Test public void testTempGroupElementShouldNotBeResolable1() {
- StringBuffer proc = new StringBuffer("CREATE PROCEDURE") //$NON-NLS-1$
+ StringBuffer proc = new StringBuffer("CREATE VIRTUAL PROCEDURE") //$NON-NLS-1$
.append("\nBEGIN") //$NON-NLS-1$
.append("\n select 1 as a into #temp;") //$NON-NLS-1$
.append("\n insert into #temp (a) values (#temp.a);") //$NON-NLS-1$
@@ -897,7 +828,7 @@
}
@Test public void testProcedureCreate() throws Exception {
- StringBuffer proc = new StringBuffer("CREATE PROCEDURE") //$NON-NLS-1$
+ StringBuffer proc = new StringBuffer("CREATE VIRTUAL PROCEDURE") //$NON-NLS-1$
.append("\nBEGIN") //$NON-NLS-1$
.append("\n create local temporary table t1 (e1 string);") //$NON-NLS-1$
.append("\n select e1 from t1;") //$NON-NLS-1$
@@ -914,7 +845,7 @@
* it is not ok to redefine the loopCursor
*/
@Test public void testProcedureCreate1() {
- StringBuffer proc = new StringBuffer("CREATE PROCEDURE") //$NON-NLS-1$
+ StringBuffer proc = new StringBuffer("CREATE VIRTUAL PROCEDURE") //$NON-NLS-1$
.append("\nBEGIN") //$NON-NLS-1$
.append("\n LOOP ON (SELECT pm1.g1.e1 FROM pm1.g1) AS loopCursor") //$NON-NLS-1$
.append("\n BEGIN") //$NON-NLS-1$
@@ -928,7 +859,7 @@
}
@Test public void testProcedureCreateDrop() {
- StringBuffer proc = new StringBuffer("CREATE PROCEDURE") //$NON-NLS-1$
+ StringBuffer proc = new StringBuffer("CREATE VIRTUAL PROCEDURE") //$NON-NLS-1$
.append("\nBEGIN") //$NON-NLS-1$
.append("\n drop table t1;") //$NON-NLS-1$
.append("\n create local temporary table t1 (e1 string);") //$NON-NLS-1$
@@ -940,7 +871,7 @@
}
@Test public void testProcedureCreateDrop1() throws Exception {
- StringBuffer proc = new StringBuffer("CREATE PROCEDURE") //$NON-NLS-1$
+ StringBuffer proc = new StringBuffer("CREATE VIRTUAL PROCEDURE") //$NON-NLS-1$
.append("\nBEGIN") //$NON-NLS-1$
.append("\n create local temporary table t1 (e1 string);") //$NON-NLS-1$
.append("\n drop table t1;") //$NON-NLS-1$
@@ -952,7 +883,7 @@
}
@Test public void testCreateAfterImplicitTempTable() throws Exception {
- StringBuffer proc = new StringBuffer("CREATE PROCEDURE") //$NON-NLS-1$
+ StringBuffer proc = new StringBuffer("CREATE VIRTUAL PROCEDURE") //$NON-NLS-1$
.append("\nBEGIN") //$NON-NLS-1$
.append("\n select e1 into #temp from pm1.g1;") //$NON-NLS-1$
.append("\n create local temporary table #temp (e1 string);") //$NON-NLS-1$
@@ -979,16 +910,15 @@
* delete procedures should not reference input or changing vars.
*/
@Test public void testDefect16451() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure += "BEGIN\n"; //$NON-NLS-1$
- procedure += "Select pm1.g1.e2 from pm1.g1 where e1 = INPUTS.e1;\n"; //$NON-NLS-1$
- procedure += "ROWS_UPDATED = 0;"; //$NON-NLS-1$
+ String procedure = "FOR EACH ROW "; //$NON-NLS-1$
+ procedure += "BEGIN ATOMIC\n"; //$NON-NLS-1$
+ procedure += "Select pm1.g1.e2 from pm1.g1 where e1 = NEW.e1;\n"; //$NON-NLS-1$
procedure += "END\n"; //$NON-NLS-1$
String userUpdateStr = "delete from vm1.g1 where e1='x'"; //$NON-NLS-1$
helpFailUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.DELETE, "Symbol INPUTS.e1 is specified with an unknown group context"); //$NON-NLS-1$
+ Table.TriggerEvent.DELETE, "Symbol \"NEW\".e1 is specified with an unknown group context"); //$NON-NLS-1$
}
@Test public void testInvalidVirtualProcedure3() throws Exception {
Modified: trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -70,7 +70,7 @@
import org.teiid.query.sql.lang.*;
import org.teiid.query.sql.navigator.DeepPreOrderNavigator;
import org.teiid.query.sql.proc.CommandStatement;
-import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.proc.CreateProcedureCommand;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
@@ -2407,7 +2407,7 @@
+"select * from xmltest.doc1 where node1 = x; " //$NON-NLS-1$
+"end "; //$NON-NLS-1$
- CreateUpdateProcedureCommand command = (CreateUpdateProcedureCommand) helpResolve(sql);
+ CreateProcedureCommand command = (CreateProcedureCommand) helpResolve(sql);
CommandStatement cmdStmt = (CommandStatement)command.getBlock().getStatements().get(1);
@@ -2887,7 +2887,7 @@
helpResolveUpdateProcedure(procedure, userUpdateStr);
}
- CreateUpdateProcedureCommand helpResolveUpdateProcedure(String procedure,
+ CreateProcedureCommand helpResolveUpdateProcedure(String procedure,
String userUpdateStr) throws QueryParserException,
QueryResolverException, TeiidComponentException,
QueryMetadataException {
@@ -2896,7 +2896,7 @@
ProcedureContainer userCommand = (ProcedureContainer)QueryParser.getQueryParser().parseCommand(userUpdateStr);
QueryResolver.resolveCommand(userCommand, metadata);
- return (CreateUpdateProcedureCommand)QueryResolver.expandCommand(userCommand, metadata, AnalysisRecord.createNonRecordingRecord());
+ return (CreateProcedureCommand)QueryResolver.expandCommand(userCommand, metadata, AnalysisRecord.createNonRecordingRecord());
}
// validating AssignmentStatement, variable type and assigned type
Modified: trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -1143,7 +1143,7 @@
String userQuery = "Insert into vm1.g1 (e1, e2) values ('String', 1)"; //$NON-NLS-1$
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ String rewritProc = "CREATE VIRTUAL PROCEDURE\n"; //$NON-NLS-1$
rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
rewritProc = rewritProc + "END"; //$NON-NLS-1$
@@ -1165,7 +1165,7 @@
String userQuery = "Insert into vm1.g1 (e1, e2) values ('String', 1)"; //$NON-NLS-1$
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ String rewritProc = "CREATE VIRTUAL PROCEDURE\n"; //$NON-NLS-1$
rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
rewritProc = rewritProc + "SELECT COUNT(*) FROM pm1.g1;\n"; //$NON-NLS-1$
rewritProc = rewritProc + "END"; //$NON-NLS-1$
Modified: trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCreateUpdateProcedureCommand.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCreateUpdateProcedureCommand.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCreateUpdateProcedureCommand.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -22,20 +22,11 @@
package org.teiid.query.sql.proc;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-
import junit.framework.TestCase;
import org.teiid.core.util.UnitTestUtil;
import org.teiid.query.resolver.TestResolver;
-import org.teiid.query.sql.lang.Command;
-import org.teiid.query.sql.lang.Option;
-import org.teiid.query.sql.lang.Query;
import org.teiid.query.sql.lang.StoredProcedure;
-import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.unittest.RealMetadataFactory;
@@ -54,151 +45,62 @@
// ################################## TEST HELPERS ################################
- public static final CreateUpdateProcedureCommand sample1() {
- return new CreateUpdateProcedureCommand(TestBlock.sample1());
+ public static final CreateProcedureCommand sample1() {
+ return new CreateProcedureCommand(TestBlock.sample1());
}
- public static final CreateUpdateProcedureCommand sample2() {
- return new CreateUpdateProcedureCommand(TestBlock.sample2());
+ public static final CreateProcedureCommand sample2() {
+ return new CreateProcedureCommand(TestBlock.sample2());
}
- public static final CreateUpdateProcedureCommand sample3() {
- return new CreateUpdateProcedureCommand(TestBlock.sample1());
+ public static final CreateProcedureCommand sample3() {
+ return new CreateProcedureCommand(TestBlock.sample1());
}
// ################################## ACTUAL TESTS ################################
public void testGetBlock() {
- CreateUpdateProcedureCommand b1 = sample1();
+ CreateProcedureCommand b1 = sample1();
assertTrue("Incorrect Block on command", b1.getBlock().equals(TestBlock.sample1())); //$NON-NLS-1$
}
public void testSetBlock() {
- CreateUpdateProcedureCommand b1 = (CreateUpdateProcedureCommand)sample1().clone();
+ CreateProcedureCommand b1 = (CreateProcedureCommand)sample1().clone();
b1.setBlock(TestBlock.sample2());
assertTrue("Incorrect Block on command", b1.getBlock().equals(TestBlock.sample2())); //$NON-NLS-1$
}
public void testSelfEquivalence(){
- CreateUpdateProcedureCommand s1 = sample1();
+ CreateProcedureCommand s1 = sample1();
int equals = 0;
UnitTestUtil.helpTestEquivalence(equals, s1, s1);
}
public void testEquivalence(){
- CreateUpdateProcedureCommand s1 = sample1();
- CreateUpdateProcedureCommand s1a = sample1();
+ CreateProcedureCommand s1 = sample1();
+ CreateProcedureCommand s1a = sample1();
int equals = 0;
UnitTestUtil.helpTestEquivalence(equals, s1, s1a);
}
public void testNonEquivalence(){
- CreateUpdateProcedureCommand s1 = sample1();
- CreateUpdateProcedureCommand s2 = sample2();
+ CreateProcedureCommand s1 = sample1();
+ CreateProcedureCommand s2 = sample2();
int equals = -1;
UnitTestUtil.helpTestEquivalence(equals, s1, s2);
}
/**
- * We've had some defects in the past with state added to
- * CreateUpdateProcedureCommand but not added to the clone
- * method. We don't currently have any unit tests that exercise
- * the clone method very well. So this method simply asserts
- * that the number of fields that this test class thinks is in
- * CreateUpdateProcedureCommand is still current. I.e., if someone
- * adds state to CreateUpdateProcedureCommand but doesn't update
- * this test, the test will fail. The failure message is a reminder
- * to update the clone() method. So this isn't really a test of the
- * clone() method, per se.
- * see defect 14018
- * @since 4.2
- */
- public void testCloneMethod() {
- Field[] fields = CreateUpdateProcedureCommand.class.getDeclaredFields();
-
- final int EXPECTED_NUMBER_OF_FIELDS = 7; //<---update me if necessary!
- int actualNumberOfFields = fields.length;
-
- // Workaround for Java bug 4546736 and 4407429 (same bug) -
- // the Class literal "synthetic" field can be returned from the call
- // to getDeclaredFields(), it seems to show up as the last entry in the
- // Field array, and has a dollar sign "$" in it's name.
- if (fields[fields.length-1].getType().equals(Class.class) &&
- fields[fields.length-1].getName().indexOf("$") != -1) { //$NON-NLS-1$
-
- actualNumberOfFields--;
- }
-
- assertEquals("New state has been added to the class CreateUpdateProcedureCommand; please update this test, and update the clone() method if necessary.", EXPECTED_NUMBER_OF_FIELDS, actualNumberOfFields); //$NON-NLS-1$
- }
-
- /**
- * tests that a CreateUpdateProcedureCommand with non-null variables for all of its
- * state produces a clone that has non-null variables for all of its state.
- */
- public void testCloneMethod2() throws Exception{
- CreateUpdateProcedureCommand s1 = sample1();
-
- //Command class state
- s1.addExternalGroupsToContext(new HashSet());
- s1.setIsResolved(true);
- s1.setOption(new Option());
- s1.setTemporaryMetadata(new HashMap());
-
- //CreateUpdateProcedure class state
- s1.setProjectedSymbols(new ArrayList());
- s1.setResultsCommand(new Query());
- s1.setSymbolMap(new HashMap());
- s1.setUpdateProcedure(true);
- s1.setVirtualGroup(new GroupSymbol("x")); //$NON-NLS-1$
- s1.setUserCommand(new Query());
-
- CreateUpdateProcedureCommand cloned = (CreateUpdateProcedureCommand)s1.clone();
-
- Class clazz = CreateUpdateProcedureCommand.class;
- Class superClazz = Command.class;
-
- Field field = null;
- //Command class state
- field = superClazz.getDeclaredField("tempGroupIDs"); //$NON-NLS-1$
- field.setAccessible( true );
- assertNotNull(field.get(cloned));
- field = superClazz.getDeclaredField("externalGroups"); //$NON-NLS-1$
- field.setAccessible( true );
- assertNotNull(field.get(cloned));
- field = superClazz.getDeclaredField("isResolved"); //$NON-NLS-1$
- field.setAccessible( true );
- assertTrue(((Boolean)field.get(cloned)).booleanValue());
- field = superClazz.getDeclaredField("option"); //$NON-NLS-1$
- field.setAccessible( true );
- assertNotNull(field.get(cloned));
-
- //CreateUpdateProcedure class state
- field = clazz.getDeclaredField("block"); //$NON-NLS-1$
- field.setAccessible( true );
- assertNotNull(field.get(cloned));
- field = clazz.getDeclaredField("symbolMap"); //$NON-NLS-1$
- field.setAccessible( true );
- assertNotNull(field.get(cloned));
- field = clazz.getDeclaredField("isUpdateProcedure"); //$NON-NLS-1$
- field.setAccessible( true );
- assertTrue(((Boolean)field.get(cloned)).booleanValue());
- field = clazz.getDeclaredField("projectedSymbols"); //$NON-NLS-1$
- field.setAccessible( true );
- assertNotNull(field.get(cloned));
- }
-
- /**
* Test cloning obj with mostly null state, test for NPE
*/
public void testCloneMethod3() {
- CreateUpdateProcedureCommand s1 = new CreateUpdateProcedureCommand();
- CreateUpdateProcedureCommand s2 = (CreateUpdateProcedureCommand)s1.clone();
+ CreateProcedureCommand s1 = new CreateProcedureCommand();
+ CreateProcedureCommand s2 = (CreateProcedureCommand)s1.clone();
UnitTestUtil.helpTestEquivalence(0, s1, s2);
}
public void testProjectedSymbols() {
- CreateUpdateProcedureCommand cupc = new CreateUpdateProcedureCommand();
+ CreateProcedureCommand cupc = new CreateProcedureCommand();
cupc.setUpdateProcedure(false);
StoredProcedure sp = (StoredProcedure)TestResolver.helpResolve("call TEIIDSP9(p1=>1, p2=>?)", RealMetadataFactory.exampleBQTCached());
sp.setCallableStatement(true);
Modified: trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -37,58 +37,15 @@
import org.teiid.query.parser.QueryParser;
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.sql.LanguageObject;
-import org.teiid.query.sql.lang.BetweenCriteria;
-import org.teiid.query.sql.lang.Command;
-import org.teiid.query.sql.lang.CompareCriteria;
-import org.teiid.query.sql.lang.CompoundCriteria;
-import org.teiid.query.sql.lang.Criteria;
-import org.teiid.query.sql.lang.Delete;
-import org.teiid.query.sql.lang.DynamicCommand;
-import org.teiid.query.sql.lang.ExistsCriteria;
-import org.teiid.query.sql.lang.From;
-import org.teiid.query.sql.lang.GroupBy;
-import org.teiid.query.sql.lang.Insert;
-import org.teiid.query.sql.lang.IsNullCriteria;
-import org.teiid.query.sql.lang.JoinPredicate;
-import org.teiid.query.sql.lang.JoinType;
-import org.teiid.query.sql.lang.Limit;
-import org.teiid.query.sql.lang.MatchCriteria;
-import org.teiid.query.sql.lang.NotCriteria;
-import org.teiid.query.sql.lang.Option;
-import org.teiid.query.sql.lang.OrderBy;
-import org.teiid.query.sql.lang.Query;
-import org.teiid.query.sql.lang.SPParameter;
-import org.teiid.query.sql.lang.Select;
-import org.teiid.query.sql.lang.SetCriteria;
-import org.teiid.query.sql.lang.SetQuery;
-import org.teiid.query.sql.lang.StoredProcedure;
-import org.teiid.query.sql.lang.SubqueryCompareCriteria;
-import org.teiid.query.sql.lang.SubqueryFromClause;
-import org.teiid.query.sql.lang.SubquerySetCriteria;
-import org.teiid.query.sql.lang.UnaryFromClause;
-import org.teiid.query.sql.lang.Update;
+import org.teiid.query.sql.lang.*;
import org.teiid.query.sql.lang.SetQuery.Operation;
import org.teiid.query.sql.proc.AssignmentStatement;
import org.teiid.query.sql.proc.Block;
import org.teiid.query.sql.proc.CommandStatement;
-import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.proc.CreateProcedureCommand;
import org.teiid.query.sql.proc.DeclareStatement;
import org.teiid.query.sql.proc.RaiseErrorStatement;
-import org.teiid.query.sql.symbol.AggregateSymbol;
-import org.teiid.query.sql.symbol.AliasSymbol;
-import org.teiid.query.sql.symbol.CaseExpression;
-import org.teiid.query.sql.symbol.Constant;
-import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.query.sql.symbol.Expression;
-import org.teiid.query.sql.symbol.ExpressionSymbol;
-import org.teiid.query.sql.symbol.Function;
-import org.teiid.query.sql.symbol.GroupSymbol;
-import org.teiid.query.sql.symbol.MultipleElementSymbol;
-import org.teiid.query.sql.symbol.Reference;
-import org.teiid.query.sql.symbol.ScalarSubquery;
-import org.teiid.query.sql.symbol.SearchedCaseExpression;
-import org.teiid.query.sql.symbol.TestCaseExpression;
-import org.teiid.query.sql.symbol.TestSearchedCaseExpression;
+import org.teiid.query.sql.symbol.*;
import org.teiid.query.unittest.RealMetadataFactory;
@SuppressWarnings("nls")
@@ -1453,8 +1410,8 @@
b.addStatement(cmdStmt);
b.addStatement(assigStmt);
b.addStatement(errStmt);
- CreateUpdateProcedureCommand cup = new CreateUpdateProcedureCommand(b);
- helpTest(cup, "CREATE PROCEDURE\nBEGIN\nDELETE FROM g;\na = 1;\nERROR 'My Error';\nEND"); //$NON-NLS-1$
+ CreateProcedureCommand cup = new CreateProcedureCommand(b);
+ helpTest(cup, "CREATE VIRTUAL PROCEDURE\nBEGIN\nDELETE FROM g;\na = 1;\nERROR 'My Error';\nEND"); //$NON-NLS-1$
}
@Test public void testCreateUpdateProcedure2() {
@@ -1467,8 +1424,8 @@
b.addStatement(cmdStmt);
b.addStatement(assigStmt);
b.addStatement(errStmt);
- CreateUpdateProcedureCommand cup = new CreateUpdateProcedureCommand(b);
- helpTest(cup, "CREATE PROCEDURE\nBEGIN\nDELETE FROM g;\na = 1;\nERROR 'My Error';\nEND"); //$NON-NLS-1$
+ CreateProcedureCommand cup = new CreateProcedureCommand(b);
+ helpTest(cup, "CREATE VIRTUAL PROCEDURE\nBEGIN\nDELETE FROM g;\na = 1;\nERROR 'My Error';\nEND"); //$NON-NLS-1$
}
@Test public void testCreateUpdateProcedure3() {
@@ -1481,8 +1438,8 @@
b.addStatement(cmdStmt);
b.addStatement(assigStmt);
b.addStatement(errStmt);
- CreateUpdateProcedureCommand cup = new CreateUpdateProcedureCommand(b);
- helpTest(cup, "CREATE PROCEDURE\nBEGIN\nDELETE FROM g;\na = 1;\nERROR 'My Error';\nEND"); //$NON-NLS-1$
+ CreateProcedureCommand cup = new CreateProcedureCommand(b);
+ helpTest(cup, "CREATE VIRTUAL PROCEDURE\nBEGIN\nDELETE FROM g;\na = 1;\nERROR 'My Error';\nEND"); //$NON-NLS-1$
}
@Test public void testSubqueryCompareCriteria1() {
Modified: trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2011-11-22 12:49:12 UTC (rev 3682)
+++ trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2011-11-22 12:55:13 UTC (rev 3683)
@@ -916,7 +916,6 @@
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
@@ -932,7 +931,6 @@
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
procedure = procedure + "var1 = Select pm1.g1.e2, pm1.g1.e1 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
@@ -948,7 +946,6 @@
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
procedure = procedure + "var1 = Select pm1.g1.e2, pm1.g1.e1 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
@@ -963,7 +960,6 @@
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "DECLARE string MaxTran;\n"; //$NON-NLS-1$
procedure = procedure + "MaxTran = SELECT MAX(e1) FROM pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
String userQuery = "UPDATE vm1.g3 SET x='x' where y = 1"; //$NON-NLS-1$
@@ -978,7 +974,6 @@
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "DECLARE string var;\n"; //$NON-NLS-1$
procedure = procedure + "var = null;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
String userQuery = "UPDATE vm1.g3 SET x='x' where y = 1"; //$NON-NLS-1$
@@ -995,7 +990,6 @@
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "var1 = SELECT COUNT(*) FROM myCursor;\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = 0;\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
String userQuery = "UPDATE vm1.g3 SET x='x' where y = 1"; //$NON-NLS-1$
@@ -1028,10 +1022,10 @@
}
@Test public void testSelectIntoTempGroup() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ String procedure = "CREATE VIRTUAL PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "SELECT e1, e2, e3, e4 INTO #myTempTable FROM pm1.g2;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = SELECT COUNT(*) FROM #myTempTable;\n"; //$NON-NLS-1$
+ procedure = procedure + "SELECT COUNT(*) FROM #myTempTable;\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
String userQuery = "UPDATE vm1.g3 SET x='x' where y = 1"; //$NON-NLS-1$
@@ -1048,7 +1042,7 @@
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "SELECT e1, e2, e3, e4 INTO #myTempTable FROM pm1.g2;\n"; //$NON-NLS-1$
procedure = procedure + "SELECT e1, e2, e3 INTO #myTempTable FROM pm1.g2;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = SELECT COUNT(*) FROM #myTempTable;\n"; //$NON-NLS-1$
+ procedure = procedure + "SELECT COUNT(*) FROM #myTempTable;\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
String userQuery = "UPDATE vm1.g3 SET x='x' where y = 1"; //$NON-NLS-1$
@@ -1057,15 +1051,12 @@
Table.TriggerEvent.UPDATE);
}
- /**
- * Defect 24346 with type mismatch
- */
@Test public void testInvalidSelectIntoTempGroup1() {
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "create local temporary table #myTempTable (e1 integer);\n"; //$NON-NLS-1$
procedure = procedure + "SELECT e1 INTO #myTempTable FROM pm1.g2;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = SELECT COUNT(*) FROM #myTempTable;\n"; //$NON-NLS-1$
+ procedure = procedure + "SELECT COUNT(*) FROM #myTempTable;\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
String userQuery = "UPDATE vm1.g3 SET x='x' where y = 1"; //$NON-NLS-1$
@@ -1081,7 +1072,6 @@
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "SELECT e1, e2, e3, e4 INTO pm1.g1 FROM pm1.g2;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = 0;\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
String userQuery = "UPDATE vm1.g3 SET x='x' where y = 1"; //$NON-NLS-1$
@@ -1104,7 +1094,6 @@
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "SELECT e1, e2, e3, e4, 'val' INTO pm1.g1 FROM pm1.g2;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = 0;\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
String userQuery = "UPDATE vm1.g3 SET x='x' where y = 1"; //$NON-NLS-1$
@@ -1119,7 +1108,6 @@
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "SELECT e1, e2, e3 INTO pm1.g1 FROM pm1.g2;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = 0;\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
String userQuery = "UPDATE vm1.g3 SET x='x' where y = 1"; //$NON-NLS-1$
@@ -1134,7 +1122,6 @@
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "SELECT e1, convert(e2, string), e3, e4 INTO pm1.g1 FROM pm1.g2;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = 0;\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
String userQuery = "UPDATE vm1.g3 SET x='x' where y = 1"; //$NON-NLS-1$
@@ -1153,7 +1140,6 @@
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "SELECT * INTO pm1.g1 FROM pm1.g2, pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = 0;\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
String userQuery = "UPDATE vm1.g3 SET x='x' where y = 1"; //$NON-NLS-1$
@@ -1168,7 +1154,6 @@
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "SELECT e1, e2, e3, e4 INTO vm1.g1 FROM pm1.g2;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = 0;\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
String userQuery = "UPDATE vm1.g3 SET x='x' where y = 1"; //$NON-NLS-1$
13 years, 1 month
teiid SVN: r3682 - trunk/documentation/caching-guide/src/main/docbook/en-US/content.
by teiid-commits@lists.jboss.org
Author: van.halbert
Date: 2011-11-22 07:49:12 -0500 (Tue, 22 Nov 2011)
New Revision: 3682
Modified:
trunk/documentation/caching-guide/src/main/docbook/en-US/content/results.xml
Log:
TEIID-1844 added the missing right paren in the example
Modified: trunk/documentation/caching-guide/src/main/docbook/en-US/content/results.xml
===================================================================
--- trunk/documentation/caching-guide/src/main/docbook/en-US/content/results.xml 2011-11-22 01:39:42 UTC (rev 3681)
+++ trunk/documentation/caching-guide/src/main/docbook/en-US/content/results.xml 2011-11-22 12:49:12 UTC (rev 3682)
@@ -55,7 +55,7 @@
</para>
<example>
<title>Advanced ResultSet Caching</title>
- <programlisting>/*+ cache(pref_mem ttl:60000 */ select col from t</programlisting>
+ <programlisting>/*+ cache(pref_mem ttl:60000) */ select col from t</programlisting>
<para>In this example the memory preference has been enabled and the time to live is set to 60000 milliseconds or 1 minute.
The ttl for an entry is actually treated as it's maximum age and the entry may be purged sooner if the maximum number of cache entries has been reached.</para>
</example>
13 years, 1 month
teiid SVN: r3681 - branches/7.6.x/engine/src/main/java/org/teiid/query/optimizer/relational.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-11-21 20:39:42 -0500 (Mon, 21 Nov 2011)
New Revision: 3681
Modified:
branches/7.6.x/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java
Log:
TEIID-1846 fix for access pattern failure. the unit test was committed to trunk
Modified: branches/7.6.x/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java
===================================================================
--- branches/7.6.x/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java 2011-11-21 23:03:58 UTC (rev 3680)
+++ branches/7.6.x/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java 2011-11-22 01:39:42 UTC (rev 3681)
@@ -623,7 +623,7 @@
if (c != null) {
if (c instanceof TriggerAction) {
TriggerAction ta = (TriggerAction)c;
- ProcessorPlan plan = new TriggerActionPlanner().optimize(container, ta, idGenerator, metadata, capFinder, analysisRecord, context);
+ ProcessorPlan plan = new TriggerActionPlanner().optimize((ProcedureContainer) container.clone(), ta, idGenerator, metadata, capFinder, analysisRecord, context);
sourceNode.setProperty(NodeConstants.Info.PROCESSOR_PLAN, plan);
return true;
}
13 years, 1 month
teiid SVN: r3680 - in trunk: documentation/reference/src/main/docbook/en-US/content and 31 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-11-21 18:03:58 -0500 (Mon, 21 Nov 2011)
New Revision: 3680
Removed:
trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolveVirtualGroupCriteriaVisitor.java
trunk/engine/src/main/java/org/teiid/query/sql/proc/CriteriaSelector.java
trunk/engine/src/main/java/org/teiid/query/sql/proc/HasCriteria.java
trunk/engine/src/main/java/org/teiid/query/sql/proc/TranslateCriteria.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/CriteriaTranslatorVisitor.java
trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCriteriaSelector.java
trunk/engine/src/test/java/org/teiid/query/sql/proc/TestHasCriteria.java
trunk/engine/src/test/java/org/teiid/query/sql/proc/TestTranslateCriteria.java
Modified:
trunk/build/kits/jboss-container/teiid-releasenotes.html
trunk/documentation/reference/src/main/docbook/en-US/content/procedures.xml
trunk/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java
trunk/engine/src/main/java/org/teiid/query/optimizer/QueryOptimizer.java
trunk/engine/src/main/java/org/teiid/query/optimizer/TriggerActionPlanner.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/JoinUtil.java
trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
trunk/engine/src/main/java/org/teiid/query/processor/proc/ExecDynamicSqlInstruction.java
trunk/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java
trunk/engine/src/main/java/org/teiid/query/resolver/ProcedureContainerResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/command/InsertResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java
trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java
trunk/engine/src/main/java/org/teiid/query/sql/ProcedureReservedWords.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/Delete.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/Insert.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/ProcedureContainer.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/StoredProcedure.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/TranslatableProcedureContainer.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/Update.java
trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/AbstractSymbolMappingVisitor.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
trunk/engine/src/main/resources/org/teiid/query/i18n.properties
trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
trunk/engine/src/test/java/org/teiid/query/optimizer/proc/TestProcedurePlanner.java
trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestCalculateCostUtil.java
trunk/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java
trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java
trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java
trunk/engine/src/test/java/org/teiid/query/resolver/TestProcedureResolving.java
trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java
trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
trunk/engine/src/test/java/org/teiid/query/sql/proc/TestIfStatement.java
trunk/engine/src/test/java/org/teiid/query/sql/proc/TestWhileStatement.java
trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java
trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestStaticSymbolMappingVisitor.java
trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java
Log:
TEIID-1842 initial removal of translate based update procedures
Modified: trunk/build/kits/jboss-container/teiid-releasenotes.html
===================================================================
--- trunk/build/kits/jboss-container/teiid-releasenotes.html 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/build/kits/jboss-container/teiid-releasenotes.html 2011-11-21 23:03:58 UTC (rev 3680)
@@ -10,7 +10,7 @@
<P><A HREF="http://www.teiid.org/"><IMG SRC="https://www.jboss.org/dms/teiid/images/teiid-banner.png" NAME="graphics1" ALT="Teiid" ALIGN=BOTTOM WIDTH=800></A>
<H1>Teiid ${project.version} Release Notes</H1>
-<P>Teiid ${project.version} adds performance and integration features.
+<P>Teiid ${project.version} is the first Teiid release compatible with JBoss AS 7.x.
<H2>Overview</H2>
<UL>
@@ -26,35 +26,20 @@
</UL>
<H2><A NAME="Highlights"></A>Highlights</H2>
<UL>
- <LI><B>Procedure language features</B> - Added support for compound/block statements, BEGIN [[NOT] ATOMIC], loop/block labels, and the leave statement. See the reference for more.
- <LI><B>File Enhancements</B> - the file translator can now optionally (via the ExceptionIfFileNotFound property) throw an exception if the path refers to a file that doesn't exist. The file resource adapter can be configured to map file names and can prevent parent path .. references. See the Admin Guide or the file-ds.xml template for more.
- <LI><B>TEXTTABLE Enhancements</B> - TEXTTABLE can now parse fixed width files that do not use a row delimiter and can optionally produce fixed values that haven't been trimmed.
- <LI><B>Temp table transactions</B> - Internal materialized views and temp table usage from a session and within procedures can take advantage of greater transaction support.
- <LI><B>Buffering Improvements</B>
- <ul>
- <li>Added the ability to inline memory based or small lobs.
- <li>Added tracking of the memory held by soft references and general batch overhead. This ensures more efficient cache/memory utilization when dealing with 10s of millions or more of batches/pages.
- <li>Also switched to a concurrent LFRU algorithm that significantly reduces writes and read misses with temporary tables.
- <li>Added a memory buffer to better handle file storage as fixed blocks. The memory buffer may optionally be configured as off-heap for better large memory performance - see the Admin Guide for more.
- <li>Serialization was improved for both internal batches and client/server batches.
- </ul>
- <LI><B>GSSAPI</B> - both the Teiid JDBC client/server and the ODBC pg backend can now support GSSAPI for single sign-on.
- <LI><B>Server-side Query Timeouts</B> - default query timeouts can be configured at both the VDB (via the query-timeout VDB property) and entire server (via the teiid-jboss-beans.xml query-timeout property).
- <LI><B>Native Queries</B> - added the ability to specify native query SQL for JDBC physical tables and stored procedures via extension metadata. See the Reference for more.
- <LI><B>View removal hint</B> - the NO_UNNEST hint now also applies to FROM clause views and subqueries. It will instruct the planner to not perform view flattening.
- <LI><B>Non-blocking statement execution</B> - Teiid JDBC extensions TeiidStatement and TeiidPreparedStatement can be used to submit queries against embedded connections with a callback to process results in a non-blocking manner.
- <LI><B>NON_STRICT limit hint</B> - the NON_STRICT hint can be used with unordered limits to tell the optimizer to not inhibit push operations even if the results will not be consistent with the logical application of the limit.
- <LI><B>Source Hints</B> - user and transformation queries can specify a meta source hint, e.g. SELECT /*+ sh my-oracle:'leading' */ * FROM TBL. The hint information will be passed to the translator. The Oracle translator will by default treat the source hint as an Oracle hint. See the Reference and Developers Guide for more.
- <LI><B>Hive Translator</B> - Hive translator has been added as a technology preview.
+ <LI><B>CallableStatement Named Parameters</B> - you can now use CallableStatement named parameter get/set methods.
</UL>
<h2><a name="Compatibility">Compatibility Issues</a></h2>
<ul>
- <li>TRANSLATE/HAS CRITERIA has been deprecated. An alternative approach to update procedures will be introduced in a subsequent version.
<li>Support for named parameter syntax using param=value has been deprecated, since it is ambiguous with a comparison predicate boolean value expression. param<b>=></b>value should be used instead.
<li>Support for using the FROM clause post item hints MAKEDEP/MAKENOTDEP has been deprecated. Use the pre item comment hint syntax instead, e.g. /*+ MAKEDEP */ tbl
</ul>
+<h4>from 7.6</h4>
+<ul>
+ <li>TRANSLATE/HAS CRITERIA has been removed. INSTEAD OF trigger actions should be used instead. INPUTS and INPUT are no longer procedure reserved words.
+</ul>
+
<h4>from 7.5</h4>
<ul>
<li>Leave was added as a reserved word.
Modified: trunk/documentation/reference/src/main/docbook/en-US/content/procedures.xml
===================================================================
--- trunk/documentation/reference/src/main/docbook/en-US/content/procedures.xml 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/documentation/reference/src/main/docbook/en-US/content/procedures.xml 2011-11-21 23:03:58 UTC (rev 3680)
@@ -622,206 +622,5 @@
</example>
</section>
</section>
- <section>
- <title>Create Procedure</title>
- <para>Update procedures defined by "CREATE PROCEDURE ..." have been deprecated.
- The TRANSLATE CRITERIA mechanism and associated logic is typically not adequite to correctly define an updatable view.</para>
- <section>
- <title>Definition</title>
- <para>
- Usage:
- <synopsis label="Usage" >CREATE PROCEDURE
- BEGIN
- ...
- END</synopsis>
- </para>
- <para>The CREATE PROCEDURE line demarcates the beginning of
- the procedure. The BEGIN and END keywords are used to denote block
- boundaries. Within the body of the procedure, any valid <link linkend="procedure_language">statement</link> may be used.
- </para>
- </section>
- <section>
- <title>Special Variables</title>
- <para>You can use a number of special variables when defining your update procedure.</para>
- <section id="input_variables">
- <title>INPUT Variables</title>
- <para>Every attribute in the view whose UPDATE and INSERT transformations you are defining has an equivalent variable named INPUTS.<column_name></para>
- <para>When an INSERT or an UPDATE command is executed against the view, these variables are initialized to the values in the INSERT VALUES clause or the UPDATE SET clause respectively.</para>
- <para>In an UPDATE procedure, the default value of these variables, if they are not set by the command, is null. In an INSERT procedure, the default value of these variables is the default value of the virtual table attributes, based on their defined types. See CHANGING Variables for distinguishing defaults from passed values.</para>
- <warning>
- <para>In prior release of Teiid INPUT was also accepted as the quailifer for an input variable. As of Teidd 7, INPUT is a reserved word, so INPUTS is the preferred qualifier.</para>
- </warning>
- </section>
- <section>
- <title>CHANGING Variables</title>
- <para>Similar to INPUT Variables, every attribute in the view whose UPDATE and INSERT transformations you are defining has an equivalent variable named CHANGING.<column_name></para>
- <para>When an INSERT or an UPDATE command is executed against the view, these variables are initialized to <literal>true</literal> or <literal>false</literal> depending on whether the INPUT variable was set by the command.</para>
- <para>For example, for a view with columns A, B, C:</para>
- <informaltable>
- <tgroup cols="2">
- <thead>
- <row>
- <entry>If User Executes...</entry>
- <entry>Then...</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry><code>INSERT INTO VT (A, B) VALUES (0, 1)</code></entry>
- <entry>CHANGING.A = true, CHANGING.B = true, CHANGING.C = false</entry>
- </row>
- <row>
- <entry><code>UPDATE VT SET C = 2</code></entry>
- <entry>CHANGING.A = false, CHANGING.B = false, CHANGING.C = true</entry>
- </row>
- </tbody>
- </tgroup>
- </informaltable>
- </section>
- <section id="rowsupdated_variable">
- <title>ROWS_UPDATED Variable</title>
- <para> Teiid returns the value of the integer VARIABLES.ROWS_UPDATED variable as a response to an update command executed against
- the view. Your procedure must set the value that returns
- when an application executes an update command against the view,
- which triggers invocation of the update procedure. For
- example, if an UPDATE command is issued that affects 5 records, the
- ROWS_UPDATED should be set appropriately so that the user will
- receive '5' for the count of records affected.</para>
- <example>
- <title>Sample Usage</title>
- <programlisting language="SQL"><![CDATA[...
- UPDATE FOO SET X = 1 WHERE TRANSLATE CRITERIA;
- VARIABLES.ROWS_UPDATED = VARIABLES.ROWCOUNT;
- ...]]></programlisting>
- </example>
- </section>
- </section>
- <section>
- <title>Update Procedure Command Criteria</title>
- <para> You can use a number of special SQL clauses when defining
- UPDATE or DELETE procedures. These make it easier to do variable
- substitutions in WHERE clauses or to check on the change state of
- variables without using a lot of conditional logic.</para>
- <section>
- <title>HAS CRITERIA</title>
- <warning><para>HAS CRITERIA has been deprecated. An alternative approach to update procedures will be introduced in a subsequent version.</para></warning>
- <para>You can use the HAS CRITERIA clause to check whether the user’s command has a particular kind of criteria on a particular set of attributes. This clause evaluates to either true or false. You can use it anywhere you can use a criteria within a procedure.</para>
- <para>
- Usage:
- <synopsis>HAS [criteria operator] CRITERIA [ON (column list)]</synopsis>
- </para>
- <itemizedlist>
- <para>Syntax Rules</para>
- <listitem>
- <para>The criteria operator, can be one of =, <, >, <=, >=, <>, LIKE, IS NULL, or IN.
- </para>
- </listitem>
- <listitem>
- <para>If the ON clause is present, HAS CRITERIA will return true only if criteria was present on all of the specified columns.
- </para>
- </listitem>
- <listitem>
- <para>The columns in a HAS CRITERIA ON clause always refer to view columns.
- </para>
- </listitem>
- </itemizedlist>
- <para>Each unoptimized conjunct of the user criteria is evaluated against the criteria selector. If any conjunct matches then HAS CRITERIA evaluates to TRUE. The use of OR or NOT will prevent contained predicates from matching the criteria selector.</para>
- <para>Some samples of the HAS CRITERIA clause:</para>
- <informaltable>
- <tgroup cols="2">
- <thead>
- <row>
- <entry>SQL</entry>
- <entry>Result</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry><code>HAS CRITERIA</code></entry>
- <entry>Checks simply whether there was any criteria at all.</entry>
- </row>
- <row>
- <entry><code>HAS CRITERIA ON (column1, column2)</code></entry>
- <entry>Checks whether the criteria uses column1 and column2.</entry>
- </row>
- <row>
- <entry><code>HAS = CRITERIA ON (column1)</code></entry>
- <entry>Checks whether the criteria has a comparison criteria with = operator.</entry>
- </row>
- <row>
- <entry><code>HAS LIKE CRITERIA</code></entry>
- <entry>Checks whether the criteria has a match criteria using LIKE.</entry>
- </row>
- </tbody>
- </tgroup>
- </informaltable>
- <para>The HAS CRITERIA predicate is most commonly used in
- an IF clause, to determine if the user issued a particular form of
- command and to respond appropriately.</para>
- </section>
- <section>
- <title>TRANSLATE CRITERIA</title>
- <warning><para>TRANSLATE CRITERIA has been deprecated. An alternative approach to update procedures will be introduced in a subsequent version.</para></warning>
- <para>You can use the TRANSLATE CRITERIA clause to convert the criteria from the user application’s SQL command into the form required to interact with the target source or view tables. The TRANSLATE CRITERIA statement uses the SELECT transformation to infer the column mapping. This clause evaluates to a translated criteria that is evaluated in the context of a command.
- You can use these mappings either to replace the default mappings generated from the SELECT transformation or to specify a reverse expression when a virtual column is defined by an expression.</para>
- <para>
- Usage:
- <synopsis>TRANSLATE [criteria operator] CRITERIA [ON (column list)] [WITH (mapping list)]</synopsis>
- </para>
- <para>If there is no user criteria, then the translated criteria is always treated as TRUE.</para>
- <itemizedlist>
- <para>Syntax Rules</para>
- <listitem>
- <para>The criteria operator, can be one of =, <, >, <=, >=, <>, LIKE, IS NULL, or IN.
- </para>
- </listitem>
- <listitem>
- <para>If the ON clause is present, TRANSLATE CRITERIA will only form criteria using the specified columns.
- </para>
- </listitem>
- <listitem>
- <para>The columns in a TRANSLATE CRITERIA ON clause always refer to view columns.
- </para>
- </listitem>
- <listitem>
- <para>The WITH clause always has items with form <elem> = <expression> where the left hand side must refer to a view column.
- </para>
- </listitem>
- <listitem>
- <para>If the WITH clause or a specific mapping is not specified, then a mapping is created based on the SELECT clause of the SELECT transformation (the view column gets mapped to expression in SELECT clause at same position).
- </para>
- </listitem>
- </itemizedlist>
- <para>Each unoptimized conjunct of the user criteria is translated using the criteria selector. If a conjunct does not match the selector, it will not be translated - which effectively treats the conjunct as TRUE. The use of OR or NOT will prevent contained predicates from matching the criteria selector.</para>
- <para>Some samples of TRANSLATE CRITERIA:</para>
- <informaltable>
- <tgroup cols="2">
- <colspec colwidth="1*"/>
- <colspec colwidth="1*"/>
- <thead>
- <row>
- <entry>SQL</entry>
- <entry>Result</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry><code>TRANSLATE CRITERIA</code></entry>
- <entry>Translates any user criteria using the default mappings.</entry>
- </row>
- <row>
- <entry>TRANSLATE CRITERIA WITH (column1 = 'A', column2 = INPUTS.column2 + 2)</entry>
- <entry>Translates any criteria with some additional mappings: column1 is always mapped to 'A' and column2 is mapped to the incoming column2 value + 2.</entry>
- </row>
- <row>
- <entry><code>TRANSLATE = CRITERIA ON (column1)</code></entry>
- <entry>Translates only criteria that have = comparison operator and involve column1.</entry>
- </row>
- </tbody>
- </tgroup>
- </informaltable>
- </section>
- </section>
- </section>
</section>
</chapter>
\ No newline at end of file
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -23,7 +23,10 @@
package org.teiid.dqp.internal.process;
import java.io.Serializable;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import org.teiid.adminapi.Admin;
@@ -330,13 +333,6 @@
this.modTime = modTime;
}
- public Set<CacheID> replicatableKeys() {
- if (this.distributedCache == this.localCache) {
- return Collections.EMPTY_SET;
- }
- return this.distributedCache.keys();
- }
-
public static Collection<String> getCacheTypes(){
ArrayList<String> caches = new ArrayList<String>();
caches.add(Admin.Cache.PREPARED_PLAN_CACHE.toString());
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/QueryOptimizer.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/QueryOptimizer.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/QueryOptimizer.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -22,7 +22,6 @@
package org.teiid.query.optimizer;
-import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -54,10 +53,8 @@
import org.teiid.query.sql.lang.Query;
import org.teiid.query.sql.lang.SPParameter;
import org.teiid.query.sql.lang.StoredProcedure;
-import org.teiid.query.sql.lang.TranslatableProcedureContainer;
import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.util.CommandContext;
@@ -143,7 +140,6 @@
ProcedureContainer container = (ProcedureContainer)cupc.getUserCommand();
ProcedurePlan plan = (ProcedurePlan)result;
if (container != null) {
- LinkedHashMap<ElementSymbol, Expression> params = container.getProcedureParameters();
if (container instanceof StoredProcedure) {
plan.setRequiresTransaction(container.getUpdateCount() > 0);
StoredProcedure sp = (StoredProcedure)container;
@@ -164,12 +160,9 @@
plan.setOutParams(outParams);
}
}
+ plan.setParams(sp.getProcedureParameters());
}
- plan.setParams(params);
plan.setMetadata(metadata);
- if (container instanceof TranslatableProcedureContainer) {
- plan.setImplicitParams(((TranslatableProcedureContainer)container).getImplicitParams());
- }
}
break;
case Command.TYPE_BATCHED_UPDATE:
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/TriggerActionPlanner.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/TriggerActionPlanner.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/TriggerActionPlanner.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -46,17 +46,7 @@
import org.teiid.query.resolver.util.ResolverUtil;
import org.teiid.query.rewriter.QueryRewriter;
import org.teiid.query.sql.LanguageObject;
-import org.teiid.query.sql.ProcedureReservedWords;
-import org.teiid.query.sql.lang.Delete;
-import org.teiid.query.sql.lang.From;
-import org.teiid.query.sql.lang.Insert;
-import org.teiid.query.sql.lang.ProcedureContainer;
-import org.teiid.query.sql.lang.Query;
-import org.teiid.query.sql.lang.QueryCommand;
-import org.teiid.query.sql.lang.Select;
-import org.teiid.query.sql.lang.TranslatableProcedureContainer;
-import org.teiid.query.sql.lang.UnaryFromClause;
-import org.teiid.query.sql.lang.Update;
+import org.teiid.query.sql.lang.*;
import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
import org.teiid.query.sql.proc.TriggerAction;
import org.teiid.query.sql.symbol.ElementSymbol;
@@ -72,7 +62,7 @@
public ProcessorPlan optimize(ProcedureContainer userCommand, TriggerAction ta, IDGenerator idGenerator, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, AnalysisRecord analysisRecord, CommandContext context)
throws QueryMetadataException, TeiidComponentException, QueryResolverException, TeiidProcessingException {
//TODO consider caching the plans without using the changing vars
- QueryRewriter.rewrite(ta, null, metadata, context, QueryResolver.getVariableValues(userCommand, true, metadata), userCommand.getType());
+ QueryRewriter.rewrite(ta, metadata, context, QueryResolver.getVariableValues(userCommand, true, metadata));
QueryCommand query = null;
Map<ElementSymbol, Expression> params = new HashMap<ElementSymbol, Expression>();
@@ -94,11 +84,9 @@
}
for (Map.Entry<ElementSymbol, Expression> entry : QueryResolver.getVariableValues(userCommand, false, metadata).entrySet()) {
- if (entry.getKey().getGroupSymbol().getShortName().equalsIgnoreCase(ProcedureReservedWords.INPUTS)) {
+ if (entry.getKey().getGroupSymbol().getShortName().equalsIgnoreCase(SQLConstants.Reserved.NEW)) {
Expression value = entry.getValue() instanceof SingleElementSymbol ? entry.getValue() : new ExpressionSymbol("x", entry.getValue()); //$NON-NLS-1$
- ElementSymbol newElementSymbol = entry.getKey().clone();
- newElementSymbol.getGroupSymbol().setName(SQLConstants.Reserved.NEW);
- params.put(newElementSymbol, value);
+ params.put(entry.getKey(), value);
if (userCommand instanceof Update) {
((Query)query).getSelect().addSymbol((SelectSymbol) value);
}
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -22,17 +22,7 @@
package org.teiid.query.optimizer.relational;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryPlannerException;
@@ -81,51 +71,11 @@
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.LanguageVisitor;
import org.teiid.query.sql.LanguageObject.Util;
-import org.teiid.query.sql.lang.CacheHint;
-import org.teiid.query.sql.lang.Command;
-import org.teiid.query.sql.lang.Criteria;
-import org.teiid.query.sql.lang.Delete;
-import org.teiid.query.sql.lang.ExistsCriteria;
-import org.teiid.query.sql.lang.From;
-import org.teiid.query.sql.lang.FromClause;
-import org.teiid.query.sql.lang.GroupBy;
-import org.teiid.query.sql.lang.Insert;
-import org.teiid.query.sql.lang.JoinPredicate;
-import org.teiid.query.sql.lang.JoinType;
-import org.teiid.query.sql.lang.Limit;
-import org.teiid.query.sql.lang.Option;
-import org.teiid.query.sql.lang.OrderBy;
-import org.teiid.query.sql.lang.ProcedureContainer;
-import org.teiid.query.sql.lang.Query;
-import org.teiid.query.sql.lang.QueryCommand;
-import org.teiid.query.sql.lang.Select;
-import org.teiid.query.sql.lang.SetQuery;
-import org.teiid.query.sql.lang.SourceHint;
-import org.teiid.query.sql.lang.StoredProcedure;
-import org.teiid.query.sql.lang.SubqueryContainer;
-import org.teiid.query.sql.lang.SubqueryFromClause;
-import org.teiid.query.sql.lang.TableFunctionReference;
-import org.teiid.query.sql.lang.TargetedCommand;
-import org.teiid.query.sql.lang.TranslatableProcedureContainer;
-import org.teiid.query.sql.lang.UnaryFromClause;
-import org.teiid.query.sql.lang.Update;
-import org.teiid.query.sql.lang.WithQueryCommand;
+import org.teiid.query.sql.lang.*;
import org.teiid.query.sql.navigator.PreOrPostOrderNavigator;
import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
import org.teiid.query.sql.proc.TriggerAction;
-import org.teiid.query.sql.symbol.AggregateSymbol;
-import org.teiid.query.sql.symbol.AliasSymbol;
-import org.teiid.query.sql.symbol.Constant;
-import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.query.sql.symbol.Expression;
-import org.teiid.query.sql.symbol.ExpressionSymbol;
-import org.teiid.query.sql.symbol.GroupSymbol;
-import org.teiid.query.sql.symbol.MultipleElementSymbol;
-import org.teiid.query.sql.symbol.Reference;
-import org.teiid.query.sql.symbol.ScalarSubquery;
-import org.teiid.query.sql.symbol.SelectSymbol;
-import org.teiid.query.sql.symbol.SingleElementSymbol;
-import org.teiid.query.sql.symbol.WindowFunction;
+import org.teiid.query.sql.symbol.*;
import org.teiid.query.sql.util.SymbolMap;
import org.teiid.query.sql.visitor.AggregateSymbolCollectorVisitor;
import org.teiid.query.sql.visitor.CorrelatedReferenceCollectorVisitor;
@@ -605,15 +555,16 @@
if (c != null) {
if (c instanceof TriggerAction) {
TriggerAction ta = (TriggerAction)c;
- ProcessorPlan plan = new TriggerActionPlanner().optimize(container, ta, idGenerator, metadata, capFinder, analysisRecord, context);
+ ProcessorPlan plan = new TriggerActionPlanner().optimize((ProcedureContainer)container.clone(), ta, idGenerator, metadata, capFinder, analysisRecord, context);
sourceNode.setProperty(NodeConstants.Info.PROCESSOR_PLAN, plan);
return true;
}
if (c.getCacheHint() != null) {
if (container instanceof StoredProcedure) {
- boolean noCache = isNoCacheGroup(metadata, ((StoredProcedure) container).getProcedureID(), option);
+ StoredProcedure sp = (StoredProcedure)container;
+ boolean noCache = isNoCacheGroup(metadata, sp.getProcedureID(), option);
if (!noCache) {
- if (context.isResultSetCacheEnabled() && container.areResultsCachable() && LobManager.getLobIndexes(new ArrayList<ElementSymbol>(container.getProcedureParameters().keySet())) == null) {
+ if (context.isResultSetCacheEnabled() && container.areResultsCachable() && LobManager.getLobIndexes(new ArrayList<ElementSymbol>(sp.getProcedureParameters().keySet())) == null) {
container.getGroup().setGlobalTable(true);
container.setCacheHint(c.getCacheHint());
recordAnnotation(analysisRecord, Annotation.CACHED_PROCEDURE, Priority.LOW, "SimpleQueryResolver.procedure_cache_used", container.getGroup()); //$NON-NLS-1$
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -345,7 +345,7 @@
}
// Simplify criteria if possible
try {
- return QueryRewriter.rewriteCriteria(criteria, null, null, metadata);
+ return QueryRewriter.rewriteCriteria(criteria, null, metadata);
} catch(TeiidProcessingException e) {
throw new QueryPlannerException(e, QueryPlugin.Util.getString("ERR.015.004.0023", criteria)); //$NON-NLS-1$
} catch (TeiidComponentException e) {
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/JoinUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/JoinUtil.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/JoinUtil.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -140,7 +140,7 @@
Criteria crit) {
Criteria simplifiedCrit = (Criteria)replaceWithNullValues(innerGroups, crit);
try {
- simplifiedCrit = QueryRewriter.rewriteCriteria(simplifiedCrit, null, null, metadata);
+ simplifiedCrit = QueryRewriter.rewriteCriteria(simplifiedCrit, null, metadata);
} catch (TeiidException err) {
//log the exception
return true;
Modified: trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -35,6 +35,7 @@
import org.teiid.query.QueryPlugin;
import org.teiid.query.function.FunctionMethods;
import org.teiid.query.sql.lang.CacheHint;
+import org.teiid.query.sql.lang.CompareCriteria;
import org.teiid.query.sql.lang.FromClause;
import org.teiid.query.sql.lang.JoinType;
import org.teiid.query.sql.lang.Limit;
@@ -44,7 +45,6 @@
import org.teiid.query.sql.lang.SourceHint;
import org.teiid.query.sql.lang.ExistsCriteria.SubqueryHint;
import org.teiid.query.sql.proc.Block;
-import org.teiid.query.sql.proc.CriteriaSelector;
import org.teiid.query.sql.proc.Statement;
public class SQLParserUtil {
@@ -338,25 +338,17 @@
int getOperator(String opString) {
if (opString.equals("=")) { //$NON-NLS-1$
- return CriteriaSelector.COMPARE_EQ;
+ return CompareCriteria.EQ;
} else if (opString.equals("<>") || opString.equals("!=")) { //$NON-NLS-1$ //$NON-NLS-2$
- return CriteriaSelector.COMPARE_NE;
+ return CompareCriteria.NE;
} else if (opString.equals("<")) { //$NON-NLS-1$
- return CriteriaSelector.COMPARE_LT;
+ return CompareCriteria.LT;
} else if (opString.equals(">")) { //$NON-NLS-1$
- return CriteriaSelector.COMPARE_GT;
+ return CompareCriteria.GT;
} else if (opString.equals("<=")) { //$NON-NLS-1$
- return CriteriaSelector.COMPARE_LE;
+ return CompareCriteria.LE;
} else if (opString.equals(">=")) { //$NON-NLS-1$
- return CriteriaSelector.COMPARE_GE;
- } else if (opString.equalsIgnoreCase("like")) { //$NON-NLS-1$
- return CriteriaSelector.LIKE;
- } else if (opString.equalsIgnoreCase("in")) { //$NON-NLS-1$
- return CriteriaSelector.IN;
- } else if (opString.equalsIgnoreCase("is")) { //$NON-NLS-1$
- return CriteriaSelector.IS_NULL;
- } else if (opString.equalsIgnoreCase("between")) { //$NON-NLS-1$
- return CriteriaSelector.BETWEEN;
+ return CompareCriteria.GE;
}
Assertion.failed("unknown operator"); //$NON-NLS-1$
Modified: trunk/engine/src/main/java/org/teiid/query/processor/proc/ExecDynamicSqlInstruction.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/proc/ExecDynamicSqlInstruction.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/processor/proc/ExecDynamicSqlInstruction.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -52,7 +52,6 @@
import org.teiid.query.parser.QueryParser;
import org.teiid.query.processor.ProcessorPlan;
import org.teiid.query.resolver.QueryResolver;
-import org.teiid.query.resolver.util.ResolveVirtualGroupCriteriaVisitor;
import org.teiid.query.rewriter.QueryRewriter;
import org.teiid.query.sql.ProcedureReservedWords;
import org.teiid.query.sql.lang.Command;
@@ -160,21 +159,13 @@
command.addExternalGroupToContext(using);
}
- // Resolve any groups
- if (parentProcCommand.isUpdateProcedure()) {
- ResolveVirtualGroupCriteriaVisitor.resolveCriteria(command,
- parentProcCommand.getVirtualGroup(), metadata);
- }
-
QueryResolver.resolveCommand(command, metadata.getDesignTimeMetadata());
validateDynamicCommand(procEnv, command);
// create a new set of variables including vars
Map<ElementSymbol, Expression> nameValueMap = createVariableValuesMap(localContext);
- nameValueMap.putAll(QueryResolver.getVariableValues(parentProcCommand.getUserCommand(), false, metadata));
ValidationVisitor visitor = new ValidationVisitor();
- visitor.setUpdateProc(parentProcCommand);
Request.validateWithVisitor(visitor, metadata, command);
if (dynamicCommand.getAsColumns() != null
@@ -187,8 +178,8 @@
}
}
- command = QueryRewriter.rewrite(command, parentProcCommand, metadata,
- procEnv.getContext(), nameValueMap, parentProcCommand.getUserCommand().getType());
+ command = QueryRewriter.rewrite(command, metadata, procEnv.getContext(),
+ nameValueMap);
ProcessorPlan commandPlan = QueryOptimizer.optimizePlan(command, metadata,
idGenerator, capFinder, AnalysisRecord
Modified: trunk/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -73,7 +73,6 @@
import org.teiid.query.sql.lang.Criteria;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
-import org.teiid.query.sql.symbol.Reference;
import org.teiid.query.sql.util.VariableContext;
import org.teiid.query.tempdata.TempTableStore;
import org.teiid.query.util.CommandContext;
@@ -107,7 +106,6 @@
private boolean lastBatch = false;
private LinkedHashMap<ElementSymbol, Expression> params;
private List<ElementSymbol> outParams;
- private Map<ElementSymbol, Reference> implicitParams;
private QueryMetadataInterface metadata;
private Map<String, CursorState> cursorStates = new HashMap<String, CursorState>();
@@ -249,13 +247,6 @@
setParameterValue(param, context, 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.push(originalProgram);
}
this.evaluatedParams = true;
@@ -429,7 +420,6 @@
plan.setOutputElements(this.getOutputElements());
plan.setParams(params);
plan.setOutParams(outParams);
- plan.setImplicitParams(implicitParams);
plan.setMetadata(metadata);
plan.requiresTransaction = requiresTransaction;
return plan;
@@ -494,10 +484,6 @@
this.params = params;
}
- public void setImplicitParams(Map<ElementSymbol, Reference> implicitParams) {
- this.implicitParams = implicitParams;
- }
-
private void createVariableContext() {
this.currentVarContext = new VariableContext(true);
this.currentVarContext.setValue(ROWS_UPDATED, 0);
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/ProcedureContainerResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/ProcedureContainerResolver.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/ProcedureContainerResolver.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -119,7 +119,7 @@
List<ElementSymbol> changingElements = new ArrayList<ElementSymbol>(elements.size());
for(int i=0; i<elements.size(); i++) {
ElementSymbol virtualElmnt = elements.get(i);
- ElementSymbol changeElement = (ElementSymbol)virtualElmnt.clone();
+ ElementSymbol changeElement = virtualElmnt.clone();
changeElement.setType(DataTypeManager.DefaultDataClasses.BOOLEAN);
changingElements.add(changeElement);
}
@@ -278,34 +278,10 @@
}
ProcedureContainerResolver.addScalarGroup(procName, childMetadata, externalGroups, tempElements, updatable);
- } else if (type != Command.TYPE_DELETE) {
- createInputChangingMetadata(childMetadata, tma, container, externalGroups);
}
}
QueryResolver.setChildMetadata(currentCommand, childMetadata.getData(), externalGroups);
}
- static void createInputChangingMetadata(
- TempMetadataStore discoveredMetadata,
- QueryMetadataInterface metadata, GroupSymbol group, GroupContext externalGroups)
- throws QueryMetadataException, TeiidComponentException {
- //Look up elements for the virtual group
- List<ElementSymbol> elements = ResolverUtil.resolveElementsInGroup(group, metadata);
-
- // Create the INPUT variables
- List<ElementSymbol> inputElments = new ArrayList<ElementSymbol>(elements.size());
- for(int i=0; i<elements.size(); i++) {
- ElementSymbol virtualElmnt = elements.get(i);
- ElementSymbol inputElement = (ElementSymbol)virtualElmnt.clone();
- inputElments.add(inputElement);
- }
-
- ProcedureContainerResolver.addScalarGroup(ProcedureReservedWords.INPUT, discoveredMetadata, externalGroups, inputElments, false);
- ProcedureContainerResolver.addScalarGroup(ProcedureReservedWords.INPUTS, discoveredMetadata, externalGroups, inputElments, false);
-
- // Switch type to be boolean for all CHANGING variables
- ProcedureContainerResolver.addChanging(discoveredMetadata, externalGroups, elements);
- }
-
}
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -48,21 +48,9 @@
import org.teiid.query.metadata.TempMetadataID;
import org.teiid.query.metadata.TempMetadataStore;
import org.teiid.query.parser.QueryParser;
-import org.teiid.query.resolver.command.AlterResolver;
-import org.teiid.query.resolver.command.BatchedUpdateResolver;
-import org.teiid.query.resolver.command.DeleteResolver;
-import org.teiid.query.resolver.command.DynamicCommandResolver;
-import org.teiid.query.resolver.command.ExecResolver;
-import org.teiid.query.resolver.command.InsertResolver;
-import org.teiid.query.resolver.command.SetQueryResolver;
-import org.teiid.query.resolver.command.SimpleQueryResolver;
-import org.teiid.query.resolver.command.TempTableResolver;
-import org.teiid.query.resolver.command.UpdateProcedureResolver;
-import org.teiid.query.resolver.command.UpdateResolver;
-import org.teiid.query.resolver.command.XMLQueryResolver;
+import org.teiid.query.resolver.command.*;
import org.teiid.query.resolver.util.ResolverUtil;
import org.teiid.query.resolver.util.ResolverVisitor;
-import org.teiid.query.sql.ProcedureReservedWords;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.Criteria;
import org.teiid.query.sql.lang.From;
@@ -97,7 +85,8 @@
*/
public class QueryResolver {
- private static final CommandResolver SIMPLE_QUERY_RESOLVER = new SimpleQueryResolver();
+ private static final String BINDING_GROUP = "INPUTS"; //$NON-NLS-1$
+ private static final CommandResolver SIMPLE_QUERY_RESOLVER = new SimpleQueryResolver();
private static final CommandResolver SET_QUERY_RESOLVER = new SetQueryResolver();
private static final CommandResolver XML_QUERY_RESOLVER = new XMLQueryResolver();
private static final CommandResolver EXEC_RESOLVER = new ExecResolver();
@@ -195,8 +184,7 @@
ResolverVisitor.resolveLanguageObject(elementSymbol, metadata);
elementSymbol.setIsExternalReference(true);
if (!positional) {
- symbolMap.put(new ElementSymbol(ProcedureReservedWords.INPUT + ElementSymbol.SEPARATOR + name), elementSymbol.clone());
- symbolMap.put(new ElementSymbol(ProcedureReservedWords.INPUTS + ElementSymbol.SEPARATOR + name), elementSymbol.clone());
+ symbolMap.put(new ElementSymbol(BINDING_GROUP + ElementSymbol.SEPARATOR + name), elementSymbol.clone());
elementSymbol.setShortName(name);
}
elements.add(elementSymbol);
@@ -221,8 +209,8 @@
GroupContext externalGroups = new GroupContext();
- ProcedureContainerResolver.addScalarGroup(ProcedureReservedWords.INPUT, rootExternalStore, externalGroups, elements);
- ProcedureContainerResolver.addScalarGroup(ProcedureReservedWords.INPUTS, rootExternalStore, externalGroups, elements);
+ ProcedureContainerResolver.addScalarGroup("INPUT", rootExternalStore, externalGroups, elements); //$NON-NLS-1$
+ ProcedureContainerResolver.addScalarGroup(BINDING_GROUP, rootExternalStore, externalGroups, elements);
QueryResolver.setChildMetadata(currentCommand, rootExternalStore.getData(), externalGroups);
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/command/InsertResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/command/InsertResolver.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/command/InsertResolver.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -36,6 +36,7 @@
import org.teiid.core.TeiidComponentException;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.Assertion;
+import org.teiid.language.SQLConstants;
import org.teiid.query.QueryPlugin;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.metadata.TempMetadataAdapter;
@@ -263,7 +264,7 @@
result.put(varSymbol, new Constant(Boolean.TRUE));
if (!changingOnly) {
varSymbol = varSymbol.clone();
- varSymbol.getGroupSymbol().setName(ProcedureReservedWords.INPUTS);
+ varSymbol.getGroupSymbol().setName(SQLConstants.Reserved.NEW);
result.put(varSymbol, (Expression)valIter.next());
}
}
@@ -281,7 +282,7 @@
if (!changingOnly) {
Expression value = ResolverUtil.getDefault(varSymbol, metadata);
varSymbol = varSymbol.clone();
- varSymbol.getGroupSymbol().setName(ProcedureReservedWords.INPUTS);
+ varSymbol.getGroupSymbol().setName(SQLConstants.Reserved.NEW);
result.put(varSymbol, value);
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -27,19 +27,15 @@
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryResolverException;
-import org.teiid.api.exception.query.QueryValidatorException;
import org.teiid.api.exception.query.UnresolvedSymbolDescription;
import org.teiid.client.metadata.ParameterInfo;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.types.DataTypeManager;
-import org.teiid.language.SQLConstants;
import org.teiid.logging.LogManager;
import org.teiid.query.QueryPlugin;
-import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.metadata.SupportConstants;
import org.teiid.query.metadata.TempMetadataAdapter;
import org.teiid.query.metadata.TempMetadataID;
@@ -47,10 +43,8 @@
import org.teiid.query.resolver.CommandResolver;
import org.teiid.query.resolver.ProcedureContainerResolver;
import org.teiid.query.resolver.QueryResolver;
-import org.teiid.query.resolver.util.ResolveVirtualGroupCriteriaVisitor;
import org.teiid.query.resolver.util.ResolverUtil;
import org.teiid.query.resolver.util.ResolverVisitor;
-import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.ProcedureReservedWords;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.Criteria;
@@ -59,22 +53,11 @@
import org.teiid.query.sql.lang.SPParameter;
import org.teiid.query.sql.lang.StoredProcedure;
import org.teiid.query.sql.lang.SubqueryContainer;
-import org.teiid.query.sql.proc.AssignmentStatement;
-import org.teiid.query.sql.proc.Block;
-import org.teiid.query.sql.proc.CommandStatement;
-import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
-import org.teiid.query.sql.proc.DeclareStatement;
-import org.teiid.query.sql.proc.ExpressionStatement;
-import org.teiid.query.sql.proc.IfStatement;
-import org.teiid.query.sql.proc.LoopStatement;
-import org.teiid.query.sql.proc.Statement;
-import org.teiid.query.sql.proc.TriggerAction;
-import org.teiid.query.sql.proc.WhileStatement;
+import org.teiid.query.sql.proc.*;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.symbol.SingleElementSymbol;
-import org.teiid.query.sql.util.SymbolMap;
import org.teiid.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
@@ -82,32 +65,6 @@
*/
public class UpdateProcedureResolver implements CommandResolver {
- public void resolveVirtualGroupElements(CreateUpdateProcedureCommand procCommand, QueryMetadataInterface metadata)
- throws QueryMetadataException, QueryResolverException, TeiidComponentException {
-
- // virtual group on procedure
- GroupSymbol virtualGroup = procCommand.getVirtualGroup();
-
- if (!metadata.isVirtualGroup(virtualGroup.getMetadataID())) {
- //if this is a compensating procedure, just return
- return;
- }
-
- ResolveVirtualGroupCriteriaVisitor.resolveCriteria(procCommand, virtualGroup, metadata);
-
- // get a symbol map between virtual elements and the elements that define
- // then in the query transformation, this info is used in evaluating/validating
- // has criteria/translate criteria clauses
- Command transformCmd;
- try {
- transformCmd = QueryResolver.resolveView(virtualGroup, metadata.getVirtualPlan(virtualGroup.getMetadataID()), SQLConstants.Reserved.SELECT, metadata).getCommand();
- } catch (QueryValidatorException e) {
- throw new QueryResolverException(e, e.getMessage());
- }
- Map<ElementSymbol, Expression> symbolMap = SymbolMap.createSymbolMap(virtualGroup, LanguageObject.Util.deepClone(transformCmd.getProjectedSymbols(), SingleElementSymbol.class), metadata).asMap();
- procCommand.setSymbolMap(symbolMap);
- }
-
/**
* @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command, TempMetadataAdapter, boolean)
*/
@@ -129,8 +86,6 @@
// virtual group elements in HAS and TRANSLATE criteria have to be resolved
if(procCommand.isUpdateProcedure()){
- resolveVirtualGroupElements(procCommand, metadata);
-
//add the default variables
String countVar = ProcedureReservedWords.VARIABLES + ElementSymbol.SEPARATOR + ProcedureReservedWords.ROWS_UPDATED;
ElementSymbol updateCount = new ElementSymbol(countVar);
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateResolver.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateResolver.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -33,6 +33,7 @@
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryResolverException;
import org.teiid.core.TeiidComponentException;
+import org.teiid.language.SQLConstants;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.metadata.TempMetadataAdapter;
import org.teiid.query.resolver.ProcedureContainerResolver;
@@ -105,7 +106,7 @@
result.put(leftSymbol, new Constant(Boolean.TRUE));
if (!changingOnly) {
leftSymbol = leftSymbol.clone();
- leftSymbol.getGroupSymbol().setName(ProcedureReservedWords.INPUTS);
+ leftSymbol.getGroupSymbol().setName(SQLConstants.Reserved.NEW);
result.put(leftSymbol, entry.getValue());
}
}
Deleted: trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolveVirtualGroupCriteriaVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolveVirtualGroupCriteriaVisitor.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolveVirtualGroupCriteriaVisitor.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -1,116 +0,0 @@
-/*
- * 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 org.teiid.query.resolver.util;
-
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-
-import org.teiid.api.exception.query.QueryResolverException;
-import org.teiid.core.TeiidComponentException;
-import org.teiid.core.TeiidRuntimeException;
-import org.teiid.query.metadata.QueryMetadataInterface;
-import org.teiid.query.sql.LanguageObject;
-import org.teiid.query.sql.LanguageVisitor;
-import org.teiid.query.sql.lang.CompareCriteria;
-import org.teiid.query.sql.navigator.DeepPreOrderNavigator;
-import org.teiid.query.sql.proc.CriteriaSelector;
-import org.teiid.query.sql.proc.TranslateCriteria;
-import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.query.sql.symbol.GroupSymbol;
-
-
-/**
- */
-public class ResolveVirtualGroupCriteriaVisitor extends LanguageVisitor {
-
- private List virtualGroup;
-
- private QueryMetadataInterface metadata;
-
- /**
- * Constructor for ResolveElementsVisitor with no specified groups. In this
- * case every element's group will be looked up based on the group name.
- * @param iterator
- */
- public ResolveVirtualGroupCriteriaVisitor(GroupSymbol virtualGroup, QueryMetadataInterface metadata) {
- this.virtualGroup = Arrays.asList(new Object[] {virtualGroup});
- this.metadata = metadata;
- }
-
- public void visit(TranslateCriteria obj) {
- if(obj.hasTranslations()) {
- Iterator transIter = obj.getTranslations().iterator();
- while(transIter.hasNext()) {
- CompareCriteria ccrit = (CompareCriteria) transIter.next();
- ElementSymbol element = (ElementSymbol) ccrit.getLeftExpression();
- try {
- ResolverVisitor.resolveLanguageObject(element, virtualGroup, metadata);
- } catch(QueryResolverException e) {
- throw new TeiidRuntimeException(e);
- } catch(TeiidComponentException e) {
- throw new TeiidRuntimeException(e);
- }
- }
- }
- }
-
- public void visit(CriteriaSelector obj) {
- if(obj.hasElements()) {
- Iterator elmntIter = obj.getElements().iterator();
- while(elmntIter.hasNext()) {
- ElementSymbol virtualElement = (ElementSymbol) elmntIter.next();
- try {
- ResolverVisitor.resolveLanguageObject(virtualElement, virtualGroup, metadata);
- } catch(QueryResolverException e) {
- throw new TeiidRuntimeException(e);
- } catch(TeiidComponentException e) {
- throw new TeiidRuntimeException(e);
- }
- }
- }
- }
-
- public static void resolveCriteria(LanguageObject obj, GroupSymbol virtualGroup, QueryMetadataInterface metadata)
- throws TeiidComponentException, QueryResolverException {
- if(obj == null) {
- return;
- }
-
- // Resolve elements, deal with errors
- ResolveVirtualGroupCriteriaVisitor resolveVisitor = new ResolveVirtualGroupCriteriaVisitor(virtualGroup, metadata);
-
- try {
- DeepPreOrderNavigator.doVisit(obj, resolveVisitor);
- } catch (TeiidRuntimeException e) {
- if (e.getChild() instanceof QueryResolverException) {
- throw (QueryResolverException)e.getChild();
- }
- if (e.getChild() instanceof TeiidComponentException) {
- throw (TeiidComponentException)e.getChild();
- }
- throw e;
- }
- }
-
-}
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -47,31 +47,9 @@
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.LanguageVisitor;
-import org.teiid.query.sql.ProcedureReservedWords;
-import org.teiid.query.sql.lang.BetweenCriteria;
-import org.teiid.query.sql.lang.CompareCriteria;
-import org.teiid.query.sql.lang.ExpressionCriteria;
-import org.teiid.query.sql.lang.GroupContext;
-import org.teiid.query.sql.lang.IsNullCriteria;
-import org.teiid.query.sql.lang.MatchCriteria;
-import org.teiid.query.sql.lang.SetClause;
-import org.teiid.query.sql.lang.SetCriteria;
-import org.teiid.query.sql.lang.SubqueryCompareCriteria;
-import org.teiid.query.sql.lang.SubquerySetCriteria;
+import org.teiid.query.sql.lang.*;
import org.teiid.query.sql.navigator.PostOrderNavigator;
-import org.teiid.query.sql.symbol.AggregateSymbol;
-import org.teiid.query.sql.symbol.CaseExpression;
-import org.teiid.query.sql.symbol.Constant;
-import org.teiid.query.sql.symbol.DerivedColumn;
-import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.query.sql.symbol.Expression;
-import org.teiid.query.sql.symbol.Function;
-import org.teiid.query.sql.symbol.GroupSymbol;
-import org.teiid.query.sql.symbol.QueryString;
-import org.teiid.query.sql.symbol.Reference;
-import org.teiid.query.sql.symbol.SearchedCaseExpression;
-import org.teiid.query.sql.symbol.XMLQuery;
-import org.teiid.query.sql.symbol.XMLSerialize;
+import org.teiid.query.sql.symbol.*;
import org.teiid.query.sql.symbol.ElementSymbol.DisplayMode;
@@ -217,15 +195,6 @@
resolveAgainstGroups(shortCanonicalName, matchedGroups, matches);
if (matches.size() > 1) {
- if (isExternal && matches.size() == 2) {
- if ((isScalar(matches.get(0).element, ProcedureReservedWords.INPUTS) && isScalar(matches.get(1).element, ProcedureReservedWords.INPUT))) {
- matches.removeLast();
- break;
- } else if (isScalar(matches.get(1).element, ProcedureReservedWords.INPUTS) && isScalar(matches.get(0).element, ProcedureReservedWords.INPUT)) {
- matches.removeFirst();
- break;
- }
- }
throw handleUnresolvedElement(elementSymbol, QueryPlugin.Util.getString("ERR.015.008.0053", elementSymbol)); //$NON-NLS-1$
}
@@ -253,14 +222,6 @@
if (expectedGroupContext != null && !ResolverUtil.nameMatchesGroup(expectedGroupContext, resolvedGroup.getCanonicalName())) {
return false;
}
- if (isExternal //convert input to inputs
- && isScalar(resolvedSymbol, ProcedureReservedWords.INPUT)) {
- resolvedSymbol = new ElementSymbol(shortCanonicalName);
- resolvedSymbol.setGroupSymbol(new GroupSymbol(ProcedureReservedWords.INPUTS));
- resolveElementSymbol(resolvedSymbol);
- oldName = resolvedSymbol.getOutputName();
- resolvedGroup = resolvedSymbol.getGroupSymbol();
- }
elementSymbol.setIsExternalReference(isExternal);
elementSymbol.setType(resolvedSymbol.getType());
elementSymbol.setMetadataID(resolvedSymbol.getMetadataID());
@@ -271,11 +232,6 @@
return true;
}
- private boolean isScalar(ElementSymbol resolvedSymbol, String group) throws QueryMetadataException, TeiidComponentException {
- return metadata.isScalarGroup(resolvedSymbol.getGroupSymbol().getMetadataID())
- && group.equals(resolvedSymbol.getGroupSymbol().getCanonicalName());
- }
-
private void resolveAgainstGroups(String elementShortName,
Collection<GroupSymbol> matchedGroups, LinkedList<ElementMatch> matches) throws QueryMetadataException,
TeiidComponentException {
@@ -953,7 +909,7 @@
// 2. Attempt to set the target types of all contained expressions,
// and collect their type names for the next step
- ArrayList thenTypeNames = new ArrayList(whenCount + 1);
+ ArrayList<String> thenTypeNames = new ArrayList<String>(whenCount + 1);
Expression then = null;
// Set the types of the WHEN and THEN parts
for (int i = 0; i < whenCount; i++) {
@@ -974,7 +930,7 @@
// Invariants: all the expressions' types are non-null
// 3. Perform implicit type conversions
- String thenTypeName = ResolverUtil.getCommonType((String[])thenTypeNames.toArray(new String[thenTypeNames.size()]));
+ String thenTypeName = ResolverUtil.getCommonType(thenTypeNames.toArray(new String[thenTypeNames.size()]));
if (thenTypeName == null) {
throw new QueryResolverException("ERR.015.008.0068", QueryPlugin.Util.getString("ERR.015.008.0068", "THEN/ELSE", obj)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
Modified: trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -27,19 +27,7 @@
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.StringTokenizer;
+import java.util.*;
import org.teiid.api.exception.query.ExpressionEvaluationException;
import org.teiid.api.exception.query.FunctionExecutionException;
@@ -74,90 +62,19 @@
import org.teiid.query.resolver.ProcedureContainerResolver;
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.resolver.util.ResolverUtil;
-import org.teiid.query.resolver.util.ResolverVisitor;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.ProcedureReservedWords;
import org.teiid.query.sql.LanguageObject.Util;
-import org.teiid.query.sql.lang.AbstractSetCriteria;
-import org.teiid.query.sql.lang.ArrayTable;
-import org.teiid.query.sql.lang.BatchedUpdateCommand;
-import org.teiid.query.sql.lang.BetweenCriteria;
-import org.teiid.query.sql.lang.Command;
-import org.teiid.query.sql.lang.CompareCriteria;
-import org.teiid.query.sql.lang.CompoundCriteria;
-import org.teiid.query.sql.lang.Criteria;
-import org.teiid.query.sql.lang.Delete;
-import org.teiid.query.sql.lang.DependentSetCriteria;
-import org.teiid.query.sql.lang.ExistsCriteria;
-import org.teiid.query.sql.lang.ExpressionCriteria;
-import org.teiid.query.sql.lang.From;
-import org.teiid.query.sql.lang.FromClause;
-import org.teiid.query.sql.lang.GroupBy;
-import org.teiid.query.sql.lang.Insert;
-import org.teiid.query.sql.lang.Into;
-import org.teiid.query.sql.lang.IsNullCriteria;
-import org.teiid.query.sql.lang.JoinPredicate;
-import org.teiid.query.sql.lang.JoinType;
-import org.teiid.query.sql.lang.Limit;
-import org.teiid.query.sql.lang.MatchCriteria;
-import org.teiid.query.sql.lang.NotCriteria;
-import org.teiid.query.sql.lang.OrderBy;
-import org.teiid.query.sql.lang.OrderByItem;
-import org.teiid.query.sql.lang.ProcedureContainer;
-import org.teiid.query.sql.lang.Query;
-import org.teiid.query.sql.lang.QueryCommand;
-import org.teiid.query.sql.lang.SPParameter;
-import org.teiid.query.sql.lang.Select;
-import org.teiid.query.sql.lang.SetClause;
-import org.teiid.query.sql.lang.SetClauseList;
-import org.teiid.query.sql.lang.SetCriteria;
-import org.teiid.query.sql.lang.SetQuery;
-import org.teiid.query.sql.lang.StoredProcedure;
-import org.teiid.query.sql.lang.SubqueryCompareCriteria;
-import org.teiid.query.sql.lang.SubqueryContainer;
-import org.teiid.query.sql.lang.SubqueryFromClause;
-import org.teiid.query.sql.lang.SubquerySetCriteria;
-import org.teiid.query.sql.lang.TextTable;
-import org.teiid.query.sql.lang.TranslatableProcedureContainer;
-import org.teiid.query.sql.lang.UnaryFromClause;
-import org.teiid.query.sql.lang.Update;
-import org.teiid.query.sql.lang.WithQueryCommand;
-import org.teiid.query.sql.lang.XMLTable;
+import org.teiid.query.sql.lang.*;
import org.teiid.query.sql.lang.PredicateCriteria.Negatable;
import org.teiid.query.sql.navigator.DeepPostOrderNavigator;
import org.teiid.query.sql.navigator.PostOrderNavigator;
-import org.teiid.query.sql.proc.AssignmentStatement;
-import org.teiid.query.sql.proc.Block;
-import org.teiid.query.sql.proc.CommandStatement;
-import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
-import org.teiid.query.sql.proc.CriteriaSelector;
-import org.teiid.query.sql.proc.ExpressionStatement;
-import org.teiid.query.sql.proc.HasCriteria;
-import org.teiid.query.sql.proc.IfStatement;
-import org.teiid.query.sql.proc.LoopStatement;
-import org.teiid.query.sql.proc.Statement;
-import org.teiid.query.sql.proc.TranslateCriteria;
-import org.teiid.query.sql.proc.TriggerAction;
-import org.teiid.query.sql.proc.WhileStatement;
-import org.teiid.query.sql.symbol.AggregateSymbol;
-import org.teiid.query.sql.symbol.AliasSymbol;
-import org.teiid.query.sql.symbol.CaseExpression;
-import org.teiid.query.sql.symbol.Constant;
-import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.query.sql.symbol.Expression;
-import org.teiid.query.sql.symbol.ExpressionSymbol;
-import org.teiid.query.sql.symbol.Function;
-import org.teiid.query.sql.symbol.GroupSymbol;
-import org.teiid.query.sql.symbol.Reference;
-import org.teiid.query.sql.symbol.ScalarSubquery;
-import org.teiid.query.sql.symbol.SearchedCaseExpression;
-import org.teiid.query.sql.symbol.SingleElementSymbol;
+import org.teiid.query.sql.proc.*;
+import org.teiid.query.sql.symbol.*;
import org.teiid.query.sql.symbol.AggregateSymbol.Type;
import org.teiid.query.sql.util.SymbolMap;
import org.teiid.query.sql.visitor.AggregateSymbolCollectorVisitor;
import org.teiid.query.sql.visitor.CorrelatedReferenceCollectorVisitor;
-import org.teiid.query.sql.visitor.CriteriaTranslatorVisitor;
-import org.teiid.query.sql.visitor.ElementCollectorVisitor;
import org.teiid.query.sql.visitor.EvaluatableVisitor;
import org.teiid.query.sql.visitor.ExpressionMappingVisitor;
import org.teiid.query.sql.visitor.FunctionCollectorVisitor;
@@ -197,40 +114,36 @@
private QueryMetadataInterface metadata;
private CommandContext context;
- private CreateUpdateProcedureCommand procCommand;
private boolean rewriteSubcommands;
private boolean processing;
private Evaluator evaluator;
private Map<ElementSymbol, Expression> variables; //constant propagation
- private int commandType;
private QueryRewriter(QueryMetadataInterface metadata,
- CommandContext context, CreateUpdateProcedureCommand procCommand) {
+ CommandContext context) {
this.metadata = metadata;
this.context = context;
- this.procCommand = procCommand;
this.evaluator = new Evaluator(Collections.emptyMap(), null, context);
}
public static Command evaluateAndRewrite(Command command, Evaluator eval, CommandContext context, QueryMetadataInterface metadata) throws TeiidProcessingException, TeiidComponentException {
- QueryRewriter queryRewriter = new QueryRewriter(metadata, context, null);
+ QueryRewriter queryRewriter = new QueryRewriter(metadata, context);
queryRewriter.evaluator = eval;
queryRewriter.rewriteSubcommands = true;
queryRewriter.processing = true;
return queryRewriter.rewriteCommand(command, false);
}
- public static Command rewrite(Command command, CreateUpdateProcedureCommand procCommand, QueryMetadataInterface metadata, CommandContext context, Map<ElementSymbol, Expression> variableValues, int commandType) throws TeiidComponentException, TeiidProcessingException{
- QueryRewriter rewriter = new QueryRewriter(metadata, context, procCommand);
+ public static Command rewrite(Command command, QueryMetadataInterface metadata, CommandContext context, Map<ElementSymbol, Expression> variableValues) throws TeiidComponentException, TeiidProcessingException{
+ QueryRewriter rewriter = new QueryRewriter(metadata, context);
rewriter.rewriteSubcommands = true;
rewriter.variables = variableValues;
- rewriter.commandType = commandType;
return rewriter.rewriteCommand(command, false);
}
public static Command rewrite(Command command, QueryMetadataInterface metadata, CommandContext context) throws TeiidComponentException, TeiidProcessingException{
- return rewrite(command, null, metadata, context, null, Command.TYPE_UNKNOWN);
+ return rewrite(command, metadata, context, null);
}
/**
@@ -244,7 +157,6 @@
private Command rewriteCommand(Command command, boolean removeOrderBy) throws TeiidComponentException, TeiidProcessingException{
boolean oldRewriteAggs = rewriteAggs;
QueryMetadataInterface oldMetadata = metadata;
- CreateUpdateProcedureCommand oldProcCommand = procCommand;
Map tempMetadata = command.getTemporaryMetadata();
if(tempMetadata != null) {
@@ -285,7 +197,6 @@
command = rewriteDelete((Delete) command);
break;
case Command.TYPE_UPDATE_PROCEDURE:
- procCommand = (CreateUpdateProcedureCommand) command;
command = rewriteUpdateProcedure((CreateUpdateProcedureCommand) command);
break;
case Command.TYPE_BATCHED_UPDATE:
@@ -304,23 +215,13 @@
this.rewriteAggs = oldRewriteAggs;
this.metadata = oldMetadata;
- this.procCommand = oldProcCommand;
return command;
}
private Command rewriteUpdateProcedure(CreateUpdateProcedureCommand command)
throws TeiidComponentException, TeiidProcessingException{
- Map<ElementSymbol, Expression> oldVariables = variables;
- if (command.getUserCommand() != null) {
- variables = QueryResolver.getVariableValues(command.getUserCommand(), false, metadata);
- commandType = command.getUserCommand().getType();
- }
-
Block block = rewriteBlock(command.getBlock());
command.setBlock(block);
-
- variables = oldVariables;
-
return command;
}
@@ -439,163 +340,6 @@
}
}
- /**
- * <p>The HasCriteria evaluates to a TRUE_CRITERIA or a FALSE_CRITERIA, it checks to see
- * if type of criteria on the elements specified by the CriteriaSelector is specified on
- * the user's command.</p>
- */
- private Criteria rewriteCriteria(HasCriteria hasCrit) {
- Criteria userCrit = null;
- Command userCommand = procCommand.getUserCommand();
- int cmdType = userCommand.getType();
- switch(cmdType) {
- case Command.TYPE_DELETE:
- userCrit = ((Delete)userCommand).getCriteria();
- break;
- case Command.TYPE_UPDATE:
- userCrit = ((Update)userCommand).getCriteria();
- break;
- default:
- return FALSE_CRITERIA;
- }
-
- if(userCrit == null) {
- return FALSE_CRITERIA;
- }
-
- // get the CriteriaSelector, elements on the selector and the selector type
- CriteriaSelector selector = hasCrit.getSelector();
-
- Collection hasCritElmts = null;
- if(selector.hasElements()) {
- hasCritElmts = selector.getElements();
- // collect elements present on the user's criteria and check if
- // all of the hasCriteria elements are among them
- Collection<ElementSymbol> userElmnts = ElementCollectorVisitor.getElements(userCrit, true);
- if(!userElmnts.containsAll(hasCritElmts)) {
- return FALSE_CRITERIA;
- }
- }
-
- int selectorType = selector.getSelectorType();
- // if no selector type specified return true
- // already checked all HAS elements present on user criteria
- if(selectorType == CriteriaSelector.NO_TYPE) {
- return TRUE_CRITERIA;
- }
-
- // collect all predicate criteria present on the user's criteria
- for (Criteria predicateCriteria : Criteria.separateCriteriaByAnd(userCrit)) {
- // atleast one of the hasElemnets should be on this predicate else
- // proceed to the next predicate
- Collection<ElementSymbol> predElmnts = ElementCollectorVisitor.getElements(predicateCriteria, true);
- if(selector.hasElements()) {
- Iterator hasIter = hasCritElmts.iterator();
- boolean containsElmnt = false;
- while(hasIter.hasNext()) {
- ElementSymbol hasElmnt = (ElementSymbol) hasIter.next();
- if(predElmnts.contains(hasElmnt)) {
- containsElmnt = true;
- }
- }
-
- if(!containsElmnt) {
- continue;
- }
- }
-
- // check if the predicate criteria type maches the type specified
- // by the criteria selector
- switch(selectorType) {
- case CriteriaSelector.IN:
- if(predicateCriteria instanceof SetCriteria) {
- return TRUE_CRITERIA;
- }
- break;
- case CriteriaSelector.LIKE:
- if(predicateCriteria instanceof MatchCriteria) {
- return TRUE_CRITERIA;
- }
- break;
- case CriteriaSelector.IS_NULL:
- if(predicateCriteria instanceof IsNullCriteria) {
- return TRUE_CRITERIA;
- }
- break;
- case CriteriaSelector.BETWEEN:
- if(predicateCriteria instanceof BetweenCriteria) {
- return TRUE_CRITERIA;
- }
- break;
- default: // EQ, GT, LT, GE, LE criteria
- if(predicateCriteria instanceof CompareCriteria) {
- CompareCriteria compCrit = (CompareCriteria) predicateCriteria;
- if(compCrit.getOperator() == selectorType) {
- return TRUE_CRITERIA;
- }
- }
- break;
- }
- }
-
- return FALSE_CRITERIA;
- }
-
- /**
- * <p>TranslateCriteria is evaluated by translating elements on parts(restricted by the type
- * of criteria and elements specified on the CriteriaSelector) the user's criteria
- * using the translations provided on the TranslateCriteria and symbol mapping between
- * virtual group elements and the expressions on the query transformation defining the
- * virtual group.</p>
- */
- private Criteria rewriteCriteria(TranslateCriteria transCrit)
- throws TeiidComponentException, TeiidProcessingException{
-
- // criteria translated
- Criteria translatedCriteria = null;
-
- // get the user's command from the procedure
- Command userCmd = procCommand.getUserCommand();
-
- if (!(userCmd instanceof TranslatableProcedureContainer)) {
- return FALSE_CRITERIA;
- }
-
- Criteria userCriteria = ((TranslatableProcedureContainer)userCmd).getCriteria();
-
- if (userCriteria == null) {
- return TRUE_CRITERIA;
- }
-
- // get the symbolmap between virtual elements and theie counterpart expressions
- // from the virtual group's query transform
- CriteriaTranslatorVisitor translateVisitor = new CriteriaTranslatorVisitor(procCommand.getSymbolMap());
-
- translateVisitor.setCriteriaSelector(transCrit.getSelector());
- if(transCrit.hasTranslations()) {
- translateVisitor.setTranslations(transCrit.getTranslations());
- }
-
- // create a clone of user's criteria that is then translated
- Criteria userClone = (Criteria) userCriteria.clone();
-
- userClone = translateVisitor.translate(userClone);
-
- // translated criteria
- ((TranslatableProcedureContainer)userCmd).addImplicitParameters(translateVisitor.getImplicitParams());
-
- translatedCriteria = rewriteCriteria(userClone);
-
- // apply any implicit conversions
- try {
- ResolverVisitor.resolveLanguageObject(translatedCriteria, metadata);
- } catch(TeiidException ex) {
- throw new QueryValidatorException(ex, "ERR.015.009.0002", QueryPlugin.Util.getString("ERR.015.009.0002", translatedCriteria)); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- return translatedCriteria;
- }
-
private Command rewriteQuery(Query query)
throws TeiidComponentException, TeiidProcessingException{
@@ -997,8 +741,8 @@
* in the procedural language.
* @return The re-written criteria
*/
- public static Criteria rewriteCriteria(Criteria criteria, CreateUpdateProcedureCommand procCommand, CommandContext context, QueryMetadataInterface metadata) throws TeiidComponentException, TeiidProcessingException{
- return new QueryRewriter(metadata, context, procCommand).rewriteCriteria(criteria);
+ public static Criteria rewriteCriteria(Criteria criteria, CommandContext context, QueryMetadataInterface metadata) throws TeiidComponentException, TeiidProcessingException{
+ return new QueryRewriter(metadata, context).rewriteCriteria(criteria);
}
/**
@@ -1025,10 +769,6 @@
criteria = rewriteCriteria((IsNullCriteria)criteria);
} else if(criteria instanceof BetweenCriteria) {
criteria = rewriteCriteria((BetweenCriteria)criteria);
- } else if(criteria instanceof HasCriteria) {
- criteria = rewriteCriteria((HasCriteria)criteria);
- } else if(criteria instanceof TranslateCriteria) {
- criteria = rewriteCriteria((TranslateCriteria)criteria);
} else if (criteria instanceof ExistsCriteria) {
ExistsCriteria exists = (ExistsCriteria)criteria;
if (exists.shouldEvaluate() && processing) {
@@ -1111,7 +851,7 @@
*/
public static Criteria optimizeCriteria(CompoundCriteria criteria, QueryMetadataInterface metadata) {
try {
- return new QueryRewriter(metadata, null, null).rewriteCriteria(criteria, false);
+ return new QueryRewriter(metadata, null).rewriteCriteria(criteria, false);
} catch (TeiidException err) {
//shouldn't happen
return criteria;
@@ -2133,7 +1873,7 @@
}
public static Expression rewriteExpression(Expression expression, CreateUpdateProcedureCommand procCommand, CommandContext context, QueryMetadataInterface metadata) throws TeiidComponentException, TeiidProcessingException{
- return new QueryRewriter(metadata, context, procCommand).rewriteExpressionDirect(expression);
+ return new QueryRewriter(metadata, context).rewriteExpressionDirect(expression);
}
private Expression rewriteExpressionDirect(Expression expression) throws TeiidComponentException, TeiidProcessingException{
@@ -2151,10 +1891,7 @@
if (value == null) {
if (es.getGroupSymbol().getSchema() == null) {
- String grpName = es.getGroupSymbol().getShortCanonicalName();
- if (grpName.equals(ProcedureReservedWords.INPUTS)) {
- return new Constant(null, es.getType());
- }
+ String grpName = es.getGroupSymbol().getCanonicalName();
if (grpName.equals(ProcedureReservedWords.CHANGING)) {
Assertion.failed("Changing value should not be null"); //$NON-NLS-1$
}
@@ -2813,18 +2550,6 @@
return rewriteInherentUpdate(update, info);
}
- if (commandType == Command.TYPE_UPDATE && variables != null) {
- SetClauseList newChangeList = new SetClauseList();
- for (SetClause entry : update.getChangeList().getClauses()) {
- Expression rightExpr = entry.getValue();
- boolean retainChange = checkInputVariables(rightExpr);
- if (retainChange) {
- newChangeList.addClause(entry.getSymbol(), entry.getValue());
- }
- }
- update.setChangeList(newChangeList);
- }
-
// Evaluate any function on the right side of set clauses
for (SetClause entry : update.getChangeList().getClauses()) {
entry.setValue(rewriteExpressionDirect(entry.getValue()));
@@ -2959,38 +2684,6 @@
return pkCriteria;
}
- /**
- * Checks variables in an expression, if the variables are INPUT variables and if
- * none of them are changing, then this method returns a false, if all of them
- * are changing this returns a true, if some are changing and some are not, then
- * that is an invalid case and the method adds to the list of invalid variables.
- * @throws TeiidComponentException, MetaMatrixProcessingException
- */
- private boolean checkInputVariables(Expression expr) throws TeiidComponentException, TeiidProcessingException{
- Boolean result = null;
- for (ElementSymbol var : ElementCollectorVisitor.getElements(expr, false)) {
- if (var.isExternalReference() && var.getGroupSymbol().getSchema() == null && var.getGroupSymbol().getShortName().equalsIgnoreCase(ProcedureReservedWords.INPUTS)) {
-
- var = var.clone();
- var.getGroupSymbol().setShortName(ProcedureReservedWords.CHANGING);
-
- Boolean changingValue = (Boolean)((Constant)variables.get(var)).getValue();
-
- if (result == null) {
- result = changingValue;
- } else if (!result.equals(changingValue)) {
- throw new QueryValidatorException(QueryPlugin.Util.getString("VariableSubstitutionVisitor.Input_vars_should_have_same_changing_state", expr)); //$NON-NLS-1$
- }
- }
- }
-
- if (result != null) {
- return result.booleanValue();
- }
-
- return true;
- }
-
private Command rewriteDelete(Delete delete) throws TeiidComponentException, TeiidProcessingException{
UpdateInfo info = delete.getUpdateInfo();
if (info != null && info.isInherentDelete()) {
@@ -3046,14 +2739,14 @@
}
public static Command createDeleteProcedure(Delete delete, QueryMetadataInterface metadata, CommandContext context) throws QueryResolverException, QueryMetadataException, TeiidComponentException, TeiidProcessingException {
- QueryRewriter rewriter = new QueryRewriter(metadata, context, null);
+ QueryRewriter rewriter = new QueryRewriter(metadata, context);
Criteria crit = delete.getCriteria();
Query query = new Query(new Select(), new From(Arrays.asList(new UnaryFromClause(delete.getGroup()))), crit, null, null);
return rewriter.createDeleteProcedure(delete, query, delete.getGroup(), delete.getGroup().getName());
}
public static Command createUpdateProcedure(Update update, QueryMetadataInterface metadata, CommandContext context) throws QueryResolverException, QueryMetadataException, TeiidComponentException, TeiidProcessingException {
- QueryRewriter rewriter = new QueryRewriter(metadata, context, null);
+ QueryRewriter rewriter = new QueryRewriter(metadata, context);
Criteria crit = update.getCriteria();
ArrayList<SingleElementSymbol> selectSymbols = rewriter.mapChangeList(update, null);
Query query = new Query(new Select(selectSymbols), new From(Arrays.asList(new UnaryFromClause(update.getGroup()))), crit, null, null);
Modified: trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -71,13 +71,10 @@
import org.teiid.query.sql.proc.BranchingStatement;
import org.teiid.query.sql.proc.CommandStatement;
import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
-import org.teiid.query.sql.proc.CriteriaSelector;
import org.teiid.query.sql.proc.DeclareStatement;
-import org.teiid.query.sql.proc.HasCriteria;
import org.teiid.query.sql.proc.IfStatement;
import org.teiid.query.sql.proc.LoopStatement;
import org.teiid.query.sql.proc.RaiseErrorStatement;
-import org.teiid.query.sql.proc.TranslateCriteria;
import org.teiid.query.sql.proc.TriggerAction;
import org.teiid.query.sql.proc.WhileStatement;
import org.teiid.query.sql.symbol.AggregateSymbol;
@@ -185,14 +182,11 @@
public void visit(Block obj) {}
public void visit(CommandStatement obj) {}
public void visit(CreateUpdateProcedureCommand obj) {}
- public void visit(CriteriaSelector obj) {}
public void visit(DeclareStatement obj) {
visit((AssignmentStatement)obj);
}
- public void visit(HasCriteria obj) {}
public void visit(IfStatement obj) {}
public void visit(RaiseErrorStatement obj) {}
- public void visit(TranslateCriteria obj) {}
public void visit(BranchingStatement obj) {}
public void visit(WhileStatement obj) {}
public void visit(LoopStatement obj) {}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/ProcedureReservedWords.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/ProcedureReservedWords.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/sql/ProcedureReservedWords.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -27,18 +27,12 @@
import java.util.Set;
import org.teiid.language.SQLConstants;
-import org.teiid.language.SQLConstants.Reserved;
/**
* Special variable names in stored procedure language.
*/
public class ProcedureReservedWords {
- @Deprecated
- public static final String INPUT = Reserved.INPUT;
-
- public static final String INPUTS = "INPUTS"; //$NON-NLS-1$
-
public static final String ROWS_UPDATED = "ROWS_UPDATED"; //$NON-NLS-1$
public static final String ROWCOUNT = "ROWCOUNT"; //$NON-NLS-1$
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/Delete.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/Delete.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/Delete.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -22,14 +22,11 @@
package org.teiid.query.sql.lang;
-import java.util.LinkedHashMap;
import java.util.List;
import org.teiid.core.util.EquivalenceUtil;
import org.teiid.core.util.HashCodeUtil;
import org.teiid.query.sql.LanguageVisitor;
-import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.visitor.SQLStringVisitor;
@@ -165,14 +162,6 @@
EquivalenceUtil.areEqual(getCriteria(), other.getCriteria());
}
- /**
- * @see org.teiid.query.sql.lang.ProcedureContainer#getParameters()
- * @since 5.0
- */
- public LinkedHashMap<ElementSymbol, Expression> getProcedureParameters() {
- return new LinkedHashMap<ElementSymbol, Expression>();
- }
-
/**
* Return a copy of this Delete.
*/
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/Insert.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/Insert.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/Insert.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -23,7 +23,6 @@
package org.teiid.query.sql.lang;
import java.util.Collection;
-import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
@@ -32,7 +31,6 @@
import org.teiid.core.util.HashCodeUtil;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.LanguageVisitor;
-import org.teiid.query.sql.ProcedureReservedWords;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
@@ -227,23 +225,6 @@
EquivalenceUtil.areEqual(getQueryExpression(), other.getQueryExpression());
}
- /**
- * @see org.teiid.query.sql.lang.ProcedureContainer#getParameters()
- * @since 5.0
- */
- public LinkedHashMap<ElementSymbol, Expression> getProcedureParameters() {
-
- int iSize = getVariables().size();
- LinkedHashMap<ElementSymbol, Expression> map = new LinkedHashMap<ElementSymbol, Expression>();
-
- for (int j = 0; j < iSize; j++) {
- ElementSymbol symbol = (ElementSymbol)variables.get( j ).clone();
- symbol.setGroupSymbol(new GroupSymbol(ProcedureReservedWords.INPUTS));
- map.put(symbol, values.get( j ) );
- } // for
- return map;
- }
-
/**
* Return a deep copy of this Insert.
* @return Deep copy of Insert
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/ProcedureContainer.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/ProcedureContainer.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/ProcedureContainer.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -22,10 +22,6 @@
package org.teiid.query.sql.lang;
-import java.util.LinkedHashMap;
-
-import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.validator.UpdateValidator.UpdateInfo;
@@ -61,8 +57,6 @@
this.updateCount = updateCount;
}
- public abstract LinkedHashMap<ElementSymbol, Expression> getProcedureParameters();
-
public UpdateInfo getUpdateInfo() {
return updateInfo;
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/StoredProcedure.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/StoredProcedure.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/StoredProcedure.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -396,10 +396,6 @@
this.isCallableStatement = isCallableStatement;
}
- /**
- * @see org.teiid.query.sql.lang.ProcedureContainer#getProcedureParameters()
- * @since 5.0
- */
public LinkedHashMap<ElementSymbol, Expression> getProcedureParameters() {
LinkedHashMap<ElementSymbol, Expression> map = new LinkedHashMap<ElementSymbol, Expression>();
for (SPParameter element : this.getInputParameters()) {
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/TranslatableProcedureContainer.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/TranslatableProcedureContainer.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/TranslatableProcedureContainer.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -22,33 +22,7 @@
package org.teiid.query.sql.lang;
-import java.util.Map;
-
-import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.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();
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/Update.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/Update.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/Update.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -22,14 +22,11 @@
package org.teiid.query.sql.lang;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
import java.util.List;
import org.teiid.core.util.EquivalenceUtil;
import org.teiid.core.util.HashCodeUtil;
import org.teiid.query.sql.LanguageVisitor;
-import org.teiid.query.sql.ProcedureReservedWords;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.GroupSymbol;
@@ -250,24 +247,6 @@
return false;
}
- /**
- * @see org.teiid.query.sql.lang.ProcedureContainer#getProcedureParameters()
- * @since 5.0
- */
- public LinkedHashMap<ElementSymbol, Expression> getProcedureParameters() {
-
- LinkedHashMap<ElementSymbol, Expression> map = new LinkedHashMap<ElementSymbol, Expression>();
-
- for (Iterator<SetClause> iter = getChangeList().getClauses().iterator(); iter.hasNext();) {
- SetClause setClause = iter.next();
- ElementSymbol symbol = setClause.getSymbol().clone();
- symbol.setGroupSymbol(new GroupSymbol(ProcedureReservedWords.INPUTS));
- map.put( symbol, setClause.getValue() );
- }
-
- return map;
- }
-
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -75,13 +75,10 @@
import org.teiid.query.sql.proc.BranchingStatement;
import org.teiid.query.sql.proc.CommandStatement;
import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
-import org.teiid.query.sql.proc.CriteriaSelector;
import org.teiid.query.sql.proc.DeclareStatement;
-import org.teiid.query.sql.proc.HasCriteria;
import org.teiid.query.sql.proc.IfStatement;
import org.teiid.query.sql.proc.LoopStatement;
import org.teiid.query.sql.proc.RaiseErrorStatement;
-import org.teiid.query.sql.proc.TranslateCriteria;
import org.teiid.query.sql.proc.TriggerAction;
import org.teiid.query.sql.proc.WhileStatement;
import org.teiid.query.sql.symbol.AggregateSymbol;
@@ -221,11 +218,6 @@
visitNode(obj.getBlock());
postVisitVisitor(obj);
}
- public void visit(CriteriaSelector obj) {
- preVisitVisitor(obj);
- visitNodes(obj.getElements());
- postVisitVisitor(obj);
- }
public void visit(DeclareStatement obj) {
preVisitVisitor(obj);
visitNode(obj.getVariable());
@@ -284,11 +276,6 @@
preVisitVisitor(obj);
postVisitVisitor(obj);
}
- public void visit(HasCriteria obj) {
- preVisitVisitor(obj);
- visitNode(obj.getSelector());
- postVisitVisitor(obj);
- }
public void visit(IfStatement obj) {
preVisitVisitor(obj);
visitNode(obj.getCondition());
@@ -479,12 +466,6 @@
}
postVisitVisitor(obj);
}
- public void visit(TranslateCriteria obj) {
- preVisitVisitor(obj);
- visitNode(obj.getSelector());
- visitNodes(obj.getTranslations());
- postVisitVisitor(obj);
- }
public void visit(UnaryFromClause obj) {
preVisitVisitor(obj);
visitNode(obj.getGroup());
Deleted: trunk/engine/src/main/java/org/teiid/query/sql/proc/CriteriaSelector.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/proc/CriteriaSelector.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/sql/proc/CriteriaSelector.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -1,228 +0,0 @@
-/*
- * 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 org.teiid.query.sql.proc;
-
-import java.util.*;
-
-import org.teiid.core.util.EquivalenceUtil;
-import org.teiid.core.util.HashCodeUtil;
-import org.teiid.query.sql.*;
-import org.teiid.query.sql.lang.CompareCriteria;
-import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.query.sql.visitor.SQLStringVisitor;
-
-
-/**
- * <p>This class represents the criteria present on the user's query. The type of
- * criteria and the elements on which it is specified are listed in this object,
- * this object is used by <code>HasCriteria</code> and <code>TranslateCriteria</code>
- * objects to determine if a particular type of criteria is present on one or more
- * elements on a user's query</p>
- */
-public class CriteriaSelector implements LanguageObject {
-
- // constant for "=" criteria
- public static final int COMPARE_EQ = CompareCriteria.EQ;
-
- // constant for "<>" criteria
- public static final int COMPARE_NE = CompareCriteria.NE;
-
- // constant for "<" criteria
- public static final int COMPARE_LT = CompareCriteria.LT;
-
- // constant for ">" criteria
- public static final int COMPARE_GT = CompareCriteria.GT;
-
- // constant for "<=" criteria
- public static final int COMPARE_LE = CompareCriteria.LE;
-
- // constant for ">=" criteria
- public static final int COMPARE_GE = CompareCriteria.GE;
-
- // constant for "LIKE" criteria
- public static final int LIKE = 7;
-
- // constant for "IN" criteria
- public static final int IN = 8;
-
- // constant for "IS NULL" criteria
- public static final int IS_NULL = 9;
-
- // constant for "BETWEEN" criteria
- public static final int BETWEEN = 10;
-
- // constant for ">=" criteria
- public static final int NO_TYPE = 0;
-
- // type of criteria
- private int selectorType = NO_TYPE;
-
- // elements on which criteria is present
- private List elements;
-
- /**
- * Constructor for CriteriaSelector.
- */
- public CriteriaSelector() {
- super();
- }
-
- /**
- * Constructor for CriteriaSelector.
- * @param selectorType The type criteria presents on the elements
- * @param elements The elements on which
- */
- public CriteriaSelector(int selectorType, List elements) {
- this.selectorType = selectorType;
- this.elements = elements;
- }
-
- /**
- * Get the type of criteria on the user query's elements
- * @return An int value giving the type of criteria
- */
- public int getSelectorType() {
- return this.selectorType;
- }
-
- /**
- * Set the type of criteria on the user query's elements
- * @param type The type of criteria
- */
- public void setSelectorType(int type) {
- this.selectorType = type;
- }
-
- /**
- * Get elements on which criteria is pecified on the user's query
- * @return A collection of elements used in criteria
- */
- public List getElements() {
- return this.elements;
- }
-
- /**
- * Set elements on which criteria is pecified on the user's query
- * @param elements A collection of elements used in criteria
- */
- public void setElements(List elements) {
- this.elements = elements;
- }
-
- /**
- * Add an element to the collection of elements on which
- * criteria is pecified on the user's query
- * @param element The elementSymbol object being added
- */
- public void addElement(ElementSymbol element) {
- if(elements == null) {
- elements = new ArrayList();
- }
- elements.add(element);
- }
-
- /**
- * Return a boolean indicating if the seletor has any elements
- * @return A boolean indicating if the seletor has any elements
- */
- public boolean hasElements() {
- return (elements != null && !elements.isEmpty());
- }
-
- // =========================================================================
- // P R O C E S S I N G M E T H O D S
- // =========================================================================
-
- public void acceptVisitor(LanguageVisitor visitor) {
- visitor.visit(this);
- }
-
- /**
- * Deep clone statement to produce a new identical statement.
- * @return Deep clone
- */
- public Object clone() {
- CriteriaSelector copy = new CriteriaSelector();
-
- copy.setSelectorType(this.selectorType);
- if(this.hasElements()) {
- Iterator stmtIter = this.elements.iterator();
- while(stmtIter.hasNext()) {
- copy.addElement((ElementSymbol)((ElementSymbol) stmtIter.next()).clone());
- }
- }
- return copy;
- }
-
- /**
- * Compare two CriteriaSelector for equality. They will only evaluate to equal if
- * they are IDENTICAL: the selectorType and elements present 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 CriteriaSelector)) {
- return false;
- }
-
- CriteriaSelector other = (CriteriaSelector) obj;
-
- return
- // Compare the selector type
- getSelectorType() == other.getSelectorType() &&
- // Compare the elements
- EquivalenceUtil.areEqual(getElements(), other.getElements());
- }
-
- /**
- * Get hashcode for CriteriaSelector. WARNING: This hash code relies on the
- * hash codes of the elements and the selectortype on this object. 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 = 0;
- if(hasElements()) {
- myHash = HashCodeUtil.hashCode(myHash, this.getElements());
- }
- myHash = HashCodeUtil.hashCode(myHash, this.getSelectorType());
- return myHash;
- }
-
- /**
- * Returns a string representation of an instance of this class.
- * @return String representation of object
- */
- public String toString() {
- return SQLStringVisitor.getSQLString(this);
- }
-
-} // END CLASS
Deleted: trunk/engine/src/main/java/org/teiid/query/sql/proc/HasCriteria.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/proc/HasCriteria.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/sql/proc/HasCriteria.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -1,133 +0,0 @@
-/*
- * 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 org.teiid.query.sql.proc;
-
-import org.teiid.core.util.EquivalenceUtil;
-import org.teiid.core.util.HashCodeUtil;
-import org.teiid.query.sql.*;
-import org.teiid.query.sql.lang.PredicateCriteria;
-import org.teiid.query.sql.visitor.SQLStringVisitor;
-
-
-/**
- * <p>This object represents the criteria used in the stored procedure language
- * to determine if a type of criteria is specified on a user's query.</p>
- */
-public class HasCriteria extends PredicateCriteria {
-
- // the selector object used to determine if a type of criteria is specified
- // on the user's query
- private CriteriaSelector criteriaSelector;
-
- /**
- * Constructor for HasCriteria.
- */
- public HasCriteria() {
- }
-
- /**
- * Constructor for HasCriteria.
- * @param selector The <code>CriteriaSelector</code> of this obj
- */
- public HasCriteria(CriteriaSelector selector) {
- this.criteriaSelector = selector;
- }
-
- /**
- * Get the <code>CriteriaSelector</code>
- * @return <code>CriteriaSelector</code> of this obj
- */
- public CriteriaSelector getSelector() {
- return criteriaSelector;
- }
-
- /**
- * Set the <code>CriteriaSelector</code>
- * @param selector The <code>CriteriaSelector</code> of this obj
- */
- public void setSelector(CriteriaSelector selector) {
- this.criteriaSelector = selector;
- }
-
- // =========================================================================
- // P R O C E S S I N G M E T H O D S
- // =========================================================================
-
- public void acceptVisitor(LanguageVisitor visitor) {
- visitor.visit(this);
- }
-
- /**
- * Deep clone statement to produce a new identical statement.
- * @return Deep clone
- */
- public Object clone() {
- HasCriteria copy = new HasCriteria();
- copy.setSelector((CriteriaSelector)this.criteriaSelector.clone());
- return copy;
- }
-
- /**
- * Compare two HasCriteria for equality. They will only evaluate to equal if
- * they are IDENTICAL: the criteriaSelectors 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 HasCriteria)) {
- return false;
- }
-
- // Compare the command
- return EquivalenceUtil.areEqual(getSelector(), ((HasCriteria)obj).getSelector());
- }
-
- /**
- * Get hashcode for HasCriteria. WARNING: This hash code relies on the
- * hash codes of the CriteriaSelector on this object. Hash code is only
- * valid after the CriteriaSelector has been set on this object.
- * @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 = 0;
- myHash = HashCodeUtil.hashCode(myHash, this.getSelector());
- return myHash;
- }
-
- /**
- * Returns a string representation of an instance of this class.
- * @return String representation of object
- */
- public String toString() {
- return SQLStringVisitor.getSQLString(this);
- }
-
-} // END CLASS
Deleted: trunk/engine/src/main/java/org/teiid/query/sql/proc/TranslateCriteria.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/proc/TranslateCriteria.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/sql/proc/TranslateCriteria.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -1,205 +0,0 @@
-/*
- * 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 org.teiid.query.sql.proc;
-
-import java.util.*;
-
-import org.teiid.core.util.EquivalenceUtil;
-import org.teiid.core.util.HashCodeUtil;
-import org.teiid.query.sql.*;
-import org.teiid.query.sql.lang.*;
-import org.teiid.query.sql.visitor.SQLStringVisitor;
-
-
-/**
- * <p>This object represents the criteria used in the stored procedure language
- * that translates the portion of the user's criteria by doing symbol mapping to
- * the elements of the physical group that defines the virtual group and translating
- * the user's criteria using the element-expressions pairs represented as a list of
- * comapreCriteria on this this object.</p>
- */
-public class TranslateCriteria extends PredicateCriteria {
-
- // the selector object used to determine if a type of criteria is specified
- // on the user's query
- private CriteriaSelector criteriaSelector;
-
- // List of comparecriteria(element-value pairs) used to translate the user's criteria
- private List translations;
-
- /**
- * Constructor for TranslateCriteria.
- */
- public TranslateCriteria() {
- }
-
- /**
- * Constructor for TranslateCriteria.
- * @param selector The <code>CriteriaSelector</code> of this obj
- */
- public TranslateCriteria(CriteriaSelector selector) {
- this.criteriaSelector = selector;
- }
-
- /**
- * Constructor for TranslateCriteria.
- * @param selector The <code>CriteriaSelector</code> of this obj
- * @param critCollect A list of comparecriteria used to translate user's criteria
- */
- public TranslateCriteria(CriteriaSelector selector, List translations) {
- this.criteriaSelector = selector;
- this.translations = translations;
- }
-
- /**
- * Get the <code>CriteriaSelector</code>
- * @return <code>CriteriaSelector</code> of this obj
- */
- public CriteriaSelector getSelector() {
- return criteriaSelector;
- }
-
- /**
- * Set the <code>CriteriaSelector</code>
- * @param selector The <code>CriteriaSelector</code> of this obj
- */
- public void setSelector(CriteriaSelector selector) {
- this.criteriaSelector = selector;
- }
-
- /**
- * Return a boolean indicating if the object has any translations.
- * @return A boolean indicating if the object has any translations
- */
- public boolean hasTranslations() {
- if(this.translations != null) {
- return (this.translations.size() > 0);
- }
- return false;
- }
-
- /**
- * Set a list of comparecriteria(element-value pairs) used to translate the user's criteria.
- * @param critCollect A list of criteria used to translate user's criteria
- */
- public void setTranslations(List translations) {
- this.translations = translations;
- }
-
- /**
- * Add a comparecriteria(element-value pair) to the list used to translate the user's criteria.
- * @param criteria A <code>ComapareCriteria</code> object to be added to a collection
- */
- public void addTranslation(CompareCriteria criteria) {
- if(this.translations == null) {
- this.translations = new ArrayList();
- }
-
- this.translations.add(criteria);
- }
-
- /**
- * Get a list of comparecriteria(element-value pairs) used to translate the user's criteria.
- * @return A list of criteria used to translate user's criteria
- */
- public List getTranslations() {
- return this.translations;
- }
-
- // =========================================================================
- // P R O C E S S I N G M E T H O D S
- // =========================================================================
-
- public void acceptVisitor(LanguageVisitor visitor) {
- visitor.visit(this);
- }
-
- /**
- * Deep clone statement to produce a new identical statement.
- * @return Deep clone
- */
- public Object clone() {
- TranslateCriteria copy = new TranslateCriteria();
- copy.setSelector((CriteriaSelector)this.criteriaSelector.clone());
- if(this.hasTranslations()) {
- List newTrans = new ArrayList(this.getTranslations().size());
- Iterator transIter = this.getTranslations().iterator();
- while(transIter.hasNext()) {
- Criteria crit = (Criteria) transIter.next();
- newTrans.add(crit);
- }
- copy.setTranslations(newTrans);
- }
- return copy;
- }
-
- /**
- * Compare two TranslateCriteria for equality. They will only evaluate to equal if
- * they are IDENTICAL: the criteriaSelectors 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 TranslateCriteria)) {
- return false;
- }
-
- TranslateCriteria other = (TranslateCriteria) obj;
-
- return
- // Compare the selector
- EquivalenceUtil.areEqual(getSelector(), other.getSelector()) &&
- // Compare the selector
- EquivalenceUtil.areEqual(getTranslations(), other.getTranslations());
- }
-
- /**
- * Get hashcode for TranslateCriteria. WARNING: This hash code relies on the
- * hash code of the criteria selector on this object. Hash code is only valid
- * after the object 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 = 0;
- myHash = HashCodeUtil.hashCode(myHash, this.getSelector());
- myHash = HashCodeUtil.hashCode(myHash, this.getTranslations());
- return myHash;
- }
-
- /**
- * Returns a string representation of an instance of this class.
- * @return String representation of object
- */
- public String toString() {
- return SQLStringVisitor.getSQLString(this);
- }
-
-} // END CLASS
Modified: trunk/engine/src/main/java/org/teiid/query/sql/visitor/AbstractSymbolMappingVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/visitor/AbstractSymbolMappingVisitor.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/sql/visitor/AbstractSymbolMappingVisitor.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -32,7 +32,6 @@
import org.teiid.query.sql.lang.StoredProcedure;
import org.teiid.query.sql.lang.UnaryFromClause;
import org.teiid.query.sql.lang.Update;
-import org.teiid.query.sql.proc.CriteriaSelector;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.GroupSymbol;
@@ -171,27 +170,6 @@
super.visit(obj);
}
- /**
- * Swap elements in CriteriaSelector
- * @param obj Object to remap
- */
- public void visit(CriteriaSelector obj) {
- CriteriaSelector selector = obj;
- if(selector.hasElements()) {
- // Map each element and reset
- List elements = selector.getElements();
- List mappedElements = new ArrayList(elements.size());
-
- Iterator elemIter = elements.iterator();
- while(elemIter.hasNext()) {
- ElementSymbol elem = (ElementSymbol) elemIter.next();
- mappedElements.add(getMappedElement(elem));
- }
-
- selector.setElements(mappedElements);
- }
- }
-
/* ############### Helper Methods ################## */
/**
Deleted: trunk/engine/src/main/java/org/teiid/query/sql/visitor/CriteriaTranslatorVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/visitor/CriteriaTranslatorVisitor.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/sql/visitor/CriteriaTranslatorVisitor.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -1,185 +0,0 @@
-/*
- * 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 org.teiid.query.sql.visitor;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.Map;
-
-import org.teiid.core.util.Assertion;
-import org.teiid.query.rewriter.QueryRewriter;
-import org.teiid.query.sql.lang.AbstractSetCriteria;
-import org.teiid.query.sql.lang.BetweenCriteria;
-import org.teiid.query.sql.lang.CompareCriteria;
-import org.teiid.query.sql.lang.Criteria;
-import org.teiid.query.sql.lang.IsNullCriteria;
-import org.teiid.query.sql.lang.MatchCriteria;
-import org.teiid.query.sql.navigator.DeepPostOrderNavigator;
-import org.teiid.query.sql.proc.CriteriaSelector;
-import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.query.sql.symbol.Expression;
-import org.teiid.query.sql.symbol.Reference;
-
-
-/**
- * <p> This class is used to translate criteria specified on the user's update command against
- * the virtual group, the elements on this criteria are replaced by elements on the query
- * transformation that defines the virtual group. Parts of the criteria are selectively translated
- * if a CriteriaSelector is specified, also if the user explicitly defines translations for some
- * of the elements those translations override any symbol mappings.</p>
- */
-public class CriteriaTranslatorVisitor extends ExpressionMappingVisitor {
-
- // criteria selector specified on the TranslateCriteria obj
- private CriteriaSelector selector;
-
- // translation in for of CompareCriteria objs on the TranslateCriteria obj
- private Collection translations;
-
- private Map<ElementSymbol, Reference> implicitParams = new HashMap<ElementSymbol, Reference>();
-
- /**
- * <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
- */
- public CriteriaTranslatorVisitor(Map symbolMap) {
- super(symbolMap);
- Assertion.isNotNull(symbolMap);
- }
-
- /**
- * <p>Set the criteria selector used to restrict the part of the criteria that needs to be
- * translated.</p>
- * @param selector The <code>CriteriaSelector</code> on the <code>TranslateCriteria</code>
- * object
- */
- public void setCriteriaSelector(CriteriaSelector selector) {
- this.selector = selector;
- }
-
- /**
- * <p> Set the translations to be used to replace elements on the user's command against
- * the virtual group.</p>
- * @param translations Collection of <code>ComapreCriteria</code> objects used to
- * specify translations
- */
- public void setTranslations(Collection translations) {
- this.translations = translations;
- }
-
- /* ############### Helper Methods ################## */
-
- private boolean selectorContainsCriteriaElements(Criteria criteria, int criteriaType) {
- int selectorType = selector.getSelectorType();
- if(selectorType!= CriteriaSelector.NO_TYPE && selectorType != criteriaType) {
- return false;
- } else if(selector.hasElements()) {
- Iterator selectElmnIter = selector.getElements().iterator();
- Collection<ElementSymbol> critElmnts = ElementCollectorVisitor.getElements(criteria, true);
- while(selectElmnIter.hasNext()) {
- ElementSymbol selectElmnt = (ElementSymbol) selectElmnIter.next();
- if(critElmnts.contains(selectElmnt)) {
- return true;
- }
- }
- return false;
- }
- return true;
- }
-
- @Override
- public Expression replaceExpression(Expression obj) {
- if (this.translations != null && obj instanceof ElementSymbol) {
- Iterator transIter = this.translations.iterator();
- while(transIter.hasNext()) {
- CompareCriteria compCrit = (CompareCriteria) transIter.next();
- Collection<ElementSymbol> leftElmnts = ElementCollectorVisitor.getElements(compCrit.getLeftExpression(), true);
- // there is always only one element
- 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);
- }
-
- public Map<ElementSymbol, Reference> getImplicitParams() {
- return implicitParams;
- }
-
- public Criteria translate(Criteria crit) {
- LinkedList<Criteria> crits = new LinkedList<Criteria>();
- for (Criteria conjunct : Criteria.separateCriteriaByAnd(crit)) {
- if (conjunct instanceof BetweenCriteria) {
- if (!selectorContainsCriteriaElements(conjunct, CriteriaSelector.BETWEEN)) {
- continue;
- }
- } else if (conjunct instanceof CompareCriteria) {
- if (!selectorContainsCriteriaElements(conjunct, ((CompareCriteria)conjunct).getOperator())) {
- continue;
- }
- } else if (conjunct instanceof IsNullCriteria) {
- if (!selectorContainsCriteriaElements(conjunct, CriteriaSelector.IS_NULL)) {
- continue;
- }
- } else if (conjunct instanceof MatchCriteria) {
- if (!selectorContainsCriteriaElements(conjunct, CriteriaSelector.LIKE)) {
- continue;
- }
- } else if (conjunct instanceof AbstractSetCriteria) {
- if (!selectorContainsCriteriaElements(conjunct, CriteriaSelector.IN)) {
- continue;
- }
- } else if (!selectorContainsCriteriaElements(conjunct, CriteriaSelector.NO_TYPE)) {
- continue;
- }
- DeepPostOrderNavigator.doVisit(conjunct, this);
- crits.add(conjunct);
- }
- if (crits.isEmpty()) {
- return QueryRewriter.TRUE_CRITERIA;
- }
- return Criteria.combineCriteria(crits);
- }
-
-}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -98,14 +98,11 @@
import org.teiid.query.sql.proc.BranchingStatement;
import org.teiid.query.sql.proc.CommandStatement;
import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
-import org.teiid.query.sql.proc.CriteriaSelector;
import org.teiid.query.sql.proc.DeclareStatement;
-import org.teiid.query.sql.proc.HasCriteria;
import org.teiid.query.sql.proc.IfStatement;
import org.teiid.query.sql.proc.LoopStatement;
import org.teiid.query.sql.proc.RaiseErrorStatement;
import org.teiid.query.sql.proc.Statement;
-import org.teiid.query.sql.proc.TranslateCriteria;
import org.teiid.query.sql.proc.TriggerAction;
import org.teiid.query.sql.proc.WhileStatement;
import org.teiid.query.sql.proc.Statement.Labeled;
@@ -1517,96 +1514,6 @@
createAssignment(obj);
}
- public void visit( HasCriteria obj ) {
- append(HAS);
- append(SPACE);
- visitNode(obj.getSelector());
- }
-
- public void visit( TranslateCriteria obj ) {
- append(TRANSLATE);
- append(SPACE);
- visitNode(obj.getSelector());
-
- if (obj.hasTranslations()) {
- append(SPACE);
- append(WITH);
- append(SPACE);
- append("("); //$NON-NLS-1$
- Iterator critIter = obj.getTranslations().iterator();
-
- while (critIter.hasNext()) {
- visitNode((Criteria)critIter.next());
- if (critIter.hasNext()) {
- append(", "); //$NON-NLS-1$
- }
- if (!critIter.hasNext()) {
- append(")"); //$NON-NLS-1$
- }
- }
- }
- }
-
- public void visit( CriteriaSelector obj ) {
- int selectorType = obj.getSelectorType();
-
- switch (selectorType) {
- case CriteriaSelector.COMPARE_EQ:
- append("= "); //$NON-NLS-1$
- break;
- case CriteriaSelector.COMPARE_GE:
- append(">= "); //$NON-NLS-1$
- break;
- case CriteriaSelector.COMPARE_GT:
- append("> "); //$NON-NLS-1$
- break;
- case CriteriaSelector.COMPARE_LE:
- append("<= "); //$NON-NLS-1$
- break;
- case CriteriaSelector.COMPARE_LT:
- append("< "); //$NON-NLS-1$
- break;
- case CriteriaSelector.COMPARE_NE:
- append("<> "); //$NON-NLS-1$
- break;
- case CriteriaSelector.IN:
- append(IN);
- append(SPACE);
- break;
- case CriteriaSelector.IS_NULL:
- append(IS);
- append(SPACE);
- append(NULL);
- append(SPACE);
- break;
- case CriteriaSelector.LIKE:
- append(LIKE);
- append(SPACE);
- break;
- case CriteriaSelector.BETWEEN:
- append(BETWEEN);
- append(SPACE);
- break;
- }
-
- append(CRITERIA);
- if (obj.hasElements()) {
- append(SPACE);
- append(ON);
- append(SPACE);
- append("("); //$NON-NLS-1$
-
- Iterator elmtIter = obj.getElements().iterator();
- while (elmtIter.hasNext()) {
- visitNode((ElementSymbol)elmtIter.next());
- if (elmtIter.hasNext()) {
- append(", "); //$NON-NLS-1$
- }
- }
- append(")"); //$NON-NLS-1$
- }
- }
-
public void visit( RaiseErrorStatement obj ) {
append(ERROR);
append(SPACE);
Modified: trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -30,7 +30,6 @@
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import net.sf.saxon.om.Name11Checker;
@@ -55,92 +54,24 @@
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.resolver.util.ResolverUtil;
import org.teiid.query.sql.LanguageObject;
-import org.teiid.query.sql.LanguageVisitor;
-import org.teiid.query.sql.ProcedureReservedWords;
-import org.teiid.query.sql.lang.AlterProcedure;
-import org.teiid.query.sql.lang.AlterTrigger;
-import org.teiid.query.sql.lang.AlterView;
-import org.teiid.query.sql.lang.BatchedUpdateCommand;
-import org.teiid.query.sql.lang.BetweenCriteria;
-import org.teiid.query.sql.lang.Command;
-import org.teiid.query.sql.lang.CompareCriteria;
-import org.teiid.query.sql.lang.CompoundCriteria;
-import org.teiid.query.sql.lang.Create;
-import org.teiid.query.sql.lang.Criteria;
-import org.teiid.query.sql.lang.Delete;
-import org.teiid.query.sql.lang.DependentSetCriteria;
-import org.teiid.query.sql.lang.Drop;
-import org.teiid.query.sql.lang.DynamicCommand;
-import org.teiid.query.sql.lang.ExistsCriteria;
-import org.teiid.query.sql.lang.GroupBy;
-import org.teiid.query.sql.lang.Insert;
-import org.teiid.query.sql.lang.Into;
-import org.teiid.query.sql.lang.IsNullCriteria;
-import org.teiid.query.sql.lang.Limit;
-import org.teiid.query.sql.lang.MatchCriteria;
-import org.teiid.query.sql.lang.NotCriteria;
-import org.teiid.query.sql.lang.Option;
-import org.teiid.query.sql.lang.OrderBy;
-import org.teiid.query.sql.lang.OrderByItem;
-import org.teiid.query.sql.lang.Query;
-import org.teiid.query.sql.lang.QueryCommand;
-import org.teiid.query.sql.lang.SPParameter;
-import org.teiid.query.sql.lang.Select;
-import org.teiid.query.sql.lang.SetClause;
-import org.teiid.query.sql.lang.SetClauseList;
-import org.teiid.query.sql.lang.SetCriteria;
-import org.teiid.query.sql.lang.SetQuery;
-import org.teiid.query.sql.lang.StoredProcedure;
-import org.teiid.query.sql.lang.SubqueryCompareCriteria;
-import org.teiid.query.sql.lang.SubqueryContainer;
-import org.teiid.query.sql.lang.SubqueryFromClause;
-import org.teiid.query.sql.lang.SubquerySetCriteria;
-import org.teiid.query.sql.lang.TextTable;
-import org.teiid.query.sql.lang.Update;
-import org.teiid.query.sql.lang.WithQueryCommand;
-import org.teiid.query.sql.lang.XMLTable;
+import org.teiid.query.sql.lang.*;
import org.teiid.query.sql.lang.SetQuery.Operation;
import org.teiid.query.sql.lang.XMLTable.XMLColumn;
import org.teiid.query.sql.navigator.PreOrderNavigator;
-import org.teiid.query.sql.proc.AssignmentStatement;
import org.teiid.query.sql.proc.Block;
import org.teiid.query.sql.proc.BranchingStatement;
-import org.teiid.query.sql.proc.CommandStatement;
import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
-import org.teiid.query.sql.proc.CriteriaSelector;
-import org.teiid.query.sql.proc.DeclareStatement;
-import org.teiid.query.sql.proc.HasCriteria;
import org.teiid.query.sql.proc.LoopStatement;
-import org.teiid.query.sql.proc.TranslateCriteria;
import org.teiid.query.sql.proc.WhileStatement;
import org.teiid.query.sql.proc.BranchingStatement.BranchingMode;
import org.teiid.query.sql.proc.Statement.Labeled;
-import org.teiid.query.sql.symbol.AggregateSymbol;
-import org.teiid.query.sql.symbol.Constant;
-import org.teiid.query.sql.symbol.DerivedColumn;
-import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.query.sql.symbol.Expression;
-import org.teiid.query.sql.symbol.Function;
-import org.teiid.query.sql.symbol.GroupSymbol;
-import org.teiid.query.sql.symbol.QueryString;
-import org.teiid.query.sql.symbol.Reference;
-import org.teiid.query.sql.symbol.ScalarSubquery;
-import org.teiid.query.sql.symbol.SingleElementSymbol;
-import org.teiid.query.sql.symbol.TextLine;
-import org.teiid.query.sql.symbol.WindowFunction;
-import org.teiid.query.sql.symbol.XMLAttributes;
-import org.teiid.query.sql.symbol.XMLElement;
-import org.teiid.query.sql.symbol.XMLForest;
-import org.teiid.query.sql.symbol.XMLNamespaces;
-import org.teiid.query.sql.symbol.XMLParse;
-import org.teiid.query.sql.symbol.XMLQuery;
+import org.teiid.query.sql.symbol.*;
import org.teiid.query.sql.symbol.AggregateSymbol.Type;
import org.teiid.query.sql.visitor.AggregateSymbolCollectorVisitor;
import org.teiid.query.sql.visitor.ElementCollectorVisitor;
import org.teiid.query.sql.visitor.EvaluatableVisitor;
import org.teiid.query.sql.visitor.FunctionCollectorVisitor;
import org.teiid.query.sql.visitor.GroupCollectorVisitor;
-import org.teiid.query.sql.visitor.GroupsUsedByElementsVisitor;
import org.teiid.query.sql.visitor.SQLStringVisitor;
import org.teiid.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
import org.teiid.query.validator.UpdateValidator.UpdateInfo;
@@ -172,13 +103,6 @@
private boolean inQuery;
- // update procedure being validated
- private CreateUpdateProcedureCommand updateProc;
-
- public void setUpdateProc(CreateUpdateProcedureCommand updateProc) {
- this.updateProc = updateProc;
- }
-
public void reset() {
super.reset();
this.isXML = false;
@@ -406,27 +330,7 @@
// ############### Visitor methods for stored procedure lang objects ##################
- public void visit(AssignmentStatement obj) {
-
- ElementSymbol variable = obj.getVariable();
-
- validateAssignment(obj, variable);
- }
-
@Override
- public void visit(CommandStatement obj) {
- if (obj.getCommand() instanceof StoredProcedure) {
- StoredProcedure proc = (StoredProcedure)obj.getCommand();
- for (SPParameter param : proc.getParameters()) {
- if ((param.getParameterType() == SPParameter.RETURN_VALUE
- || param.getParameterType() == SPParameter.OUT) && param.getExpression() instanceof ElementSymbol) {
- validateAssignment(obj, (ElementSymbol)param.getExpression());
- }
- }
- }
- }
-
- @Override
public void visit(StoredProcedure obj) {
for (SPParameter param : obj.getInputParameters()) {
try {
@@ -451,15 +355,6 @@
}
}
- private void validateAssignment(LanguageObject obj,
- ElementSymbol variable) {
- String groupName = variable.getGroupSymbol().getCanonicalName();
- //This will actually get detected by the resolver, since we inject an automatic declaration.
- if(groupName.equals(ProcedureReservedWords.CHANGING) || groupName.equals(ProcedureReservedWords.INPUTS)) {
- handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0012", ProcedureReservedWords.INPUTS, ProcedureReservedWords.CHANGING), obj); //$NON-NLS-1$
- }
- }
-
@Override
public void visit(ScalarSubquery obj) {
validateSubquery(obj);
@@ -482,49 +377,8 @@
return;
}
-
- // set the state to validate this procedure
- this.updateProc = obj;
- validateContainsRowsUpdatedVariable(obj);
}
- public void visit(DeclareStatement obj) {
- validateAssignment(obj, obj.getVariable());
- }
-
- @Override
- public void visit(HasCriteria obj) {
- if (this.updateProc == null || !this.updateProc.isUpdateProcedure()) {
- handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0019"), obj); //$NON-NLS-1$
- }
- }
-
- public void visit(TranslateCriteria obj) {
- if (this.updateProc == null || !this.updateProc.isUpdateProcedure()) {
- handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0019"), obj); //$NON-NLS-1$
- }
- if(obj.hasTranslations()) {
- Collection selectElmnts = null;
- if(obj.getSelector().hasElements()) {
- selectElmnts = obj.getSelector().getElements();
- }
- Iterator critIter = obj.getTranslations().iterator();
- while(critIter.hasNext()) {
- CompareCriteria transCrit = (CompareCriteria) critIter.next();
- Collection<ElementSymbol> leftElmnts = ElementCollectorVisitor.getElements(transCrit.getLeftExpression(), true);
- // there is always only one element
- ElementSymbol leftExpr = leftElmnts.iterator().next();
-
- if(selectElmnts != null && !selectElmnts.contains(leftExpr)) {
- handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0021"), leftExpr); //$NON-NLS-1$
- }
- }
- }
-
- // additional validation checks
- validateTranslateCriteria(obj);
- }
-
public void visit(CompoundCriteria obj) {
// Validate use of 'rowlimit' or 'rowlimitexception' pseudo-function - each occurrence must be in a single
// CompareCriteria which is entirely it's own conjunct (not OR'ed with anything else)
@@ -563,85 +417,6 @@
// ######################### Validation methods #########################
- /**
- * A valid translated expression is not an <code>AggregateSymbol</code> and
- * does not include elements not present on the groups of the command using
- * the translated criteria.
- */
- protected void validateTranslateCriteria(TranslateCriteria obj) {
- if(this.currentCommand == null) {
- return;
- }
- Map symbolMap = this.updateProc.getSymbolMap();
- Command userCommand = this.updateProc.getUserCommand();
- // modeler validation
- if(userCommand == null) {
- return;
- }
- Criteria userCrit = null;
- int userCmdType = userCommand.getType();
- switch(userCmdType) {
- case Command.TYPE_DELETE:
- userCrit = ((Delete)userCommand).getCriteria();
- break;
- case Command.TYPE_UPDATE:
- userCrit = ((Update)userCommand).getCriteria();
- break;
- default:
- break;
- }
- // nothing to validate if there is no user criteria
- if(userCrit == null) {
- return;
- }
-
- Collection<ElementSymbol> transleElmnts = ElementCollectorVisitor.getElements(obj, true);
- Collection<GroupSymbol> groups = GroupCollectorVisitor.getGroups(this.currentCommand, true);
- int selectType = obj.getSelector().getSelectorType();
-
- for (Criteria predCrit : Criteria.separateCriteriaByAnd(userCrit)) {
- if(selectType != CriteriaSelector.NO_TYPE) {
- if(predCrit instanceof CompareCriteria) {
- CompareCriteria ccCrit = (CompareCriteria) predCrit;
- if(selectType != ccCrit.getOperator()) {
- continue;
- }
- } else if(predCrit instanceof MatchCriteria) {
- if(selectType != CriteriaSelector.LIKE) {
- continue;
- }
- } else if(predCrit instanceof IsNullCriteria) {
- if(selectType != CriteriaSelector.IS_NULL) {
- continue;
- }
- } else if(predCrit instanceof SetCriteria) {
- if(selectType != CriteriaSelector.IN) {
- continue;
- }
- } else if(predCrit instanceof BetweenCriteria) {
- if(selectType != CriteriaSelector.BETWEEN) {
- continue;
- }
- }
- }
- Iterator<ElementSymbol> critEmlntIter = ElementCollectorVisitor.getElements(predCrit, true).iterator();
- // collect all elements elements on the criteria map to
- while(critEmlntIter.hasNext()) {
- ElementSymbol criteriaElement = critEmlntIter.next();
- if(transleElmnts.contains(criteriaElement)) {
- Expression mappedExpr = (Expression) symbolMap.get(criteriaElement);
- if(mappedExpr instanceof AggregateSymbol) {
- handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0022", criteriaElement), criteriaElement); //$NON-NLS-1$
- }
-
- if (!groups.containsAll(GroupsUsedByElementsVisitor.getGroups(mappedExpr))) {
- handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0023", criteriaElement), criteriaElement); //$NON-NLS-1$
- }
- }
- }
- }
- }
-
protected void validateSelectElements(Select obj) {
if(isXML) {
return;
@@ -980,32 +755,6 @@
}
}
- /**
- * Validate that the command assigns a value to the ROWS_UPDATED variable
- * @param obj
- * @since 4.2
- */
- protected void validateContainsRowsUpdatedVariable(CreateUpdateProcedureCommand obj) {
- final Collection<ElementSymbol> assignVars = new ArrayList<ElementSymbol>();
- // Use visitor to find assignment statements
- LanguageVisitor visitor = new LanguageVisitor() {
- public void visit(AssignmentStatement stmt) {
- assignVars.add(stmt.getVariable());
- }
- };
- PreOrderNavigator.doVisit(obj, visitor);
- boolean foundVar = false;
- for (ElementSymbol variable : assignVars) {
- if(variable.getShortName().equalsIgnoreCase(ProcedureReservedWords.ROWS_UPDATED)) {
- foundVar = true;
- break;
- }
- }
- if(!foundVar) {
- handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0016", ProcedureReservedWords.ROWS_UPDATED), obj); //$NON-NLS-1$
- }
- }
-
private void validateRowLimitFunctionNotInInvalidCriteria(Criteria obj) {
// Collect all occurrances of rowlimit and rowlimitexception functions
List<Function> rowLimitFunctions = new ArrayList<Function>();
Modified: trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
===================================================================
--- trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2011-11-21 23:03:58 UTC (rev 3680)
@@ -933,85 +933,6 @@
}
/**
- * Parse criteria selector
- * @throws ParseException if parsing failed
- */
-CriteriaSelector criteriaSelector() :
-{
- CriteriaSelector critSelector = new CriteriaSelector();
-
- String element = null;
- List elements = new ArrayList(2);
- Token operator = null;
-}
-{
- [(operator = <EQ> |
- operator = <NE> |
- operator = <NE2> |
- operator = <LE> |
- operator = <GE> |
- operator = <LT> |
- operator = <GT> |
- operator = <IN> |
- operator = <LIKE> |
- (operator = <IS> <NULL>) |
- operator = <BETWEEN>)
- {
- critSelector.setSelectorType(getOperator(operator.image));
- }
- ]
-
- <CRITERIA>
-
- [LOOKAHEAD(4)<ON>
- <LPAREN>
-
- element = id()
-
- {
- elements.add(new ElementSymbol(element));
- }
-
- (<COMMA>
- element = id()
-
- {
- elements.add(new ElementSymbol(element));
- }
- )*
- <RPAREN>
-
- {
- critSelector.setElements(elements);
-
- }
- ]
-
- {
- return critSelector;
- }
-}
-
-/**
- * Parse has criteria
- * @throws ParseException
- */
-HasCriteria hasCriteria() :
-{
- HasCriteria hasCrit = new HasCriteria();
- CriteriaSelector critSelector = null;
-}
-{
- <HAS>
- critSelector = criteriaSelector()
-
- {
- hasCrit.setSelector(critSelector);
- return hasCrit;
- }
-}
-
-/**
* Parse declare statement
* @throws ParseException if parsing failed
*/
@@ -1134,69 +1055,6 @@
}
}
-TranslateCriteria translateCriteria(ParseInfo info) :
-{
- String element = null;
- Expression value = null;
- ElementSymbol leftSymbol = null;
-
- CriteriaSelector critSelector = null;
- TranslateCriteria transCriteria = new TranslateCriteria();
-
- CompareCriteria compCrit = null;
-
- List critList = null;
-}
-{
-
- <TRANSLATE>
- critSelector = criteriaSelector()
-
- [<WITH>
- {
- critList = new ArrayList(2);
- }
- <LPAREN>
- element = id()
- <EQ>
- value = expression(info)
- {
- compCrit = new CompareCriteria();
- leftSymbol = new ElementSymbol(element);
- compCrit.setLeftExpression(leftSymbol);
- compCrit.setRightExpression(value);
- compCrit.setOperator(CompareCriteria.EQ);
- critList.add(compCrit);
- compCrit = null;
- }
- ( <COMMA>
- element = id()
- <EQ>
- value = expression(info)
- {
- compCrit = new CompareCriteria();
- leftSymbol = new ElementSymbol(element);
- compCrit.setLeftExpression(leftSymbol);
- compCrit.setRightExpression(value);
- compCrit.setOperator(CompareCriteria.EQ);
- critList.add(compCrit);
- compCrit = null;
- }
- )*
- <RPAREN>
- ]
-
- {
- transCriteria.setSelector(critSelector);
-
- if ( critList != null) {
- transCriteria.setTranslations(critList);
- }
-
- return transCriteria;
- }
-}
-
/**
* Parse create update procedure command
* @throws ParseException if parsing failed
@@ -2741,8 +2599,6 @@
}
{
(
- LOOKAHEAD(2) ex = translateCriteria(info)
- |
(ex = commonValueExpression(info)
[(
LOOKAHEAD(2) ex=betweenCrit(info, ex) |
@@ -2755,8 +2611,7 @@
)]
)
|
- ex=existsCriteria(info) |
- ex = hasCriteria()
+ ex=existsCriteria(info)
)
{
return ex;
Modified: trunk/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2011-11-21 23:03:58 UTC (rev 3680)
@@ -171,17 +171,12 @@
ERR.015.012.0009 = The updatable view query has a FROM clause that is not a single table, pass-through processing will not be used for UPDATE/DELETE operations.
ERR.015.012.0010 = The updatable view query does not project the column {0}, which is required to make {1} a target of INSERT operations.
ERR.015.012.0011 = There must be exactly one projected symbol in the subcommand of an IN clause.
-ERR.015.012.0012 = An AssignmentStatement cannot change the value of a {0} or {1} variable.
ERR.015.012.0013 = The query defining an updatable virtual group cannot use LIMIT.
ERR.015.012.0014 = The non-simple query defining an updatable view does not have a valid key preserving delete target.
ERR.015.012.0015 = The query defining an updatable view has no valid target for INSERTs.
ERR.015.012.0016 = Variable {0} not assigned any value in this procedure.
ERR.015.012.0017 = Variables declared the procedure''s DeclareStatement cannot be one of the special variables: {0}, {1} and {2}.
ERR.015.012.0018 = Inherent INSERT is not possible on a view defined by a non-partitioned UNION.
-ERR.015.012.0019 = Translate/HasCriteria cannot be used in a non-update procedure.
-ERR.015.012.0021 = Element being translated in the WITH clause not among the elements on the ON clause of the TranslateCriteria.
-ERR.015.012.0022 = Unable to translate criteria on the update command against the virtual group, the element {0} is mapped to an aggregate symbol in the virtual group''s query transform, and cannot be translated.
-ERR.015.012.0023 = Unable to translate criteria on the update command against the virtual group, the element {0} is mapped to an expression whose elements are not present on the command in the procedure using the translated criteria.
ERR.015.012.0024 = The following data elements are not supported in the SELECT clause: {0}.
ERR.015.012.0025 = Command must project at least one symbol
ERR.015.012.0026 = Expressions of type OBJECT, CLOB, BLOB, or XML cannot be used in SELECT DISTINCT, ORDER BY, GROUP BY, KEYS, or non-all set queries: [{0}]
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -56,24 +56,7 @@
import org.teiid.query.optimizer.relational.rules.RuleChooseDependent;
import org.teiid.query.parser.QueryParser;
import org.teiid.query.processor.ProcessorPlan;
-import org.teiid.query.processor.relational.AccessNode;
-import org.teiid.query.processor.relational.DependentAccessNode;
-import org.teiid.query.processor.relational.EnhancedSortMergeJoinStrategy;
-import org.teiid.query.processor.relational.GroupingNode;
-import org.teiid.query.processor.relational.JoinNode;
-import org.teiid.query.processor.relational.JoinStrategy;
-import org.teiid.query.processor.relational.MergeJoinStrategy;
-import org.teiid.query.processor.relational.NestedLoopJoinStrategy;
-import org.teiid.query.processor.relational.NestedTableJoinStrategy;
-import org.teiid.query.processor.relational.NullNode;
-import org.teiid.query.processor.relational.PlanExecutionNode;
-import org.teiid.query.processor.relational.ProjectIntoNode;
-import org.teiid.query.processor.relational.ProjectNode;
-import org.teiid.query.processor.relational.RelationalNode;
-import org.teiid.query.processor.relational.RelationalPlan;
-import org.teiid.query.processor.relational.SelectNode;
-import org.teiid.query.processor.relational.SortNode;
-import org.teiid.query.processor.relational.UnionAllNode;
+import org.teiid.query.processor.relational.*;
import org.teiid.query.processor.relational.SortUtility.Mode;
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.resolver.TestResolver;
@@ -5593,24 +5576,9 @@
@Test public void testCase3966() {
ProcessorPlan plan = helpPlan("insert into vm1.g37 (e1, e2, e3, e4) values('test', 1, convert('true', boolean) , convert('12', double) )", RealMetadataFactory.example1Cached(), //$NON-NLS-1$
- new String[] {} );
+ new String[] {"INSERT INTO pm4.g1 (pm4.g1.e1, pm4.g1.e2, pm4.g1.e3, pm4.g1.e4) VALUES ('test', 1, TRUE, 12.0)"} );
- checkNodeTypes(plan, new int[] {
- 0, // Access
- 0, // DependentAccess
- 0, // DependentSelect
- 0, // DependentProject
- 0, // DupRemove
- 0, // Grouping
- 0, // Join
- 0, // MergeJoin
- 0, // Null
- 1, // PlanExecution
- 1, // Project
- 0, // Select
- 0, // Sort
- 0 // UnionAll
- });
+ checkNodeTypes(plan, FULL_PUSHDOWN);
}
/*
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/proc/TestProcedurePlanner.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/proc/TestProcedurePlanner.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/proc/TestProcedurePlanner.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -91,128 +91,6 @@
// TESTS
// =============================================================================
- @Test public void testCreateUpdateProcedure1() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Declare String var1;\n"; //$NON-NLS-1$
- procedure = procedure + "if(var1 = 'x' or var1 = 'y')\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2, Input.e2, CHANGING.e2, CHANGING.e1 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = 1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "INSERT into vm1.g1 (e1) values('x')"; //$NON-NLS-1$
-
- helpPlanProcedure(userUpdateStr, procedure,
- TriggerEvent.INSERT);
- }
-
- // special variable CHANGING used with declared variable
- @Test public void testCreateUpdateProcedure2() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "if(CHANGING.e1 = 'true')\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2, Input.e2 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = INPUT.e1, pm1.g1.e2 = INPUT.e2;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = 1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpPlanProcedure(userUpdateStr, procedure,
- TriggerEvent.UPDATE);
- }
-
- // special variable CHANGING and INPUT used in conpound criteria
- @Test public void testCreateUpdateProcedure3() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "if(CHANGING.e1='false' and INPUT.e1=1)\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2, Input.e2 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = INPUT.e1, pm1.g1.e2 = INPUT.e2;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = 1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpPlanProcedure(userUpdateStr, procedure,
- TriggerEvent.UPDATE);
- }
-
- // special variable CHANGING and INPUT used in conpound criteria, with declared variables
- @Test public void testCreateUpdateProcedure4() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "if(CHANGING.e4 ='true' and INPUT.e2=1 or var1 < 30)\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2, Input.e2 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = INPUT.e1, pm1.g1.e2 = INPUT.e2;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = 1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpPlanProcedure(userUpdateStr, procedure,
- TriggerEvent.UPDATE);
- }
-
- // virtual group elements used in procedure(HAS CRITERIA)
- @Test public void testCreateUpdateProcedure5() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = Select pm1.g1.e2 from pm1.g1 where HAS CRITERIA ON (vm1.g1.e1, vm1.g1.e1);\n"; //$NON-NLS-1$
- procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = 'x', pm1.g1.e2 = var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpPlanProcedure(userUpdateStr, procedure,
- TriggerEvent.UPDATE);
- }
-
- // virtual group elements used in procedure in if statement(HAS CRITERIA)
- @Test public void testCreateUpdateProcedure6() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "if(HAS CRITERIA ON (vm1.g1.e1, vm1.g1.e1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = Select pm1.g1.e2 from pm1.g1 where HAS CRITERIA ON (vm1.g1.e1, vm1.g1.e1);\n"; //$NON-NLS-1$
- procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = 'x', pm1.g1.e2 = var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpPlanProcedure(userUpdateStr, procedure,
- TriggerEvent.UPDATE);
- }
-
- // testing rows updated incremented, Input and assignment statements
- @Test public void testCreateUpdateProcedure7() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = INPUT.e1, pm1.g1.e2 = INPUT.e2;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = 1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e2=40"; //$NON-NLS-1$
-
- helpPlanProcedure(userUpdateStr, procedure,
- TriggerEvent.UPDATE);
- }
-
// testing select into with virtual group in from clause
@Test public void testCreateVirtualProcedure1() throws Exception {
String procedure = "CREATE VIRTUAL PROCEDURE "; //$NON-NLS-1$
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestCalculateCostUtil.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestCalculateCostUtil.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestCalculateCostUtil.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -61,7 +61,7 @@
Criteria result = QueryParser.getQueryParser().parseCriteria(critString);
QueryResolver.resolveCriteria(result, metadata);
- result = QueryRewriter.rewriteCriteria(result, null, new CommandContext(), metadata);
+ result = QueryRewriter.rewriteCriteria(result, new CommandContext(), metadata);
return result;
}
Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -50,15 +50,6 @@
import org.teiid.query.sql.lang.UnaryFromClause;
import org.teiid.query.sql.lang.Update;
import org.teiid.query.sql.lang.SetQuery.Operation;
-import org.teiid.query.sql.proc.AssignmentStatement;
-import org.teiid.query.sql.proc.Block;
-import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
-import org.teiid.query.sql.proc.CriteriaSelector;
-import org.teiid.query.sql.proc.DeclareStatement;
-import org.teiid.query.sql.proc.HasCriteria;
-import org.teiid.query.sql.proc.IfStatement;
-import org.teiid.query.sql.proc.Statement;
-import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.Function;
@@ -754,90 +745,6 @@
TestParser.helpTest(sql, "SELECT b FROM (t1 LEFT OUTER JOIN /*+ optional */ t2 ON t1.a = t2.a) LEFT OUTER JOIN /*+ optional */ t3 ON t1.a = t3.a", query); //$NON-NLS-1$
}
- @Test public void testOptionalFromClause10(){
- //declare var1
- ElementSymbol var1 = new ElementSymbol("var1"); //$NON-NLS-1$
- String shortType = new String("short"); //$NON-NLS-1$
- Statement declStmt = new DeclareStatement(var1, shortType);
-
- //ifblock
- List symbols = new ArrayList();
- symbols.add(new ElementSymbol("a1")); //$NON-NLS-1$
- Select select = new Select(symbols);
-
- From from = new From();
- from.addGroup(new GroupSymbol("g")); //$NON-NLS-1$
-
- Criteria criteria = new CompareCriteria(new ElementSymbol("a2"), CompareCriteria.EQ, //$NON-NLS-1$
- new Constant(new Integer(5)));
-
- Query query = new Query();
- query.setSelect(select);
- query.setFrom(from);
- query.setCriteria(criteria);
-
- AssignmentStatement queryStmt = new AssignmentStatement(var1, query);
-
- Block ifBlock = new Block();
- ifBlock.addStatement(queryStmt);
-
- //else block
- ElementSymbol var2 = new ElementSymbol("var2"); //$NON-NLS-1$
- Statement elseDeclStmt = new DeclareStatement(var2, shortType);
-
- List elseSymbols = new ArrayList();
- elseSymbols.add(new ElementSymbol("b1")); //$NON-NLS-1$
- Select elseSelect = new Select(elseSymbols);
-
- Query elseQuery = new Query();
- elseQuery.setSelect(elseSelect);
- From elseFrom = (From)from.clone();
- UnaryFromClause ufc = new UnaryFromClause();
- ufc.setGroup(new GroupSymbol("h")); //$NON-NLS-1$
- ufc.setOptional(true);
- elseFrom.addClause(ufc);
- elseQuery.setFrom(elseFrom);
- elseQuery.setCriteria(criteria);
-
- AssignmentStatement elseQueryStmt = new AssignmentStatement(var2, elseQuery);
-
- Block elseBlock = new Block();
- List elseStmts = new ArrayList();
- elseStmts.add(elseDeclStmt);
- elseStmts.add(elseQueryStmt);
-
- elseBlock.setStatements(elseStmts);
-
- //has criteria
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
- elements.add(a);
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.IN);
- critSelector.setElements(elements);
-
- HasCriteria hasSelector = new HasCriteria();
- hasSelector.setSelector(critSelector);
-
- IfStatement stmt = new IfStatement(hasSelector, ifBlock, elseBlock);
-
- Block block = new Block();
- block.addStatement(declStmt);
- block.addStatement(stmt);
-
- CreateUpdateProcedureCommand cmd = new CreateUpdateProcedureCommand();
- cmd.setBlock(block);
-
- TestParser.helpTest("CREATE PROCEDURE BEGIN DECLARE short var1;"+ //$NON-NLS-1$
- " IF(HAS IN CRITERIA ON (a)) BEGIN var1 = (SELECT a1 FROM g WHERE a2 = 5); END"+ //$NON-NLS-1$
- " ELSE BEGIN DECLARE short var2; var2 = SELECT b1 FROM g, /*+ optional */ h WHERE a2 = 5; END" + //$NON-NLS-1$
- " END", "CREATE PROCEDURE"+"\n"+"BEGIN"+"\n"+"DECLARE short var1;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
- "IF(HAS IN CRITERIA ON (a))"+"\n"+"BEGIN"+"\n"+ "var1 = (SELECT a1 FROM g WHERE a2 = 5);"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- "END"+"\n"+"ELSE"+"\n"+"BEGIN"+"\n"+"DECLARE short var2;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
- "var2 = (SELECT b1 FROM g, /*+ optional */ h WHERE a2 = 5);"+"\n"+"END"+"\n"+"END", cmd); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- }
-
@Test public void testStoredQueryWithOption(){
StoredProcedure storedQuery = new StoredProcedure();
storedQuery.setProcedureName("proc1"); //$NON-NLS-1$
Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -41,90 +41,12 @@
import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.language.SQLConstants.Reserved;
import org.teiid.language.SortSpecification.NullOrdering;
-import org.teiid.query.sql.lang.ArrayTable;
-import org.teiid.query.sql.lang.BetweenCriteria;
-import org.teiid.query.sql.lang.Command;
-import org.teiid.query.sql.lang.CompareCriteria;
-import org.teiid.query.sql.lang.CompoundCriteria;
-import org.teiid.query.sql.lang.Create;
-import org.teiid.query.sql.lang.Criteria;
-import org.teiid.query.sql.lang.Delete;
-import org.teiid.query.sql.lang.Drop;
-import org.teiid.query.sql.lang.DynamicCommand;
-import org.teiid.query.sql.lang.ExistsCriteria;
-import org.teiid.query.sql.lang.ExpressionCriteria;
-import org.teiid.query.sql.lang.From;
-import org.teiid.query.sql.lang.FromClause;
-import org.teiid.query.sql.lang.GroupBy;
-import org.teiid.query.sql.lang.Insert;
-import org.teiid.query.sql.lang.Into;
-import org.teiid.query.sql.lang.IsNullCriteria;
-import org.teiid.query.sql.lang.JoinPredicate;
-import org.teiid.query.sql.lang.JoinType;
-import org.teiid.query.sql.lang.MatchCriteria;
-import org.teiid.query.sql.lang.NotCriteria;
-import org.teiid.query.sql.lang.OrderBy;
-import org.teiid.query.sql.lang.OrderByItem;
-import org.teiid.query.sql.lang.PredicateCriteria;
-import org.teiid.query.sql.lang.Query;
-import org.teiid.query.sql.lang.SPParameter;
-import org.teiid.query.sql.lang.Select;
-import org.teiid.query.sql.lang.SetClauseList;
-import org.teiid.query.sql.lang.SetCriteria;
-import org.teiid.query.sql.lang.SetQuery;
-import org.teiid.query.sql.lang.StoredProcedure;
-import org.teiid.query.sql.lang.SubqueryCompareCriteria;
-import org.teiid.query.sql.lang.SubqueryFromClause;
-import org.teiid.query.sql.lang.SubquerySetCriteria;
-import org.teiid.query.sql.lang.TableFunctionReference;
-import org.teiid.query.sql.lang.TextTable;
-import org.teiid.query.sql.lang.UnaryFromClause;
-import org.teiid.query.sql.lang.Update;
-import org.teiid.query.sql.lang.WithQueryCommand;
-import org.teiid.query.sql.lang.XMLTable;
+import org.teiid.query.sql.lang.*;
import org.teiid.query.sql.lang.SetQuery.Operation;
import org.teiid.query.sql.lang.TextTable.TextColumn;
-import org.teiid.query.sql.proc.AssignmentStatement;
-import org.teiid.query.sql.proc.Block;
-import org.teiid.query.sql.proc.BranchingStatement;
-import org.teiid.query.sql.proc.CommandStatement;
-import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
-import org.teiid.query.sql.proc.CriteriaSelector;
-import org.teiid.query.sql.proc.DeclareStatement;
-import org.teiid.query.sql.proc.HasCriteria;
-import org.teiid.query.sql.proc.IfStatement;
-import org.teiid.query.sql.proc.LoopStatement;
-import org.teiid.query.sql.proc.RaiseErrorStatement;
-import org.teiid.query.sql.proc.Statement;
-import org.teiid.query.sql.proc.TranslateCriteria;
-import org.teiid.query.sql.proc.WhileStatement;
+import org.teiid.query.sql.proc.*;
import org.teiid.query.sql.proc.BranchingStatement.BranchingMode;
-import org.teiid.query.sql.symbol.AggregateSymbol;
-import org.teiid.query.sql.symbol.AliasSymbol;
-import org.teiid.query.sql.symbol.CaseExpression;
-import org.teiid.query.sql.symbol.Constant;
-import org.teiid.query.sql.symbol.DerivedColumn;
-import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.query.sql.symbol.Expression;
-import org.teiid.query.sql.symbol.ExpressionSymbol;
-import org.teiid.query.sql.symbol.Function;
-import org.teiid.query.sql.symbol.GroupSymbol;
-import org.teiid.query.sql.symbol.MultipleElementSymbol;
-import org.teiid.query.sql.symbol.Reference;
-import org.teiid.query.sql.symbol.ScalarSubquery;
-import org.teiid.query.sql.symbol.SearchedCaseExpression;
-import org.teiid.query.sql.symbol.TestCaseExpression;
-import org.teiid.query.sql.symbol.TestSearchedCaseExpression;
-import org.teiid.query.sql.symbol.TextLine;
-import org.teiid.query.sql.symbol.WindowFunction;
-import org.teiid.query.sql.symbol.WindowSpecification;
-import org.teiid.query.sql.symbol.XMLAttributes;
-import org.teiid.query.sql.symbol.XMLElement;
-import org.teiid.query.sql.symbol.XMLForest;
-import org.teiid.query.sql.symbol.XMLNamespaces;
-import org.teiid.query.sql.symbol.XMLParse;
-import org.teiid.query.sql.symbol.XMLQuery;
-import org.teiid.query.sql.symbol.XMLSerialize;
+import org.teiid.query.sql.symbol.*;
@SuppressWarnings("nls")
public class TestParser {
@@ -178,20 +100,6 @@
assertEquals("Block does not match: ", expectedBlock, actualBlock); //$NON-NLS-1$
}
- private void helpCriteriaSelectorTest(String selector, String expectedString, CriteriaSelector expectedSelector) throws ParseException {
- CriteriaSelector actualSelector = new SQLParser(new StringReader(selector)).criteriaSelector();
- String actualString = actualSelector.toString();
- assertEquals("Parse string does not match: ", expectedString, actualString); //$NON-NLS-1$
- assertEquals("CriteriaSelector does not match: ", expectedSelector, actualSelector); //$NON-NLS-1$
- }
-
- private void helpCriteriaTest(String crit, String expectedString, Criteria expectedCrit) throws QueryParserException {
- Criteria actualCrit = QueryParser.getQueryParser().parseCriteria(crit);
- String actualString = actualCrit.toString();
- assertEquals("Parse string does not match: ", expectedString, actualString); //$NON-NLS-1$
- assertEquals("Criteria does not match: ", expectedCrit, actualCrit); //$NON-NLS-1$
- }
-
private void helpStmtTest(String stmt, String expectedString, Statement expectedStmt) throws ParseException {
Statement actualStmt = new SQLParser(new StringReader(stmt)).statement(new ParseInfo());
String actualString = actualStmt.toString();
@@ -3185,311 +3093,6 @@
stmt);
}
- @Test public void testCriteriaSelector0() throws Exception {
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.IS_NULL);
- critSelector.addElement(a);
-
- helpCriteriaSelectorTest("IS NULL CRITERIA ON (a)", "IS NULL CRITERIA ON (a)", critSelector); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- @Test public void testCriteriaSelector1() throws Exception {
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.COMPARE_EQ);
- critSelector.addElement(a);
-
- helpCriteriaSelectorTest("= CRITERIA ON (a)", "= CRITERIA ON (a)", critSelector); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- @Test public void testCriteriaSelector2() throws Exception {
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.COMPARE_NE);
- critSelector.addElement(a);
-
- helpCriteriaSelectorTest("<> CRITERIA ON (a)", "<> CRITERIA ON (a)", critSelector); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- @Test public void testCriteriaSelector3() throws Exception {
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.COMPARE_LT);
- critSelector.addElement(a);
-
- helpCriteriaSelectorTest("< CRITERIA ON (a)", "< CRITERIA ON (a)", critSelector); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- @Test public void testCriteriaSelector4() throws Exception {
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.COMPARE_GT);
- critSelector.addElement(a);
-
- helpCriteriaSelectorTest("> CRITERIA ON (a)", "> CRITERIA ON (a)", critSelector); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- @Test public void testCriteriaSelector5() throws Exception {
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.COMPARE_GE);
- critSelector.addElement(a);
-
- helpCriteriaSelectorTest(">= CRITERIA ON (a)", ">= CRITERIA ON (a)", critSelector); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- @Test public void testCriteriaSelector6() throws Exception {
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.COMPARE_LE);
- critSelector.addElement(a);
-
- helpCriteriaSelectorTest("<= CRITERIA ON (a)", "<= CRITERIA ON (a)", critSelector); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- @Test public void testCriteriaSelector7() throws Exception {
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.LIKE);
- critSelector.addElement(a);
-
- helpCriteriaSelectorTest("LIKE CRITERIA ON (a)", "LIKE CRITERIA ON (a)", critSelector); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
-
- @Test public void testCriteriaSelector8() throws Exception {
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.IN);
- critSelector.addElement(a);
-
- helpCriteriaSelectorTest("IN CRITERIA ON (a)", "IN CRITERIA ON (a)", critSelector); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- @Test public void testCriteriaSelector9() throws Exception {
- //ElementSymbol a = new ElementSymbol("a");
-
- CriteriaSelector critSelector = new CriteriaSelector();
- //critSelector.setSelectorType(CriteriaSelector.IS_NULL);
- //critSelector.addElement(a);
-
- helpCriteriaSelectorTest("CRITERIA", "CRITERIA", critSelector); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- @Test public void testCriteriaSelector10() throws Exception {
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.BETWEEN);
- critSelector.addElement(a);
-
- helpCriteriaSelectorTest("BETWEEN CRITERIA ON (a)", "BETWEEN CRITERIA ON (a)", critSelector); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**HAS IS NULL CRITERIA ON (a)*/
- @Test public void testHasIsNullCriteria() throws Exception {
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
- elements.add(a);
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.IS_NULL);
- critSelector.setElements(elements);
-
- HasCriteria hasSelector = new HasCriteria();
- hasSelector.setSelector(critSelector);
-
- helpCriteriaTest("HAS IS NULL CRITERIA ON (a)", "HAS IS NULL CRITERIA ON (a)", //$NON-NLS-1$ //$NON-NLS-2$
- hasSelector);
- }
-
- /**HAS LIKE CRITERIA ON (a)*/
- @Test public void testHasLikeCriteria() throws Exception {
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
- elements.add(a);
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.LIKE);
- critSelector.setElements(elements);
-
- HasCriteria hasSelector = new HasCriteria();
- hasSelector.setSelector(critSelector);
-
- helpCriteriaTest("HAS LIKE CRITERIA ON (a)", "HAS LIKE CRITERIA ON (a)", //$NON-NLS-1$ //$NON-NLS-2$
- hasSelector);
- }
-
- @Test public void testHasEQCriteria() throws Exception {
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List<ElementSymbol> elements = new ArrayList<ElementSymbol>();
- elements.add(a);
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.COMPARE_EQ);
- critSelector.setElements(elements);
-
- HasCriteria hasSelector = new HasCriteria();
- hasSelector.setSelector(critSelector);
-
- helpCriteriaTest("HAS = CRITERIA ON (a)", "HAS = CRITERIA ON (a)", //$NON-NLS-1$ //$NON-NLS-2$
- hasSelector);
- }
-
- @Test public void testHasNECriteria() throws Exception {
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
- elements.add(a);
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.COMPARE_NE);
- critSelector.setElements(elements);
-
- HasCriteria hasSelector = new HasCriteria();
- hasSelector.setSelector(critSelector);
-
- helpCriteriaTest("HAS <> CRITERIA ON (a)", "HAS <> CRITERIA ON (a)", //$NON-NLS-1$ //$NON-NLS-2$
- hasSelector);
- }
-
- /**HAS IN CRITERIA ON (a)*/
- @Test public void testHasInCriteria() throws Exception {
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List<ElementSymbol> elements = new ArrayList<ElementSymbol>();
- elements.add(a);
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.IN);
- critSelector.setElements(elements);
-
- HasCriteria hasSelector = new HasCriteria();
- hasSelector.setSelector(critSelector);
-
- helpCriteriaTest("HAS IN CRITERIA ON (a)", "HAS IN CRITERIA ON (a)", //$NON-NLS-1$ //$NON-NLS-2$
- hasSelector);
- }
-
- /**HAS COMPARE_LT CRITERIA ON (a)*/
- @Test public void testHasLTCriteria() throws Exception {
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List<ElementSymbol> elements = new ArrayList<ElementSymbol>();
- elements.add(a);
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.COMPARE_LT);
- critSelector.setElements(elements);
-
- HasCriteria hasSelector = new HasCriteria();
- hasSelector.setSelector(critSelector);
-
- helpCriteriaTest("HAS < CRITERIA ON (a)", "HAS < CRITERIA ON (a)", //$NON-NLS-1$ //$NON-NLS-2$
- hasSelector);
- }
-
- /**HAS COMPARE_LE CRITERIA ON (a)*/
- @Test public void testHasLECriteria() throws Exception {
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List<ElementSymbol> elements = new ArrayList<ElementSymbol>();
- elements.add(a);
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.COMPARE_LE);
- critSelector.setElements(elements);
-
- HasCriteria hasSelector = new HasCriteria();
- hasSelector.setSelector(critSelector);
-
- helpCriteriaTest("HAS <= CRITERIA ON (a)", "HAS <= CRITERIA ON (a)", //$NON-NLS-1$ //$NON-NLS-2$
- hasSelector);
- }
-
- /**HAS COMPARE_GT CRITERIA ON (a)*/
- @Test public void testHasGTCriteria() throws Exception {
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
- elements.add(a);
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.COMPARE_GT);
- critSelector.setElements(elements);
-
- HasCriteria hasSelector = new HasCriteria();
- hasSelector.setSelector(critSelector);
-
- helpCriteriaTest("HAS > CRITERIA ON (a)", "HAS > CRITERIA ON (a)", //$NON-NLS-1$ //$NON-NLS-2$
- hasSelector);
- }
-
- /**HAS COMPARE_GE CRITERIA ON (a)*/
- @Test public void testHasGECriteria() throws Exception {
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
- elements.add(a);
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.COMPARE_GE);
- critSelector.setElements(elements);
-
- HasCriteria hasSelector = new HasCriteria();
- hasSelector.setSelector(critSelector);
-
- helpCriteriaTest("HAS >= CRITERIA ON (a)", "HAS >= CRITERIA ON (a)", //$NON-NLS-1$ //$NON-NLS-2$
- hasSelector);
- }
-
- /**HAS BETWEEN CRITERIA ON (a)*/
- @Test public void testHasBetweenCriteria() throws Exception {
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
- elements.add(a);
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.BETWEEN);
- critSelector.setElements(elements);
-
- HasCriteria hasSelector = new HasCriteria();
- hasSelector.setSelector(critSelector);
-
- helpCriteriaTest("HAS BETWEEN CRITERIA ON (a)", "HAS BETWEEN CRITERIA ON (a)", //$NON-NLS-1$ //$NON-NLS-2$
- hasSelector);
- }
-
- @Test public void testTranslateCriteria() throws Exception {
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
- elements.add(a);
-
- Criteria crit = new CompareCriteria(a, CompareCriteria.EQ,
- new Constant(new Integer(5)));
- List critList = new ArrayList();
- critList.add(crit);
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.IS_NULL);
- critSelector.setElements(elements);
-
- TranslateCriteria transCriteria = new TranslateCriteria(critSelector, critList);
-
- helpCriteriaTest("TRANSLATE IS NULL CRITERIA ON (a) WITH (a = 5)", //$NON-NLS-1$
- "TRANSLATE IS NULL CRITERIA ON (a) WITH (a = 5)", //$NON-NLS-1$
- transCriteria);
-
- //helpCriteriaTest("TRANSLATE IS NULL CRITERIA ON (a) USING transFuncEQ (a)",
- //"TRANSLATE IS NULL CRITERIA ON (a) USING transFuncEQ (a)",
- //transCriteria);
-
- }
-
@Test public void testAssignStatement() throws Exception {
ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
@@ -3679,1234 +3282,6 @@
helpException("create virtual procedure begin execute string z into #g using x=variables.y; end"); //$NON-NLS-1$
}
- /** original test */
- @Test public void testCreateUpdateProcedureCommand(){
- helpTestCreateUpdateProcedureCommandCase3025("CREATE PROCEDURE\nBEGIN\nDECLARE short var1;"+ //$NON-NLS-1$
- "IF(HAS IS NULL CRITERIA ON (a))\nBEGIN\nvar1 = (SELECT a1 FROM g WHERE a2 = 5);\nEND\n"+ //$NON-NLS-1$
- "ELSE\nBEGIN\nDECLARE short var2;\nvar2 = (SELECT b1 FROM g WHERE a2 = 5);\nEND\n" + //$NON-NLS-1$
- " END"); //$NON-NLS-1$
-
- }
-
- @Test public void testCreateUpdateProcedureCommandCase3025_1(){
-
- helpTestCreateUpdateProcedureCommandCase3025("CREATE PROCEDURE\nBEGIN\nDECLARE short var1;"+ //$NON-NLS-1$
- "IF(HAS IS NULL CRITERIA ON (a))\nBEGIN\nvar1 = (SELECT a1 FROM g WHERE a2 = 5);\nEND\n"+ //$NON-NLS-1$
- "ELSE\nBEGIN\nDECLARE short var2;\nvar2 = (SELECT b1 FROM g WHERE a2 = 5);\nEND\n" + //$NON-NLS-1$
- " END"); //$NON-NLS-1$
-
- }
-
- @Test public void testCreateUpdateProcedureCommandCase3025_2(){
- helpTestCreateUpdateProcedureCommandCase3025("CREATE PROCEDURE\nBEGIN\nDECLARE short var1;"+ //$NON-NLS-1$
- "IF(HAS IS NULL CRITERIA ON (a))\nBEGIN\nvar1 = ((SELECT a1 FROM g WHERE a2 = 5) );\nEND\n"+ //$NON-NLS-1$
- "ELSE\nBEGIN\nDECLARE short var2;\nvar2 = (SELECT b1 FROM g WHERE a2 = 5);\nEND\n" + //$NON-NLS-1$
- " END"); //$NON-NLS-1$
- }
-
- private void helpTestCreateUpdateProcedureCommandCase3025(String procedureString){
- //declare var1
- ElementSymbol var1 = new ElementSymbol("var1"); //$NON-NLS-1$
- String shortType = new String("short"); //$NON-NLS-1$
- Statement declStmt = new DeclareStatement(var1, shortType);
-
- //ifblock
- List<ElementSymbol> symbols = new ArrayList<ElementSymbol>();
- symbols.add(new ElementSymbol("a1")); //$NON-NLS-1$
- Select select = new Select(symbols);
-
- From from = new From();
- from.addGroup(new GroupSymbol("g")); //$NON-NLS-1$
-
- Criteria criteria = new CompareCriteria(new ElementSymbol("a2"), CompareCriteria.EQ, //$NON-NLS-1$
- new Constant(new Integer(5)));
-
- Query query = new Query();
- query.setSelect(select);
- query.setFrom(from);
- query.setCriteria(criteria);
-
- AssignmentStatement queryStmt = new AssignmentStatement(var1, query);
-
- Block ifBlock = new Block();
- ifBlock.addStatement(queryStmt);
-
- //else block
- ElementSymbol var2 = new ElementSymbol("var2"); //$NON-NLS-1$
- Statement elseDeclStmt = new DeclareStatement(var2, shortType);
-
- List<ElementSymbol> elseSymbols = new ArrayList<ElementSymbol>();
- elseSymbols.add(new ElementSymbol("b1")); //$NON-NLS-1$
- Select elseSelect = new Select(elseSymbols);
-
- Query elseQuery = new Query();
- elseQuery.setSelect(elseSelect);
- elseQuery.setFrom(from);
- elseQuery.setCriteria(criteria);
-
- AssignmentStatement elseQueryStmt = new AssignmentStatement(var2, elseQuery);
-
- Block elseBlock = new Block();
- List elseStmts = new ArrayList();
- elseStmts.add(elseDeclStmt);
- elseStmts.add(elseQueryStmt);
-
- elseBlock.setStatements(elseStmts);
-
- //has criteria
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
- elements.add(a);
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.IS_NULL);
- critSelector.setElements(elements);
-
- HasCriteria hasSelector = new HasCriteria();
- hasSelector.setSelector(critSelector);
-
- IfStatement stmt = new IfStatement(hasSelector, ifBlock, elseBlock);
-
- Block block = new Block();
-
- block.addStatement(declStmt);
- block.addStatement(stmt);
-
- CreateUpdateProcedureCommand cmd = new CreateUpdateProcedureCommand();
- cmd.setBlock(block);
-
- helpTest(procedureString, "CREATE PROCEDURE"+"\n"+"BEGIN"+"\n"+"DECLARE short var1;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- "IF(HAS IS NULL CRITERIA ON (a))"+"\n"+"BEGIN"+"\n"+ "var1 = (SELECT a1 FROM g WHERE a2 = 5);"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- "END"+"\n"+"ELSE"+"\n"+"BEGIN"+"\n"+"DECLARE short var2;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
- "var2 = (SELECT b1 FROM g WHERE a2 = 5);"+"\n"+"END"+"\n"+"END", cmd); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
-
- }
-
- /** test an expression in parentheses in an assignment statement */
- @Test public void testCreateUpdateProcedureCommandCase3025_3(){
-
- String procedureString = "CREATE PROCEDURE\nBEGIN\nDECLARE short var1;"+ //$NON-NLS-1$
- "IF(HAS IS NULL CRITERIA ON (a))\nBEGIN\nvar1 = (concat('x', 'y') );\nEND\n"+ //$NON-NLS-1$
- "ELSE\nBEGIN\nDECLARE short var2;\nvar2 = (SELECT b1 FROM g WHERE a2 = 5);\nEND\n" + //$NON-NLS-1$
- " END"; //$NON-NLS-1$
-
- helpTestCreateUpdateProcedureCommandCase3025_Expression(procedureString);
- }
-
- /** test an expression in parentheses in an assignment statement */
- @Test public void testCreateUpdateProcedureCommandCase3025_4(){
-
- String procedureString = "CREATE PROCEDURE\nBEGIN\nDECLARE short var1;"+ //$NON-NLS-1$
- "IF(HAS IS NULL CRITERIA ON (a))\nBEGIN\nvar1 = ((concat('x', 'y') ));\nEND\n"+ //$NON-NLS-1$
- "ELSE\nBEGIN\nDECLARE short var2;\nvar2 = (SELECT b1 FROM g WHERE a2 = 5);\nEND\n" + //$NON-NLS-1$
- " END"; //$NON-NLS-1$
-
- helpTestCreateUpdateProcedureCommandCase3025_Expression(procedureString);
- }
-
- /** test an expression without parentheses in an assignment statement */
- @Test public void testCreateUpdateProcedureCommandCase3025_5(){
-
- String procedureString = "CREATE PROCEDURE\nBEGIN\nDECLARE short var1;"+ //$NON-NLS-1$
- "IF(HAS IS NULL CRITERIA ON (a))\nBEGIN\nvar1 = concat('x', 'y') ;\nEND\n"+ //$NON-NLS-1$
- "ELSE\nBEGIN\nDECLARE short var2;\nvar2 = (SELECT b1 FROM g WHERE a2 = 5);\nEND\n" + //$NON-NLS-1$
- " END"; //$NON-NLS-1$
-
- helpTestCreateUpdateProcedureCommandCase3025_Expression(procedureString);
- }
-
-
- /** test an expression in parentheses in an assignment statement */
- private void helpTestCreateUpdateProcedureCommandCase3025_Expression(String procedureString){
- String expectedString = "CREATE PROCEDURE"+"\n"+"BEGIN"+"\n"+"DECLARE short var1;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- "IF(HAS IS NULL CRITERIA ON (a))"+"\n"+"BEGIN"+"\n"+ "var1 = concat('x', 'y');"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- "END"+"\n"+"ELSE"+"\n"+"BEGIN"+"\n"+"DECLARE short var2;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
- "var2 = (SELECT b1 FROM g WHERE a2 = 5);"+"\n"+"END"+"\n"+"END"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
-
- //declare var1
- ElementSymbol var1 = new ElementSymbol("var1"); //$NON-NLS-1$
- String shortType = new String("short"); //$NON-NLS-1$
- Statement declStmt = new DeclareStatement(var1, shortType);
-
- //ifblock
- Expression[] args = new Expression[] {new Constant("x"), new Constant("y")}; //$NON-NLS-1$ //$NON-NLS-2$
- Function function = new Function("concat", args); //$NON-NLS-1$
- AssignmentStatement queryStmt = new AssignmentStatement(var1, function);
-
- Block ifBlock = new Block();
- ifBlock.addStatement(queryStmt);
-
- //else block
- ElementSymbol var2 = new ElementSymbol("var2"); //$NON-NLS-1$
- Statement elseDeclStmt = new DeclareStatement(var2, shortType);
-
- List<ElementSymbol> elseSymbols = new ArrayList<ElementSymbol>();
- elseSymbols.add(new ElementSymbol("b1")); //$NON-NLS-1$
- Select elseSelect = new Select(elseSymbols);
-
- From from = new From();
- from.addGroup(new GroupSymbol("g")); //$NON-NLS-1$
-
- Criteria criteria = new CompareCriteria(new ElementSymbol("a2"), CompareCriteria.EQ, //$NON-NLS-1$
- new Constant(new Integer(5)));
-
- Query elseQuery = new Query();
- elseQuery.setSelect(elseSelect);
- elseQuery.setFrom(from);
- elseQuery.setCriteria(criteria);
-
- AssignmentStatement elseQueryStmt = new AssignmentStatement(var2, elseQuery);
-
- Block elseBlock = new Block();
- List elseStmts = new ArrayList();
- elseStmts.add(elseDeclStmt);
- elseStmts.add(elseQueryStmt);
-
- elseBlock.setStatements(elseStmts);
-
- //has criteria
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
- elements.add(a);
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.IS_NULL);
- critSelector.setElements(elements);
-
- HasCriteria hasSelector = new HasCriteria();
- hasSelector.setSelector(critSelector);
-
- IfStatement stmt = new IfStatement(hasSelector, ifBlock, elseBlock);
-
- Block block = new Block();
-
- block.addStatement(declStmt);
- block.addStatement(stmt);
-
- CreateUpdateProcedureCommand cmd = new CreateUpdateProcedureCommand();
- cmd.setBlock(block);
-
- helpTest(procedureString, expectedString, cmd);
- }
-
- /**IF statement with has criteria */
- @Test public void testCreateUpdateProcedureCommand1(){
- //declare var1
- ElementSymbol var1 = new ElementSymbol("var1"); //$NON-NLS-1$
- String shortType = new String("short"); //$NON-NLS-1$
- Statement declStmt = new DeclareStatement(var1, shortType);
-
- //ifblock
- List symbols = new ArrayList();
- symbols.add(new ElementSymbol("a1")); //$NON-NLS-1$
- Select select = new Select(symbols);
-
- From from = new From();
- from.addGroup(new GroupSymbol("g")); //$NON-NLS-1$
-
- Criteria criteria = new CompareCriteria(new ElementSymbol("a2"), CompareCriteria.EQ, //$NON-NLS-1$
- new Constant(new Integer(5)));
-
- Query query = new Query();
- query.setSelect(select);
- query.setFrom(from);
- query.setCriteria(criteria);
-
- AssignmentStatement queryStmt = new AssignmentStatement(var1, query);
-
- Block ifBlock = new Block();
- ifBlock.addStatement(queryStmt);
-
- //else block
- ElementSymbol var2 = new ElementSymbol("var2"); //$NON-NLS-1$
- Statement elseDeclStmt = new DeclareStatement(var2, shortType);
-
- List elseSymbols = new ArrayList();
- elseSymbols.add(new ElementSymbol("b1")); //$NON-NLS-1$
- Select elseSelect = new Select(elseSymbols);
-
- Query elseQuery = new Query();
- elseQuery.setSelect(elseSelect);
- elseQuery.setFrom(from);
- elseQuery.setCriteria(criteria);
-
- AssignmentStatement elseQueryStmt = new AssignmentStatement(var2, elseQuery);
-
- Block elseBlock = new Block();
- List elseStmts = new ArrayList();
- elseStmts.add(elseDeclStmt);
- elseStmts.add(elseQueryStmt);
-
- elseBlock.setStatements(elseStmts);
-
- //has criteria
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
- elements.add(a);
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setElements(elements);
-
- HasCriteria hasSelector = new HasCriteria();
- hasSelector.setSelector(critSelector);
-
- IfStatement stmt = new IfStatement(hasSelector, ifBlock, elseBlock);
-
- Block block = new Block();
- block.addStatement(declStmt);
- block.addStatement(stmt);
-
- CreateUpdateProcedureCommand cmd = new CreateUpdateProcedureCommand();
- cmd.setBlock(block);
-
- helpTest("CREATE PROCEDURE BEGIN DECLARE short var1;"+ //$NON-NLS-1$
- " IF(HAS CRITERIA ON (a)) BEGIN var1 = SELECT a1 FROM g WHERE a2 = 5; END"+ //$NON-NLS-1$
- " ELSE BEGIN DECLARE short var2; var2 = SELECT b1 FROM g WHERE a2 = 5; END" + //$NON-NLS-1$
- " END", "CREATE PROCEDURE"+"\n"+"BEGIN"+"\n"+"DECLARE short var1;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
- "IF(HAS CRITERIA ON (a))"+"\n"+"BEGIN"+"\n"+ "var1 = (SELECT a1 FROM g WHERE a2 = 5);"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- "END"+"\n"+"ELSE"+"\n"+"BEGIN"+"\n"+"DECLARE short var2;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
- "var2 = (SELECT b1 FROM g WHERE a2 = 5);"+"\n"+"END"+"\n"+"END", cmd); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- }
-
- @Test public void testCreateUpdateProcedureCommand0(){
- //declare var1
- ElementSymbol var1 = new ElementSymbol("var1"); //$NON-NLS-1$
- String shortType = new String("short"); //$NON-NLS-1$
- Statement declStmt = new DeclareStatement(var1, shortType);
-
- //ifblock
- List symbols = new ArrayList();
- symbols.add(new ElementSymbol("a1")); //$NON-NLS-1$
- Select select = new Select(symbols);
-
- From from = new From();
- from.addGroup(new GroupSymbol("g")); //$NON-NLS-1$
-
- Criteria criteria = new CompareCriteria(new ElementSymbol("a2"), CompareCriteria.EQ, //$NON-NLS-1$
- new Constant(new Integer(5)));
-
- Query query = new Query();
- query.setSelect(select);
- query.setFrom(from);
- query.setCriteria(criteria);
-
- AssignmentStatement queryStmt = new AssignmentStatement(var1, query);
-
- Block ifBlock = new Block();
- ifBlock.addStatement(queryStmt);
-
- //else block
- ElementSymbol var2 = new ElementSymbol("var2"); //$NON-NLS-1$
- Statement elseDeclStmt = new DeclareStatement(var2, shortType);
-
- List elseSymbols = new ArrayList();
- elseSymbols.add(new ElementSymbol("b1")); //$NON-NLS-1$
- Select elseSelect = new Select(elseSymbols);
-
- Query elseQuery = new Query();
- elseQuery.setSelect(elseSelect);
- elseQuery.setFrom(from);
- elseQuery.setCriteria(criteria);
-
- AssignmentStatement elseQueryStmt = new AssignmentStatement(var2, elseQuery);
-
- Block elseBlock = new Block();
- List elseStmts = new ArrayList();
- elseStmts.add(elseDeclStmt);
- elseStmts.add(elseQueryStmt);
-
- elseBlock.setStatements(elseStmts);
-
- //has criteria
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
- elements.add(a);
-
- CriteriaSelector critSelector = new CriteriaSelector();
- //critSelector.setElements(elements);
-
- HasCriteria hasSelector = new HasCriteria();
- hasSelector.setSelector(critSelector);
-
- IfStatement stmt = new IfStatement(hasSelector, ifBlock, elseBlock);
-
- Block block = new Block();
- block.addStatement(declStmt);
- block.addStatement(stmt);
-
- CreateUpdateProcedureCommand cmd = new CreateUpdateProcedureCommand();
- cmd.setBlock(block);
-
- helpTest("CREATE PROCEDURE BEGIN DECLARE short var1;"+ //$NON-NLS-1$
- " IF(HAS CRITERIA) BEGIN var1 = SELECT a1 FROM g WHERE a2 = 5; END"+ //$NON-NLS-1$
- " ELSE BEGIN DECLARE short var2; var2 = SELECT b1 FROM g WHERE a2 = 5; END" + //$NON-NLS-1$
- " END", "CREATE PROCEDURE"+"\n"+"BEGIN"+"\n"+"DECLARE short var1;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
- "IF(HAS CRITERIA)"+"\n"+"BEGIN"+"\n"+ "var1 = (SELECT a1 FROM g WHERE a2 = 5);"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- "END"+"\n"+"ELSE"+"\n"+"BEGIN"+"\n"+"DECLARE short var2;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
- "var2 = (SELECT b1 FROM g WHERE a2 = 5);"+"\n"+"END"+"\n"+"END", cmd); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- }
-
- /**IF statement with has LIKE criteria */
- @Test public void testCreateUpdateProcedureCommand2(){
- //declare var1
- ElementSymbol var1 = new ElementSymbol("var1"); //$NON-NLS-1$
- String shortType = new String("short"); //$NON-NLS-1$
- Statement declStmt = new DeclareStatement(var1, shortType);
-
- //ifblock
- List symbols = new ArrayList();
- symbols.add(new ElementSymbol("a1")); //$NON-NLS-1$
- Select select = new Select(symbols);
-
- From from = new From();
- from.addGroup(new GroupSymbol("g")); //$NON-NLS-1$
-
- Criteria criteria = new CompareCriteria(new ElementSymbol("a2"), CompareCriteria.EQ, //$NON-NLS-1$
- new Constant(new Integer(5)));
-
- Query query = new Query();
- query.setSelect(select);
- query.setFrom(from);
- query.setCriteria(criteria);
-
- AssignmentStatement queryStmt = new AssignmentStatement(var1, query);
-
- Block ifBlock = new Block();
- ifBlock.addStatement(queryStmt);
-
- //else block
- ElementSymbol var2 = new ElementSymbol("var2"); //$NON-NLS-1$
- Statement elseDeclStmt = new DeclareStatement(var2, shortType);
-
- List elseSymbols = new ArrayList();
- elseSymbols.add(new ElementSymbol("b1")); //$NON-NLS-1$
- Select elseSelect = new Select(elseSymbols);
-
- Query elseQuery = new Query();
- elseQuery.setSelect(elseSelect);
- elseQuery.setFrom(from);
- elseQuery.setCriteria(criteria);
-
- AssignmentStatement elseQueryStmt = new AssignmentStatement(var2, elseQuery);
-
- Block elseBlock = new Block();
- List elseStmts = new ArrayList();
- elseStmts.add(elseDeclStmt);
- elseStmts.add(elseQueryStmt);
-
- elseBlock.setStatements(elseStmts);
-
- //has criteria
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
- elements.add(a);
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.LIKE);
- critSelector.setElements(elements);
-
- HasCriteria hasSelector = new HasCriteria();
- hasSelector.setSelector(critSelector);
-
- IfStatement stmt = new IfStatement(hasSelector, ifBlock, elseBlock);
-
- Block block = new Block();
- block.addStatement(declStmt);
- block.addStatement(stmt);
-
- CreateUpdateProcedureCommand cmd = new CreateUpdateProcedureCommand();
- cmd.setBlock(block);
-
- helpTest("CREATE PROCEDURE BEGIN DECLARE short var1;"+ //$NON-NLS-1$
- " IF(HAS LIKE CRITERIA ON (a)) BEGIN var1 = SELECT a1 FROM g WHERE a2 = 5; END"+ //$NON-NLS-1$
- " ELSE BEGIN DECLARE short var2; var2 = SELECT b1 FROM g WHERE a2 = 5; END" + //$NON-NLS-1$
- " END", "CREATE PROCEDURE"+"\n"+"BEGIN"+"\n"+"DECLARE short var1;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
- "IF(HAS LIKE CRITERIA ON (a))"+"\n"+"BEGIN"+"\n"+ "var1 = (SELECT a1 FROM g WHERE a2 = 5);"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- "END"+"\n"+"ELSE"+"\n"+"BEGIN"+"\n"+"DECLARE short var2;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
- "var2 = (SELECT b1 FROM g WHERE a2 = 5);"+"\n"+"END"+"\n"+"END", cmd); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- }
-
- /**IF statement with has IN criteria */
- @Test public void testCreateUpdateProcedureCommand3(){
- //declare var1
- ElementSymbol var1 = new ElementSymbol("var1"); //$NON-NLS-1$
- String shortType = new String("short"); //$NON-NLS-1$
- Statement declStmt = new DeclareStatement(var1, shortType);
-
- //ifblock
- List symbols = new ArrayList();
- symbols.add(new ElementSymbol("a1")); //$NON-NLS-1$
- Select select = new Select(symbols);
-
- From from = new From();
- from.addGroup(new GroupSymbol("g")); //$NON-NLS-1$
-
- Criteria criteria = new CompareCriteria(new ElementSymbol("a2"), CompareCriteria.EQ, //$NON-NLS-1$
- new Constant(new Integer(5)));
-
- Query query = new Query();
- query.setSelect(select);
- query.setFrom(from);
- query.setCriteria(criteria);
-
- AssignmentStatement queryStmt = new AssignmentStatement(var1, query);
-
- Block ifBlock = new Block();
- ifBlock.addStatement(queryStmt);
-
- //else block
- ElementSymbol var2 = new ElementSymbol("var2"); //$NON-NLS-1$
- Statement elseDeclStmt = new DeclareStatement(var2, shortType);
-
- List elseSymbols = new ArrayList();
- elseSymbols.add(new ElementSymbol("b1")); //$NON-NLS-1$
- Select elseSelect = new Select(elseSymbols);
-
- Query elseQuery = new Query();
- elseQuery.setSelect(elseSelect);
- elseQuery.setFrom(from);
- elseQuery.setCriteria(criteria);
-
- AssignmentStatement elseQueryStmt = new AssignmentStatement(var2, elseQuery);
-
- Block elseBlock = new Block();
- List elseStmts = new ArrayList();
- elseStmts.add(elseDeclStmt);
- elseStmts.add(elseQueryStmt);
-
- elseBlock.setStatements(elseStmts);
-
- //has criteria
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
- elements.add(a);
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.IN);
- critSelector.setElements(elements);
-
- HasCriteria hasSelector = new HasCriteria();
- hasSelector.setSelector(critSelector);
-
- IfStatement stmt = new IfStatement(hasSelector, ifBlock, elseBlock);
-
- Block block = new Block();
- block.addStatement(declStmt);
- block.addStatement(stmt);
-
- CreateUpdateProcedureCommand cmd = new CreateUpdateProcedureCommand();
- cmd.setBlock(block);
-
- helpTest("CREATE PROCEDURE BEGIN DECLARE short var1;"+ //$NON-NLS-1$
- " IF(HAS IN CRITERIA ON (a)) BEGIN var1 = SELECT a1 FROM g WHERE a2 = 5; END"+ //$NON-NLS-1$
- " ELSE BEGIN DECLARE short var2; var2 = SELECT b1 FROM g WHERE a2 = 5; END" + //$NON-NLS-1$
- " END", "CREATE PROCEDURE"+"\n"+"BEGIN"+"\n"+"DECLARE short var1;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
- "IF(HAS IN CRITERIA ON (a))"+"\n"+"BEGIN"+"\n"+ "var1 = (SELECT a1 FROM g WHERE a2 = 5);"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- "END"+"\n"+"ELSE"+"\n"+"BEGIN"+"\n"+"DECLARE short var2;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
- "var2 = (SELECT b1 FROM g WHERE a2 = 5);"+"\n"+"END"+"\n"+"END", cmd); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- }
-
- /**IF statement with has <> criteria */
- @Test public void testCreateUpdateProcedureCommand4(){
- //declare var1
- ElementSymbol var1 = new ElementSymbol("var1"); //$NON-NLS-1$
- String shortType = new String("short"); //$NON-NLS-1$
- Statement declStmt = new DeclareStatement(var1, shortType);
-
- //ifblock
- List symbols = new ArrayList();
- symbols.add(new ElementSymbol("a1")); //$NON-NLS-1$
- Select select = new Select(symbols);
-
- From from = new From();
- from.addGroup(new GroupSymbol("g")); //$NON-NLS-1$
-
- Criteria criteria = new CompareCriteria(new ElementSymbol("a2"), CompareCriteria.EQ, //$NON-NLS-1$
- new Constant(new Integer(5)));
-
- Query query = new Query();
- query.setSelect(select);
- query.setFrom(from);
- query.setCriteria(criteria);
-
- AssignmentStatement queryStmt = new AssignmentStatement(var1, query);
-
- Block ifBlock = new Block();
- ifBlock.addStatement(queryStmt);
-
- //else block
- ElementSymbol var2 = new ElementSymbol("var2"); //$NON-NLS-1$
- Statement elseDeclStmt = new DeclareStatement(var2, shortType);
-
- List elseSymbols = new ArrayList();
- elseSymbols.add(new ElementSymbol("b1")); //$NON-NLS-1$
- Select elseSelect = new Select(elseSymbols);
-
- Query elseQuery = new Query();
- elseQuery.setSelect(elseSelect);
- elseQuery.setFrom(from);
- elseQuery.setCriteria(criteria);
-
- AssignmentStatement elseQueryStmt = new AssignmentStatement(var2, elseQuery);
-
- Block elseBlock = new Block();
- List elseStmts = new ArrayList();
- elseStmts.add(elseDeclStmt);
- elseStmts.add(elseQueryStmt);
-
- elseBlock.setStatements(elseStmts);
-
- //has criteria
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
- elements.add(a);
-
- CriteriaSelector critSelector = new CriteriaSelector();
- critSelector.setSelectorType(CriteriaSelector.COMPARE_NE);
- critSelector.setElements(elements);
-
- HasCriteria hasSelector = new HasCriteria();
- hasSelector.setSelector(critSelector);
-
- IfStatement stmt = new IfStatement(hasSelector, ifBlock, elseBlock);
-
- Block block = new Block();
- block.addStatement(declStmt);
- block.addStatement(stmt);
-
- CreateUpdateProcedureCommand cmd = new CreateUpdateProcedureCommand();
- cmd.setBlock(block);
-
- helpTest("CREATE PROCEDURE BEGIN DECLARE short var1;"+ //$NON-NLS-1$
- " IF(HAS <> CRITERIA ON (a)) BEGIN var1 = SELECT a1 FROM g WHERE a2 = 5; END"+ //$NON-NLS-1$
- " ELSE BEGIN DECLARE short var2; var2 = SELECT b1 FROM g WHERE a2 = 5; END" + //$NON-NLS-1$
- " END", "CREATE PROCEDURE"+"\n"+"BEGIN"+"\n"+"DECLARE short var1;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
- "IF(HAS <> CRITERIA ON (a))"+"\n"+"BEGIN"+"\n"+ "var1 = (SELECT a1 FROM g WHERE a2 = 5);"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- "END"+"\n"+"ELSE"+"\n"+"BEGIN"+"\n"+"DECLARE short var2;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
- "var2 = (SELECT b1 FROM g WHERE a2 = 5);"+"\n"+"END"+"\n"+"END", cmd); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- }
-
- /**Has criteria in WHERE clause*/
- @Test public void testCreateUpdateProcedureCommand5(){
- //declare var1
- ElementSymbol var1 = new ElementSymbol("var1"); //$NON-NLS-1$
- String shortType = new String("short"); //$NON-NLS-1$
- Statement declStmt = new DeclareStatement(var1, shortType);
-
- //ifblock
- List symbols = new ArrayList();
- symbols.add(new ElementSymbol("a1")); //$NON-NLS-1$
- Select select = new Select(symbols);
-
- From from = new From();
- from.addGroup(new GroupSymbol("g")); //$NON-NLS-1$
-
- Criteria criteria = new CompareCriteria(new ElementSymbol("a2"), CompareCriteria.EQ, //$NON-NLS-1$
- new Constant(new Integer(5)));
-
- Query query = new Query();
- query.setSelect(select);
- query.setFrom(from);
- query.setCriteria(criteria);
-
- AssignmentStatement queryStmt = new AssignmentStatement(var1, query);
-
- Block ifBlock = new Block();
- ifBlock.addStatement(queryStmt);
-
- //else block
- ElementSymbol var2 = new ElementSymbol("var2"); //$NON-NLS-1$
- Statement elseDeclStmt = new DeclareStatement(var2, shortType);
-
- //element for has criteria
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
- elements.add(a);
-
- List elseSymbols = new ArrayList();
- elseSymbols.add(new ElementSymbol("b1")); //$NON-NLS-1$
- Select elseSelect = new Select(elseSymbols);
-
- Query elseQuery = new Query();
- elseQuery.setSelect(elseSelect);
- elseQuery.setFrom(from);
-
- CriteriaSelector critSelector2 = new CriteriaSelector();
- //critSelector2.setSelectorType(CriteriaSelector.COMPARE_NE);
- critSelector2.setElements(elements);
-
- HasCriteria hasSelector2 = new HasCriteria();
- hasSelector2.setSelector(critSelector2);
- //has criteria for else block
- elseQuery.setCriteria(hasSelector2);
-
- AssignmentStatement elseQueryStmt = new AssignmentStatement(var2, elseQuery);
-
- Block elseBlock = new Block();
- List elseStmts = new ArrayList();
- elseStmts.add(elseDeclStmt);
- elseStmts.add(elseQueryStmt);
-
- elseBlock.setStatements(elseStmts);
-
- CriteriaSelector critSelector1 = new CriteriaSelector();
- critSelector1.setSelectorType(CriteriaSelector.COMPARE_NE);
- critSelector1.setElements(elements);
-
- HasCriteria hasSelector1 = new HasCriteria();
- hasSelector1.setSelector(critSelector1);
-
- IfStatement stmt = new IfStatement(hasSelector1, ifBlock, elseBlock);
-
- Block block = new Block();
- block.addStatement(declStmt);
- block.addStatement(stmt);
-
- CreateUpdateProcedureCommand cmd = new CreateUpdateProcedureCommand();
- cmd.setBlock(block);
-
- helpTest("CREATE PROCEDURE BEGIN DECLARE short var1;"+ //$NON-NLS-1$
- " IF(HAS <> CRITERIA ON (a)) BEGIN var1 = SELECT a1 FROM g WHERE a2 = 5; END"+ //$NON-NLS-1$
- " ELSE BEGIN DECLARE short var2; var2 = SELECT b1 FROM g WHERE HAS CRITERIA ON (a); END" + //$NON-NLS-1$
- " END", "CREATE PROCEDURE"+"\n"+"BEGIN"+"\n"+"DECLARE short var1;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
- "IF(HAS <> CRITERIA ON (a))"+"\n"+"BEGIN"+"\n"+ "var1 = (SELECT a1 FROM g WHERE a2 = 5);"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- "END"+"\n"+"ELSE"+"\n"+"BEGIN"+"\n"+"DECLARE short var2;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
- "var2 = (SELECT b1 FROM g WHERE HAS CRITERIA ON (a));"+"\n"+"END"+"\n"+"END", cmd); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- }
-
- /** Translate criteria (empty criteriaSelector in WHERE clause*/
- @Test public void testCreateUpdateProcedureCommand7(){
- //declare var1
- ElementSymbol var1 = new ElementSymbol("var1"); //$NON-NLS-1$
- String shortType = new String("short"); //$NON-NLS-1$
- Statement declStmt = new DeclareStatement(var1, shortType);
-
- //ifblock
- List symbols = new ArrayList();
- symbols.add(new ElementSymbol("a1")); //$NON-NLS-1$
- Select select = new Select(symbols);
-
- From from = new From();
- from.addGroup(new GroupSymbol("g")); //$NON-NLS-1$
-
- Criteria criteria = new CompareCriteria(new ElementSymbol("a2"), CompareCriteria.EQ, //$NON-NLS-1$
- new Constant(new Integer(5)));
-
- Query query = new Query();
- query.setSelect(select);
- query.setFrom(from);
- query.setCriteria(criteria);
-
- AssignmentStatement queryStmt = new AssignmentStatement(var1, query);
-
- Block ifBlock = new Block();
- ifBlock.addStatement(queryStmt);
-
- //else block
- ElementSymbol var2 = new ElementSymbol("var2"); //$NON-NLS-1$
- Statement elseDeclStmt = new DeclareStatement(var2, shortType);
-
- //element for has criteria
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
- elements.add(a);
-
- List elseSymbols = new ArrayList();
- elseSymbols.add(new ElementSymbol("b1")); //$NON-NLS-1$
- Select elseSelect = new Select(elseSymbols);
-
- Query elseQuery = new Query();
- elseQuery.setSelect(elseSelect);
- elseQuery.setFrom(from);
-
- Criteria crit = new CompareCriteria(a, CompareCriteria.EQ,
- new Constant(new Integer(5)));
- List critList = new ArrayList();
- critList.add(crit);
-
- CriteriaSelector critSelector2 = new CriteriaSelector();
- //critSelector2.setSelectorType(CriteriaSelector.IS_NULL);
- critSelector2.setElements(elements);
-
- TranslateCriteria transCriteria = new TranslateCriteria(critSelector2, critList);
- elseQuery.setCriteria(transCriteria);
-
- AssignmentStatement elseQueryStmt = new AssignmentStatement(var2, elseQuery);
-
- Block elseBlock = new Block();
- List elseStmts = new ArrayList();
- elseStmts.add(elseDeclStmt);
- elseStmts.add(elseQueryStmt);
-
- elseBlock.setStatements(elseStmts);
-
- CriteriaSelector critSelector1 = new CriteriaSelector();
- critSelector1.setSelectorType(CriteriaSelector.COMPARE_NE);
- critSelector1.setElements(elements);
-
- HasCriteria hasSelector1 = new HasCriteria();
- hasSelector1.setSelector(critSelector1);
-
- IfStatement stmt = new IfStatement(hasSelector1, ifBlock, elseBlock);
-
- Block block = new Block();
- block.addStatement(declStmt);
- block.addStatement(stmt);
-
- CreateUpdateProcedureCommand cmd = new CreateUpdateProcedureCommand();
- cmd.setBlock(block);
-
- helpTest("CREATE PROCEDURE BEGIN DECLARE short var1;"+ //$NON-NLS-1$
- " IF(HAS <> CRITERIA ON (a)) BEGIN var1 = SELECT a1 FROM g WHERE a2 = 5; END"+ //$NON-NLS-1$
- " ELSE BEGIN DECLARE short var2; var2 = (SELECT b1 FROM g WHERE TRANSLATE CRITERIA ON (a) WITH (a = 5)); END" + //$NON-NLS-1$
- " END", "CREATE PROCEDURE"+"\n"+"BEGIN"+"\n"+"DECLARE short var1;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
- "IF(HAS <> CRITERIA ON (a))"+"\n"+"BEGIN"+"\n"+ "var1 = (SELECT a1 FROM g WHERE a2 = 5);"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- "END"+"\n"+"ELSE"+"\n"+"BEGIN"+"\n"+"DECLARE short var2;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
- "var2 = (SELECT b1 FROM g WHERE TRANSLATE CRITERIA ON (a) WITH (a = 5));"+"\n"+"END"+"\n"+"END", cmd); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- }
-
- /** Translate criteria (is null criteriaSelector in WHERE clause*/
- @Test public void testCreateUpdateProcedureCommand9(){
- //declare var1
- ElementSymbol var1 = new ElementSymbol("var1"); //$NON-NLS-1$
- String shortType = new String("short"); //$NON-NLS-1$
- Statement declStmt = new DeclareStatement(var1, shortType);
-
- //ifblock
- List symbols = new ArrayList();
- symbols.add(new ElementSymbol("a1")); //$NON-NLS-1$
- Select select = new Select(symbols);
-
- From from = new From();
- from.addGroup(new GroupSymbol("g")); //$NON-NLS-1$
-
- Criteria criteria = new CompareCriteria(new ElementSymbol("a2"), CompareCriteria.EQ, //$NON-NLS-1$
- new Constant(new Integer(5)));
-
- Query query = new Query();
- query.setSelect(select);
- query.setFrom(from);
- query.setCriteria(criteria);
-
- AssignmentStatement queryStmt = new AssignmentStatement(var1, query);
-
- Block ifBlock = new Block();
- ifBlock.addStatement(queryStmt);
-
- //else block
- ElementSymbol var2 = new ElementSymbol("var2"); //$NON-NLS-1$
- Statement elseDeclStmt = new DeclareStatement(var2, shortType);
-
- //element for has criteria
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
- elements.add(a);
-
- List elseSymbols = new ArrayList();
- elseSymbols.add(new ElementSymbol("b1")); //$NON-NLS-1$
- Select elseSelect = new Select(elseSymbols);
-
- Query elseQuery = new Query();
- elseQuery.setSelect(elseSelect);
- elseQuery.setFrom(from);
-
- Criteria crit = new CompareCriteria(a, CompareCriteria.EQ,
- new Constant(new Integer(5)));
- List critList = new ArrayList();
- critList.add(crit);
-
- CriteriaSelector critSelector2 = new CriteriaSelector();
- critSelector2.setSelectorType(CriteriaSelector.IS_NULL);
- critSelector2.setElements(elements);
-
- TranslateCriteria transCriteria = new TranslateCriteria(critSelector2, critList);
- elseQuery.setCriteria(transCriteria);
-
- AssignmentStatement elseQueryStmt = new AssignmentStatement(var2, elseQuery);
-
- Block elseBlock = new Block();
- List elseStmts = new ArrayList();
- elseStmts.add(elseDeclStmt);
- elseStmts.add(elseQueryStmt);
-
- elseBlock.setStatements(elseStmts);
-
- CriteriaSelector critSelector1 = new CriteriaSelector();
- critSelector1.setSelectorType(CriteriaSelector.COMPARE_NE);
- critSelector1.setElements(elements);
-
- HasCriteria hasSelector1 = new HasCriteria();
- hasSelector1.setSelector(critSelector1);
-
- IfStatement stmt = new IfStatement(hasSelector1, ifBlock, elseBlock);
-
- Block block = new Block();
- block.addStatement(declStmt);
- block.addStatement(stmt);
-
- CreateUpdateProcedureCommand cmd = new CreateUpdateProcedureCommand();
- cmd.setBlock(block);
-
- helpTest("CREATE PROCEDURE BEGIN DECLARE short var1;"+ //$NON-NLS-1$
- " IF(HAS <> CRITERIA ON (a)) BEGIN var1 = SELECT a1 FROM g WHERE a2 = 5; END"+ //$NON-NLS-1$
- " ELSE BEGIN DECLARE short var2; var2 = SELECT b1 FROM g WHERE TRANSLATE IS NULL CRITERIA ON (a) WITH (a = 5); END" + //$NON-NLS-1$
- " END", "CREATE PROCEDURE"+"\n"+"BEGIN"+"\n"+"DECLARE short var1;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
- "IF(HAS <> CRITERIA ON (a))"+"\n"+"BEGIN"+"\n"+ "var1 = (SELECT a1 FROM g WHERE a2 = 5);"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- "END"+"\n"+"ELSE"+"\n"+"BEGIN"+"\n"+"DECLARE short var2;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
- "var2 = (SELECT b1 FROM g WHERE TRANSLATE IS NULL CRITERIA ON (a) WITH (a = 5));"+"\n"+"END"+"\n"+"END", cmd); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- }
-
- /** Translate criteria ( only with WHERE clause) */
- @Test public void testCreateUpdateProcedureCommand10(){
- //declare var1
- ElementSymbol var1 = new ElementSymbol("var1"); //$NON-NLS-1$
- String shortType = new String("short"); //$NON-NLS-1$
- Statement declStmt = new DeclareStatement(var1, shortType);
-
- //ifblock
- List symbols = new ArrayList();
- symbols.add(new ElementSymbol("a1")); //$NON-NLS-1$
- Select select = new Select(symbols);
-
- From from = new From();
- from.addGroup(new GroupSymbol("g")); //$NON-NLS-1$
-
- Criteria criteria = new CompareCriteria(new ElementSymbol("a2"), CompareCriteria.EQ, //$NON-NLS-1$
- new Constant(new Integer(5)));
-
- Query query = new Query();
- query.setSelect(select);
- query.setFrom(from);
- query.setCriteria(criteria);
-
- AssignmentStatement queryStmt = new AssignmentStatement(var1, query);
-
- Block ifBlock = new Block();
- ifBlock.addStatement(queryStmt);
-
- //else block
- ElementSymbol var2 = new ElementSymbol("var2"); //$NON-NLS-1$
- Statement elseDeclStmt = new DeclareStatement(var2, shortType);
-
- //element for has criteria
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
- elements.add(a);
-
- List elseSymbols = new ArrayList();
- elseSymbols.add(new ElementSymbol("b1")); //$NON-NLS-1$
- Select elseSelect = new Select(elseSymbols);
-
- Query elseQuery = new Query();
- elseQuery.setSelect(elseSelect);
- elseQuery.setFrom(from);
-
- Criteria crit = new CompareCriteria(a, CompareCriteria.EQ,
- new Constant(new Integer(5)));
- List critList = new ArrayList();
- critList.add(crit);
-
- TranslateCriteria transCriteria = new TranslateCriteria();
- CriteriaSelector critSelector2 = new CriteriaSelector();
- transCriteria.setTranslations(critList);
- transCriteria.setSelector(critSelector2);
-
- elseQuery.setCriteria(transCriteria);
-
- AssignmentStatement elseQueryStmt = new AssignmentStatement(var2, elseQuery);
-
- Block elseBlock = new Block();
- List elseStmts = new ArrayList();
- elseStmts.add(elseDeclStmt);
- elseStmts.add(elseQueryStmt);
-
- elseBlock.setStatements(elseStmts);
-
- CriteriaSelector critSelector1 = new CriteriaSelector();
- critSelector1.setSelectorType(CriteriaSelector.COMPARE_NE);
- critSelector1.setElements(elements);
-
- HasCriteria hasSelector1 = new HasCriteria();
- hasSelector1.setSelector(critSelector1);
-
- IfStatement stmt = new IfStatement(hasSelector1, ifBlock, elseBlock);
-
- Block block = new Block();
- block.addStatement(declStmt);
- block.addStatement(stmt);
-
- CreateUpdateProcedureCommand cmd = new CreateUpdateProcedureCommand();
- cmd.setBlock(block);
-
- helpTest("CREATE PROCEDURE BEGIN DECLARE short var1;"+ //$NON-NLS-1$
- " IF(HAS <> CRITERIA ON (a)) BEGIN var1 = SELECT a1 FROM g WHERE a2 = 5; END"+ //$NON-NLS-1$
- " ELSE BEGIN DECLARE short var2; var2 = SELECT b1 FROM g WHERE TRANSLATE CRITERIA WITH (a = 5); END" + //$NON-NLS-1$
- " END", "CREATE PROCEDURE"+"\n"+"BEGIN"+"\n"+"DECLARE short var1;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
- "IF(HAS <> CRITERIA ON (a))"+"\n"+"BEGIN"+"\n"+ "var1 = (SELECT a1 FROM g WHERE a2 = 5);"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- "END"+"\n"+"ELSE"+"\n"+"BEGIN"+"\n"+"DECLARE short var2;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
- "var2 = (SELECT b1 FROM g WHERE TRANSLATE CRITERIA WITH (a = 5));"+"\n"+"END"+"\n"+"END", cmd); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- }
-
- /** Translate criteria ( only with WHERE clause) */
- @Test public void testCreateUpdateProcedureCommand12(){
- //declare var1
- ElementSymbol var1 = new ElementSymbol("var1"); //$NON-NLS-1$
- String shortType = new String("short"); //$NON-NLS-1$
- Statement declStmt = new DeclareStatement(var1, shortType);
-
- //ifblock
- List symbols = new ArrayList();
- symbols.add(new ElementSymbol("a1")); //$NON-NLS-1$
- Select select = new Select(symbols);
-
- From from = new From();
- from.addGroup(new GroupSymbol("g")); //$NON-NLS-1$
-
- Criteria criteria = new CompareCriteria(new ElementSymbol("a2"), CompareCriteria.EQ, //$NON-NLS-1$
- new Constant(new Integer(5)));
-
- Query query = new Query();
- query.setSelect(select);
- query.setFrom(from);
- query.setCriteria(criteria);
-
- AssignmentStatement queryStmt = new AssignmentStatement(var1, query);
-
- Block ifBlock = new Block();
- ifBlock.addStatement(queryStmt);
-
- //else block
- ElementSymbol var2 = new ElementSymbol("var2"); //$NON-NLS-1$
- Statement elseDeclStmt = new DeclareStatement(var2, shortType);
-
- //element for has criteria
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
- elements.add(a);
-
- List elseSymbols = new ArrayList();
- elseSymbols.add(new ElementSymbol("b1")); //$NON-NLS-1$
- Select elseSelect = new Select(elseSymbols);
-
- Query elseQuery = new Query();
- elseQuery.setSelect(elseSelect);
- elseQuery.setFrom(from);
-
-
- Criteria crit1 = new CompareCriteria(a, CompareCriteria.EQ,
- new Constant(new Integer(5)));
- ElementSymbol m = new ElementSymbol("m"); //$NON-NLS-1$
- Criteria crit2= new CompareCriteria(m, CompareCriteria.EQ,
- new Constant(new Integer(6)));
- List critList = new ArrayList();
- critList.add(crit1);
- critList.add(crit2);
-
- TranslateCriteria transCriteria = new TranslateCriteria();
- CriteriaSelector critSelector2 = new CriteriaSelector();
- transCriteria.setTranslations(critList);
- transCriteria.setSelector(critSelector2);
-
- elseQuery.setCriteria(transCriteria);
-
- AssignmentStatement elseQueryStmt = new AssignmentStatement(var2, elseQuery);
-
- Block elseBlock = new Block();
- List elseStmts = new ArrayList();
- elseStmts.add(elseDeclStmt);
- elseStmts.add(elseQueryStmt);
-
- elseBlock.setStatements(elseStmts);
-
- CriteriaSelector critSelector1 = new CriteriaSelector();
- critSelector1.setSelectorType(CriteriaSelector.COMPARE_NE);
- critSelector1.setElements(elements);
-
- HasCriteria hasSelector1 = new HasCriteria();
- hasSelector1.setSelector(critSelector1);
-
- IfStatement stmt = new IfStatement(hasSelector1, ifBlock, elseBlock);
-
- Block block = new Block();
- block.addStatement(declStmt);
- block.addStatement(stmt);
-
- CreateUpdateProcedureCommand cmd = new CreateUpdateProcedureCommand();
- cmd.setBlock(block);
-
- helpTest("CREATE PROCEDURE BEGIN DECLARE short var1;"+ //$NON-NLS-1$
- " IF(HAS <> CRITERIA ON (a)) BEGIN var1 = SELECT a1 FROM g WHERE a2 = 5; END"+ //$NON-NLS-1$
- " ELSE BEGIN DECLARE short var2; var2 = SELECT b1 FROM g WHERE TRANSLATE CRITERIA WITH (a = 5, m = 6); END" + //$NON-NLS-1$
- " END", "CREATE PROCEDURE"+"\n"+"BEGIN"+"\n"+"DECLARE short var1;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
- "IF(HAS <> CRITERIA ON (a))"+"\n"+"BEGIN"+"\n"+ "var1 = (SELECT a1 FROM g WHERE a2 = 5);"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- "END"+"\n"+"ELSE"+"\n"+"BEGIN"+"\n"+"DECLARE short var2;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
- "var2 = (SELECT b1 FROM g WHERE TRANSLATE CRITERIA WITH (a = 5, m = 6));"+"\n"+"END"+"\n"+"END", cmd); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
-
- }
-
- /** Translate criteria (with only Criteria in WHERE clause) */
- @Test public void testCreateUpdateProcedureCommand11(){
- //declare var1
- ElementSymbol var1 = new ElementSymbol("var1"); //$NON-NLS-1$
- String shortType = new String("short"); //$NON-NLS-1$
- Statement declStmt = new DeclareStatement(var1, shortType);
-
- //ifblock
- List symbols = new ArrayList();
- symbols.add(new ElementSymbol("a1")); //$NON-NLS-1$
- Select select = new Select(symbols);
-
- From from = new From();
- from.addGroup(new GroupSymbol("g")); //$NON-NLS-1$
-
- Criteria criteria = new CompareCriteria(new ElementSymbol("a2"), CompareCriteria.EQ, //$NON-NLS-1$
- new Constant(new Integer(5)));
-
- Query query = new Query();
- query.setSelect(select);
- query.setFrom(from);
- query.setCriteria(criteria);
-
- AssignmentStatement queryStmt = new AssignmentStatement(var1, query);
-
- Block ifBlock = new Block();
- ifBlock.addStatement(queryStmt);
-
- //else block
- ElementSymbol var2 = new ElementSymbol("var2"); //$NON-NLS-1$
- Statement elseDeclStmt = new DeclareStatement(var2, shortType);
-
- //element for has criteria
- ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
- elements.add(a);
-
- List elseSymbols = new ArrayList();
- elseSymbols.add(new ElementSymbol("b1")); //$NON-NLS-1$
- Select elseSelect = new Select(elseSymbols);
-
- Query elseQuery = new Query();
- elseQuery.setSelect(elseSelect);
- elseQuery.setFrom(from);
-
- Criteria crit = new CompareCriteria(a, CompareCriteria.EQ,
- new Constant(new Integer(5)));
- List critList = new ArrayList();
- critList.add(crit);
-
- CriteriaSelector critSelector = new CriteriaSelector();
- TranslateCriteria transCrit = new TranslateCriteria();
- transCrit.setSelector(critSelector);
-
- elseQuery.setCriteria(transCrit);
-
- AssignmentStatement elseQueryStmt = new AssignmentStatement(var2, elseQuery);
-
- Block elseBlock = new Block();
- List elseStmts = new ArrayList();
- elseStmts.add(elseDeclStmt);
- elseStmts.add(elseQueryStmt);
-
- elseBlock.setStatements(elseStmts);
-
- CriteriaSelector critSelector1 = new CriteriaSelector();
- critSelector1.setSelectorType(CriteriaSelector.COMPARE_NE);
- critSelector1.setElements(elements);
-
- HasCriteria hasSelector1 = new HasCriteria();
- hasSelector1.setSelector(critSelector1);
-
- IfStatement stmt = new IfStatement(hasSelector1, ifBlock, elseBlock);
-
- Block block = new Block();
- block.addStatement(declStmt);
- block.addStatement(stmt);
-
- CreateUpdateProcedureCommand cmd = new CreateUpdateProcedureCommand();
- cmd.setBlock(block);
-
- helpTest("CREATE PROCEDURE BEGIN DECLARE short var1;"+ //$NON-NLS-1$
- " IF(HAS <> CRITERIA ON (a)) BEGIN var1 = SELECT a1 FROM g WHERE a2 = 5; END"+ //$NON-NLS-1$
- " ELSE BEGIN DECLARE short var2; var2 = SELECT b1 FROM g WHERE TRANSLATE CRITERIA; END" + //$NON-NLS-1$
- " END", "CREATE PROCEDURE"+"\n"+"BEGIN"+"\n"+"DECLARE short var1;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
- "IF(HAS <> CRITERIA ON (a))"+"\n"+"BEGIN"+"\n"+ "var1 = (SELECT a1 FROM g WHERE a2 = 5);"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- "END"+"\n"+"ELSE"+"\n"+"BEGIN"+"\n"+"DECLARE short var2;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
- "var2 = (SELECT b1 FROM g WHERE TRANSLATE CRITERIA);"+"\n"+"END"+"\n"+"END", cmd); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- }
-
- /**IF statement with has criteria no on */
- @Test public void testCreateUpdateProcedureCommand8(){
- //declare var1
- ElementSymbol var1 = new ElementSymbol("var1"); //$NON-NLS-1$
- String shortType = new String("short"); //$NON-NLS-1$
- Statement declStmt = new DeclareStatement(var1, shortType);
-
- //ifblock
- List symbols = new ArrayList();
- symbols.add(new ElementSymbol("a1")); //$NON-NLS-1$
- Select select = new Select(symbols);
-
- From from = new From();
- from.addGroup(new GroupSymbol("g")); //$NON-NLS-1$
-
- Criteria criteria = new CompareCriteria(new ElementSymbol("a2"), CompareCriteria.EQ, //$NON-NLS-1$
- new Constant(new Integer(5)));
-
- Query query = new Query();
- query.setSelect(select);
- query.setFrom(from);
- query.setCriteria(criteria);
-
- AssignmentStatement queryStmt = new AssignmentStatement(var1, query);
-
- Block ifBlock = new Block();
- ifBlock.addStatement(queryStmt);
-
- //else block
- ElementSymbol var2 = new ElementSymbol("var2"); //$NON-NLS-1$
- Statement elseDeclStmt = new DeclareStatement(var2, shortType);
-
- List elseSymbols = new ArrayList();
- elseSymbols.add(new ElementSymbol("b1")); //$NON-NLS-1$
- Select elseSelect = new Select(elseSymbols);
-
- Query elseQuery = new Query();
- elseQuery.setSelect(elseSelect);
- elseQuery.setFrom(from);
- elseQuery.setCriteria(criteria);
-
- AssignmentStatement elseQueryStmt = new AssignmentStatement(var2, elseQuery);
-
- Block elseBlock = new Block();
- List elseStmts = new ArrayList();
- elseStmts.add(elseDeclStmt);
- elseStmts.add(elseQueryStmt);
-
- elseBlock.setStatements(elseStmts);
-
- CriteriaSelector critSelector = new CriteriaSelector();
-
- HasCriteria hasSelector = new HasCriteria();
- hasSelector.setSelector(critSelector);
-
- IfStatement stmt = new IfStatement(hasSelector, ifBlock, elseBlock);
-
- Block block = new Block();
- block.addStatement(declStmt);
- block.addStatement(stmt);
-
- CreateUpdateProcedureCommand cmd = new CreateUpdateProcedureCommand();
- cmd.setBlock(block);
-
- helpTest("CREATE PROCEDURE BEGIN DECLARE short var1;"+ //$NON-NLS-1$
- " IF(HAS CRITERIA) BEGIN var1 = SELECT a1 FROM g WHERE a2 = 5; END"+ //$NON-NLS-1$
- " ELSE BEGIN DECLARE short var2; var2 = SELECT b1 FROM g WHERE a2 = 5; END" + //$NON-NLS-1$
- " END", "CREATE PROCEDURE"+"\n"+"BEGIN"+"\n"+"DECLARE short var1;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
- "IF(HAS CRITERIA)"+"\n"+"BEGIN"+"\n"+ "var1 = (SELECT a1 FROM g WHERE a2 = 5);"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- "END"+"\n"+"ELSE"+"\n"+"BEGIN"+"\n"+"DECLARE short var2;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
- "var2 = (SELECT b1 FROM g WHERE a2 = 5);"+"\n"+"END"+"\n"+"END", cmd); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- }
-
@Test public void testSubquerySetCriteria0() {
//test wrap up command with subquerySetCriteria
Query outer = exampleIn(false);
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -29,16 +29,7 @@
import java.math.BigInteger;
import java.sql.SQLException;
import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-import java.util.Set;
-import java.util.StringTokenizer;
+import java.util.*;
import org.junit.Test;
import org.teiid.client.metadata.ParameterInfo;
@@ -6120,27 +6111,6 @@
helpProcess(plan, dataManager, expected);
}
- @Test public void testUpdatesInLoop() {
- String sql = "update vm1.g39 set e2=3"; //$NON-NLS-1$
-
- // Plan query
- ProcessorPlan plan = helpGetPlan(sql, RealMetadataFactory.example1Cached(), TestOptimizer.getGenericFinder());
-
- // Construct data manager with data
- HardcodedDataManager dataManager = new HardcodedDataManager();
- dataManager.addData("SELECT g_0.e2 FROM pm1.g1 AS g_0 WHERE g_0.e2 = 3", //$NON-NLS-1$
- new List[] { Arrays.asList(new Object[] { new Integer(3) } )});
- dataManager.addData("UPDATE pm1.g1 SET e2 = 3 WHERE pm1.g1.e2 = 3", //$NON-NLS-1$
- new List[] { Arrays.asList(new Object[] { new Integer(1) } )});
-
- // Create expected results
- List[] expected = new List[] { Arrays.asList(0)};
-
- // Run query
- helpProcess(plan, dataManager, expected);
-
- }
-
@Test public void testRand() {
// Create query
String sql = "SELECT RAND(E2) FROM pm1.g1 where pm1.g1.e2=3"; //$NON-NLS-1$
Modified: trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -57,7 +57,6 @@
import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
import org.teiid.query.parser.QueryParser;
import org.teiid.query.processor.FakeDataManager;
-import org.teiid.query.processor.FakeDataStore;
import org.teiid.query.processor.HardcodedDataManager;
import org.teiid.query.processor.ProcessorDataManager;
import org.teiid.query.processor.ProcessorPlan;
@@ -269,114 +268,6 @@
helpTestProcess(plan, 5, dataMgr, metadata);
}
- // testing rows updated incremented, Input and assignment statements
- @Test public void testProcedureProcessor3() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = Select pm1.g1.e2 from pm1.g1 where e2=5;\n"; //$NON-NLS-1$
- procedure = procedure + "var1 = INPUT.e2;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e2=40"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure);
-
- FakeDataManager dataMgr = exampleDataManager(metadata);
-
- ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
-
- helpTestProcess(plan, 45, dataMgr, metadata);
- }
-
- // if/else test
- @Test public void testProcedureProcessor4() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "var1 = Select pm1.g1.e2 from pm1.g1 where e2=5;\n"; //$NON-NLS-1$
- procedure = procedure + "if(var1 = 5)\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "ELSE\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = Select pm1.g1.e2 from pm1.g1 where e2=5;\n"; //$NON-NLS-1$
- procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = INPUT.e1, pm1.g1.e2 = var1;\n"; //$NON-NLS-1$
- procedure = procedure + "var1 = INPUT.e2;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e2=45"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure);
-
- FakeDataManager dataMgr = exampleDataManager(metadata);
-
- ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
-
- helpTestProcess(plan, 5, dataMgr, metadata);
- }
-
- @Test public void testProcedureProcessor4WithBlockedException() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "var1 = Select pm1.g1.e2 from pm1.g1 where e2=5;\n"; //$NON-NLS-1$
- procedure = procedure + "if(var1 = 5)\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "ELSE\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = Select pm1.g1.e2 from pm1.g1 where e2=5;\n"; //$NON-NLS-1$
- procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = INPUT.e1, pm1.g1.e2 = var1;\n"; //$NON-NLS-1$
- procedure = procedure + "var1 = INPUT.e2;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e2=45"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure);
-
- FakeDataManager dataMgr = exampleDataManager(metadata);
- dataMgr.setBlockOnce();
-
- ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
-
- helpTestProcess(plan, 5, dataMgr, metadata);
- }
-
- // if/else test
- @Test public void testProcedureProcessor5() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "var1 = Select pm1.g1.e2 from pm1.g1 where e2=15;\n"; //$NON-NLS-1$
- procedure = procedure + "if(var1 = 5)\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "ELSE\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = Select pm1.g1.e2 from pm1.g1 where e2=5;\n"; //$NON-NLS-1$
- procedure = procedure + "var1 = INPUT.e2;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e2=45"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure);
-
- FakeDataManager dataMgr = exampleDataManager(metadata);
-
- ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
-
- helpTestProcess(plan, 50, dataMgr, metadata);
- }
-
// more rows than expected
@Test public void testProcedureProcessor6() throws Exception {
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
@@ -452,61 +343,6 @@
helpTestProcessFailure(plan, dataMgr, ErrorInstruction.ERROR_PREFIX + expected, metadata);
}
- /** test if statement's if block with lookup in if condition */
- @Test public void testLookupFunction1() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var2;\n"; //$NON-NLS-1$
- procedure = procedure + "if('a' = lookup('pm1.g1','e1', 'e2', 0))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "var2 = INPUT.e2;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED +1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "ELSE\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "var2 = 100;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED +13;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e2=30"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure);
- FakeDataManager dataMgr = new FakeDataManager();
- FakeDataStore.sampleData2(dataMgr);
-
- ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
- helpTestProcess(plan, 1, dataMgr, metadata);
-
- }
-
- /** test if statement's else block with lookup in if condition */
- @Test public void testLookupFunction2() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var2;\n"; //$NON-NLS-1$
- procedure = procedure + "if('a' = lookup('pm1.g1','e1', 'e2', 5))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "var2 = INPUT.e2;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED +1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "ELSE\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "var2 = 100;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED +12;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e2=30"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure);
- FakeDataManager dataMgr = new FakeDataManager();
- FakeDataStore.sampleData2(dataMgr);
-
- ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
- helpTestProcess(plan, 12, dataMgr, metadata);
- }
-
@Test public void testVirtualProcedure() throws Exception {
String userUpdateStr = "EXEC pm1.vsp2()"; //$NON-NLS-1$
@@ -866,32 +702,6 @@
helpTestProcess(plan, expected, dataMgr, metadata);
}
- //procedure with Has Criteria and Translate Criteria
- @Test public void testDefect13625() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "IF(HAS CRITERIA ON (vm1.g4.e2))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "var1 = Select pm1.g1.e2 from pm1.g1 where TRANSLATE = CRITERIA ON (vm1.g4.e2);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "if(var1 = 5)\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE g4 SET e1='x' where e2=5"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure);
-
- FakeDataManager dataMgr = exampleDataManager(metadata);
-
- ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
-
- helpTestProcess(plan, 5, dataMgr, metadata);
- }
-
@Test public void testVirtualProcedure30() throws Exception {
String userUpdateStr = "EXEC pm1.vsp30()"; //$NON-NLS-1$
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
@@ -960,7 +770,7 @@
// Set up data
HardcodedDataManager dataMgr = new HardcodedDataManager();
- dataMgr.addData("INSERT INTO pm1.g1 (e1, e2, e3, e4) VALUES (null, 5, UNKNOWN, null)", new List[] {Arrays.asList(1)});
+ dataMgr.addData("INSERT INTO pm1.g1 (pm1.g1.e2) VALUES (5)", new List[] {Arrays.asList(1)});
// Create expected results
List[] expected = new List[] {
@@ -1083,34 +893,6 @@
helpTestProcess(plan, expected, dataMgr, metadata);
}
- @Test public void testDefect17650() throws Exception {
- String procedure1 = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure1 = procedure1 + "BEGIN\n"; //$NON-NLS-1$
- procedure1 = procedure1 + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure1 = procedure1 + "IF(HAS CRITERIA ON (vm1.g1.e2))\n"; //$NON-NLS-1$
- procedure1 = procedure1 + "BEGIN\n"; //$NON-NLS-1$
- procedure1 = procedure1 + "ROWS_UPDATED = UPDATE vm1.g2 SET e1='x' where TRANSLATE = CRITERIA ON (vm1.g1.e2);\n"; //$NON-NLS-1$
- procedure1 = procedure1 + "END\n"; //$NON-NLS-1$
- procedure1 = procedure1 + "END"; //$NON-NLS-1$
-
- String procedure2 = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure2 = procedure2 + "BEGIN\n"; //$NON-NLS-1$
- procedure2 = procedure2 + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure2 = procedure2 + "Select pm1.g2.e2 from pm1.g2 where TRANSLATE CRITERIA;\n";//$NON-NLS-1$
- procedure2 = procedure2 + "ROWS_UPDATED = 5;\n"; //$NON-NLS-1$
- procedure2 = procedure2 + "END"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x' where e2=5"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure1, procedure2);
-
- FakeDataManager dataMgr = exampleDataManager(metadata);
-
- ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
-
- helpTestProcess(plan, 5, dataMgr, metadata);
- }
-
@Test public void testDefect19982() throws Exception {
String userUpdateStr = "EXEC pm1.vsp55(5)"; //$NON-NLS-1$
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
@@ -1145,33 +927,6 @@
helpTestProcess(plan, expected, dataMgr, metadata);
}
- //procedure with Has Criteria and Translate Criteria and changing
- @Test public void testDynamicCommandWithTranslate() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "IF(HAS CRITERIA ON (vm1.g4.e2))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "execute string 'Select pm1.g1.e2 x, changing.e1 y from pm1.g1 where TRANSLATE = CRITERIA ON (vm1.g4.e2)' as x integer, y boolean into #temp;\n"; //$NON-NLS-1$
- procedure = procedure + "var1 = select x from #temp;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "if(var1 = 5)\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE g4 SET e1='x' where e2=5"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure);
-
- FakeDataManager dataMgr = exampleDataManager(metadata);
-
- ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
-
- helpTestProcess(plan, 5, dataMgr, metadata);
- }
-
@Test public void testDynamicCommandWithIntoExpression() throws Exception {
//Test INTO clause with expression
@@ -1778,36 +1533,6 @@
}
/**
- * defect 23976
- * Also, even after the bug for passing procedure inputs to non-execs was fixed, the special case of
- * if (below) and while statements popped up.
- */
- @Test public void testIfEvaluation() throws Exception {
- String procedure1 = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure1 += "BEGIN\n"; //$NON-NLS-1$
- procedure1 += "DECLARE string var1 = INPUT.e1;\n"; //$NON-NLS-1$
- procedure1 += "ROWS_UPDATED = UPDATE vm1.g2 SET e1=var1;\n"; //$NON-NLS-1$
- procedure1 += "END"; //$NON-NLS-1$
-
- String procedure2 = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure2 += "BEGIN\n"; //$NON-NLS-1$
- procedure2 += "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure2 += "IF (INPUT.e1 = 1)\n"; //$NON-NLS-1$
- procedure2 += "ROWS_UPDATED = 5;\n"; //$NON-NLS-1$
- procedure2 += "ELSE\n"; //$NON-NLS-1$
- procedure2 += "ROWS_UPDATED = 4;\n"; //$NON-NLS-1$
- procedure2 += "END"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x' where e2=5"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure1, procedure2);
-
- ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
-
- helpTestProcess(plan, 4, new FakeDataManager(), metadata);
- }
-
- /**
* This is a slight variation of TestProcessor.testVariableInExecParam, where the proc wrapper can be
* removed after rewrite
*/
@@ -1862,56 +1587,6 @@
}
- /**
- * the update will not be executed, but the assignment value should still be 0
- */
- @Test public void testUpdateAssignmentNotExecuted() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1 = UPDATE pm1.g1 SET pm1.g1.e1 = INPUT.e2;"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = var1 + 1;\n"; //$NON-NLS-1$
- procedure = procedure + "END"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE g4 SET e1='x' where e2=5"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure);
-
- FakeDataManager dataMgr = exampleDataManager(metadata);
-
- ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
-
- helpTestProcess(plan, 1, dataMgr, metadata);
-
- assertTrue(plan.requiresTransaction(false));
- }
-
- @Test public void testUpdateAssignmentNotExecutedVirtual() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1 = UPDATE vm1.g2 SET e1 = INPUT.e2;"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = var1 + 1;\n"; //$NON-NLS-1$
- procedure = procedure + "END"; //$NON-NLS-1$
-
- String procedure2 = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure2 += "BEGIN\n"; //$NON-NLS-1$
- procedure2 += "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure2 += "IF (INPUT.e1 = 1)\n"; //$NON-NLS-1$
- procedure2 += "ROWS_UPDATED = 5;\n"; //$NON-NLS-1$
- procedure2 += "ELSE\n"; //$NON-NLS-1$
- procedure2 += "ROWS_UPDATED = 4;\n"; //$NON-NLS-1$
- procedure2 += "END"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x' where e2=5"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure, procedure2);
-
- FakeDataManager dataMgr = exampleDataManager(metadata);
-
- ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
-
- helpTestProcess(plan, 1, dataMgr, metadata);
- }
-
@Test public void testEvaluatableSelectWithOrderBy() throws Exception {
TransformationMetadata metadata = RealMetadataFactory.example1();
Modified: trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -49,16 +49,7 @@
import org.teiid.metadata.Table;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.mapping.relational.QueryNode;
-import org.teiid.query.mapping.xml.MappingAttribute;
-import org.teiid.query.mapping.xml.MappingChoiceNode;
-import org.teiid.query.mapping.xml.MappingCommentNode;
-import org.teiid.query.mapping.xml.MappingCriteriaNode;
-import org.teiid.query.mapping.xml.MappingDocument;
-import org.teiid.query.mapping.xml.MappingElement;
-import org.teiid.query.mapping.xml.MappingNodeConstants;
-import org.teiid.query.mapping.xml.MappingRecursiveElement;
-import org.teiid.query.mapping.xml.MappingSequenceNode;
-import org.teiid.query.mapping.xml.Namespace;
+import org.teiid.query.mapping.xml.*;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.metadata.TempMetadataAdapter;
import org.teiid.query.metadata.TempMetadataStore;
@@ -211,7 +202,7 @@
Table rs = RealMetadataFactory.createVirtualGroup("group.items", xmltest, rsQuery); //$NON-NLS-1$
// Created 2nd virtual group w/ nested result set & binding
- QueryNode rsQuery2 = new QueryNode("SELECT concat(stock.suppliers.supplierNum, '') as supplierNum, supplierName, supplierZipCode FROM stock.suppliers, stock.item_supplier WHERE stock.suppliers.supplierNum = stock.item_supplier.supplierNum AND stock.item_supplier.itemNum = input.x"); //$NON-NLS-1$ //$NON-NLS-2$
+ QueryNode rsQuery2 = new QueryNode("SELECT concat(stock.suppliers.supplierNum, '') as supplierNum, supplierName, supplierZipCode FROM stock.suppliers, stock.item_supplier WHERE stock.suppliers.supplierNum = stock.item_supplier.supplierNum AND stock.item_supplier.itemNum = inputs.x"); //$NON-NLS-1$ //$NON-NLS-2$
//QueryNode rsQuery2 = new QueryNode("xmltest.suppliers", "SELECT stock.suppliers.supplierNum, supplierName, supplierZipCode FROM stock.suppliers, stock.item_supplier WHERE stock.suppliers.supplierNum = stock.item_supplier.supplierNum AND stock.item_supplier.itemNum = ?");
rsQuery2.addBinding("xmltest.group.items.itemNum as x"); //$NON-NLS-1$
Table rs2 = RealMetadataFactory.createVirtualGroup("suppliers", xmltest, rsQuery2); //$NON-NLS-1$
Modified: trunk/engine/src/test/java/org/teiid/query/resolver/TestProcedureResolving.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/resolver/TestProcedureResolving.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/TestProcedureResolving.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -48,7 +48,6 @@
import org.teiid.query.sql.proc.LoopStatement;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
-import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.visitor.CommandCollectorVisitor;
import org.teiid.query.sql.visitor.ElementCollectorVisitor;
import org.teiid.query.unittest.RealMetadataFactory;
@@ -293,216 +292,6 @@
Table.TriggerEvent.UPDATE);
}
- // special variable ROWS_UPDATED resolution
- @Test public void testCreateUpdateProcedure10() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = Select pm1.g1.e2 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = INPUTS.e1, pm1.g1.e2 = var1;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpResolveUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // special variable ROWS_UPDATED used with declared variable
- @Test public void testCreateUpdateProcedure11() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = Select pm1.g1.e2 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = INPUTS.e1, pm1.g1.e2 = var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpResolveUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // special variable INPUT used with declared variable
- @Test public void testCreateUpdateProcedure12() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2, INPUTS.e2 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = INPUTS.e1, pm1.g1.e2 = INPUTS.e2;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpResolveUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // special variable CHANGING used with declared variable
- @Test public void testCreateUpdateProcedure14() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "if(CHANGING.e1 = 'true')\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2, INPUTS.e2 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = INPUTS.e1, pm1.g1.e2 = INPUTS.e2;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpResolveUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // special variable CHANGING and INPUT used in compound criteria
- @Test public void testCreateUpdateProcedure15() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "if(CHANGING.e1='false' and INPUTS.e1=1)\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2, INPUTS.e2 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = INPUTS.e1, pm1.g1.e2 = INPUTS.e2;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpResolveUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // special variable CHANGING and INPUT used in compound criteria, with declared variables
- @Test public void testCreateUpdateProcedure16() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "if(CHANGING.e4 ='true' and INPUTS.e2=1 or var1 < 30)\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2, INPUTS.e2 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = INPUTS.e1, pm1.g1.e2 = INPUTS.e2;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpResolveUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // special variable CHANGING compared against integer no implicit conversion available
- @Test public void testCreateUpdateProcedure17() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "if(CHANGING.e4 = {d'2000-01-01'})\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2, INPUTS.e2 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpFailUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE, "Error Code:ERR.015.008.0027 Message:The expressions in this criteria are being compared but are of differing types (boolean and date) and no implicit conversion is available: CHANGING.e4 = {d'2000-01-01'}"); //$NON-NLS-1$
- }
-
- // virtual group elements used in procedure(HAS CRITERIA)
- @Test public void testCreateUpdateProcedure18() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = Select pm1.g1.e2 from pm1.g1 where HAS CRITERIA ON (vm1.g1.e1, vm1.g1.e1);\n"; //$NON-NLS-1$
- procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = 'x', pm1.g1.e2 = var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpResolveUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // virtual group elements used in procedure in if statement(HAS CRITERIA)
- @Test public void testCreateUpdateProcedure19() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "if(HAS CRITERIA ON (vm1.g1.e1, vm1.g1.e1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = Select pm1.g1.e2 from pm1.g1 where HAS CRITERIA ON (vm1.g1.e1, vm1.g1.e1);\n"; //$NON-NLS-1$
- procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = 'x', pm1.g1.e2 = var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpResolveUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // virtual group elements used in procedure(TRANSLATE CRITERIA)
- @Test public void testCreateUpdateProcedure20() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = Select pm1.g1.e2 from pm1.g1 where Translate CRITERIA WITH (vm1.g1.e1 = 1, vm1.g1.e1 = 2);\n"; //$NON-NLS-1$
- procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = 'x', pm1.g1.e2 = var1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpResolveUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // virtual group elements used in procedure(TRANSLATE CRITERIA)
- @Test public void testCreateUpdateProcedure21() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = Select pm1.g1.e2 from pm1.g1 where Translate CRITERIA WITH (vm1.g1.e1 = 1, vm1.g1.e1 = 2);\n"; //$NON-NLS-1$
- procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = 'x', pm1.g1.e2 = INPUTS.e2;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpResolveUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // using undefined variable should fail
- @Test public void testCreateUpdateProcedure22() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
-// procedure = procedure + "DECLARE integer var1;\n";
- procedure = procedure + "var3 = var2+var1;\n"; //$NON-NLS-1$
- procedure = procedure + "var2 = Select pm1.g1.e2 from pm1.g1 where Translate CRITERIA WITH (vm1.g1.e1 = 1, vm1.g1.e1 = 2);\n"; //$NON-NLS-1$
- procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = 'x', pm1.g1.e2 = INPUTS.e2;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpFailUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // using undefined variable declared is of invalid datatype
- @Test public void testCreateUpdateProcedure23() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE struct var1;\n"; //$NON-NLS-1$
- procedure = procedure + "var1 = Select pm1.g1.e2 from pm1.g1 where Translate CRITERIA WITH (vm1.g1.e1 = 1, vm1.g1.e1 = 2);\n"; //$NON-NLS-1$
- procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = 'x', pm1.g1.e2 = INPUTS.e2;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpFailUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
// using declare variable that has parts
@Test public void testCreateUpdateProcedure24() {
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
@@ -648,23 +437,6 @@
Table.TriggerEvent.UPDATE, "Symbol pm1.g1.e2 is specified with an unknown group context"); //$NON-NLS-1$
}
- // virtual elements used on criteria of the if statement
- @Test public void testCreateUpdateProcedure35() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "if(HAS CRITERIA ON (vm1.g1.e1) and var1=1)\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpResolveUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
// physical elements used on criteria of the if statement
@Test public void testCreateUpdateProcedure36() {
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
@@ -682,38 +454,6 @@
Table.TriggerEvent.UPDATE);
}
- // TranslateCriteria on criteria of the if statement
- @Test public void testCreateUpdateProcedure37() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "if(TRANSLATE CRITERIA ON (vm1.g1.e1) WITH (vm1.g1.e1 = 1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpResolveUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // validating Translate CRITERIA, elements on it should be virtual group elements
- // but can use variables
- @Test public void testCreateUpdateProcedure38() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e1 from pm1.g1 where Translate CRITERIA WITH (pm1.g1.e2 = var1);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpFailUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
// physical elements used on criteria of the if statement
@Test public void testCreateUpdateProcedure39() {
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
@@ -731,221 +471,6 @@
Table.TriggerEvent.UPDATE);
}
- // TranslateCriteria on criteria of the if statement
- @Test public void testCreateUpdateProcedure40() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "if(TRANSLATE CRITERIA ON (e1) WITH (g1.e1 = 1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpResolveUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // TranslateCriteria on criteria of the if statement
- @Test public void testCreateUpdateProcedure41() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "if(HAS CRITERIA ON (e1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE CRITERIA ON (e1) WITH (g1.e1 = 1);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpResolveUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // TranslateCriteria on criteria of the if statement
- @Test public void testCreateUpdateProcedure42() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "if(HAS CRITERIA ON (e1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE CRITERIA ON (e1) WITH (g1.e1 = 1);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpResolveUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // TranslateCriteria on criteria of the if statement
- @Test public void testCreateUpdateProcedure43() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE CRITERIA ON (e1) WITH (g1.e1 = 1);\n"; //$NON-NLS-1$
-// procedure = procedure + "Select pm1.g1.e2, INPUTS.e2 from pm1.g1;\n";
-// procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = INPUTS.e1, pm1.g1.e2 = INPUTS.e2;\n";
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure);
-
- Command procCommand = QueryParser.getQueryParser().parseCommand(procedure);
- GroupSymbol virtualGroup = new GroupSymbol("vm1.g1"); //$NON-NLS-1$
- virtualGroup.setMetadataID(metadata.getGroupID("vm1.g1")); //$NON-NLS-1$
- QueryResolver.resolveCommand(procCommand, virtualGroup, Command.TYPE_UPDATE, metadata);
- }
-
- // special variable CHANGING compared against integer no implicit conversion available
- @Test public void testCreateUpdateProcedure44() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "if(INPUTS.e1 = 10)\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2, INPUTS.e2 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "INSERT into vm1.g1 (e1) values('x')"; //$NON-NLS-1$
-
- helpResolveUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.INSERT);
- }
-
- // special variable CHANGING compared against integer no implicit conversion available
- @Test public void testCreateUpdateProcedure45() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "if(INPUTS.e1 = 10)\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2, INPUTS.e2 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- Command procCommand = QueryParser.getQueryParser().parseCommand(procedure);
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.INSERT, procedure);
-
- GroupSymbol virtualGroup = new GroupSymbol("vm1.g1"); //$NON-NLS-1$
- virtualGroup.setMetadataID(metadata.getGroupID("vm1.g1")); //$NON-NLS-1$
-
- QueryResolver.resolveCommand(procCommand, virtualGroup, Command.TYPE_INSERT, metadata);
- }
-
- // special variable CHANGING compared against integer no implicit conversion available
- @Test public void testCreateUpdateProcedure46() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = INPUTS.e1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- Command procCommand = QueryParser.getQueryParser().parseCommand(procedure);
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure);
-
- GroupSymbol virtualGroup = new GroupSymbol("vm1.g1"); //$NON-NLS-1$
- virtualGroup.setMetadataID(metadata.getGroupID("vm1.g1")); //$NON-NLS-1$
-
- QueryResolver.resolveCommand(procCommand, virtualGroup, Command.TYPE_UPDATE, metadata);
- }
-
- // TranslateCriteria on criteria of the if statement
- @Test public void testCreateUpdateProcedure47() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "if(HAS CRITERIA ON (e1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE CRITERIA ON (e1) WITH (vm1.g1.e1 = pm1.g1.e1);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpResolveUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // validating Translate CRITERIA, elements(left elements on on it should be virtual group elements
- @Test public void testCreateUpdateProcedure48() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e1 from pm1.g1 where Translate CRITERIA WITH (vm1.g1.e1 = 1, INPUTS.e2 = 2);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpFailUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // resolving Translate CRITERIA, right element should be present on the command
- @Test public void testCreateUpdateProcedure49() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e1 from pm1.g1 where Translate CRITERIA WITH (vm1.g1.e1 = pm1.g2.e1);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpFailUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // resolving criteria selector(on HAS CRITERIA), elements on it should be virtual group elements
- @Test public void testCreateUpdateProcedure50() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "if(HAS CRITERIA ON (vm1.g1.E1, vm1.g1.e1, INPUTS.e1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpFailUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // resolving Translate CRITERIA, right side expression in the translate criteria should be elements on the command
- @Test public void testCreateUpdateProcedure51() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "var1=1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e1 from pm1.g1 where Translate CRITERIA WITH (vm1.g1.e2 = var1+vm1.g1.e2, vm1.g1.e1 = 2);\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpFailUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // validating Translate CRITERIA, elements on it should be virtual group elements
- // but can use variables, gut left exprs should always be virtual elements
- @Test public void testCreateUpdateProcedure52() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e1 from pm1.g1 where Translate CRITERIA WITH (var1 = vm1.g1.e2, vm1.g1.e1 = 2);\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpFailUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
// resolving AssignmentStatement, variable type and assigned type
// do not match and no implicit conversion available
@Test public void testCreateUpdateProcedure53() {
@@ -1315,8 +840,8 @@
}
@Test public void testAmbigousInput() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ String procedure = "FOR EACH ROW "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN ATOMIC\n"; //$NON-NLS-1$
procedure = procedure + "select e1;\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
@@ -1487,17 +1012,17 @@
// special variable INPUT compared against invalid type
@Test public void testInvalidInputInUpdate() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure += "BEGIN\n"; //$NON-NLS-1$
+ String procedure = "FOR EACH ROW "; //$NON-NLS-1$
+ procedure += "BEGIN ATOMIC\n"; //$NON-NLS-1$
procedure += "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure += "Select pm1.g1.e2, INPUTS.e2 from pm1.g1;\n"; //$NON-NLS-1$
- procedure += "ROWS_UPDATED = UPDATE pm1.g1 SET pm1.g1.e1 = INPUTS.e1, pm1.g1.e2 = INPUTS.e1;\n"; //$NON-NLS-1$
+ procedure += "Select pm1.g1.e2, new.e2 from pm1.g1;\n"; //$NON-NLS-1$
+ procedure += "UPDATE pm1.g1 SET pm1.g1.e1 = new.e1, pm1.g1.e2 = new.e1;\n"; //$NON-NLS-1$
procedure += "END\n"; //$NON-NLS-1$
String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
helpFailUpdateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE, "Error Code:ERR.015.008.0041 Message:Cannot set symbol 'pm1.g1.e2' with expected type integer to expression 'INPUTS.e1'"); //$NON-NLS-1$
+ Table.TriggerEvent.UPDATE, "Error Code:ERR.015.008.0041 Message:Cannot set symbol 'pm1.g1.e2' with expected type integer to expression '\"new\".e1'"); //$NON-NLS-1$
}
@Test public void testVirtualProcedure() throws Exception {
Modified: trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -67,23 +67,7 @@
import org.teiid.query.parser.QueryParser;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.ProcedureReservedWords;
-import org.teiid.query.sql.lang.BatchedUpdateCommand;
-import org.teiid.query.sql.lang.Command;
-import org.teiid.query.sql.lang.CompareCriteria;
-import org.teiid.query.sql.lang.Criteria;
-import org.teiid.query.sql.lang.From;
-import org.teiid.query.sql.lang.Insert;
-import org.teiid.query.sql.lang.OrderBy;
-import org.teiid.query.sql.lang.ProcedureContainer;
-import org.teiid.query.sql.lang.Query;
-import org.teiid.query.sql.lang.SPParameter;
-import org.teiid.query.sql.lang.Select;
-import org.teiid.query.sql.lang.SetCriteria;
-import org.teiid.query.sql.lang.SetQuery;
-import org.teiid.query.sql.lang.StoredProcedure;
-import org.teiid.query.sql.lang.SubqueryFromClause;
-import org.teiid.query.sql.lang.SubquerySetCriteria;
-import org.teiid.query.sql.lang.Update;
+import org.teiid.query.sql.lang.*;
import org.teiid.query.sql.navigator.DeepPreOrderNavigator;
import org.teiid.query.sql.proc.CommandStatement;
import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
@@ -2151,19 +2135,6 @@
assertFalse(groups.contains(inputSet));
}
- @Test public void testInputToInputsConversion() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = (Select pm1.g1.e2 from pm1.g1 where e2=INPUTS.e2);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e2=40"; //$NON-NLS-1$
-
- Command command = helpResolveUpdateProcedure(procedure, userUpdateStr);
- assertEquals("CREATE PROCEDURE\nBEGIN\nDECLARE integer var1;\nROWS_UPDATED = (SELECT pm1.g1.e2 FROM pm1.g1 WHERE e2 = INPUTS.e2);\nEND", command.toString());
- }
-
@Test public void testDefect16894_resolverException_1() {
helpResolve("SELECT * FROM (SELECT * FROM Pm1.g1 AS Y) AS X"); //$NON-NLS-1$
}
Modified: trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -37,7 +37,6 @@
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
-import org.teiid.api.exception.query.ExpressionEvaluationException;
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryValidatorException;
import org.teiid.client.metadata.ParameterInfo;
@@ -56,20 +55,7 @@
import org.teiid.query.parser.QueryParser;
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.resolver.util.ResolverVisitor;
-import org.teiid.query.sql.lang.Command;
-import org.teiid.query.sql.lang.CompareCriteria;
-import org.teiid.query.sql.lang.CompoundCriteria;
-import org.teiid.query.sql.lang.Criteria;
-import org.teiid.query.sql.lang.IsNullCriteria;
-import org.teiid.query.sql.lang.MatchCriteria;
-import org.teiid.query.sql.lang.ProcedureContainer;
-import org.teiid.query.sql.lang.Query;
-import org.teiid.query.sql.lang.QueryCommand;
-import org.teiid.query.sql.lang.SPParameter;
-import org.teiid.query.sql.lang.SetCriteria;
-import org.teiid.query.sql.lang.SetQuery;
-import org.teiid.query.sql.lang.StoredProcedure;
-import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.lang.*;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
@@ -118,7 +104,7 @@
Criteria expectedCrit = parseCriteria(expected, metadata);
if (rewrite) {
QueryResolver.resolveCriteria(expectedCrit, metadata);
- expectedCrit = QueryRewriter.rewriteCriteria(expectedCrit, null, null, metadata);
+ expectedCrit = QueryRewriter.rewriteCriteria(expectedCrit, null, metadata);
}
return helpTestRewriteCriteria(original, expectedCrit, metadata);
}
@@ -141,7 +127,7 @@
for (List<?> tuple : tuples) {
booleanVals.add(new Evaluator(elements, null, null).evaluate(origCrit, tuple));
}
- actual = QueryRewriter.rewriteCriteria(origCrit, null, null, metadata);
+ actual = QueryRewriter.rewriteCriteria(origCrit, null, metadata);
assertEquals("Did not rewrite correctly: ", expectedCrit, actual); //$NON-NLS-1$
for (int i = 0; i < tuples.size(); i++) {
assertEquals(tuples.get(i).toString(), booleanVals.get(i), new Evaluator(elements, null, null).evaluate(actual, tuples.get(i)));
@@ -177,7 +163,7 @@
QueryMetadataException, TeiidProcessingException {
ProcedureContainer userCommand = (ProcedureContainer)QueryParser.getQueryParser().parseCommand(userUpdateStr);
QueryResolver.resolveCommand(userCommand, metadata);
- CreateUpdateProcedureCommand proc = (CreateUpdateProcedureCommand)QueryResolver.expandCommand(userCommand, metadata, null);
+ Command proc = QueryResolver.expandCommand(userCommand, metadata, null);
QueryRewriter.rewrite(userCommand, metadata, null);
Command result = QueryRewriter.rewrite(proc, metadata, null);
return result.toString();
@@ -256,7 +242,7 @@
e1.setGroupSymbol(new GroupSymbol("g1"));
Criteria crit = new SetCriteria(e1, Collections.EMPTY_LIST); //$NON-NLS-1$
- Criteria actual = QueryRewriter.rewriteCriteria(crit, null, null, null);
+ Criteria actual = QueryRewriter.rewriteCriteria(crit, null, null);
IsNullCriteria inc = new IsNullCriteria(e1);
inc.setNegated(true);
@@ -320,7 +306,7 @@
MatchCriteria mcrit = new MatchCriteria(new ElementSymbol("pm1.g1.e1"), new Constant(null, DataTypeManager.DefaultDataClasses.STRING), '#'); //$NON-NLS-1$
Criteria expected = QueryRewriter.UNKNOWN_CRITERIA;
- Object actual = QueryRewriter.rewriteCriteria(mcrit, null, null, null);
+ Object actual = QueryRewriter.rewriteCriteria(mcrit, null, null);
assertEquals("Did not get expected rewritten criteria", expected, actual); //$NON-NLS-1$
}
@@ -440,7 +426,7 @@
Criteria origCrit = parseCriteria("PARSEDATE(pm3.g1.e1, '''') = {d'2003-05-01'}", metadata); //$NON-NLS-1$
try {
- QueryRewriter.rewriteCriteria(origCrit, null, null, null);
+ QueryRewriter.rewriteCriteria(origCrit, null, null);
fail("Expected failure"); //$NON-NLS-1$
} catch(TeiidException e) {
assertEquals("Error Code:ERR.015.001.0003 Message:Error simplifying criteria: PARSEDATE(pm3.g1.e1, '''') = {d'2003-05-01'}", e.getMessage()); //$NON-NLS-1$
@@ -603,7 +589,7 @@
Criteria expectedCrit = parseCriteria(expected, metadata);
// rewrite
- Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null, null);
+ Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null);
assertEquals("Did not rewrite correctly: ", expectedCrit, actual); //$NON-NLS-1$
}
@@ -616,7 +602,7 @@
Criteria origCrit = parseCriteria(original, metadata);
// rewrite
- Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null, null);
+ Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null);
assertEquals("Did not rewrite correctly: ", expected, actual.toString()); //$NON-NLS-1$
}
@@ -631,7 +617,7 @@
((CompareCriteria)expectedCrit).setRightExpression(new Constant(new Double(1234.5)));
// rewrite
- Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null, null);
+ Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null);
assertEquals("Did not rewrite correctly: ", expectedCrit, actual); //$NON-NLS-1$
}
@@ -645,7 +631,7 @@
Criteria expectedCrit = parseCriteria(expected, metadata);
// rewrite
- Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null, null);
+ Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null);
assertEquals("Did not rewrite correctly: ", expectedCrit, actual); //$NON-NLS-1$
}
@@ -848,677 +834,6 @@
helpTestRewriteCriteria("context(pm1.g1.e1, convert(5, string)) = 2+3", "context(pm1.g1.e1, '5') = '5'"); //$NON-NLS-1$ //$NON-NLS-2$
}
- // HAS Criteria
- @Test public void testRewriteProcedure1() throws Exception {
-
- String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "IF (HAS = CRITERIA ON (vm1.g1.e1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select vm1.g1.e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e1);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "Insert into vm1.g1 (e1, e2) values ('String', 1)"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.INSERT);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // HAS Criteria
- @Test public void testRewriteProcedure2() throws Exception {
-
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "IF (HAS = CRITERIA ON (vm1.g1.e1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select vm1.g1.e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e1);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "ELSE \n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select vm1.g1.e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e1);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "Insert into vm1.g1 (e1, e2) values ('String', 1)"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT vm1.g1.e1 FROM vm1.g1 WHERE "+FALSE_STR+";\n"; //$NON-NLS-1$ //$NON-NLS-2$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.INSERT);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // HAS Criteria
- @Test public void testRewriteProcedure3() throws Exception {
-
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "IF (HAS = CRITERIA ON (vm1.g1.e1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select vm1.g1.e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e1);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "ELSE \n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select vm1.g1.e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e1);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "Insert into vm1.g1 (e1, e2) values ('String', 1)"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT vm1.g1.e1 FROM vm1.g1 WHERE "+FALSE_STR+";\n"; //$NON-NLS-1$ //$NON-NLS-2$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.INSERT);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- @Test public void testRewriteProcedure4() throws Exception {
-
- String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "IF (INPUT.e2 = 1)\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select vm1.g1.e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e1);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "Insert into vm1.g1 (e1, e2) values ('String', 1)"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT vm1.g1.e1 FROM vm1.g1 WHERE "+FALSE_STR+";\n"; //$NON-NLS-1$ //$NON-NLS-2$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.INSERT);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // CHANGING
- @Test public void testRewriteProcedure5() throws Exception {
-
- String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "IF (CHANGING.e1 = 'false')\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e2);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "Update vm1.g1 SET e1 = 'String', e2 =1 where e2 = 10"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // CHANGING
- @Test public void testRewriteProcedure6() throws Exception {
-
- String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "IF (CHANGING.e1 = 'true')\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "Update vm1.g1 SET e1 = 'String', e2 =1 where e2 = 10"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // TRANSLATE CRITERIA
- @Test public void testRewriteProcedure7() throws Exception {
-
- String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "IF (CHANGING.e1 = 'true')\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select e2 from pm1.g1 where TRANSLATE = CRITERIA ON (vm1.g1.e2);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "Update vm1.g1 SET e1 = 'String', e2 =1 where e2 = 10"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT e2 FROM pm1.g1 WHERE pm1.g1.e2 = 10;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // TRANSLATE CRITERIA
- @Test public void testRewriteProcedure8() throws Exception {
-
- String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "IF (CHANGING.e1 = 'true')\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select e2 from pm1.g1 where TRANSLATE = CRITERIA ON (vm1.g1.e2) with (vm1.g1.e2 = convert(sqrt(pm1.g1.e2), integer));\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "Update vm1.g1 SET e1 = 'String', e2 =1 where e2 = 10"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT e2 FROM pm1.g1 WHERE convert(sqrt(pm1.g1.e2), integer) = 10;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // rewrite input/ changing variables
- @Test public void testRewriteProcedure9() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Declare String var1;\n"; //$NON-NLS-1$
- procedure = procedure + "if(var1 = 'x' or var1 = 'y')\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2, Input.e2, CHANGING.e2, CHANGING.e1 from pm1.g1 order by CHANGING.e1 + 1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "INSERT into vm1.g1 (e1) values('x')"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE String var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "IF(var1 IN ('y', 'x'))\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT pm1.g1.e2, 123, FALSE, TRUE FROM pm1.g1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.INSERT);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- @Test public void testRewriteProcedure10() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1, pm1.g2 where TRANSLATE = CRITERIA ON (e2) WITH (e2 = pm1.g1.e2 + 20);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g1 SET e1='x' where e2 = e2 + 50"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1, pm1.g2 WHERE (pm1.g1.e2 + 20) = ((pm1.g1.e2 + 20) + 50);\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // virtual group elements used in procedure in if statement(HAS CRITERIA)
- @Test public void testRewriteProcedure11() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE string var1;\n"; //$NON-NLS-1$
- procedure = procedure + "var1 = INPUT.e1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g1 SET e1=40"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE string var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "var1 = '40';\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- // with complex query transform
- @Test public void testRewriteProcedure12() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE = CRITERIA WITH (x = CONCAT(e1 , 'z'));\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g3 SET x='x' where x =CONCAT(x , 'y')"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1 WHERE CONCAT(e1, 'z') = CONCAT(CONCAT(e1, 'z'), 'y');\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- // with complex query transform
- @Test public void testRewriteProcedure13() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE = CRITERIA WITH (x = CONCAT(e1 , 'z'), y = convert(CONCAT(e1 , 'k'), integer));\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g3 SET x='x' where x =CONCAT(x , 'y') and y= 1"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1 WHERE (CONCAT(e1, 'z') = CONCAT(CONCAT(e1, 'z'), 'y')) AND (convert(CONCAT(e1, 'k'), integer) = 1);\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- @Test public void testRewriteProcedure14() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE = CRITERIA WITH (e4 = sqrt(e4));\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g3 SET x='x' where e4= 1"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1 WHERE sqrt(e4) = 1.0;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- @Test public void testRewriteProcedure15() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE = CRITERIA WITH (e4 = e4/50);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g3 SET x='x' where y= 1"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1 WHERE e2 = 0;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // virtual group elements used in procedure (TRANSLATE CRITERIA)
- @Test public void testRewriteProcedure16() throws Exception {
- String procedure = exampleTranslateUpdate();
-
- String userQuery = "UPDATE vm1.g3 SET x='x' where e4= 1"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "UPDATE pm1.g1 SET e1 = 'x' WHERE e4 = 0.02;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- @Test public void testRewriteNoUserCriteria() throws Exception {
- String procedure = exampleTranslateUpdate();
-
- String userQuery = "UPDATE vm1.g3 SET x='x'"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "UPDATE pm1.g1 SET e1 = 'x' WHERE 1 = 1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- @Test public void testRewriteOrUserCriteria() throws Exception {
- String procedure = exampleTranslateUpdate();
-
- String userQuery = "UPDATE vm1.g3 SET x='x' where x = '1' or x = '2'"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "UPDATE pm1.g1 SET e1 = 'x' WHERE CONCAT(e1, 'm') IN ('2', '1');\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- private String exampleTranslateUpdate() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "update pm1.g1 set pm1.g1.e1 = inputs.x where TRANSLATE CRITERIA;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- return procedure;
- }
-
- @Test public void testRewriteProcedure17() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE LIKE CRITERIA WITH (e4 = e4/50);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g3 SET x='x' where e4= 1"; //$NON-NLS-1$
-
- this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
- }
-
- // Bug 8212 elements in INPUT and CHANGING special groups are cese sensitive
- @Test public void testRewriteProcedure18() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select Input.E1, Input.e2, CHANGING.e2, CHANGING.E1 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "INSERT into vm1.g1 (e1, E2) values('x', 1)"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT 'x', 1, TRUE, TRUE FROM pm1.g1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.INSERT);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // elements being set in updates are dropped if INPUT var is not available, unless a default is available
- // Note that this test is a little odd in that it is an update inside of an insert
- @Test public void testRewriteProcedure19() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "update pm1.g1 set e1=Input.E1, e2=Input.e2, e3=Input.e3;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "INSERT into vm1.g1 (E2) values(1)"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "UPDATE pm1.g1 SET e1 = 'xyz', e2 = 1, e3 = TRUE;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.INSERT);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // elements being set in updates are dropped if INPUT var is not available, unless a default is supplied
-
- //this test fails because the default for E1 'xyz' cannot be converted into a integer
- @Test(expected=ExpressionEvaluationException.class) public void testRewriteProcedure21() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "update pm1.g1 set e1=convert(Input.E1, integer)+INPUT.E2, e2=Input.e2, e3=Input.e3;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "INSERT into vm1.g1 (E3) values({b'true'})"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "UPDATE pm1.g1 SET e3 = TRUE;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- this.getRewritenProcedure(procedure, userQuery, Table.TriggerEvent.INSERT);
- }
-
- @Test public void testRewriteProcedure21a() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "update pm1.g1 set e1=convert(Input.E1, integer)+INPUT.E2, e2=Input.e2, e3=Input.e3;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "INSERT into vm1.g1 (E1) values(1)"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "UPDATE pm1.g1 SET e1 = '124', e2 = 123, e3 = TRUE;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.INSERT);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // none of input variables on update statement changing
- @Test public void testRewriteProcedure22() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "update pm1.g1 set e1=convert(Input.E1, integer)+INPUT.E2, e2=Input.e2;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "update vm1.g1 set E3 = {b'true'}"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // none of input variables on update statement changing
- @Test public void testRewriteProcedure23() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "update pm1.g1 set e2=Input.e2, e3=Input.e3;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "update vm1.g1 set E1 = 'x'"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- //with an insert, defaults are used
- @Test public void testRewriteProcedure23a() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "update pm1.g1 set e2=Input.e2, e3=Input.e3;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "INSERT into vm1.g1 (E1) values('x')"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "UPDATE pm1.g1 SET e2 = 123, e3 = TRUE;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.INSERT);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- @Test public void testRewriteProcedure24() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "UPDATE pm1.g1 SET e2=Input.e2 WHERE TRANSLATE LIKE CRITERIA ON (e1) WITH (e1=concat(pm1.g1.e1, '%'));\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g1 set E2=1 where e2 = 1 and e1 LIKE 'mnopxyz_'"; //$NON-NLS-1$
-
- this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
- }
-
- // INPUT vars in insert statements replaced by default variable when user's inser ignores values
- @Test public void testRewriteProcedure25() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "INSERT into pm1.g1 (e1,e2,e3,e4) values (Input.e1, Input.e2, Input.e3, Input.e4);"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "INSERT into vm1.g1 (E2) values (1)"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "INSERT INTO pm1.g1 (e1, e2, e3, e4) VALUES ('xyz', 1, TRUE, 123.456);\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.INSERT);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- @Test public void testRewriteProcedure26() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1, pm1.g2 where TRANSLATE = CRITERIA ON (e2);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g1 SET e1='x' where e2 = e2 + 50"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1, pm1.g2 WHERE pm1.g1.e2 = (pm1.g1.e2 + 50);\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- @Test public void testRewriteProcedure27() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1, pm1.g2 where TRANSLATE = CRITERIA ON (e2);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g1 SET e1='x' where e2 LIKE 'xyz'"; //$NON-NLS-1$
-
- this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
- }
-
- /**
- * Per defect 9380 -
- * A criteria of the form
- * (? + 1) < (null)
- * caused a problem in the QueryRewriter.simplifyMathematicalCriteria method.
- * At the beginning of the method, the null constant is rewritten so that it
- * loses it's implicit type conversion to integer, then later on a function
- * descriptor couldn't be found for the "minus" operation for the two types
- * integer and MetaMatrix's null type.
- */
- @Test public void testRewriteProcedure_9380() throws Exception {
-
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var2;\n"; //$NON-NLS-1$
- procedure = procedure + "if((var1 + 1) < length(input.e1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "var2 = INPUT.e2;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g1 SET e2=30"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var2;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
//base test. no change is expected
@Test public void testRewriteLookupFunction1() {
String criteria = "lookup('pm1.g1','e1', 'e2', 1) = 'ab'"; //$NON-NLS-1$
@@ -1569,7 +884,7 @@
// rewrite
try {
- QueryRewriter.rewriteCriteria(origCrit, null, null, metadata);
+ QueryRewriter.rewriteCriteria(origCrit, null, metadata);
fail("Expected QueryValidatorException due to divide by 0"); //$NON-NLS-1$
} catch(TeiidException e) {
// looks like message is being wrapped with another exception with same message
@@ -1583,35 +898,13 @@
// rewrite
try {
- QueryRewriter.rewriteCriteria(origCrit, null, null, metadata);
+ QueryRewriter.rewriteCriteria(origCrit, null, metadata);
fail("Expected QueryValidatorException due to invalid string"); //$NON-NLS-1$
} catch(TeiidException e) {
assertEquals("Error Code:ERR.015.001.0003 Message:Unable to evaluate convert('x', integer): Error Code:ERR.015.001.0003 Message:Error while evaluating function convert", e.getMessage()); //$NON-NLS-1$
}
}
- @Test public void testDefect13458() throws Exception {
-
- String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "IF (HAS = CRITERIA ON (vm1.g1.e1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select vm1.g1.e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e1);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "delete from vm1.g1 where e1='1'"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT vm1.g1.e1 FROM vm1.g1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- Table.TriggerEvent.DELETE);
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
@Test public void testRewriteCase1954() {
helpTestRewriteCriteria("convert(pm1.g1.e2, string) = '3'", "pm1.g1.e2 = 3"); //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -1883,36 +1176,6 @@
assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
}
- /**
- * Test to ensure the update changing list retains e1 = ?
- */
- @Test public void testVariableSubstitutionVisitor() throws Exception {
- String procedure1 = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure1 += "BEGIN\n"; //$NON-NLS-1$
- procedure1 += "DECLARE string var1 = INPUT.e1;\n"; //$NON-NLS-1$
- procedure1 += "ROWS_UPDATED = UPDATE vm1.g2 SET e1=var1;\n"; //$NON-NLS-1$
- procedure1 += "END"; //$NON-NLS-1$
-
- String procedure2 = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure2 += "BEGIN\n"; //$NON-NLS-1$
- procedure2 += "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure2 += "IF (INPUT.e1 = 1)\n"; //$NON-NLS-1$
- procedure2 += "ROWS_UPDATED = 5;\n"; //$NON-NLS-1$
- procedure2 += "ELSE\n"; //$NON-NLS-1$
- procedure2 += "ROWS_UPDATED = 5;\n"; //$NON-NLS-1$
- procedure2 += "END"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1 = 'x' WHERE e2 = 5"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(Table.TriggerEvent.UPDATE, procedure1, procedure2);
-
- String rewriten = getRewritenProcedure(userUpdateStr, metadata);
-
- String expected = "CREATE PROCEDURE\nBEGIN\nDECLARE string var1 = 'x';\nUPDATE vm1.g2 SET e1 = var1;\nROWS_UPDATED = VARIABLES.ROWCOUNT;\nEND"; //$NON-NLS-1$
-
- assertEquals(expected, rewriten);
- }
-
@Test public void testRemoveEmptyLoop() {
String procedure1 = "CREATE virtual PROCEDURE "; //$NON-NLS-1$
procedure1 += "BEGIN\n"; //$NON-NLS-1$
@@ -2228,6 +1491,7 @@
helpTestRewriteCriteria(original, expected);
}
+ @SuppressWarnings("unchecked")
private void addTestData() {
this.elements = new HashMap<ElementSymbol, Integer>();
elements.put(new ElementSymbol("pm1.g1.e1"), 0);
Deleted: trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCriteriaSelector.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCriteriaSelector.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCriteriaSelector.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -1,109 +0,0 @@
-/*
- * 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 org.teiid.query.sql.proc;
-
-import java.util.*;
-
-import org.teiid.core.util.UnitTestUtil;
-import org.teiid.query.sql.proc.CriteriaSelector;
-import org.teiid.query.sql.symbol.*;
-
-import junit.framework.*;
-
-/**
- *
- * @author gchadalavadaDec 9, 2002
- */
-public class TestCriteriaSelector extends TestCase {
-
- // ################################## FRAMEWORK ################################
-
- public TestCriteriaSelector(String name) {
- super(name);
- }
-
- // ################################## TEST HELPERS ################################
-
- public static final CriteriaSelector sample1() {
- ElementSymbol sy1 = new ElementSymbol("a"); //$NON-NLS-1$
- ElementSymbol sy2 = new ElementSymbol("b"); //$NON-NLS-1$
- ElementSymbol sy3 = new ElementSymbol("c"); //$NON-NLS-1$
- List elmnts = new ArrayList(3);
- elmnts.add(sy1);
- elmnts.add(sy2);
- elmnts.add(sy3);
- CriteriaSelector cs = new CriteriaSelector(CriteriaSelector.COMPARE_EQ, elmnts);
- return cs;
- }
-
- public static final CriteriaSelector sample2() {
- ElementSymbol sy1 = new ElementSymbol("x"); //$NON-NLS-1$
- ElementSymbol sy2 = new ElementSymbol("y"); //$NON-NLS-1$
- ElementSymbol sy3 = new ElementSymbol("z"); //$NON-NLS-1$
- List elmnts = new ArrayList(3);
- elmnts.add(sy1);
- elmnts.add(sy2);
- elmnts.add(sy3);
- CriteriaSelector cs = new CriteriaSelector(CriteriaSelector.LIKE, elmnts);
- return cs;
- }
-
- // ################################## ACTUAL TESTS ################################
-
- public void testGetElements() {
- CriteriaSelector cs1 = sample1();
- Collection elmts = cs1.getElements();
- assertTrue("Incorrect number of elements in the selector", (elmts.size() == 3)); //$NON-NLS-1$
- }
-
- public void testGetType() {
- CriteriaSelector cs1 = sample1();
- assertTrue("Incorrect type in the selector", (cs1.getSelectorType() == CriteriaSelector.COMPARE_EQ)); //$NON-NLS-1$
- }
-
- public void testaddElement1() {
- CriteriaSelector cs1 = (CriteriaSelector) sample1().clone();
- cs1.addElement(new ElementSymbol("d")); //$NON-NLS-1$
- assertTrue("Incorrect number of statements in the Block", (cs1.getElements().size() == 4)); //$NON-NLS-1$
- }
-
- public void testSelfEquivalence(){
- CriteriaSelector s1 = sample1();
- int equals = 0;
- UnitTestUtil.helpTestEquivalence(equals, s1, s1);
- }
-
- public void testEquivalence(){
- CriteriaSelector s1 = sample1();
- CriteriaSelector s1a = sample1();
- int equals = 0;
- UnitTestUtil.helpTestEquivalence(equals, s1, s1a);
- }
-
- public void testNonEquivalence(){
- CriteriaSelector s1 = sample1();
- CriteriaSelector s2 = sample2();
- int equals = -1;
- UnitTestUtil.helpTestEquivalence(equals, s1, s2);
- }
-}
Deleted: trunk/engine/src/test/java/org/teiid/query/sql/proc/TestHasCriteria.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/proc/TestHasCriteria.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/test/java/org/teiid/query/sql/proc/TestHasCriteria.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -1,87 +0,0 @@
-/*
- * 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 org.teiid.query.sql.proc;
-
-import org.teiid.core.util.UnitTestUtil;
-import org.teiid.query.sql.proc.HasCriteria;
-
-import junit.framework.*;
-
-/**
- *
- * @author gchadalavadaDec 9, 2002
- */
-public class TestHasCriteria extends TestCase {
-
- // ################################## FRAMEWORK ################################
-
- public TestHasCriteria(String name) {
- super(name);
- }
-
- // ################################## TEST HELPERS ################################
-
- public static final HasCriteria sample1() {
- HasCriteria hc = new HasCriteria(TestCriteriaSelector.sample1());
- return hc;
- }
-
- public static final HasCriteria sample2() {
- HasCriteria hc = new HasCriteria(TestCriteriaSelector.sample2());
- return hc;
- }
-
- // ################################## ACTUAL TESTS ################################
-
- public void testGetCriteriaSelector() {
- HasCriteria hc1 = sample1();
- assertEquals("Incorrect criteria selector obtained", hc1.getSelector(), TestCriteriaSelector.sample1()); //$NON-NLS-1$
- }
-
- public void testSetCriteriaSelector() {
- HasCriteria hc1 = (HasCriteria) sample1().clone();
- hc1.setSelector(TestCriteriaSelector.sample2());
- assertEquals("Incorrect criteria selector obtained", hc1.getSelector(), TestCriteriaSelector.sample2()); //$NON-NLS-1$
- }
-
- public void testSelfEquivalence(){
- HasCriteria s1 = sample1();
- int equals = 0;
- UnitTestUtil.helpTestEquivalence(equals, s1, s1);
- }
-
- public void testEquivalence(){
- HasCriteria s1 = sample1();
- HasCriteria s1a = sample1();
- int equals = 0;
- UnitTestUtil.helpTestEquivalence(equals, s1, s1a);
- }
-
- public void testNonEquivalence(){
- HasCriteria s1 = sample1();
- HasCriteria s2 = sample2();
- int equals = -1;
- UnitTestUtil.helpTestEquivalence(equals, s1, s2);
- }
-
-}
Modified: trunk/engine/src/test/java/org/teiid/query/sql/proc/TestIfStatement.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/proc/TestIfStatement.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/test/java/org/teiid/query/sql/proc/TestIfStatement.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -46,14 +46,14 @@
public static final IfStatement sample1() {
Block ifBlock = TestBlock.sample1();
Block elseBlock = TestBlock.sample2();
- Criteria criteria = TestHasCriteria.sample1();
+ Criteria criteria = TestSetCriteria.sample1();
return new IfStatement(criteria, ifBlock, elseBlock);
}
public static final IfStatement sample2() {
Block ifBlock = TestBlock.sample2();
Block elseBlock = TestBlock.sample1();
- Criteria criteria = TestHasCriteria.sample2();
+ Criteria criteria = TestSetCriteria.sample2();
return new IfStatement(criteria, ifBlock, elseBlock);
}
@@ -72,7 +72,7 @@
public void testGetCondition() {
IfStatement b1 = sample1();
- assertTrue("Incorrect IfBlock on statement", b1.getCondition().equals(TestHasCriteria.sample1())); //$NON-NLS-1$
+ assertTrue("Incorrect IfBlock on statement", b1.getCondition().equals(TestSetCriteria.sample1())); //$NON-NLS-1$
}
public void testSelfEquivalence(){
Deleted: trunk/engine/src/test/java/org/teiid/query/sql/proc/TestTranslateCriteria.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/proc/TestTranslateCriteria.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/test/java/org/teiid/query/sql/proc/TestTranslateCriteria.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -1,75 +0,0 @@
-/*
- * 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 org.teiid.query.sql.proc;
-
-import org.teiid.core.util.UnitTestUtil;
-import org.teiid.query.sql.proc.TranslateCriteria;
-
-import junit.framework.*;
-
-/**
- *
- * @author gchadalavadaDec 9, 2002
- */
-public class TestTranslateCriteria extends TestCase {
-
- // ################################## FRAMEWORK ################################
-
- public TestTranslateCriteria(String name) {
- super(name);
- }
-
- // ################################## TEST HELPERS ################################
-
- public static final TranslateCriteria sample1() {
- TranslateCriteria tc = new TranslateCriteria(TestCriteriaSelector.sample1());
- return tc;
- }
-
- public static final TranslateCriteria sample2() {
- TranslateCriteria tc = new TranslateCriteria(TestCriteriaSelector.sample2());
- return tc;
- }
-
- // ################################## ACTUAL TESTS ################################
-
- public void testSelfEquivalence(){
- TranslateCriteria s1 = sample1();
- int equals = 0;
- UnitTestUtil.helpTestEquivalence(equals, s1, s1);
- }
-
- public void testEquivalence(){
- TranslateCriteria s1 = sample1();
- TranslateCriteria s1a = sample1();
- int equals = 0;
- UnitTestUtil.helpTestEquivalence(equals, s1, s1a);
- }
-
- public void testNonEquivalence(){
- TranslateCriteria s1 = sample1();
- TranslateCriteria s2 = sample2();
- int equals = -1;
- UnitTestUtil.helpTestEquivalence(equals, s1, s2);
- }
-}
Modified: trunk/engine/src/test/java/org/teiid/query/sql/proc/TestWhileStatement.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/proc/TestWhileStatement.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/test/java/org/teiid/query/sql/proc/TestWhileStatement.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -24,14 +24,13 @@
*/
package org.teiid.query.sql.proc;
+import junit.framework.TestCase;
+
import org.teiid.core.util.UnitTestUtil;
import org.teiid.query.sql.lang.Criteria;
-import org.teiid.query.sql.proc.Block;
-import org.teiid.query.sql.proc.WhileStatement;
+import org.teiid.query.sql.lang.TestSetCriteria;
-import junit.framework.TestCase;
-
public class TestWhileStatement extends TestCase{
public TestWhileStatement(String name) {
@@ -42,13 +41,13 @@
public static final WhileStatement sample1() {
Block block = TestBlock.sample1();
- Criteria criteria = TestHasCriteria.sample1();
+ Criteria criteria = TestSetCriteria.sample1();
return new WhileStatement(criteria, block);
}
public static final WhileStatement sample2() {
Block block = TestBlock.sample2();
- Criteria criteria = TestHasCriteria.sample2();
+ Criteria criteria = TestSetCriteria.sample2();
return new WhileStatement(criteria, block);
}
@@ -62,7 +61,7 @@
public void testGetCondition() {
WhileStatement b1 = sample1();
- assertTrue("Incorrect Block on statement", b1.getCondition().equals(TestHasCriteria.sample1())); //$NON-NLS-1$
+ assertTrue("Incorrect Block on statement", b1.getCondition().equals(TestSetCriteria.sample1())); //$NON-NLS-1$
}
public void testSelfEquivalence(){
Modified: trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -72,10 +72,7 @@
import org.teiid.query.sql.proc.Block;
import org.teiid.query.sql.proc.CommandStatement;
import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
-import org.teiid.query.sql.proc.CriteriaSelector;
import org.teiid.query.sql.proc.DeclareStatement;
-import org.teiid.query.sql.proc.HasCriteria;
-import org.teiid.query.sql.proc.IfStatement;
import org.teiid.query.sql.proc.RaiseErrorStatement;
import org.teiid.query.sql.symbol.AggregateSymbol;
import org.teiid.query.sql.symbol.AliasSymbol;
@@ -1413,78 +1410,6 @@
helpTest(assigStmt, "a = (SELECT x FROM g);"); //$NON-NLS-1$
}
- @Test public void testCriteriaSelector1() {
- ElementSymbol sy1 = new ElementSymbol("a"); //$NON-NLS-1$
- ElementSymbol sy2 = new ElementSymbol("b"); //$NON-NLS-1$
- ElementSymbol sy3 = new ElementSymbol("c"); //$NON-NLS-1$
- List elmnts = new ArrayList(3);
- elmnts.add(sy1);
- elmnts.add(sy2);
- elmnts.add(sy3);
- CriteriaSelector cs = new CriteriaSelector(CriteriaSelector.COMPARE_EQ, elmnts);
- helpTest(cs, "= CRITERIA ON (a, b, c)"); //$NON-NLS-1$
- }
-
- @Test public void testCriteriaSelector2() {
- ElementSymbol sy1 = new ElementSymbol("x"); //$NON-NLS-1$
- ElementSymbol sy2 = new ElementSymbol("y"); //$NON-NLS-1$
- ElementSymbol sy3 = new ElementSymbol("z"); //$NON-NLS-1$
- List elmnts = new ArrayList(3);
- elmnts.add(sy1);
- elmnts.add(sy2);
- elmnts.add(sy3);
- CriteriaSelector cs = new CriteriaSelector(CriteriaSelector.LIKE, elmnts);
- helpTest(cs, "LIKE CRITERIA ON (x, y, z)"); //$NON-NLS-1$
- }
-
- @Test public void testCriteriaSelector3() {
- ElementSymbol sy1 = new ElementSymbol("x"); //$NON-NLS-1$
- ElementSymbol sy2 = new ElementSymbol("y"); //$NON-NLS-1$
- ElementSymbol sy3 = new ElementSymbol("z"); //$NON-NLS-1$
- List elmnts = new ArrayList(3);
- elmnts.add(sy1);
- elmnts.add(sy2);
- elmnts.add(sy3);
- CriteriaSelector cs = new CriteriaSelector(CriteriaSelector.BETWEEN, elmnts);
- helpTest(cs, "BETWEEN CRITERIA ON (x, y, z)"); //$NON-NLS-1$
- }
-
- @Test public void testHasCriteria1() {
- ElementSymbol sy1 = new ElementSymbol("x"); //$NON-NLS-1$
- ElementSymbol sy2 = new ElementSymbol("y"); //$NON-NLS-1$
- ElementSymbol sy3 = new ElementSymbol("z"); //$NON-NLS-1$
- List elmnts = new ArrayList(3);
- elmnts.add(sy1);
- elmnts.add(sy2);
- elmnts.add(sy3);
- CriteriaSelector cs = new CriteriaSelector(CriteriaSelector.LIKE, elmnts);
- helpTest(new HasCriteria(cs), "HAS LIKE CRITERIA ON (x, y, z)"); //$NON-NLS-1$
- }
-
- @Test public void testHasCriteria2() {
- ElementSymbol sy1 = new ElementSymbol("x"); //$NON-NLS-1$
- ElementSymbol sy2 = new ElementSymbol("y"); //$NON-NLS-1$
- ElementSymbol sy3 = new ElementSymbol("z"); //$NON-NLS-1$
- List elmnts = new ArrayList(3);
- elmnts.add(sy1);
- elmnts.add(sy2);
- elmnts.add(sy3);
- CriteriaSelector cs = new CriteriaSelector(CriteriaSelector.LIKE, elmnts);
- helpTest(new HasCriteria(cs), "HAS LIKE CRITERIA ON (x, y, z)"); //$NON-NLS-1$
- }
-
- @Test public void testHasCriteria3() {
- ElementSymbol sy1 = new ElementSymbol("x"); //$NON-NLS-1$
- ElementSymbol sy2 = new ElementSymbol("y"); //$NON-NLS-1$
- ElementSymbol sy3 = new ElementSymbol("z"); //$NON-NLS-1$
- List elmnts = new ArrayList(3);
- elmnts.add(sy1);
- elmnts.add(sy2);
- elmnts.add(sy3);
- CriteriaSelector cs = new CriteriaSelector(CriteriaSelector.BETWEEN, elmnts);
- helpTest(new HasCriteria(cs), "HAS BETWEEN CRITERIA ON (x, y, z)"); //$NON-NLS-1$
- }
-
@Test public void testCommandStatement1() {
Query q1 = new Query();
Select select = new Select();
@@ -1518,98 +1443,6 @@
helpTest(b, "BEGIN\nDELETE FROM g;\na = 1;\nERROR 'My Error';\nEND"); //$NON-NLS-1$
}
- @Test public void testBlock2() {
- // construct If statement
-
- Delete d1 = new Delete();
- d1.setGroup(new GroupSymbol("g")); //$NON-NLS-1$
- CommandStatement cmdStmt = new CommandStatement(d1);
- Block ifblock = new Block(cmdStmt);
- // construct If criteria
- ElementSymbol sy1 = new ElementSymbol("x"); //$NON-NLS-1$
- List elmnts = new ArrayList(1);
- elmnts.add(sy1);
- CriteriaSelector cs = new CriteriaSelector(CriteriaSelector.LIKE, elmnts);
- Criteria crit = new HasCriteria(cs);
- IfStatement ifStmt = new IfStatement(crit, ifblock);
-
- // other statements
- RaiseErrorStatement errStmt = new RaiseErrorStatement(new Constant("My Error")); //$NON-NLS-1$
- Block b = new Block();
- b.addStatement(cmdStmt);
- b.addStatement(ifStmt);
- b.addStatement(errStmt);
-
- helpTest(b, "BEGIN\nDELETE FROM g;\nIF(HAS LIKE CRITERIA ON (x))\nBEGIN\nDELETE FROM g;\nEND\nERROR 'My Error';\nEND"); //$NON-NLS-1$
- }
-
- @Test public void testIfStatement1() {
- // construct If block
- Delete d1 = new Delete();
- d1.setGroup(new GroupSymbol("g")); //$NON-NLS-1$
- CommandStatement cmdStmt = new CommandStatement(d1);
- AssignmentStatement assigStmt = new AssignmentStatement(new ElementSymbol("a"), new Constant(new Integer(1))); //$NON-NLS-1$
- RaiseErrorStatement errStmt = new RaiseErrorStatement(new Constant("My Error")); //$NON-NLS-1$
- Block ifblock = new Block();
- ifblock.addStatement(cmdStmt);
- ifblock.addStatement(assigStmt);
- ifblock.addStatement(errStmt);
-
- // construct If criteria
- ElementSymbol sy1 = new ElementSymbol("x"); //$NON-NLS-1$
- List elmnts = new ArrayList(1);
- elmnts.add(sy1);
- CriteriaSelector cs = new CriteriaSelector(CriteriaSelector.LIKE, elmnts);
- Criteria crit = new HasCriteria(cs);
-
- IfStatement ifStmt = new IfStatement(crit, ifblock);
- helpTest(ifStmt, "IF(HAS LIKE CRITERIA ON (x))\nBEGIN\nDELETE FROM g;\na = 1;\nERROR 'My Error';\nEND"); //$NON-NLS-1$
- }
-
- @Test public void testIfStatement2() {
- // construct If block
- Delete d1 = new Delete();
- d1.setGroup(new GroupSymbol("g")); //$NON-NLS-1$
- CommandStatement cmdStmt = new CommandStatement(d1);
- Block ifblock = new Block(cmdStmt);
-
- // construct If criteria
- ElementSymbol sy1 = new ElementSymbol("x"); //$NON-NLS-1$
- List elmnts = new ArrayList(1);
- elmnts.add(sy1);
- CriteriaSelector cs = new CriteriaSelector(CriteriaSelector.LIKE, elmnts);
- Criteria crit = new HasCriteria(cs);
-
- IfStatement ifStmt = new IfStatement(crit, ifblock);
- helpTest(ifStmt, "IF(HAS LIKE CRITERIA ON (x))\nBEGIN\nDELETE FROM g;\nEND"); //$NON-NLS-1$
- }
-
- @Test public void testIfStatement3() {
- // construct If block
- Delete d1 = new Delete();
- d1.setGroup(new GroupSymbol("g")); //$NON-NLS-1$
- CommandStatement cmdStmt = new CommandStatement(d1);
- AssignmentStatement assigStmt = new AssignmentStatement(new ElementSymbol("a"), new Constant(new Integer(1))); //$NON-NLS-1$
- RaiseErrorStatement errStmt = new RaiseErrorStatement(new Constant("My Error")); //$NON-NLS-1$
- Block ifblock = new Block();
- ifblock.addStatement(cmdStmt);
- ifblock.addStatement(assigStmt);
- ifblock.addStatement(errStmt);
-
- // construct If criteria
- ElementSymbol sy1 = new ElementSymbol("x"); //$NON-NLS-1$
- List elmnts = new ArrayList(1);
- elmnts.add(sy1);
- CriteriaSelector cs = new CriteriaSelector(CriteriaSelector.LIKE, elmnts);
- Criteria crit = new HasCriteria(cs);
-
- Block elseblock = new Block();
- elseblock.addStatement(cmdStmt);
-
- IfStatement ifStmt = new IfStatement(crit, ifblock, elseblock);
- helpTest(ifStmt, "IF(HAS LIKE CRITERIA ON (x))\nBEGIN\nDELETE FROM g;\na = 1;\nERROR 'My Error';\nEND\nELSE\nBEGIN\nDELETE FROM g;\nEND"); //$NON-NLS-1$
- }
-
@Test public void testCreateUpdateProcedure1() {
Delete d1 = new Delete();
d1.setGroup(new GroupSymbol("g")); //$NON-NLS-1$
Modified: trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestStaticSymbolMappingVisitor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestStaticSymbolMappingVisitor.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestStaticSymbolMappingVisitor.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -47,8 +47,6 @@
import org.teiid.query.sql.lang.UnaryFromClause;
import org.teiid.query.sql.lang.Update;
import org.teiid.query.sql.navigator.DeepPreOrderNavigator;
-import org.teiid.query.sql.proc.CriteriaSelector;
-import org.teiid.query.sql.proc.TranslateCriteria;
import org.teiid.query.sql.symbol.AliasSymbol;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.ElementSymbol;
@@ -377,31 +375,4 @@
assertEquals("Stored proc param did not get mapped correctly: ", exampleElement(false, 1), innerFunc.getArg(0)); //$NON-NLS-1$
}
- public void testCriteriaSelector() {
- CriteriaSelector selector = new CriteriaSelector();
- selector.setSelectorType(CriteriaSelector.COMPARE_EQ);
- selector.addElement(exampleElement(true, 1));
-
- // Run symbol mapper
- StaticSymbolMappingVisitor visitor = new StaticSymbolMappingVisitor(getSymbolMap());
- DeepPreOrderNavigator.doVisit(selector, visitor);
-
- // Check that element got mapped
- assertEquals("Criteria selector element did not get mapped correctly: ", exampleElement(false, 1), selector.getElements().get(0)); //$NON-NLS-1$
- }
-
- public void testTranslateCriteria() {
- TranslateCriteria trans = new TranslateCriteria();
- trans.addTranslation(new CompareCriteria(exampleElement(false, 1), CompareCriteria.EQ, exampleElement(false, 2)));
-
- // Run symbol mapper
- StaticSymbolMappingVisitor visitor = new StaticSymbolMappingVisitor(getSymbolMap());
- DeepPreOrderNavigator.doVisit(trans, visitor);
-
- // Check that element got mapped
- List elements = (List) ElementCollectorVisitor.getElements(trans, false);
- assertEquals("Translate criteria element did not get mapped correctly: ", exampleElement(false, 1), elements.get(0)); //$NON-NLS-1$
- assertEquals("Translate criteria element did not get mapped correctly: ", exampleElement(false, 2), elements.get(1)); //$NON-NLS-1$
-
- }
}
Modified: trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -39,17 +39,7 @@
import org.teiid.core.TeiidComponentException;
import org.teiid.core.types.DataTypeManager;
import org.teiid.dqp.internal.process.DQPWorkContext;
-import org.teiid.metadata.Column;
-import org.teiid.metadata.ColumnSet;
-import org.teiid.metadata.ForeignKey;
-import org.teiid.metadata.FunctionMethod;
-import org.teiid.metadata.FunctionParameter;
-import org.teiid.metadata.KeyRecord;
-import org.teiid.metadata.MetadataStore;
-import org.teiid.metadata.Procedure;
-import org.teiid.metadata.ProcedureParameter;
-import org.teiid.metadata.Schema;
-import org.teiid.metadata.Table;
+import org.teiid.metadata.*;
import org.teiid.metadata.BaseColumn.NullType;
import org.teiid.metadata.Column.SearchType;
import org.teiid.metadata.ProcedureParameter.Type;
@@ -723,14 +713,14 @@
QueryNode vm1g37n1 = new QueryNode("SELECT * from pm4.g1"); //$NON-NLS-1$ //$NON-NLS-2$
Table vm1g37 = createVirtualGroup("g37", vm1, vm1g37n1); //$NON-NLS-1$
vm1g37.setSupportsUpdate(true);
+ vm1g37.setDeletePlan("for each row begin atomic end");
QueryNode vm1g38n1 = new QueryNode("SELECT a.e1, b.e2 from pm1.g1 as a, pm6.g1 as b where a.e1=b.e1"); //$NON-NLS-1$ //$NON-NLS-2$
Table vm1g38 = createVirtualGroup("g38", vm1, vm1g38n1); //$NON-NLS-1$
// Create virtual groups
QueryNode vm1g39n1 = new QueryNode("SELECT * FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
- Table vm1g39 = createUpdatableVirtualGroup("g39", vm1, vm1g39n1, "CREATE PROCEDURE BEGIN LOOP ON (SELECT pm1.g1.e2 FROM pm1.g1 where pm1.g1.e2=3) AS mycursor begin update pm1.g1 set pm1.g1.e1 = input.e1 where pm1.g1.e1 = input.e1; ROWS_UPDATED = ROWS_UPDATED + ROWCOUNT;\nupdate pm1.g1 set pm1.g1.e2 = input.e2 where pm1.g1.e2 = input.e2; END END"); //$NON-NLS-1$ //$NON-NLS-2$
-
+ Table vm1g39 = createUpdatableVirtualGroup("g39", vm1, vm1g39n1, null); //$NON-NLS-1$
// Create virtual elements
createElements(vm1g39,
new String[] { "e1", "e2", "e3", "e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
@@ -1284,12 +1274,6 @@
Procedure vsp41 = createVirtualProcedure("vsp41", pm1, null, vspqn41); //$NON-NLS-1$
vsp41.setResultSet(vsprs1());
- vm1g1.setInsertPlan("CREATE PROCEDURE BEGIN ROWS_UPDATED = INSERT INTO pm1.g1(e1, e2, e3, e4) values(INPUT.e1, INPUT.e2, INPUT.e3, INPUT.e4); END"); //$NON-NLS-1$
- vm1g1.setUpdatePlan("CREATE PROCEDURE BEGIN ROWS_UPDATED = UPDATE pm1.g1 SET e1 = INPUT.e1, e2 = INPUT.e2, e3 = INPUT.e3, e4=INPUT.e4 WHERE TRANSLATE CRITERIA; END"); //$NON-NLS-1$
- vm1g1.setDeletePlan("CREATE PROCEDURE BEGIN ROWS_UPDATED = DELETE FROM pm1.g1 WHERE TRANSLATE CRITERIA; END"); //$NON-NLS-1$
-
- vm1g37.setInsertPlan("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.setDeletePlan("CREATE PROCEDURE BEGIN ROWS_UPDATED = DELETE FROM pm4.g1 where translate criteria; END"); //$NON-NLS-1$
QueryNode vspqn37 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN DECLARE integer x; VARIABLES.x=5; INSERT INTO vm1.g1(e2) values(VARIABLES.x); SELECT ROWCOUNT; END"); //$NON-NLS-1$ //$NON-NLS-2$
Procedure vsp37 = createVirtualProcedure("vsp37", pm1, null, vspqn37); //$NON-NLS-1$
vsp37.setResultSet(vsprs1());
Modified: trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2011-11-21 20:54:23 UTC (rev 3679)
+++ trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2011-11-21 23:03:58 UTC (rev 3680)
@@ -925,52 +925,6 @@
Table.TriggerEvent.UPDATE);
}
- // validating criteria selector(on HAS CRITERIA), elements on it should be virtual group elements
- @Test public void testCreateUpdateProcedure5() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "if(HAS CRITERIA ON (vm1.g1.E1, vm1.g1.e1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpValidateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // validating Translate CRITERIA, elements on it should be virtual group elements
- @Test public void testCreateUpdateProcedure7() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e1 from pm1.g1 where Translate CRITERIA WITH (vm1.g1.e1 = 1, vm1.g1.e1 = 2);\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpValidateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // ROWS_UPDATED not assigned
- @Test public void testCreateUpdateProcedure8() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e1 from pm1.g1 where Translate CRITERIA WITH (vm1.g1.e1 = 1);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpFailProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
// validating AssignmentStatement, more than one project symbol on the
// command
@Test public void testCreateUpdateProcedure11() {
@@ -1003,166 +957,6 @@
Table.TriggerEvent.UPDATE);
}
- // TranslateCriteria on criteria of the if statement
- @Test public void testCreateUpdateProcedure13() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "if(TRANSLATE CRITERIA ON (vm1.g1.e1) WITH (vm1.g1.e1 = 1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpValidateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // INPUT ised in command
- @Test public void testCreateUpdateProcedure16() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "INSERT into pm1.g1 (pm1.g1.e1) values (INPUT.e1);\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpValidateProcedure(procedure, userUpdateStr,
- Table.TriggerEvent.UPDATE);
- }
-
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- // elements on with should be on ON
- @Test public void testCreateUpdateProcedure17() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1, pm1.g2 where TRANSLATE = CRITERIA ON (e1) WITH (e1 = 20, e2 = 30);\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpFailProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
- }
-
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- // failure, aggregate function in query transform
- @Ignore
- @Test public void testCreateUpdateProcedure18() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE = CRITERIA ON (e3);\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g3 SET x='x' where e3= 1"; //$NON-NLS-1$
-
- helpFailProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
- }
-
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- // failure, aggregate function in query transform
- @Ignore
- @Test public void testCreateUpdateProcedure18a() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE = CRITERIA ON (e3);\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g3 SET x='x' where y like '%a' and e3= 1"; //$NON-NLS-1$
-
- helpFailProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
- }
-
-
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- // failure, translated criteria elements not present on groups of command
- @Test public void testCreateUpdateProcedure19() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g2.e2 from pm1.g2 where TRANSLATE = CRITERIA ON (x, y);\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g3 SET x='x' where y= 1"; //$NON-NLS-1$
-
- helpFailProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
- }
-
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- @Test public void testCreateUpdateProcedure20() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE = CRITERIA WITH (y = e2+1);\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g3 SET x='x' where y= 1"; //$NON-NLS-1$
-
- helpValidateProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
- }
-
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- @Test public void testCreateUpdateProcedure25() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g2.e2 from pm1.g2 where TRANSLATE > CRITERIA ON (y);\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g3 SET x='x' where y > 1"; //$NON-NLS-1$
-
- helpFailProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
- }
-
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- @Test public void testCreateUpdateProcedure26() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE = CRITERIA WITH (e3 = e2+1);\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g3 SET x='x' where e3 > 1"; //$NON-NLS-1$
-
- helpValidateProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
- }
-
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- @Test public void testCreateUpdateProcedure27() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g2.e2 from pm1.g2 where TRANSLATE LIKE CRITERIA WITH (y = e2+1);\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g3 SET x='x' where y = 1"; //$NON-NLS-1$
-
- helpValidateProcedure(procedure, userQuery,
- Table.TriggerEvent.UPDATE);
- }
-
// using aggregate function within a procedure - defect #8394
@Test public void testCreateUpdateProcedure31() {
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
13 years, 1 month
teiid SVN: r3679 - in branches/7.6.x/engine/src: main/java/org/teiid/query/sql/visitor and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-11-21 15:54:23 -0500 (Mon, 21 Nov 2011)
New Revision: 3679
Modified:
branches/7.6.x/engine/src/main/java/org/teiid/query/sql/lang/Command.java
branches/7.6.x/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
branches/7.6.x/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java
Log:
TEIID-1845 fix for cache hint on a procedure
Modified: branches/7.6.x/engine/src/main/java/org/teiid/query/sql/lang/Command.java
===================================================================
--- branches/7.6.x/engine/src/main/java/org/teiid/query/sql/lang/Command.java 2011-11-21 20:41:44 UTC (rev 3678)
+++ branches/7.6.x/engine/src/main/java/org/teiid/query/sql/lang/Command.java 2011-11-21 20:54:23 UTC (rev 3679)
@@ -344,7 +344,6 @@
protected boolean sameOptionAndHint(Command cmd) {
return EquivalenceUtil.areEqual(this.cacheHint, cmd.cacheHint) &&
- EquivalenceUtil.areEqual(this.cacheHint, cmd.cacheHint) &&
EquivalenceUtil.areEqual(this.option, cmd.option);
}
Modified: branches/7.6.x/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
===================================================================
--- branches/7.6.x/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2011-11-21 20:41:44 UTC (rev 3678)
+++ branches/7.6.x/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2011-11-21 20:54:23 UTC (rev 3679)
@@ -1463,6 +1463,7 @@
}
public void visit( CreateUpdateProcedureCommand obj ) {
+ addCacheHint(obj.getCacheHint());
append(CREATE);
append(SPACE);
if (!obj.isUpdateProcedure()) {
Modified: branches/7.6.x/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java
===================================================================
--- branches/7.6.x/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java 2011-11-21 20:41:44 UTC (rev 3678)
+++ branches/7.6.x/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java 2011-11-21 20:54:23 UTC (rev 3679)
@@ -1055,6 +1055,14 @@
TestParser.helpTest(sql, "/*+ cache */ SELECT * FROM t1", query); //$NON-NLS-1$
}
+ @Test public void testCacheProc() {
+ String sql = "/*+ cache */ CREATE VIRTUAL PROCEDURE BEGIN END"; //$NON-NLS-1$
+ CreateUpdateProcedureCommand command = new CreateUpdateProcedureCommand(new Block());
+ command.setUpdateProcedure(false);
+ command.setCacheHint(new CacheHint());
+ TestParser.helpTest(sql, "/*+ cache */ CREATE VIRTUAL PROCEDURE\nBEGIN\nEND", command); //$NON-NLS-1$
+ }
+
@Test public void testCacheScope() {
String sql = "/*+ cache(pref_mem scope:session) */ SELECT * FROM t1"; //$NON-NLS-1$
13 years, 1 month
teiid SVN: r3678 - in branches/7.6.x: engine/src/main/java/org/teiid/query/optimizer/relational and 3 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-11-21 15:41:44 -0500 (Mon, 21 Nov 2011)
New Revision: 3678
Modified:
branches/7.6.x/build/kits/jboss-container/teiid-releasenotes.html
branches/7.6.x/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java
branches/7.6.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
branches/7.6.x/engine/src/main/resources/org/teiid/query/i18n.properties
branches/7.6.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
branches/7.6.x/engine/src/test/java/org/teiid/query/processor/TestTriggerActions.java
Log:
TEIID-1843 fix for stackoverflow
Modified: branches/7.6.x/build/kits/jboss-container/teiid-releasenotes.html
===================================================================
--- branches/7.6.x/build/kits/jboss-container/teiid-releasenotes.html 2011-11-21 16:58:13 UTC (rev 3677)
+++ branches/7.6.x/build/kits/jboss-container/teiid-releasenotes.html 2011-11-21 20:41:44 UTC (rev 3678)
@@ -50,7 +50,7 @@
<h2><a name="Compatibility">Compatibility Issues</a></h2>
<ul>
- <li>TRANSLATE/HAS CRITERIA has been deprecated. An alternative approach to update procedures will be introduced in a subsequent version.
+ <li>TRANSLATE/HAS CRITERIA has been deprecated. INSTEAD OF trigger actions should be used instead.
<li>Support for named parameter syntax using param=value has been deprecated, since it is ambiguous with a comparison predicate boolean value expression. param<b>=></b>value should be used instead.
<li>Support for using the FROM clause post item hints MAKEDEP/MAKENOTDEP has been deprecated. Use the pre item comment hint syntax instead, e.g. /*+ MAKEDEP */ tbl
</ul>
Modified: branches/7.6.x/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java
===================================================================
--- branches/7.6.x/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java 2011-11-21 16:58:13 UTC (rev 3677)
+++ branches/7.6.x/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java 2011-11-21 20:41:44 UTC (rev 3678)
@@ -159,6 +159,11 @@
private PlanHints hints = new PlanHints();
private Option option;
private SourceHint sourceHint;
+ private static ThreadLocal<Boolean> planningLoop = new ThreadLocal<Boolean>() {
+ protected Boolean initialValue() {
+ return Boolean.FALSE;
+ }
+ };
public ProcessorPlan optimize(
Command command)
@@ -314,18 +319,23 @@
CorrelatedReferenceCollectorVisitor.collectReferences(subCommand, localGroupSymbols, correlatedReferences);
ProcessorPlan procPlan = QueryOptimizer.optimizePlan(subCommand, metadata, idGenerator, capFinder, analysisRecord, context);
container.getCommand().setProcessorPlan(procPlan);
- if (!correlatedReferences.isEmpty()) {
- SymbolMap map = new SymbolMap();
- for (Reference reference : correlatedReferences) {
- map.addMapping(reference.getExpression(), reference.getExpression());
- }
- container.getCommand().setCorrelatedReferences(map);
- }
+ setCorrelatedReferences(container, correlatedReferences);
}
node.addGroups(GroupsUsedByElementsVisitor.getGroups(node.getCorrelatedReferenceElements()));
}
}
+ private void setCorrelatedReferences(SubqueryContainer<?> container,
+ List<Reference> correlatedReferences) {
+ if (!correlatedReferences.isEmpty()) {
+ SymbolMap map = new SymbolMap();
+ for (Reference reference : correlatedReferences) {
+ map.addMapping(reference.getExpression(), reference.getExpression());
+ }
+ container.getCommand().setCorrelatedReferences(map);
+ }
+ }
+
private static Set<GroupSymbol> getGroupSymbols(PlanNode plan) {
Set<GroupSymbol> groupSymbols = new HashSet<GroupSymbol>();
for (PlanNode source : NodeEditor.findAllNodes(plan, NodeConstants.Types.SOURCE)) {
@@ -588,6 +598,14 @@
context.accessedPlanningObject(sp.getProcedureID());
}
}
+ for (SubqueryContainer<?> subqueryContainer : ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(container)) {
+ if (subqueryContainer.getCommand().getCorrelatedReferences() != null) {
+ continue;
+ }
+ List<Reference> correlatedReferences = new ArrayList<Reference>();
+ CorrelatedReferenceCollectorVisitor.collectReferences(subqueryContainer.getCommand(), Arrays.asList(container.getGroup()), correlatedReferences);
+ setCorrelatedReferences(subqueryContainer, correlatedReferences);
+ }
String cacheString = "transformation/" + container.getClass().getSimpleName().toUpperCase(); //$NON-NLS-1$
Command c = (Command)metadata.getFromMetadataCache(metadataId, cacheString);
if (c == null) {
@@ -637,13 +655,22 @@
throw new QueryPlannerException(QueryPlugin.Util.getString("RelationalPlanner.nonpushdown_command", container)); //$NON-NLS-1$
}
- //treat this as an update procedure
- if (container instanceof Update) {
- c = QueryRewriter.createUpdateProcedure((Update)container, metadata, context);
- } else {
- c = QueryRewriter.createDeleteProcedure((Delete)container, metadata, context);
+ try {
+ if (planningLoop.get()) {
+ throw new QueryPlannerException(QueryPlugin.Util.getString("RelationalPlanner.nonpushdown_expression", container)); //$NON-NLS-1$
+ }
+ planningLoop.set(Boolean.TRUE);
+
+ //treat this as an update procedure
+ if (container instanceof Update) {
+ c = QueryRewriter.createUpdateProcedure((Update)container, metadata, context);
+ } else {
+ c = QueryRewriter.createDeleteProcedure((Delete)container, metadata, context);
+ }
+ addNestedCommand(sourceNode, container.getGroup(), container, c, false);
+ } finally {
+ planningLoop.set(Boolean.FALSE);
}
- addNestedCommand(sourceNode, container.getGroup(), container, c, false);
return false;
}
Modified: branches/7.6.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
===================================================================
--- branches/7.6.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2011-11-21 16:58:13 UTC (rev 3677)
+++ branches/7.6.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2011-11-21 20:41:44 UTC (rev 3678)
@@ -1060,7 +1060,7 @@
} else if (criteria instanceof DependentSetCriteria) {
criteria = rewriteDependentSetCriteria((DependentSetCriteria)criteria);
} else if (criteria instanceof ExpressionCriteria) {
- return new CompareCriteria(((ExpressionCriteria) criteria).getExpression(), CompareCriteria.EQ, new Constant(Boolean.TRUE));
+ return rewriteCriteria(new CompareCriteria(((ExpressionCriteria) criteria).getExpression(), CompareCriteria.EQ, new Constant(Boolean.TRUE)));
}
return evaluateCriteria(criteria);
Modified: branches/7.6.x/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- branches/7.6.x/engine/src/main/resources/org/teiid/query/i18n.properties 2011-11-21 16:58:13 UTC (rev 3677)
+++ branches/7.6.x/engine/src/main/resources/org/teiid/query/i18n.properties 2011-11-21 20:41:44 UTC (rev 3678)
@@ -924,6 +924,7 @@
connection_factory_not_found=Failed to find the Connection Factory with JNDI name {0}. Please check the name or deploy the Connection Factory with specified name.
RelationalPlanner.nonpushdown_command=Source UPDATE or DELETE command "{0}" contains non-pushdown constructs and no compensating action can be taken as the table lacks a unique key or the source does not support equality predicates.
+RelationalPlanner.nonpushdown_expression=Source UPDATE or DELETE command "{0}" contains non-pushdown constructs that cannot be simplified into a compensating action.
Translate.error=Cannot translate criteria "{0}", it is not matched by selector "{1}"
Modified: branches/7.6.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
===================================================================
--- branches/7.6.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2011-11-21 16:58:13 UTC (rev 3677)
+++ branches/7.6.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2011-11-21 20:41:44 UTC (rev 3678)
@@ -41,6 +41,7 @@
import java.util.StringTokenizer;
import org.junit.Test;
+import org.teiid.api.exception.query.QueryPlannerException;
import org.teiid.client.metadata.ParameterInfo;
import org.teiid.common.buffer.BlockedException;
import org.teiid.common.buffer.BufferManager;
@@ -7573,6 +7574,17 @@
helpProcess(plan, dataManager, expected);
}
+ @Test(expected=QueryPlannerException.class) public void testUpdateCompensationNotPossible() throws Exception {
+ String sql = "update pm1.g1 set e4 = (select e4 from pm1.g2 where pm1.g2.e2 = pm1.g1.e2) where e1 = 'a'"; //$NON-NLS-1$
+
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+
+ BasicSourceCapabilities caps = getTypicalCapabilities();
+ caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, false);
+ helpGetPlan(helpParse(sql), RealMetadataFactory.example4(), new DefaultCapabilitiesFinder(caps), createCommandContext());
+ }
+
@Test public void testDupSelect() throws Exception {
String sql = "select e1, e1 from pm1.g1";
Modified: branches/7.6.x/engine/src/test/java/org/teiid/query/processor/TestTriggerActions.java
===================================================================
--- branches/7.6.x/engine/src/test/java/org/teiid/query/processor/TestTriggerActions.java 2011-11-21 16:58:13 UTC (rev 3677)
+++ branches/7.6.x/engine/src/test/java/org/teiid/query/processor/TestTriggerActions.java 2011-11-21 20:41:44 UTC (rev 3678)
@@ -124,6 +124,27 @@
assertEquals("UPDATE pm1.g1 SET e2 = 5 WHERE e2 = 2", dm.getQueries().get(0));
}
+ @Test public void testUpdateWithChanging() 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 update pm1.g1 set e2 = case when changing.y then new.y end where e2 = old.y; END");
+ t.setInsertPlan("");
+
+ String sql = "update gx set y = 5";
+
+ FakeDataManager dm = new FakeDataManager();
+ FakeDataStore.addTable("pm1.g1", dm, metadata);
+
+ 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);
+ assertEquals("UPDATE pm1.g1 SET e2 = 5 WHERE e2 = 2", dm.getQueries().get(0));
+ }
+
@Test public void testUpdateWithNonConstant() throws Exception {
TransformationMetadata metadata = TestUpdateValidator.example1();
TestUpdateValidator.createView("select 1 as x, 2 as y", metadata, GX);
13 years, 1 month
teiid SVN: r3677 - branches/7.6.x/console.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2011-11-21 11:58:13 -0500 (Mon, 21 Nov 2011)
New Revision: 3677
Modified:
branches/7.6.x/console/pom.xml
Log:
misc:removing the dependency com.sun.tools that is failing on eclipse builds
Modified: branches/7.6.x/console/pom.xml
===================================================================
--- branches/7.6.x/console/pom.xml 2011-11-21 13:30:16 UTC (rev 3676)
+++ branches/7.6.x/console/pom.xml 2011-11-21 16:58:13 UTC (rev 3677)
@@ -58,6 +58,12 @@
<groupId>org.rhq</groupId>
<artifactId>rhq-jmx-plugin</artifactId>
<version>${org.rhq.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.sun</groupId>
+ <artifactId>tools</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
13 years, 1 month
teiid SVN: r3676 - branches/7.6.x/console/src/main/resources/META-INF.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2011-11-21 08:30:16 -0500 (Mon, 21 Nov 2011)
New Revision: 3676
Modified:
branches/7.6.x/console/src/main/resources/META-INF/rhq-plugin.xml
Log:
TEIID-1840: making the hostname property read-only
Modified: branches/7.6.x/console/src/main/resources/META-INF/rhq-plugin.xml
===================================================================
--- branches/7.6.x/console/src/main/resources/META-INF/rhq-plugin.xml 2011-11-19 13:32:27 UTC (rev 3675)
+++ branches/7.6.x/console/src/main/resources/META-INF/rhq-plugin.xml 2011-11-21 13:30:16 UTC (rev 3676)
@@ -394,7 +394,7 @@
<c:simple-property name="JdbcSocketConfiguration.enabled" displayName="Enable"
description="Enable Socket based JDBC access" required="false" readOnly="false" />
<c:simple-property name="JdbcSocketConfiguration.hostName" displayName="Host Name"
- description="Host Name" required="false" readOnly="false" />
+ description="Host Name" required="false" readOnly="true" />
<c:simple-property name="JdbcSocketConfiguration.portNumber" displayName="Port Number"
description="Port Number" required="false" readOnly="false" />
<c:simple-property name="JdbcSocketConfiguration.sslEnabled" displayName="SSL Enabled"
13 years, 1 month
teiid SVN: r3675 - in branches/7.6.x/connectors/connector-ws/src: main/resources/org/teiid/resource/adapter/ws and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-11-19 08:32:27 -0500 (Sat, 19 Nov 2011)
New Revision: 3675
Modified:
branches/7.6.x/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSConnectionImpl.java
branches/7.6.x/connectors/connector-ws/src/main/resources/org/teiid/resource/adapter/ws/i18n.properties
branches/7.6.x/connectors/connector-ws/src/test/java/org/teiid/resource/adapter/ws/TestWSAdapter.java
Log:
TEIID-1836 adding a null check to avoid an npe
Modified: branches/7.6.x/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSConnectionImpl.java
===================================================================
--- branches/7.6.x/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSConnectionImpl.java 2011-11-18 21:31:46 UTC (rev 3674)
+++ branches/7.6.x/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSConnectionImpl.java 2011-11-19 13:32:27 UTC (rev 3675)
@@ -210,6 +210,9 @@
String defaultEndpoint = mcf.getEndPoint();
String defaultQueryString = null;
String defaultFragment = null;
+ if (defaultEndpoint == null) {
+ throw new WebServiceException(WSManagedConnectionFactory.UTIL.getString("null_default_endpoint")); //$NON-NLS-1$
+ }
String[] parts = defaultEndpoint.split("\\?", 2); //$NON-NLS-1$
defaultEndpoint = parts[0];
if (parts.length > 1) {
Modified: branches/7.6.x/connectors/connector-ws/src/main/resources/org/teiid/resource/adapter/ws/i18n.properties
===================================================================
--- branches/7.6.x/connectors/connector-ws/src/main/resources/org/teiid/resource/adapter/ws/i18n.properties 2011-11-18 21:31:46 UTC (rev 3674)
+++ branches/7.6.x/connectors/connector-ws/src/main/resources/org/teiid/resource/adapter/ws/i18n.properties 2011-11-19 13:32:27 UTC (rev 3675)
@@ -20,4 +20,5 @@
# 02110-1301 USA.
#
-null_endpoint=An endpoint must be specified by the procedure call or have a default value set by the EndPoint datasource property.
\ No newline at end of file
+null_endpoint=An endpoint must be specified by the procedure call or have a default value set by the EndPoint datasource property.
+null_default_endpoint=The use of a relative endpoint in a procedure call requires a a default endpoint on the datasource.
\ No newline at end of file
Modified: branches/7.6.x/connectors/connector-ws/src/test/java/org/teiid/resource/adapter/ws/TestWSAdapter.java
===================================================================
--- branches/7.6.x/connectors/connector-ws/src/test/java/org/teiid/resource/adapter/ws/TestWSAdapter.java 2011-11-18 21:31:46 UTC (rev 3674)
+++ branches/7.6.x/connectors/connector-ws/src/test/java/org/teiid/resource/adapter/ws/TestWSAdapter.java 2011-11-19 13:32:27 UTC (rev 3675)
@@ -32,11 +32,18 @@
public class TestWSAdapter {
- @Test(expected=WebServiceException.class) public void testMissingBinding() throws ResourceException {
+ @Test(expected=WebServiceException.class) public void testMissingEndpoint() throws ResourceException {
WSManagedConnectionFactory wsmcf = new WSManagedConnectionFactory();
WSConnectionImpl conn = (WSConnectionImpl)wsmcf.createConnectionFactory().getConnection();
conn.createDispatch(HTTPBinding.HTTP_BINDING, null, StreamSource.class, Mode.PAYLOAD);
}
+
+ @Test(expected=WebServiceException.class) public void testMissingEndpoint1() throws ResourceException {
+ WSManagedConnectionFactory wsmcf = new WSManagedConnectionFactory();
+
+ WSConnectionImpl conn = (WSConnectionImpl)wsmcf.createConnectionFactory().getConnection();
+ conn.createDispatch(HTTPBinding.HTTP_BINDING, "/x", StreamSource.class, Mode.PAYLOAD); //$NON-NLS-1$
+ }
}
13 years, 1 month
teiid SVN: r3674 - in branches/7.6.x/connectors/connector-ws/src: main/java/org/teiid/resource/adapter/ws and 8 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-11-18 16:31:46 -0500 (Fri, 18 Nov 2011)
New Revision: 3674
Added:
branches/7.6.x/connectors/connector-ws/src/test/
branches/7.6.x/connectors/connector-ws/src/test/java/
branches/7.6.x/connectors/connector-ws/src/test/java/org/
branches/7.6.x/connectors/connector-ws/src/test/java/org/teiid/
branches/7.6.x/connectors/connector-ws/src/test/java/org/teiid/resource/
branches/7.6.x/connectors/connector-ws/src/test/java/org/teiid/resource/adapter/
branches/7.6.x/connectors/connector-ws/src/test/java/org/teiid/resource/adapter/ws/
branches/7.6.x/connectors/connector-ws/src/test/java/org/teiid/resource/adapter/ws/TestWSAdapter.java
Modified:
branches/7.6.x/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSConnectionImpl.java
branches/7.6.x/connectors/connector-ws/src/main/resources/org/teiid/resource/adapter/ws/i18n.properties
Log:
TEIID-1836 adding a null check to avoid a cxf npe
Modified: branches/7.6.x/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSConnectionImpl.java
===================================================================
--- branches/7.6.x/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSConnectionImpl.java 2011-11-18 20:03:35 UTC (rev 3673)
+++ branches/7.6.x/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSConnectionImpl.java 2011-11-18 21:31:46 UTC (rev 3674)
@@ -1,3 +1,25 @@
+/*
+ * 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 org.teiid.resource.adapter.ws;
import java.io.IOException;
@@ -212,6 +234,9 @@
}
} else {
endpoint = mcf.getEndPoint();
+ if (endpoint == null) {
+ throw new WebServiceException(WSManagedConnectionFactory.UTIL.getString("null_endpoint")); //$NON-NLS-1$
+ }
}
Dispatch<T> dispatch = null;
if (HTTPBinding.HTTP_BINDING.equals(binding) && type == DataSource.class) {
Modified: branches/7.6.x/connectors/connector-ws/src/main/resources/org/teiid/resource/adapter/ws/i18n.properties
===================================================================
--- branches/7.6.x/connectors/connector-ws/src/main/resources/org/teiid/resource/adapter/ws/i18n.properties 2011-11-18 20:03:35 UTC (rev 3673)
+++ branches/7.6.x/connectors/connector-ws/src/main/resources/org/teiid/resource/adapter/ws/i18n.properties 2011-11-18 21:31:46 UTC (rev 3674)
@@ -20,3 +20,4 @@
# 02110-1301 USA.
#
+null_endpoint=An endpoint must be specified by the procedure call or have a default value set by the EndPoint datasource property.
\ No newline at end of file
Added: branches/7.6.x/connectors/connector-ws/src/test/java/org/teiid/resource/adapter/ws/TestWSAdapter.java
===================================================================
--- branches/7.6.x/connectors/connector-ws/src/test/java/org/teiid/resource/adapter/ws/TestWSAdapter.java (rev 0)
+++ branches/7.6.x/connectors/connector-ws/src/test/java/org/teiid/resource/adapter/ws/TestWSAdapter.java 2011-11-18 21:31:46 UTC (rev 3674)
@@ -0,0 +1,42 @@
+/*
+ * 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 org.teiid.resource.adapter.ws;
+
+import javax.resource.ResourceException;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.Service.Mode;
+import javax.xml.ws.http.HTTPBinding;
+
+import org.junit.Test;
+
+public class TestWSAdapter {
+
+ @Test(expected=WebServiceException.class) public void testMissingBinding() throws ResourceException {
+ WSManagedConnectionFactory wsmcf = new WSManagedConnectionFactory();
+
+ WSConnectionImpl conn = (WSConnectionImpl)wsmcf.createConnectionFactory().getConnection();
+ conn.createDispatch(HTTPBinding.HTTP_BINDING, null, StreamSource.class, Mode.PAYLOAD);
+ }
+
+}
Property changes on: branches/7.6.x/connectors/connector-ws/src/test/java/org/teiid/resource/adapter/ws/TestWSAdapter.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
13 years, 1 month