teiid SVN: r1783 - trunk/test-integration/db.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2010-01-27 10:35:58 -0500 (Wed, 27 Jan 2010)
New Revision: 1783
Modified:
trunk/test-integration/db/pom.xml
Log:
Teiid-773 - fix the dependency setting related to referencing test-jar's needed for compile and testing.
Modified: trunk/test-integration/db/pom.xml
===================================================================
--- trunk/test-integration/db/pom.xml 2010-01-27 04:57:41 UTC (rev 1782)
+++ trunk/test-integration/db/pom.xml 2010-01-27 15:35:58 UTC (rev 1783)
@@ -29,19 +29,20 @@
<artifactId>junit</artifactId>
<version>4.4</version>
</dependency>
-
+
+
<dependency>
<groupId>org.jboss.teiid</groupId>
<artifactId>teiid-client-jdbc</artifactId>
<type>test-jar</type>
- <scope>provided</scope>
+ <scope>compile</scope>
</dependency>
-
+
<dependency>
<groupId>org.jboss.teiid</groupId>
<artifactId>teiid-engine</artifactId>
<type>test-jar</type>
- <scope>provided</scope>
+ <scope>compile</scope>
</dependency>
<dependency>
@@ -388,6 +389,7 @@
<phase>integration-test</phase>
<configuration>
<tasks>
+
<property name="maven.runtime.classpath" refid="maven.runtime.classpath" />
<property name="scenario.dir" value="${scenario.dir}"></property>
<property name="queryset.artifacts.dir" value="${queryset.artifacts.dir}"></property>
@@ -399,6 +401,7 @@
<property name="proj.dir" value="${project.basedir}" />
<ant antfile="src/main/resources/ctc_tests/ctc.xml" />
+
</tasks>
</configuration>
<goals>
14 years, 11 months
teiid SVN: r1782 - in trunk: client/src/main/java/com/metamatrix/dqp/embedded and 12 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-01-26 23:57:41 -0500 (Tue, 26 Jan 2010)
New Revision: 1782
Added:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedPlan.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java
Removed:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedPlanCache.java
Modified:
trunk/build/kit-runtime/deploy.properties
trunk/client/src/main/java/com/metamatrix/dqp/embedded/DQPEmbeddedProperties.java
trunk/client/src/main/java/com/metamatrix/dqp/message/ResultsMessage.java
trunk/common-core/src/main/java/com/metamatrix/core/util/HashCodeUtil.java
trunk/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java
trunk/engine/src/main/java/com/metamatrix/query/parser/ParseInfo.java
trunk/engine/src/main/java/com/metamatrix/query/parser/QueryParser.java
trunk/engine/src/main/java/com/metamatrix/query/parser/SQLParserUtil.java
trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java
trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Query.java
trunk/engine/src/main/java/com/metamatrix/query/sql/lang/SetQuery.java
trunk/engine/src/main/java/com/metamatrix/query/sql/proc/CreateUpdateProcedureCommand.java
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/SQLStringVisitor.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
trunk/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj
trunk/engine/src/test/java/com/metamatrix/dqp/message/TestResultsMessage.java
trunk/engine/src/test/java/com/metamatrix/query/parser/TestOptionsAndHints.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCoreRequestHandling.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedPlanCache.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatementBatchedUpdate.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java
Log:
TEIID-168 re-added result set caching backed by the buffermanager and added a query cache hint to use instead of the execution property - still need to add this to the docs. no considerations are currently made for transactional state though.
Modified: trunk/build/kit-runtime/deploy.properties
===================================================================
--- trunk/build/kit-runtime/deploy.properties 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/build/kit-runtime/deploy.properties 2010-01-27 04:57:41 UTC (rev 1782)
@@ -75,21 +75,12 @@
#Maximum number of records in all lookup tables (default 200000)
CodeTables.maxRows=200000
-#Denotes whether or not result set caching is enabled. (default false)
-ResultSetCache.enabled=false
+#Denotes whether or not result set caching is enabled. (default true)
+ResultSetCache.enabled=true
-#The maximum size of an result set cache entry in bytes. 0 indicates no limit. (default 1001024)
-#ResultSetCache.maxEntrySize=1001024
-
#The maximum number of result set cache entries. 0 indicates no limit. (default 1024)
#ResultSetCache.maxEntries=1024
-#The maximum time in seconds a result set will be kept in cache before being automatically cleared. 0 indicates no limit. (default 3600)
-#ResultSetCache.maxAge=3600
-
-#Defines whether caching is restricted to a specific session ('session') or a specific VDB version ('vdb'). (default vdb)
-#ResultSetCache.scope=vdb
-
#
# Session Service Settings
#
Modified: trunk/client/src/main/java/com/metamatrix/dqp/embedded/DQPEmbeddedProperties.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/dqp/embedded/DQPEmbeddedProperties.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/client/src/main/java/com/metamatrix/dqp/embedded/DQPEmbeddedProperties.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -42,6 +42,7 @@
// cache properties
public static final String USE_RESULTSET_CACHE = "ResultSetCache.enabled"; //$NON-NLS-1$
+ public static final String MAX_RESULTSET_CACHE_ENTRIES = "ResultSetCache.maxEntries"; //$NON-NLS-1$
public static final String MAX_CODE_TABLE_RECORDS_PER_TABLE = "CodeTables.maxRowsPerTable"; //$NON-NLS-1$
public static final String MAX_CODE_TABLE_RECORDS = "CodeTables.maxRows"; //$NON-NLS-1$
public static final String MAX_CODE_TABLES = "CodeTables.maxCount"; //$NON-NLS-1$
Modified: trunk/client/src/main/java/com/metamatrix/dqp/message/ResultsMessage.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/dqp/message/ResultsMessage.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/client/src/main/java/com/metamatrix/dqp/message/ResultsMessage.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -57,9 +57,6 @@
/** Warning could be schema validation errors or partial results warnings */
private List<Throwable> warnings;
- /** Schemas associated with xml results. */
- private Collection schemas;
-
/** First row index */
private int firstRow = 0;
@@ -172,17 +169,9 @@
return planDescription;
}
-
/**
* @return
*/
- public Collection getSchemas() {
- return schemas;
- }
-
- /**
- * @return
- */
public List getWarnings() {
return warnings;
}
@@ -227,13 +216,6 @@
}
/**
- * @param collection
- */
- public void setSchemas(Collection collection) {
- schemas = collection;
- }
-
- /**
* @param list
*/
public void setWarnings(List<Throwable> list) {
@@ -295,9 +277,6 @@
this.warnings = ExceptionHolder.toThrowables(holderList);
}
- //Schemas
- schemas = ExternalizeUtil.readList(in);
-
firstRow = in.readInt();
lastRow = in.readInt();
finalRow = in.readInt();
@@ -334,8 +313,6 @@
out.writeObject(this.warnings);
}
- //Schemas
- ExternalizeUtil.writeCollection(out, schemas);
out.writeInt(firstRow);
out.writeInt(lastRow);
out.writeInt(finalRow);
Modified: trunk/common-core/src/main/java/com/metamatrix/core/util/HashCodeUtil.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/HashCodeUtil.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/common-core/src/main/java/com/metamatrix/core/util/HashCodeUtil.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -22,7 +22,6 @@
package com.metamatrix.core.util;
-import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -71,17 +70,13 @@
return hashCode(previous, (x == 0.0) ? 0L : Double.doubleToLongBits(x));
}
- public static final int hashCode(int previous, Object x) {
- return (x == null) ? (PRIME*previous) : (PRIME*previous) + x.hashCode();
- }
-
- public static final int hashCode(int previous, Object[] x) {
+ public static final int hashCode(int previous, Object... x) {
if(x == null) {
return PRIME*previous;
}
- int hc = 0;
+ int hc = previous;
for(int i=0; i<x.length; i++) {
- hc = hashCode(hc, x[i]);
+ hc = (x[i] == null) ? (PRIME*hc) : (PRIME*hc) + x[i].hashCode();
}
return hc;
}
@@ -107,26 +102,6 @@
}
/**
- * Compute a hash code on a large list by walking the list
- * and combining the hash code at every exponential index:
- * 1, 2, 4, 8, ... This has been shown to give a good hash
- * for good time complexity.
- */
- public static final int expHashCode(int previous, List x) {
- if(x == null) {
- return PRIME*previous;
- }
- int hc = (PRIME*previous) + x.size();
- int index = 1;
- int xlen = x.size()+1; // switch to 1-based
- while(index < xlen) {
- hc = hashCode(hc, x.get(index-1));
- index = index << 1; // left shift by 1 to double
- }
- return hc;
- }
-
- /**
* Compute a hash code on a large collection by walking the list
* and combining the hash code at every exponential index:
* 1, 2, 4, 8, ... This has been shown to give a good hash
@@ -134,7 +109,7 @@
* the collection and pull the necessary hash code values.
* Slower than a List or array but faster than getting EVERY value.
*/
- public static final int expHashCode(int previous, Collection x) {
+ public static final int expHashCode(int previous, List x) {
if(x == null || x.size() == 0) {
return PRIME*previous;
}
Modified: trunk/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java
===================================================================
--- trunk/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -72,7 +72,6 @@
import org.teiid.connector.language.ISubqueryInCriteria;
import org.teiid.connector.language.IUpdate;
import org.teiid.connector.language.IParameter.Direction;
-import org.teiid.connector.language.ISetQuery.Operation;
import org.teiid.connector.metadata.runtime.MetadataObject;
import org.teiid.connector.visitor.framework.AbstractLanguageVisitor;
Modified: trunk/engine/src/main/java/com/metamatrix/query/parser/ParseInfo.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/parser/ParseInfo.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/engine/src/main/java/com/metamatrix/query/parser/ParseInfo.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -39,6 +39,8 @@
// treat a double quoted variable as variable instead of string
public boolean ansiQuotedIdentifiers=Boolean.valueOf(System.getProperty("teiid.ansi_quoted_identifiers", Boolean.TRUE.toString())).booleanValue(); //$NON-NLS-1$
+ public boolean cache;
+
public ParseInfo() { }
public boolean useAnsiQuotedIdentifiers() {
Modified: trunk/engine/src/main/java/com/metamatrix/query/parser/QueryParser.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/parser/QueryParser.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/engine/src/main/java/com/metamatrix/query/parser/QueryParser.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -116,6 +116,7 @@
QueryParserException qpe = null;
try {
Command result = parseCommandWithParser(sql, parseInfo);
+ result.setCache(parseInfo.cache);
return result;
} catch (QueryParserException e) {
qpe = e;
Modified: trunk/engine/src/main/java/com/metamatrix/query/parser/SQLParserUtil.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/parser/SQLParserUtil.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/engine/src/main/java/com/metamatrix/query/parser/SQLParserUtil.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -31,6 +31,7 @@
import com.metamatrix.core.util.StringUtil;
import com.metamatrix.query.QueryPlugin;
import com.metamatrix.query.sql.ReservedWords;
+import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.FromClause;
import com.metamatrix.query.sql.lang.JoinType;
import com.metamatrix.query.sql.lang.Option;
@@ -157,22 +158,33 @@
}
void setFromClauseOptions(Token groupID, FromClause fromClause){
- Token optToken = groupID.specialToken;
+ String[] parts = getComment(groupID);
+
+ for (int i = 0; i < parts.length; i++) {
+ if (parts[i].equalsIgnoreCase(Option.OPTIONAL)) {
+ fromClause.setOptional(true);
+ }
+ }
+ }
+
+ private String[] getComment(Token t) {
+ Token optToken = t.specialToken;
if (optToken == null) {
- return;
+ return new String[0];
}
String hint = optToken.image.substring(2, optToken.image.length() - 2);
String[] parts = hint.split("\\s"); //$NON-NLS-1$
+ return parts;
+ }
+
+ void setQueryCacheOption(Token t, ParseInfo p) {
+ String[] parts = getComment(t);
- HashSet<String> set = new HashSet<String>();
-
for (int i = 0; i < parts.length; i++) {
- set.add(parts[i].toLowerCase());
+ if (parts[i].equalsIgnoreCase(Command.CACHE)) {
+ p.cache = true;
+ }
}
-
- if (set.contains(Option.OPTIONAL)) {
- fromClause.setOptional(true);
- }
}
/**
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -50,6 +50,8 @@
* SQL update statement, etc.
*/
public abstract class Command implements LanguageObject {
+
+ public static final String CACHE = "cache"; //$NON-NLS-1$
/**
* Represents an unknown type of command
@@ -126,6 +128,8 @@
private ProcessorPlan plan;
private SymbolMap correlatedReferences;
+
+ private boolean cache;
/**
* Return type of command to make it easier to build switch statements by command type.
@@ -232,6 +236,10 @@
if (this.correlatedReferences != null) {
copy.correlatedReferences = this.correlatedReferences.clone();
}
+ if(this.getOption() != null) {
+ copy.setOption( (Option) this.getOption().clone() );
+ }
+ copy.cache = this.cache;
}
/**
@@ -337,6 +345,14 @@
this.plan = plan;
}
+ public boolean isCache() {
+ return cache;
+ }
+
+ public void setCache(boolean cache) {
+ this.cache = cache;
+ }
+
/**
* Returns a string representation of an instance of this class.
* @return String representation of object
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Query.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Query.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Query.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -351,10 +351,6 @@
copy.setLimit( (Limit) getLimit().clone());
}
- if(getOption() != null) {
- copy.setOption( (Option) getOption().clone());
- }
-
// Defect 13751: should clone isXML state.
copy.setIsXML(getIsXML());
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/SetQuery.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/SetQuery.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/SetQuery.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -180,11 +180,7 @@
if(this.getLimit() != null) {
copy.setLimit( (Limit) this.getLimit().clone() );
}
-
- if(this.getOption() != null) {
- copy.setOption( (Option) this.getOption().clone() );
- }
-
+
return copy;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/proc/CreateUpdateProcedureCommand.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/proc/CreateUpdateProcedureCommand.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/proc/CreateUpdateProcedureCommand.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -153,10 +153,6 @@
public Object clone() {
CreateUpdateProcedureCommand copy = new CreateUpdateProcedureCommand();
- if (this.getOption() != null) {
- copy.setOption((Option)this.getOption().clone());
- }
-
//Clone this class state
if (this.block != null) {
copy.setBlock((Block)this.block.clone());
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/SQLStringVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/SQLStringVisitor.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/SQLStringVisitor.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -35,6 +35,7 @@
import com.metamatrix.query.sql.LanguageVisitor;
import com.metamatrix.query.sql.ReservedWords;
import com.metamatrix.query.sql.lang.BetweenCriteria;
+import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.CompareCriteria;
import com.metamatrix.query.sql.lang.CompoundCriteria;
import com.metamatrix.query.sql.lang.Create;
@@ -481,9 +482,7 @@
}
public void visit(JoinPredicate obj) {
- if (obj.isOptional()) {
- addOptionComment(obj);
- }
+ addOptionComment(obj);
if(obj.hasHint()) {
parts.add("(");//$NON-NLS-1$
@@ -557,14 +556,14 @@
}
private void addOptionComment(FromClause obj) {
- parts.add(BEGIN_COMMENT);
- parts.add(SPACE);
- if (obj.isOptional()) {
- parts.add(Option.OPTIONAL);
- parts.add(SPACE);
- }
- parts.add(END_COMMENT);
- parts.add(SPACE);
+ if (obj.isOptional()) {
+ parts.add(BEGIN_COMMENT);
+ parts.add(SPACE);
+ parts.add(Option.OPTIONAL);
+ parts.add(SPACE);
+ parts.add(END_COMMENT);
+ parts.add(SPACE);
+ }
}
public void visit(JoinType obj) {
@@ -791,6 +790,7 @@
}
public void visit(Query obj) {
+ addCacheHint(obj);
parts.add(registerNode(obj.getSelect()));
if(obj.getInto() != null){
@@ -920,6 +920,7 @@
}
public void visit(SetQuery obj) {
+ addCacheHint(obj);
QueryCommand query = obj.getLeftQuery();
if(query instanceof Query) {
parts.add(registerNode(query));
@@ -975,6 +976,7 @@
}
public void visit(StoredProcedure obj) {
+ addCacheHint(obj);
//exec clause
parts.add(ReservedWords.EXEC);
parts.add(SPACE);
@@ -1016,10 +1018,19 @@
}
}
+ private void addCacheHint(Command obj) {
+ if (obj.isCache()) {
+ parts.add(BEGIN_COMMENT);
+ parts.add(SPACE);
+ parts.add(Command.CACHE);
+ parts.add(SPACE);
+ parts.add(END_COMMENT);
+ parts.add(SPACE);
+ }
+ }
+
public void visit(SubqueryFromClause obj) {
- if(obj.isOptional()) {
- addOptionComment(obj);
- }
+ addOptionComment(obj);
parts.add("(");//$NON-NLS-1$
parts.add(registerNode(obj.getCommand()));
parts.add(")");//$NON-NLS-1$
@@ -1046,9 +1057,7 @@
public void visit(UnaryFromClause obj) {
- if(obj.isOptional()) {
- addOptionComment(obj);
- }
+ addOptionComment(obj);
parts.add(registerNode(obj.getGroup()));
addFromClasueDepOptions(obj);
}
Added: trunk/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -0,0 +1,58 @@
+/*
+ * 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.dqp.internal.process;
+
+import com.metamatrix.common.buffer.TupleBuffer;
+import com.metamatrix.query.analysis.AnalysisRecord;
+import com.metamatrix.query.sql.lang.Command;
+
+public class CachedResults {
+ private Command command;
+ private AnalysisRecord analysisRecord;
+ private TupleBuffer results;
+
+ public AnalysisRecord getAnalysisRecord() {
+ return analysisRecord;
+ }
+
+ public void setAnalysisRecord(AnalysisRecord analysisRecord) {
+ this.analysisRecord = analysisRecord;
+ }
+
+ public TupleBuffer getResults() {
+ return results;
+ }
+
+ public void setResults(TupleBuffer results) {
+ this.results = results;
+ }
+
+ public void setCommand(Command command) {
+ this.command = command;
+ }
+
+ public Command getCommand() {
+ return command;
+ }
+
+}
Property changes on: trunk/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -133,6 +133,7 @@
private static final int DEFAULT_PROCESSOR_TIMESLICE = 2000;
private static final String PROCESS_PLAN_QUEUE_NAME = "QueryProcessorQueue"; //$NON-NLS-1$
private static final int DEFAULT_MAX_PROCESS_WORKERS = 15;
+ private static final int DEFAULT_MAX_RESULTSET_CACHE_ENTRIES = 1024;
// System properties for Code Table
private int maxCodeTableRecords = DEFAULT_MAX_CODE_TABLE_RECORDS;
@@ -144,10 +145,10 @@
// Resources
private BufferManager bufferManager;
private ProcessorDataManager dataTierMgr;
- private PreparedPlanCache prepPlanCache;
+ private SessionAwareCache<PreparedPlan> prepPlanCache;
+ private SessionAwareCache<CachedResults> rsCache;
private TransactionService transactionService;
private MetadataService metadataService;
- //private ResultSetCache rsCache;
// Query worker pool for processing plans
private WorkerPool processWorkerPool;
@@ -219,7 +220,7 @@
if(holder != null && !holder.isCanceled()) {
RequestInfo req = new RequestInfo(holder.requestID, holder.requestMsg.getCommandString(), holder.requestMsg.getSubmittedTimestamp(), holder.requestMsg.getProcessingTimestamp());
- req.setSessionToken(holder.dqpWorkContext.getSessionToken());
+ req.setSessionToken(holder.getDqpWorkContext().getSessionToken());
if (holder.getTransactionContext() != null && holder.getTransactionContext().isInTransaction()) {
req.setTransactionId(holder.getTransactionContext().getTxnID());
}
@@ -234,7 +235,7 @@
// add all the subrequest messages
AtomicRequestMessage arm = conInfo.getAtomicRequestMessage();
RequestInfo info = new RequestInfo(arm.getRequestID(), arm.getCommand().toString(), arm.getSubmittedTimestamp(), arm.getProcessingTimestamp());
- info.setSessionToken(holder.dqpWorkContext.getSessionToken());
+ info.setSessionToken(holder.getDqpWorkContext().getSessionToken());
info.setConnectorBindingUUID(arm.getConnectorBindingID());
info.setNodeID(arm.getAtomicRequestID().getNodeID());
info.setExecutionID(arm.getAtomicRequestID().getExecutionId());
@@ -475,9 +476,9 @@
public void clearResultSetCache() {
//clear cache in server
- /*if(rsCache != null){
- rsCache.clear();
- }*/
+ if(rsCache != null){
+ rsCache.clearAll();
+ }
}
void logMMCommand(RequestWorkItem workItem, boolean isBegin, boolean isCancel, int rowCount) {
@@ -548,9 +549,9 @@
return transactionService;
}
- /*ResultSetCache getRsCache() {
+ SessionAwareCache<CachedResults> getRsCache() {
return rsCache;
- }*/
+ }
int getProcessorTimeSlice() {
return this.processorTimeslice;
@@ -610,15 +611,13 @@
this.chunkSize = PropertiesUtils.getIntProperty(props, DQPEmbeddedProperties.STREAMING_BATCH_SIZE, 100) * 1024;
//result set cache
- /*if(PropertiesUtils.getBooleanProperty(props, DQPEmbeddedProperties.USE_RESULTSET_CACHE, false)){
- this.rsCache = new ResultSetCache();
- PropertiesUtils.setBeanProperties(this.rsCache, props, "ResultSetCache"); //$NON-NLS-1$
- this.rsCache.start(cacheFactory);
- }*/
+ if(PropertiesUtils.getBooleanProperty(props, DQPEmbeddedProperties.USE_RESULTSET_CACHE, true)){
+ this.rsCache = new SessionAwareCache<CachedResults>(PropertiesUtils.getIntProperty(props, DQPEmbeddedProperties.MAX_RESULTSET_CACHE_ENTRIES, DEFAULT_MAX_RESULTSET_CACHE_ENTRIES));
+ }
//prepared plan cache
- int maxSizeTotal = PropertiesUtils.getIntProperty(props, DQPEmbeddedProperties.MAX_PLAN_CACHE_SIZE, PreparedPlanCache.DEFAULT_MAX_SIZE_TOTAL);
- prepPlanCache = new PreparedPlanCache(maxSizeTotal);
+ int maxSizeTotal = PropertiesUtils.getIntProperty(props, DQPEmbeddedProperties.MAX_PLAN_CACHE_SIZE, SessionAwareCache.DEFAULT_MAX_SIZE_TOTAL);
+ prepPlanCache = new SessionAwareCache<PreparedPlan>(maxSizeTotal);
// Processor debug flag
LogManager.logInfo(LogConstants.CTX_DQP, DQPPlugin.Util.getString("DQPCore.Processor_debug_allowed_{0}", this.processorDebugAllowed)); //$NON-NLS-1$
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -30,7 +30,7 @@
import java.util.Map;
import org.teiid.dqp.internal.process.DQPCore.ClientState;
-import org.teiid.dqp.internal.process.PreparedPlanCache.CacheID;
+import org.teiid.dqp.internal.process.SessionAwareCache.CacheID;
import org.teiid.dqp.internal.process.multisource.MultiSourceMetadataWrapper;
import com.metamatrix.api.exception.MetaMatrixComponentException;
@@ -78,7 +78,7 @@
private MetadataService metadataService;
private DQPCore requestManager;
private QueryMetadataInterface metadata;
- private PreparedPlanCache planCache;
+ private SessionAwareCache<PreparedPlan> planCache;
private ApplicationEnvironment env;
private String vdbName;
@@ -86,7 +86,7 @@
private RequestID requestID;
- public MetaDataProcessor(MetadataService metadataService, DQPCore requestManager, PreparedPlanCache planCache, ApplicationEnvironment env, String vdbName, String vdbVersion) {
+ public MetaDataProcessor(MetadataService metadataService, DQPCore requestManager, SessionAwareCache<PreparedPlan> planCache, ApplicationEnvironment env, String vdbName, String vdbVersion) {
this.metadataService = metadataService;
this.requestManager = requestManager;
this.planCache = planCache;
@@ -215,8 +215,8 @@
ParseInfo info = new ParseInfo();
// Defect 19747 - the parser needs the following connection property to decide whether to treat double-quoted strings as variable names
info.ansiQuotedIdentifiers = isDoubleQuotedVariablesAllowed;
- CacheID id = new PreparedPlanCache.CacheID(workContext, info, sql);
- PreparedPlanCache.PreparedPlan plan = planCache.getPreparedPlan(id);
+ CacheID id = new CacheID(workContext, info, sql);
+ PreparedPlan plan = planCache.get(id);
if(plan != null) {
command = plan.getCommand();
} else {
Added: trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedPlan.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedPlan.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedPlan.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -0,0 +1,94 @@
+/*
+ * 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.dqp.internal.process;
+
+import java.util.List;
+
+import com.metamatrix.query.analysis.AnalysisRecord;
+import com.metamatrix.query.processor.ProcessorPlan;
+import com.metamatrix.query.sql.lang.Command;
+import com.metamatrix.query.sql.symbol.Reference;
+
+class PreparedPlan{
+ private ProcessorPlan plan;
+ private Command command;
+ private List<Reference> refs;
+ private AnalysisRecord analysisRecord;
+
+ /**
+ * Return the ProcessorPlan.
+ */
+ public ProcessorPlan getPlan(){
+ return plan;
+ }
+
+ /**
+ * Return the plan description.
+ */
+ public AnalysisRecord getAnalysisRecord(){
+ return this.analysisRecord;
+ }
+
+ /**
+ * Return the Command .
+ */
+ public Command getCommand(){
+ return command;
+ }
+
+ /**
+ * Return the list of Reference.
+ */
+ public List<Reference> getReferences(){
+ return refs;
+ }
+
+ /**
+ * Set the ProcessorPlan.
+ */
+ public void setPlan(ProcessorPlan planValue){
+ plan = planValue;
+ }
+
+ /**
+ * Set the plan description.
+ */
+ public void setAnalysisRecord(AnalysisRecord analysisRecord){
+ this.analysisRecord = analysisRecord;
+ }
+
+ /**
+ * Set the Command.
+ */
+ public void setCommand(Command commandValue){
+ command = commandValue;
+ }
+
+ /**
+ * Set the list of Reference.
+ */
+ public void setReferences(List<Reference> refsValue){
+ refs = refsValue;
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedPlan.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedPlanCache.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedPlanCache.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedPlanCache.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -1,203 +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.dqp.internal.process;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import com.metamatrix.core.util.HashCodeUtil;
-import com.metamatrix.core.util.LRUCache;
-import com.metamatrix.query.analysis.AnalysisRecord;
-import com.metamatrix.query.parser.ParseInfo;
-import com.metamatrix.query.processor.ProcessorPlan;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.symbol.Reference;
-import com.metamatrix.vdb.runtime.VDBKey;
-
-/**
- * This class is used to cache plan and related objects for prepared statement
- */
-public class PreparedPlanCache {
- public static final int DEFAULT_MAX_SIZE_TOTAL = 250;
-
- private Map<CacheID, PreparedPlan> cache;
- private int maxSize;
-
- PreparedPlanCache(){
- this(DEFAULT_MAX_SIZE_TOTAL);
- }
-
- PreparedPlanCache (int maxSize ){
- if(maxSize < 0){
- maxSize = DEFAULT_MAX_SIZE_TOTAL;
- }
- this.maxSize = maxSize;
- cache = Collections.synchronizedMap(new LRUCache<CacheID, PreparedPlan>(maxSize));
- }
-
- /**
- * Return the PreparedPlan for the given session and SQl query
- * @param sql SQL query string
- * @param session ClientConnection
- * @return PreparedPlan for the given clientConn and SQl query. Null if not exist.
- */
- public PreparedPlan getPreparedPlan(CacheID id){
- id.setSessionId(id.originalSessionId);
- PreparedPlan result = cache.get(id);
- if (result == null) {
- id.setSessionId(null);
- }
- return cache.get(id);
- }
-
- /**
- * Create PreparedPlan for the given clientConn and SQl query
- */
- public void putPreparedPlan(CacheID id, boolean sessionSpecific, PreparedPlan plan){
- if (sessionSpecific) {
- id.setSessionId(id.originalSessionId);
- } else {
- id.setSessionId(null);
- }
- this.cache.put(id, plan);
- }
-
- /**
- * Clear all the cached plans for all the clientConns
- * @param clientConn ClientConnection
- */
- public void clearAll(){
- cache.clear();
- }
-
- static class CacheID{
- private String sql;
- private VDBKey vdbInfo;
- private ParseInfo pi;
- private String sessionId;
- private String originalSessionId;
- private int hashCode;
-
- CacheID(DQPWorkContext context, ParseInfo pi, String sql){
- this.sql = sql;
- this.vdbInfo = new VDBKey(context.getVdbName(), context.getVdbVersion());
- this.pi = pi;
- this.originalSessionId = context.getConnectionID();
- }
-
- private void setSessionId(String sessionId) {
- this.sessionId = sessionId;
- hashCode = HashCodeUtil.hashCode(HashCodeUtil.hashCode(HashCodeUtil.hashCode(HashCodeUtil.hashCode(0, vdbInfo), sql), pi), sessionId);
- }
-
- public boolean equals(Object obj){
- if(obj == this) {
- return true;
- }
- if(! (obj instanceof CacheID)) {
- return false;
- }
- CacheID that = (CacheID)obj;
- return this.pi.equals(that.pi) && this.vdbInfo.equals(that.vdbInfo) && this.sql.equals(that.sql)
- && ((this.sessionId == null && that.sessionId == null) || this.sessionId.equals(that.sessionId));
- }
-
- public int hashCode() {
- return hashCode;
- }
- }
-
- static class PreparedPlan{
- private ProcessorPlan plan;
- private Command command;
- private List<Reference> refs;
- private AnalysisRecord analysisRecord;
-
- /**
- * Return the ProcessorPlan.
- */
- public ProcessorPlan getPlan(){
- return plan;
- }
-
- /**
- * Return the plan description.
- */
- public AnalysisRecord getAnalysisRecord(){
- return this.analysisRecord;
- }
-
- /**
- * Return the Command .
- */
- public Command getCommand(){
- return command;
- }
-
- /**
- * Return the list of Reference.
- */
- public List<Reference> getReferences(){
- return refs;
- }
-
- /**
- * Set the ProcessorPlan.
- */
- public void setPlan(ProcessorPlan planValue){
- plan = planValue;
- }
-
- /**
- * Set the plan description.
- */
- public void setAnalysisRecord(AnalysisRecord analysisRecord){
- this.analysisRecord = analysisRecord;
- }
-
- /**
- * Set the Command.
- */
- public void setCommand(Command commandValue){
- command = commandValue;
- }
-
- /**
- * Set the list of Reference.
- */
- public void setReferences(List<Reference> refsValue){
- refs = refsValue;
- }
-
- }
-
- //for testing purpose
- int getSpaceUsed() {
- return cache.size();
- }
- int getSpaceAllowed() {
- return maxSize;
- }
-
-}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -27,8 +27,7 @@
import java.util.LinkedList;
import java.util.List;
-import org.teiid.dqp.internal.process.PreparedPlanCache.CacheID;
-import org.teiid.dqp.internal.process.PreparedPlanCache.PreparedPlan;
+import org.teiid.dqp.internal.process.SessionAwareCache.CacheID;
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.query.ExpressionEvaluationException;
@@ -62,10 +61,10 @@
* Specific request for handling prepared statement calls.
*/
public class PreparedStatementRequest extends Request {
- private PreparedPlanCache prepPlanCache;
+ private SessionAwareCache<PreparedPlan> prepPlanCache;
private PreparedPlan prepPlan;
- public PreparedStatementRequest(PreparedPlanCache prepPlanCache) {
+ public PreparedStatementRequest(SessionAwareCache<PreparedPlan> prepPlanCache) {
this.prepPlanCache = prepPlanCache;
}
@@ -132,8 +131,8 @@
*/
protected void generatePlan() throws QueryPlannerException, QueryParserException, QueryResolverException, QueryValidatorException, MetaMatrixComponentException {
String sqlQuery = requestMsg.getCommands()[0];
- CacheID id = new PreparedPlanCache.CacheID(this.workContext, Request.createParseInfo(this.requestMsg), sqlQuery);
- prepPlan = prepPlanCache.getPreparedPlan(id);
+ CacheID id = new CacheID(this.workContext, Request.createParseInfo(this.requestMsg), sqlQuery);
+ prepPlan = prepPlanCache.get(id);
if (prepPlan == null) {
//if prepared plan does not exist, create one
prepPlan = new PreparedPlan();
@@ -149,7 +148,7 @@
// Defect 13751: Clone the plan in its current state (i.e. before processing) so that it can be used for later queries
prepPlan.setPlan(processPlan.clone());
prepPlan.setAnalysisRecord(analysisRecord);
- this.prepPlanCache.putPreparedPlan(id, this.context.isSessionFunctionEvaluated(), prepPlan);
+ this.prepPlanCache.put(id, this.context.isSessionFunctionEvaluated(), prepPlan);
}
} else {
LogManager.logTrace(LogConstants.CTX_DQP, new Object[] { "Query exist in cache: ", sqlQuery }); //$NON-NLS-1$
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -37,6 +37,7 @@
import javax.transaction.SystemException;
import org.teiid.connector.xa.api.TransactionContext;
+import org.teiid.dqp.internal.process.SessionAwareCache.CacheID;
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixException;
@@ -84,32 +85,24 @@
/*
* Obtained at construction time
*/
- protected final DQPCore dqpCore;
+ private final DQPCore dqpCore;
final RequestMessage requestMsg;
final RequestID requestID;
- protected Request request; //provides the processing plan, held on a temporary basis
- final private int processorTimeslice;
- //protected ResultSetCache rsCache;
- //protected CacheID cid;
- final private TransactionService transactionService;
- final DQPWorkContext dqpWorkContext;
+ private Request request; //provides the processing plan, held on a temporary basis
+ private final int processorTimeslice;
+ private CacheID cid;
+ private final TransactionService transactionService;
+ private final DQPWorkContext dqpWorkContext;
- //results request
- private ResultsReceiver<ResultsMessage> resultsReceiver;
- private int begin;
- private int end;
-
/*
* obtained during new
*/
private volatile QueryProcessor processor;
private BatchCollector collector;
- protected Command originalCommand;
+ private Command originalCommand;
private AnalysisRecord analysisRecord;
private TransactionContext transactionContext;
- protected TupleBuffer resultsBuffer;
- private TupleBatch savedBatch;
- private Collection schemas; // These are schemas associated with XML results
+ TupleBuffer resultsBuffer;
private boolean returnsUpdateCount;
/*
@@ -119,22 +112,21 @@
private Map<AtomicRequestID, DataTierTupleSource> connectorInfo = new ConcurrentHashMap<AtomicRequestID, DataTierTupleSource>(4);
// This exception contains details of all the atomic requests that failed when query is run in partial results mode.
private List<MetaMatrixException> warnings = new LinkedList<MetaMatrixException>();
-
private boolean doneProducingBatches;
- protected boolean isClosed;
+ private boolean isClosed;
private volatile boolean isCanceled;
private volatile boolean closeRequested;
-
+ //results request
+ private ResultsReceiver<ResultsMessage> resultsReceiver;
+ private int begin;
+ private int end;
+ private TupleBatch savedBatch;
private Map<Integer, LobWorkItem> lobStreams = Collections.synchronizedMap(new HashMap<Integer, LobWorkItem>(4));
public RequestWorkItem(DQPCore dqpCore, RequestMessage requestMsg, Request request, ResultsReceiver<ResultsMessage> receiver, RequestID requestID, DQPWorkContext workContext) {
this.requestMsg = requestMsg;
this.requestID = requestID;
this.processorTimeslice = dqpCore.getProcessorTimeSlice();
- /*this.rsCache = dqpCore.getRsCache();
- if (this.rsCache != null) {
- this.cid = this.rsCache.createCacheID(workContext, requestMsg.getCommandString(), requestMsg.getParameterValues());
- }*/
this.transactionService = dqpCore.getTransactionServiceDirect();
this.dqpCore = dqpCore;
this.request = request;
@@ -142,6 +134,10 @@
this.requestResults(1, requestMsg.getFetchSize(), receiver);
}
+ private boolean isForwardOnly() {
+ return this.cid == null && requestMsg.getCursorType() == ResultSet.TYPE_FORWARD_ONLY;
+ }
+
/**
* Ask for results.
* @param beginRow
@@ -230,19 +226,15 @@
}
protected void processMore() throws SystemException, BlockedException, MetaMatrixCoreException {
- this.processor.getContext().setTimeSliceEnd(System.currentTimeMillis() + this.processorTimeslice);
+ if (this.processor != null) {
+ this.processor.getContext().setTimeSliceEnd(System.currentTimeMillis() + this.processorTimeslice);
+ }
if (!doneProducingBatches) {
sendResultsIfNeeded(null);
collector.collectTuples();
doneProducingBatches = this.resultsBuffer.isFinal();
}
if (doneProducingBatches) {
- /*if(rsCache != null && requestMsg.useResultSetCache() && originalCommand.areResultsCachable()){
- boolean sessionScope = this.processor.getContext().isSessionFunctionEvaluated();
- CacheResults cr = new CacheResults();
- cr.setCommand(originalCommand);
- cr.setAnalysisRecord(analysisRecord);
- }*/
if (this.transactionState == TransactionState.ACTIVE) {
boolean endState = true;
/*
@@ -282,7 +274,9 @@
int rowcount = -1;
if (this.resultsBuffer != null) {
try {
- this.processor.closeProcessing();
+ if (this.processor != null) {
+ this.processor.closeProcessing();
+ }
} catch (MetaMatrixComponentException e) {
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
LogManager.logDetail(LogConstants.CTX_DQP, e, e.getMessage());
@@ -293,7 +287,18 @@
LogManager.logDetail(LogConstants.CTX_DQP, "Removing tuplesource for the request " + requestID); //$NON-NLS-1$
}
rowcount = resultsBuffer.getRowCount();
- resultsBuffer.remove();
+ if (this.processor != null) {
+ if (this.cid == null || !this.doneProducingBatches) {
+ resultsBuffer.remove();
+ } else {
+ boolean sessionScope = this.processor.getContext().isSessionFunctionEvaluated();
+ CachedResults cr = new CachedResults();
+ cr.setCommand(originalCommand);
+ cr.setAnalysisRecord(analysisRecord);
+ cr.setResults(this.resultsBuffer);
+ dqpCore.getRsCache().put(cid, sessionScope, cr);
+ }
+ }
for (DataTierTupleSource connectorRequest : this.connectorInfo.values()) {
try {
@@ -306,6 +311,7 @@
}
this.resultsBuffer = null;
+ this.processor = null;
}
if (this.transactionState == TransactionState.ACTIVE) {
@@ -338,8 +344,24 @@
}
protected void processNew() throws MetaMatrixProcessingException, MetaMatrixComponentException {
+ SessionAwareCache<CachedResults> rsCache = dqpCore.getRsCache();
+ CacheID cacheId = new CacheID(this.dqpWorkContext, Request.createParseInfo(requestMsg), requestMsg.getCommandString());
+ cacheId.setParameters(requestMsg.getParameterValues());
+ if (rsCache != null) {
+ CachedResults cr = rsCache.get(cacheId);
+ if (cr != null && (requestMsg.useResultSetCache() || cr.getCommand().isCache())) {
+ this.resultsBuffer = cr.getResults();
+ this.analysisRecord = cr.getAnalysisRecord();
+ this.originalCommand = cr.getCommand();
+ this.doneProducingBatches = true;
+ return;
+ }
+ }
request.processRequest();
originalCommand = request.userCommand;
+ if ((requestMsg.useResultSetCache() || originalCommand.isCache()) && rsCache != null && originalCommand.areResultsCachable()) {
+ this.cid = cacheId;
+ }
processor = request.processor;
collector = processor.createBatchCollector();
collector.setBatchHandler(new BatchHandler() {
@@ -348,11 +370,8 @@
}
});
resultsBuffer = collector.getTupleBuffer();
- if (requestMsg.getCursorType() == ResultSet.TYPE_FORWARD_ONLY) {
- resultsBuffer.setForwardOnly(true);
- }
+ resultsBuffer.setForwardOnly(isForwardOnly());
analysisRecord = request.analysisRecord;
- schemas = request.schemas;
transactionContext = request.transactionContext;
if (this.transactionContext != null && this.transactionContext.isInTransaction()) {
this.transactionState = TransactionState.ACTIVE;
@@ -361,6 +380,7 @@
if (option != null && option.getPlanOnly()) {
doneProducingBatches = true;
resultsBuffer.close();
+ this.cid = null;
}
if (analysisRecord.recordQueryPlan()) {
@@ -406,7 +426,7 @@
boolean last = false;
if (endRow == batch.getEndRow()) {
last = batch.getTerminationFlag();
- } else if (fromBuffer && requestMsg.getCursorType() == ResultSet.TYPE_FORWARD_ONLY) {
+ } else if (fromBuffer && isForwardOnly()) {
savedBatch = batch;
}
int firstOffset = beginRow - batch.getBeginRow();
@@ -416,26 +436,25 @@
batch = new TupleBatch(beginRow, rows);
batch.setTerminationFlag(last);
} else if (!fromBuffer){
- result = requestMsg.getCursorType() != ResultSet.TYPE_FORWARD_ONLY;
+ result = !isForwardOnly();
}
int finalRowCount = this.resultsBuffer.isFinal()?this.resultsBuffer.getRowCount():(batch.getTerminationFlag()?batch.getEndRow():-1);
- response = createResultsMessage(requestMsg, batch.getAllTuples(), this.processor.getProcessorPlan().getOutputElements(), analysisRecord);
+ response = createResultsMessage(requestMsg, batch.getAllTuples(), this.originalCommand.getProjectedSymbols(), analysisRecord);
response.setFirstRow(batch.getBeginRow());
response.setLastRow(batch.getEndRow());
response.setUpdateResult(this.returnsUpdateCount);
// set final row
response.setFinalRow(finalRowCount);
- // send any schemas associated with the results
- response.setSchemas(this.schemas);
-
// send any warnings with the response object
List<Throwable> responseWarnings = new ArrayList<Throwable>();
- List<Exception> currentWarnings = processor.getAndClearWarnings();
- if (currentWarnings != null) {
- responseWarnings.addAll(currentWarnings);
- }
+ if (this.processor != null) {
+ List<Exception> currentWarnings = processor.getAndClearWarnings();
+ if (currentWarnings != null) {
+ responseWarnings.addAll(currentWarnings);
+ }
+ }
synchronized (warnings) {
responseWarnings.addAll(this.warnings);
this.warnings.clear();
Added: trunk/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -0,0 +1,151 @@
+/*
+ * 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.dqp.internal.process;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import com.metamatrix.core.util.EquivalenceUtil;
+import com.metamatrix.core.util.HashCodeUtil;
+import com.metamatrix.core.util.LRUCache;
+import com.metamatrix.query.parser.ParseInfo;
+import com.metamatrix.vdb.runtime.VDBKey;
+
+/**
+ * This class is used to cache session aware objects
+ */
+public class SessionAwareCache<T> {
+ public static final int DEFAULT_MAX_SIZE_TOTAL = 250;
+
+ private Map<CacheID, T> cache;
+ private int maxSize;
+
+ private AtomicInteger cacheHit = new AtomicInteger();
+
+ SessionAwareCache(){
+ this(DEFAULT_MAX_SIZE_TOTAL);
+ }
+
+ SessionAwareCache (int maxSize ){
+ if(maxSize < 0){
+ maxSize = DEFAULT_MAX_SIZE_TOTAL;
+ }
+ this.maxSize = maxSize;
+ cache = Collections.synchronizedMap(new LRUCache<CacheID, T>(maxSize));
+ }
+
+ public T get(CacheID id){
+ id.setSessionId(id.originalSessionId);
+ T result = cache.get(id);
+ if (result == null) {
+ id.setSessionId(null);
+ result = cache.get(id);
+ }
+ if (result != null) {
+ cacheHit.getAndIncrement();
+ }
+ return result;
+ }
+
+ public int getCacheHitCount() {
+ return cacheHit.get();
+ }
+
+ /**
+ * Create PreparedPlan for the given clientConn and SQl query
+ */
+ public void put(CacheID id, boolean sessionSpecific, T t){
+ if (sessionSpecific) {
+ id.setSessionId(id.originalSessionId);
+ } else {
+ id.setSessionId(null);
+ }
+ this.cache.put(id, t);
+ }
+
+ /**
+ * Clear all the cached plans for all the clientConns
+ * @param clientConn ClientConnection
+ */
+ public void clearAll(){
+ cache.clear();
+ }
+
+ static class CacheID{
+ private String sql;
+ private VDBKey vdbInfo;
+ private ParseInfo pi;
+ private String sessionId;
+ private String originalSessionId;
+ private List<?> parameters;
+
+ CacheID(DQPWorkContext context, ParseInfo pi, String sql){
+ this.sql = sql;
+ this.vdbInfo = new VDBKey(context.getVdbName(), context.getVdbVersion());
+ this.pi = pi;
+ this.originalSessionId = context.getConnectionID();
+ }
+
+ private void setSessionId(String sessionId) {
+ this.sessionId = sessionId;
+ }
+
+ public void setParameters(List<?> parameters) {
+ this.parameters = parameters;
+ }
+
+ public boolean equals(Object obj){
+ if(obj == this) {
+ return true;
+ }
+ if(! (obj instanceof CacheID)) {
+ return false;
+ }
+ CacheID that = (CacheID)obj;
+ return this.pi.equals(that.pi) && this.vdbInfo.equals(that.vdbInfo) && this.sql.equals(that.sql)
+ && EquivalenceUtil.areEqual(this.sessionId, that.sessionId)
+ && EquivalenceUtil.areEqual(this.parameters, that.parameters);
+ }
+
+ public int hashCode() {
+ return HashCodeUtil.hashCode(0, vdbInfo, sql, pi, sessionId, parameters);
+ }
+
+ @Override
+ public String toString() {
+ return "Cache Entry<" + originalSessionId + "> params:" + parameters + " sql:" + sql; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ }
+ }
+
+ //for testing purpose
+ int getSpaceUsed() {
+ return cache.size();
+ }
+ int getSpaceAllowed() {
+ return maxSize;
+ }
+
+}
Property changes on: trunk/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj
===================================================================
--- trunk/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj 2010-01-27 04:57:41 UTC (rev 1782)
@@ -999,10 +999,15 @@
StoredProcedure storedProcedure = new StoredProcedure();
String procName = null;
Option option = null;
+ Token execToken = null;
}
{
(
- (<EXEC> | <EXECUTE>)
+ (
+ (execToken = <EXEC> { setQueryCacheOption(execToken, info); })
+ |
+ (execToken = <EXECUTE> { setQueryCacheOption(execToken, info); })
+ )
procName = id()
{
storedProcedure.setProcedureName(procName);
@@ -1415,9 +1420,13 @@
SelectSymbol symbol = null;
Select select = new Select();
info.aggregatesAllowed = true;
+ Token selectToken = null;
}
{
- <SELECT>
+ selectToken = <SELECT>
+ {
+ setQueryCacheOption(selectToken, info);
+ }
[<ALL> | (<DISTINCT> {isDistinct=true;})]
(<STAR>
{
Modified: trunk/engine/src/test/java/com/metamatrix/dqp/message/TestResultsMessage.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/dqp/message/TestResultsMessage.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/engine/src/test/java/com/metamatrix/dqp/message/TestResultsMessage.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -70,11 +70,6 @@
results.add(new BigInteger("300")); //$NON-NLS-1$
results.add(new BigInteger("400")); //$NON-NLS-1$
message.setResults(new List[] {results});
- List schemas = new ArrayList();
- schemas.add("schema1"); //$NON-NLS-1$
- schemas.add("schema2"); //$NON-NLS-1$
- schemas.add("schema3"); //$NON-NLS-1$
- message.setSchemas(schemas);
List warnings = new ArrayList();
warnings.add(new Exception("warning1")); //$NON-NLS-1$
warnings.add(new Exception("warning2")); //$NON-NLS-1$
@@ -134,13 +129,6 @@
assertEquals(new BigInteger("300"), copy.getResults()[0].get(2)); //$NON-NLS-1$
assertEquals(new BigInteger("400"), copy.getResults()[0].get(3)); //$NON-NLS-1$
- assertNotNull(copy.getSchemas());
- assertEquals(3, copy.getSchemas().size());
- // We know that the implementation creates a List
- assertTrue(copy.getSchemas().contains("schema1")); //$NON-NLS-1$
- assertTrue(copy.getSchemas().contains("schema2")); //$NON-NLS-1$
- assertTrue(copy.getSchemas().contains("schema3")); //$NON-NLS-1$
-
assertNotNull(copy.getWarnings());
assertEquals(2, copy.getWarnings().size());
assertEquals(Exception.class, copy.getWarnings().get(0).getClass());
Modified: trunk/engine/src/test/java/com/metamatrix/query/parser/TestOptionsAndHints.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/parser/TestOptionsAndHints.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/engine/src/test/java/com/metamatrix/query/parser/TestOptionsAndHints.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -22,10 +22,14 @@
package com.metamatrix.query.parser;
+import static org.junit.Assert.*;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import org.junit.Test;
+
import com.metamatrix.query.sql.lang.AbstractCompareCriteria;
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.CompareCriteria;
@@ -58,13 +62,10 @@
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.Reference;
-
-import junit.framework.TestCase;
-
-public class TestOptionsAndHints extends TestCase {
+public class TestOptionsAndHints {
/** Select a From db.g1 MAKENOTDEP, db.g2 MAKENOTDEP WHERE a = b */
- public void testOptionMakeNotDepInline4(){
+ @Test public void testOptionMakeNotDepInline4(){
GroupSymbol g1 = new GroupSymbol("db.g1"); //$NON-NLS-1$
GroupSymbol g2 = new GroupSymbol("c", "db.g2"); //$NON-NLS-1$ //$NON-NLS-2$
ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
@@ -93,7 +94,7 @@
}
/** Select a From db.g1 JOIN db.g2 MAKEDEP ON a = b */
- public void testOptionMakeDepInline1(){
+ @Test public void testOptionMakeDepInline1(){
GroupSymbol g1 = new GroupSymbol("db.g1"); //$NON-NLS-1$
GroupSymbol g2 = new GroupSymbol("db.g2"); //$NON-NLS-1$
ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
@@ -118,7 +119,7 @@
}
/** Select a From db.g1 MAKEDEP JOIN db.g2 ON a = b */
- public void testOptionMakeDepInline2(){
+ @Test public void testOptionMakeDepInline2(){
GroupSymbol g1 = new GroupSymbol("db.g1"); //$NON-NLS-1$
GroupSymbol g2 = new GroupSymbol("db.g2"); //$NON-NLS-1$
ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
@@ -143,7 +144,7 @@
}
/** Select a From (db.g1 MAKEDEP JOIN db.g2 ON a = b) LEFT OUTER JOIN db.g3 MAKEDEP ON a = c */
- public void testOptionMakeDepInline3(){
+ @Test public void testOptionMakeDepInline3(){
GroupSymbol g1 = new GroupSymbol("db.g1"); //$NON-NLS-1$
GroupSymbol g2 = new GroupSymbol("db.g2"); //$NON-NLS-1$
GroupSymbol g3 = new GroupSymbol("db.g3"); //$NON-NLS-1$
@@ -174,7 +175,7 @@
}
/** Select a From db.g1 MAKEDEP, db.g2 MAKEDEP WHERE a = b */
- public void testOptionMakeDepInline4(){
+ @Test public void testOptionMakeDepInline4(){
GroupSymbol g1 = new GroupSymbol("db.g1"); //$NON-NLS-1$
GroupSymbol g2 = new GroupSymbol("c", "db.g2"); //$NON-NLS-1$ //$NON-NLS-2$
ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
@@ -202,7 +203,7 @@
query);
}
- public void testOptionMakedepBankOfAmerica() throws Exception {
+ @Test public void testOptionMakedepBankOfAmerica() throws Exception {
String sql = "SELECT A.alert_id " + //$NON-NLS-1$
"FROM (FSK_ALERT AS A MAKEDEP INNER JOIN Core.FSC_PARTY_DIM AS C ON A.primary_entity_key = C.PARTY_KEY) " +//$NON-NLS-1$
"LEFT OUTER JOIN FSK_SCENARIO AS S ON A.scenario_id = S.scenario_id " +//$NON-NLS-1$
@@ -213,7 +214,7 @@
}
/** Select a From db.g1 JOIN db.g2 MAKENOTDEP ON a = b */
- public void testOptionMakeNotDepInline1(){
+ @Test public void testOptionMakeNotDepInline1(){
GroupSymbol g1 = new GroupSymbol("db.g1"); //$NON-NLS-1$
GroupSymbol g2 = new GroupSymbol("db.g2"); //$NON-NLS-1$
ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
@@ -238,7 +239,7 @@
}
/** Select a From db.g1 MAKENOTDEP JOIN db.g2 ON a = b */
- public void testOptionMakeNotDepInline2(){
+ @Test public void testOptionMakeNotDepInline2(){
GroupSymbol g1 = new GroupSymbol("db.g1"); //$NON-NLS-1$
GroupSymbol g2 = new GroupSymbol("db.g2"); //$NON-NLS-1$
ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
@@ -263,7 +264,7 @@
}
/** Select a From (db.g1 MAKENOTDEP JOIN db.g2 ON a = b) LEFT OUTER JOIN db.g3 MAKENOTDEP ON a = c */
- public void testOptionMakeNotDepInline3(){
+ @Test public void testOptionMakeNotDepInline3(){
GroupSymbol g1 = new GroupSymbol("db.g1"); //$NON-NLS-1$
GroupSymbol g2 = new GroupSymbol("db.g2"); //$NON-NLS-1$
GroupSymbol g3 = new GroupSymbol("db.g3"); //$NON-NLS-1$
@@ -293,7 +294,7 @@
query);
}
- public void testDepOptions2() {
+ @Test public void testDepOptions2() {
GroupSymbol a = new GroupSymbol("a"); //$NON-NLS-1$
GroupSymbol b = new GroupSymbol("b"); //$NON-NLS-1$
ElementSymbol x = new ElementSymbol("a.x", true); //$NON-NLS-1$
@@ -312,7 +313,7 @@
query);
}
- public void testOptionNoCache1(){
+ @Test public void testOptionNoCache1(){
GroupSymbol g = new GroupSymbol("db.g"); //$NON-NLS-1$
From from = new From();
from.addGroup(g);
@@ -334,7 +335,7 @@
query);
}
- public void testOptionNoCache2(){
+ @Test public void testOptionNoCache2(){
GroupSymbol g = new GroupSymbol("db.g"); //$NON-NLS-1$
From from = new From();
from.addGroup(g);
@@ -359,7 +360,7 @@
}
// related to defect 14423
- public void testOptionNoCache3(){
+ @Test public void testOptionNoCache3(){
GroupSymbol g = new GroupSymbol("db.g"); //$NON-NLS-1$
From from = new From();
from.addGroup(g);
@@ -381,11 +382,11 @@
}
/** SELECT a from g OPTION xyx */
- public void testFailsIllegalOption(){
+ @Test public void testFailsIllegalOption(){
TestParser.helpException("SELECT a from g OPTION xyx"); //$NON-NLS-1$
}
- public void testInsertWithOption() {
+ @Test public void testInsertWithOption() {
Insert insert = new Insert();
insert.setGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
List vars = new ArrayList();
@@ -402,7 +403,7 @@
insert);
}
- public void testDeleteWithOption() {
+ @Test public void testDeleteWithOption() {
Delete delete = new Delete();
delete.setGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
Option option = new Option();
@@ -413,7 +414,7 @@
delete);
}
- public void testUpdateWithOption() {
+ @Test public void testUpdateWithOption() {
Update update = new Update();
update.setGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
update.addChange(new ElementSymbol("a"), new Reference(0));
@@ -426,7 +427,7 @@
update);
}
- public void testOptionalFromClause1() {
+ @Test public void testOptionalFromClause1() {
String sql = "SELECT * FROM /* optional */ t1, t2"; //$NON-NLS-1$
Query query = new Query();
@@ -444,7 +445,7 @@
TestParser.helpTest(sql, "SELECT * FROM /* optional */ t1, t2", query); //$NON-NLS-1$
}
- public void testOptionalFromClause1_1() {
+ @Test public void testOptionalFromClause1_1() {
String sql = "SELECT * FROM /* optional*/ t1, t2"; //$NON-NLS-1$
Query query = new Query();
@@ -462,7 +463,7 @@
TestParser.helpTest(sql, "SELECT * FROM /* optional */ t1, t2", query); //$NON-NLS-1$
}
- public void testOptionalFromClause1_2() {
+ @Test public void testOptionalFromClause1_2() {
String sql = "SELECT * FROM /*optional */ t1, t2"; //$NON-NLS-1$
Query query = new Query();
@@ -480,7 +481,7 @@
TestParser.helpTest(sql, "SELECT * FROM /* optional */ t1, t2", query); //$NON-NLS-1$
}
- public void testOptionalFromClause1_3() {
+ @Test public void testOptionalFromClause1_3() {
String sql = "SELECT * FROM /* optional */ t1, t2"; //$NON-NLS-1$
Query query = new Query();
@@ -498,7 +499,7 @@
TestParser.helpTest(sql, "SELECT * FROM /* optional */ t1, t2", query); //$NON-NLS-1$
}
- public void testOptionalFromClause1_4() {
+ @Test public void testOptionalFromClause1_4() {
String sql = "SELECT * /* optional */ FROM /* OptiOnal */ t1, t2"; //$NON-NLS-1$
Query query = new Query();
@@ -516,7 +517,7 @@
TestParser.helpTest(sql, "SELECT * FROM /* optional */ t1, t2", query); //$NON-NLS-1$
}
- public void testOptionalFromClause1_5() {
+ @Test public void testOptionalFromClause1_5() {
String sql = "SELECT * FROM /* OptiOnal */ t1, t2"; //$NON-NLS-1$
Query query = new Query();
@@ -534,7 +535,7 @@
TestParser.helpTest(sql, "SELECT * FROM /* optional */ t1, t2", query); //$NON-NLS-1$
}
- public void testOptionalFromClause2() {
+ @Test public void testOptionalFromClause2() {
String sql = "SELECT * FROM t1, /* optional */ t2"; //$NON-NLS-1$
Query query = new Query();
@@ -552,7 +553,7 @@
TestParser.helpTest(sql, "SELECT * FROM t1, /* optional */ t2", query); //$NON-NLS-1$
}
- public void testOptionalFromClause3() {
+ @Test public void testOptionalFromClause3() {
String sql = "SELECT * FROM /* optional */ t1 AS a, t2"; //$NON-NLS-1$
Query query = new Query();
@@ -570,7 +571,7 @@
TestParser.helpTest(sql, "SELECT * FROM /* optional */ t1 AS a, t2", query); //$NON-NLS-1$
}
- public void testOptionalFromClause4() {
+ @Test public void testOptionalFromClause4() {
String sql = "SELECT * FROM t1, /* optional */ t2 as a"; //$NON-NLS-1$
Query query = new Query();
@@ -588,7 +589,7 @@
TestParser.helpTest(sql, "SELECT * FROM t1, /* optional */ t2 AS a", query); //$NON-NLS-1$
}
- public void testOptionalFromClause5() {
+ @Test public void testOptionalFromClause5() {
String sql = "SELECT * FROM t1, /* optional */ (select * from t1, t2) as x"; //$NON-NLS-1$
Query query = new Query();
@@ -615,7 +616,7 @@
TestParser.helpTest(sql, "SELECT * FROM t1, /* optional */ (SELECT * FROM t1, t2) AS x", query); //$NON-NLS-1$
}
- public void testOptionalFromClause6() {
+ @Test public void testOptionalFromClause6() {
String sql = "SELECT * FROM t1 INNER JOIN /* optional */ (select a from t1, t2) AS x ON t1.a=x.a"; //$NON-NLS-1$
Query query = new Query();
@@ -648,7 +649,7 @@
TestParser.helpTest(sql, "SELECT * FROM t1 INNER JOIN /* optional */ (SELECT a FROM t1, t2) AS x ON t1.a = x.a", query); //$NON-NLS-1$
}
- public void testOptionalFromClause7() {
+ @Test public void testOptionalFromClause7() {
String sql = "SELECT b FROM t1, /* optional */ (t2 INNER JOIN t3 ON t2.a = t3.a)"; //$NON-NLS-1$
Query query = new Query();
@@ -677,7 +678,7 @@
TestParser.helpTest(sql, "SELECT b FROM t1, /* optional */ (t2 INNER JOIN t3 ON t2.a = t3.a)", query); //$NON-NLS-1$
}
- public void testOptionalFromClause8() {
+ @Test public void testOptionalFromClause8() {
String sql = "SELECT b FROM t1, /* optional */ (/* optional */ (SELECT * FROM t1, t2) AS x INNER JOIN t3 ON x.a = t3.a)"; //$NON-NLS-1$
Query query = new Query();
@@ -715,7 +716,7 @@
TestParser.helpTest(sql, "SELECT b FROM t1, /* optional */ (/* optional */ (SELECT * FROM t1, t2) AS x INNER JOIN t3 ON x.a = t3.a)", query); //$NON-NLS-1$
}
- public void testOptionalFromClause9() {
+ @Test public void testOptionalFromClause9() {
String 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"; //$NON-NLS-1$
Query query = new Query();
@@ -749,7 +750,7 @@
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$
}
- public void testOptionalFromClause10(){
+ @Test public void testOptionalFromClause10(){
//declare var1
ElementSymbol var1 = new ElementSymbol("var1"); //$NON-NLS-1$
String shortType = new String("short"); //$NON-NLS-1$
@@ -835,7 +836,7 @@
"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$
}
- public void testStoredQueryWithOption(){
+ @Test public void testStoredQueryWithOption(){
StoredProcedure storedQuery = new StoredProcedure();
storedQuery.setProcedureName("proc1"); //$NON-NLS-1$
Option option = new Option();
@@ -845,7 +846,7 @@
}
/** Select a From db.g Option SHOWPLAN */
- public void testOptionShowPlan(){
+ @Test public void testOptionShowPlan(){
GroupSymbol g = new GroupSymbol("db.g"); //$NON-NLS-1$
From from = new From();
from.addGroup(g);
@@ -867,7 +868,7 @@
}
/** Select a From db.g Option PLANONLY */
- public void testOptionPlanOnly(){
+ @Test public void testOptionPlanOnly(){
GroupSymbol g = new GroupSymbol("db.g"); //$NON-NLS-1$
From from = new From();
from.addGroup(g);
@@ -889,7 +890,7 @@
}
/** Select a From db.g Option makedep a.b.c */
- public void testOptionMakeDependent1(){
+ @Test public void testOptionMakeDependent1(){
GroupSymbol g = new GroupSymbol("db.g"); //$NON-NLS-1$
From from = new From();
from.addGroup(g);
@@ -911,7 +912,7 @@
}
/** Select a From db.g Option makedep a.b.c, d.e.f showplan */
- public void testOptionMakeDependent2(){
+ @Test public void testOptionMakeDependent2(){
GroupSymbol g = new GroupSymbol("db.g"); //$NON-NLS-1$
From from = new From();
from.addGroup(g);
@@ -935,7 +936,7 @@
}
/** Select a From db.g Option makedep a.b.c, d.e.f, x.y.z */
- public void testOptionMakeDependent3(){
+ @Test public void testOptionMakeDependent3(){
GroupSymbol g = new GroupSymbol("db.g"); //$NON-NLS-1$
From from = new From();
from.addGroup(g);
@@ -959,7 +960,7 @@
}
/** Select a From db.g Option makenotdep a.b.c */
- public void testOptionMakeNotDependent1(){
+ @Test public void testOptionMakeNotDependent1(){
GroupSymbol g = new GroupSymbol("db.g"); //$NON-NLS-1$
From from = new From();
from.addGroup(g);
@@ -981,7 +982,7 @@
}
/** Select a From db.g Option makenotdep a.b.c, d.e.f showplan */
- public void testOptionMakeNotDependent2(){
+ @Test public void testOptionMakeNotDependent2(){
GroupSymbol g = new GroupSymbol("db.g"); //$NON-NLS-1$
From from = new From();
from.addGroup(g);
@@ -1005,7 +1006,7 @@
}
/** Select a From db.g Option makenotdep a.b.c, d.e.f, x.y.z */
- public void testOptionMakeNotDependent3(){
+ @Test public void testOptionMakeNotDependent3(){
GroupSymbol g = new GroupSymbol("db.g"); //$NON-NLS-1$
From from = new From();
from.addGroup(g);
@@ -1028,7 +1029,7 @@
query);
}
- public void testDepOptions1() {
+ @Test public void testDepOptions1() {
GroupSymbol a = new GroupSymbol("a"); //$NON-NLS-1$
GroupSymbol b = new GroupSymbol("b"); //$NON-NLS-1$
ElementSymbol x = new ElementSymbol("a.x", true); //$NON-NLS-1$
@@ -1049,7 +1050,7 @@
query);
}
- public void testOptionMakeDepInline5(){
+ @Test public void testOptionMakeDepInline5(){
GroupSymbol g1 = new GroupSymbol("db.g1"); //$NON-NLS-1$
GroupSymbol g2 = new GroupSymbol("db.g2"); //$NON-NLS-1$
GroupSymbol g3 = new GroupSymbol("db.g3"); //$NON-NLS-1$
@@ -1081,4 +1082,30 @@
TestParser.helpTest(query.toString(), query.toString(), query);
}
+ @Test public void testCache() {
+ String sql = "/* cache */ SELECT * FROM t1"; //$NON-NLS-1$
+
+ Query query = new Query();
+ Select select = new Select();
+ select.addSymbol(new AllSymbol());
+ query.setSelect(select);
+ From from = new From();
+ UnaryFromClause ufc = new UnaryFromClause();
+ from.addClause(ufc);
+ ufc.setGroup(new GroupSymbol("t1")); //$NON-NLS-1$
+ query.setFrom(from);
+ query.setCache(true);
+ TestParser.helpTest(sql, "/* cache */ SELECT * FROM t1", query); //$NON-NLS-1$
+ }
+
+ @Test public void testCache1() {
+ String sql = "/* cache */ execute foo()"; //$NON-NLS-1$
+
+ StoredProcedure sp = new StoredProcedure();
+ sp.setCache(true);
+ sp.setProcedureName("foo"); //$NON-NLS-1$
+
+ TestParser.helpTest(sql, "/* cache */ EXEC foo()", sp); //$NON-NLS-1$
+ }
+
}
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCoreRequestHandling.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCoreRequestHandling.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCoreRequestHandling.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -152,7 +152,7 @@
RequestMessage r0 = new RequestMessage("foo"); //$NON-NLS-1$
RequestID requestID = new RequestID(SESSION_STRING, 1);
RequestWorkItem workItem = addRequest(rm, r0, requestID, null, null);
- AtomicRequestMessage atomicReq = new AtomicRequestMessage(workItem.requestMsg, workItem.dqpWorkContext, 1);
+ AtomicRequestMessage atomicReq = new AtomicRequestMessage(workItem.requestMsg, workItem.getDqpWorkContext(), 1);
DataTierTupleSource info = new DataTierTupleSource(null, atomicReq, null, new ConnectorID("connID"), workItem); //$NON-NLS-1$
workItem.addConnectorRequest(atomicReq.getAtomicRequestID(), info);
@@ -166,7 +166,7 @@
RequestMessage r0 = new RequestMessage("foo"); //$NON-NLS-1$
RequestID requestID = new RequestID(SESSION_STRING, 1);
RequestWorkItem workItem = addRequest(rm, r0, requestID, null, null);
- AtomicRequestMessage atomicReq = new AtomicRequestMessage(workItem.requestMsg, workItem.dqpWorkContext, 1);
+ AtomicRequestMessage atomicReq = new AtomicRequestMessage(workItem.requestMsg, workItem.getDqpWorkContext(), 1);
DataTierTupleSource info = new DataTierTupleSource(null, atomicReq, null, new ConnectorID("connID"), workItem); //$NON-NLS-1$
workItem.addConnectorRequest(atomicReq.getAtomicRequestID(), info);
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -66,7 +66,7 @@
// Create components
MetadataService mdSvc = Mockito.mock(MetadataService.class);
Mockito.stub(mdSvc.lookupMetadata(Mockito.anyString(), Mockito.anyString())).toReturn(metadata);
- PreparedPlanCache prepPlanCache = new PreparedPlanCache();
+ SessionAwareCache<PreparedPlan> prepPlanCache = new SessionAwareCache<PreparedPlan>();
DQPCore requestMgr = new DQPCore();
DQPWorkContext workContext = new DQPWorkContext();
@@ -133,7 +133,7 @@
// Create components
MetadataService mdSvc = Mockito.mock(MetadataService.class);
Mockito.stub(mdSvc.lookupMetadata(Mockito.anyString(), Mockito.anyString())).toReturn(metadata);
- PreparedPlanCache prepPlanCache = new PreparedPlanCache();
+ SessionAwareCache<PreparedPlan> prepPlanCache = new SessionAwareCache<PreparedPlan>();
// Initialize components
ApplicationEnvironment env = new ApplicationEnvironment();
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedPlanCache.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedPlanCache.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedPlanCache.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -30,8 +30,7 @@
import org.junit.BeforeClass;
import org.junit.Test;
-import org.teiid.dqp.internal.process.PreparedPlanCache.CacheID;
-import org.teiid.dqp.internal.process.PreparedPlanCache.PreparedPlan;
+import org.teiid.dqp.internal.process.SessionAwareCache.CacheID;
import com.metamatrix.api.exception.query.QueryParserException;
import com.metamatrix.query.analysis.AnalysisRecord;
@@ -57,25 +56,25 @@
//====Tests====//
@Test public void testPutPreparedPlan(){
- PreparedPlanCache cache = new PreparedPlanCache();
+ SessionAwareCache<PreparedPlan> cache = new SessionAwareCache<PreparedPlan>();
CacheID id = new CacheID(token, pi, EXAMPLE_QUERY + 1);
//No PreparedPlan at the begining
- assertNull(cache.getPreparedPlan(id));
+ assertNull(cache.get(id));
//create one
- cache.putPreparedPlan(id, true, new PreparedPlan());
+ cache.put(id, true, new PreparedPlan());
//should have one now
- assertNotNull("Unable to get prepared plan from cache", cache.getPreparedPlan(id)); //$NON-NLS-1$
+ assertNotNull("Unable to get prepared plan from cache", cache.get(id)); //$NON-NLS-1$
}
- @Test public void testGetPreparedPlan(){
- PreparedPlanCache cache = new PreparedPlanCache();
+ @Test public void testget(){
+ SessionAwareCache<PreparedPlan> cache = new SessionAwareCache<PreparedPlan>();
helpPutPreparedPlans(cache, token, 0, 10);
helpPutPreparedPlans(cache, token2, 0, 15);
//read an entry for session2 (token2)
- PreparedPlan pPlan = cache.getPreparedPlan(new CacheID(token2, pi, EXAMPLE_QUERY + 12));
+ PreparedPlan pPlan = cache.get(new CacheID(token2, pi, EXAMPLE_QUERY + 12));
assertNotNull("Unable to get prepared plan from cache", pPlan); //$NON-NLS-1$
assertEquals("Error getting plan from cache", new RelationalPlan(new ProjectNode(12)).toString(), pPlan.getPlan().toString()); //$NON-NLS-1$
assertEquals("Error getting command from cache", EXAMPLE_QUERY + 12, pPlan.getCommand().toString()); //$NON-NLS-1$
@@ -84,30 +83,30 @@
}
@Test public void testClearAll(){
- PreparedPlanCache cache = new PreparedPlanCache();
+ SessionAwareCache<PreparedPlan> cache = new SessionAwareCache<PreparedPlan>();
//create one for each session token
helpPutPreparedPlans(cache, token, 1, 1);
helpPutPreparedPlans(cache, token2, 1, 1);
//should have one
- assertNotNull("Unable to get prepared plan from cache for token", cache.getPreparedPlan(new CacheID(token, pi, EXAMPLE_QUERY + 1))); //$NON-NLS-1$
+ assertNotNull("Unable to get prepared plan from cache for token", cache.get(new CacheID(token, pi, EXAMPLE_QUERY + 1))); //$NON-NLS-1$
cache.clearAll();
//should not exist for token
- assertNull("Failed remove from cache", cache.getPreparedPlan(new CacheID(token, pi, EXAMPLE_QUERY + 1))); //$NON-NLS-1$
+ assertNull("Failed remove from cache", cache.get(new CacheID(token, pi, EXAMPLE_QUERY + 1))); //$NON-NLS-1$
//should not exist for token2
- assertNull("Unable to get prepared plan from cache for token2", cache.getPreparedPlan(new CacheID(token2, pi, EXAMPLE_QUERY + 1))); //$NON-NLS-1$
+ assertNull("Unable to get prepared plan from cache for token2", cache.get(new CacheID(token2, pi, EXAMPLE_QUERY + 1))); //$NON-NLS-1$
}
@Test public void testMaxSize(){
- PreparedPlanCache cache = new PreparedPlanCache(100);
+ SessionAwareCache<PreparedPlan> cache = new SessionAwareCache<PreparedPlan>(100);
helpPutPreparedPlans(cache, token, 0, 101);
//the first one should be gone because the max size is 100
- assertNull(cache.getPreparedPlan(new CacheID(token, pi, EXAMPLE_QUERY + 0)));
+ assertNull(cache.get(new CacheID(token, pi, EXAMPLE_QUERY + 0)));
- assertNotNull(cache.getPreparedPlan(new CacheID(token, pi, EXAMPLE_QUERY + 12)));
+ assertNotNull(cache.get(new CacheID(token, pi, EXAMPLE_QUERY + 12)));
helpPutPreparedPlans(cache, token, 102, 50);
//"sql12" should still be there based on lru policy
- assertNotNull(cache.getPreparedPlan(new CacheID(token, pi, EXAMPLE_QUERY + 12)));
+ assertNotNull(cache.get(new CacheID(token, pi, EXAMPLE_QUERY + 12)));
helpPutPreparedPlans(cache, token2, 0, 121);
helpPutPreparedPlans(cache, token, 0, 50);
@@ -116,31 +115,31 @@
@Test public void testZeroSizeCache() {
// Create with 0 size cache
- PreparedPlanCache cache = new PreparedPlanCache(0);
+ SessionAwareCache<PreparedPlan> cache = new SessionAwareCache<PreparedPlan>(0);
assertEquals(0, cache.getSpaceAllowed());
// Add 1 plan and verify it is not in the cache
helpPutPreparedPlans(cache, token, 0, 1);
- assertNull(cache.getPreparedPlan(new CacheID(token, pi, EXAMPLE_QUERY + 0)));
+ assertNull(cache.get(new CacheID(token, pi, EXAMPLE_QUERY + 0)));
assertEquals(0, cache.getSpaceUsed());
// Add another plan and verify it is not in the cache
helpPutPreparedPlans(cache, token, 1, 1);
- assertNull(cache.getPreparedPlan(new CacheID(token, pi, EXAMPLE_QUERY + 1)));
+ assertNull(cache.get(new CacheID(token, pi, EXAMPLE_QUERY + 1)));
assertEquals(0, cache.getSpaceUsed());
}
// set init size to negative number, which should default to 100 (default)
@Test public void testNegativeSizeCacheUsesDefault() {
- PreparedPlanCache negativeSizedCache = new PreparedPlanCache(-1000);
- PreparedPlanCache defaultSizedCache = new PreparedPlanCache();
+ SessionAwareCache<PreparedPlan> negativeSizedCache = new SessionAwareCache<PreparedPlan>(-1000);
+ SessionAwareCache<PreparedPlan> defaultSizedCache = new SessionAwareCache<PreparedPlan>();
assertEquals(defaultSizedCache.getSpaceAllowed(), negativeSizedCache.getSpaceAllowed());
- assertEquals(PreparedPlanCache.DEFAULT_MAX_SIZE_TOTAL, negativeSizedCache.getSpaceAllowed());
+ assertEquals(SessionAwareCache.DEFAULT_MAX_SIZE_TOTAL, negativeSizedCache.getSpaceAllowed());
}
//====Help methods====//
- private void helpPutPreparedPlans(PreparedPlanCache cache, DQPWorkContext session, int start, int count){
+ private void helpPutPreparedPlans(SessionAwareCache<PreparedPlan> cache, DQPWorkContext session, int start, int count){
for(int i=0; i<count; i++){
Command dummy;
try {
@@ -151,7 +150,7 @@
CacheID id = new CacheID(session, pi, dummy.toString());
PreparedPlan pPlan = new PreparedPlan();
- cache.putPreparedPlan(id, true, pPlan);
+ cache.put(id, true, pPlan);
pPlan.setCommand(dummy);
pPlan.setPlan(new RelationalPlan(new ProjectNode(i)));
Map props = new HashMap();
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -60,30 +60,15 @@
private static boolean DEBUG = false;
- static class TestablePreparedPlanCache extends PreparedPlanCache {
-
- int hitCount;
-
- @Override
- public PreparedPlan getPreparedPlan(CacheID id) {
- PreparedPlan result = super.getPreparedPlan(id);
- if (result != null) {
- hitCount++;
- }
- return result;
- }
-
- }
-
static void helpTestProcessing(String preparedSql, List values, List[] expected, ProcessorDataManager dataManager, QueryMetadataInterface metadata, boolean callableStatement) throws Exception {
helpTestProcessing(preparedSql, values, expected, dataManager, metadata, callableStatement, false);
}
static void helpTestProcessing(String preparedSql, List values, List[] expected, ProcessorDataManager dataManager, QueryMetadataInterface metadata, boolean callableStatement, boolean isSessionSpecific) throws Exception {
- helpTestProcessing(preparedSql, values, expected, dataManager, (CapabilitiesFinder)null, metadata, (TestablePreparedPlanCache)null, callableStatement, isSessionSpecific, /* isAlreadyCached */false);
+ helpTestProcessing(preparedSql, values, expected, dataManager, (CapabilitiesFinder)null, metadata, null, callableStatement, isSessionSpecific, /* isAlreadyCached */false);
}
- static public void helpTestProcessing(String preparedSql, List values, List[] expected, ProcessorDataManager dataManager, CapabilitiesFinder capFinder, QueryMetadataInterface metadata, TestablePreparedPlanCache prepPlanCache, boolean callableStatement, boolean isSessionSpecific, boolean isAlreadyCached) throws Exception {
+ static public void helpTestProcessing(String preparedSql, List values, List[] expected, ProcessorDataManager dataManager, CapabilitiesFinder capFinder, QueryMetadataInterface metadata, SessionAwareCache<PreparedPlan> prepPlanCache, boolean callableStatement, boolean isSessionSpecific, boolean isAlreadyCached) throws Exception {
if ( dataManager == null ) {
// Construct data manager with data
dataManager = new FakeDataManager();
@@ -95,7 +80,7 @@
}
if ( prepPlanCache == null ) {
- prepPlanCache = new TestablePreparedPlanCache();
+ prepPlanCache = new SessionAwareCache<PreparedPlan>();
}
// expected cache hit count
@@ -107,9 +92,9 @@
* get the plan twice. Otherwise, we want it to be 1.
*/
if ( isAlreadyCached ) {
- exHitCount = prepPlanCache.hitCount + 2;
+ exHitCount = prepPlanCache.getCacheHitCount() + 2;
} else {
- exHitCount = prepPlanCache.hitCount + 1;
+ exHitCount = prepPlanCache.getCacheHitCount() + 1;
}
//Create plan or used cache plan if isPlanCached
@@ -122,7 +107,7 @@
plan = TestPreparedStatement.helpGetProcessorPlan(preparedSql, values, capFinder, metadata, prepPlanCache, SESSION_ID, callableStatement, false);
//make sure the plan is only created once
- assertEquals("should reuse the plan", exHitCount, prepPlanCache.hitCount); //$NON-NLS-1$
+ assertEquals("should reuse the plan", exHitCount, prepPlanCache.getCacheHitCount()); //$NON-NLS-1$
// If we are using FakeDataManager, stop command recording to prevent
// duplicate commands
@@ -150,7 +135,7 @@
* created and the hit count will be unchanged.
*/
if ( !isSessionSpecific ) exHitCount++;
- assertEquals(exHitCount, prepPlanCache.hitCount);
+ assertEquals(exHitCount, prepPlanCache.getCacheHitCount());
}
@Test public void testWhere() throws Exception {
@@ -212,12 +197,12 @@
List values = Arrays.asList(0);
- PreparedStatementRequest plan = helpGetProcessorPlan(preparedSql, values, capFinder, metadata, new PreparedPlanCache(), SESSION_ID, false, false);
+ PreparedStatementRequest plan = helpGetProcessorPlan(preparedSql, values, capFinder, metadata, new SessionAwareCache<PreparedPlan>(), SESSION_ID, false, false);
TestOptimizer.checkNodeTypes(plan.processPlan, TestOptimizer.FULL_PUSHDOWN);
}
- static public PreparedStatementRequest helpGetProcessorPlan(String preparedSql, List values, PreparedPlanCache prepPlanCache)
+ static public PreparedStatementRequest helpGetProcessorPlan(String preparedSql, List values, SessionAwareCache<PreparedPlan> prepPlanCache)
throws MetaMatrixComponentException, QueryParserException,
QueryResolverException, QueryValidatorException,
QueryPlannerException {
@@ -225,7 +210,7 @@
}
static public PreparedStatementRequest helpGetProcessorPlan(String preparedSql, List values,
- PreparedPlanCache prepPlanCache, int conn)
+ SessionAwareCache<PreparedPlan> prepPlanCache, int conn)
throws MetaMatrixComponentException, QueryParserException,
QueryResolverException, QueryValidatorException,
QueryPlannerException {
@@ -235,7 +220,7 @@
}
static PreparedStatementRequest helpGetProcessorPlan(String preparedSql, List values,
- CapabilitiesFinder capFinder, QueryMetadataInterface metadata, PreparedPlanCache prepPlanCache, int conn, boolean callableStatement, boolean limitResults)
+ CapabilitiesFinder capFinder, QueryMetadataInterface metadata, SessionAwareCache<PreparedPlan> prepPlanCache, int conn, boolean callableStatement, boolean limitResults)
throws MetaMatrixComponentException, QueryParserException,
QueryResolverException, QueryValidatorException,
QueryPlannerException {
@@ -280,7 +265,7 @@
values.add("a"); //$NON-NLS-1$
//Create plan
- helpGetProcessorPlan(preparedSql, values, new PreparedPlanCache());
+ helpGetProcessorPlan(preparedSql, values, new SessionAwareCache<PreparedPlan>());
}
/** SELECT pm1.g1.e1 FROM pm1.g1 WHERE pm1.g1.e2 IN (SELECT pm1.g2.e2 FROM pm1.g2 WHERE pm1.g2.e1 = ?)*/
@@ -291,7 +276,7 @@
List values = Arrays.asList("a"); //$NON-NLS-1$
//Create plan
- helpGetProcessorPlan(preparedSql, values, new PreparedPlanCache());
+ helpGetProcessorPlan(preparedSql, values, new SessionAwareCache<PreparedPlan>());
}
/** SELECT pm1.g1.e1 FROM pm1.g1 WHERE pm1.g1.e1 = ? AND pm1.g1.e2 IN (SELECT pm1.g2.e2 FROM pm1.g2 WHERE pm1.g2.e1 = ?) */
@@ -302,7 +287,7 @@
List values = Arrays.asList("d", "c"); //$NON-NLS-1$ //$NON-NLS-2$
//Create plan
- helpGetProcessorPlan(preparedSql, values, new PreparedPlanCache());
+ helpGetProcessorPlan(preparedSql, values, new SessionAwareCache<PreparedPlan>());
}
/** SELECT X.e1 FROM (SELECT pm1.g2.e1 FROM pm1.g2 WHERE pm1.g2.e1 = ?) as X */
@@ -315,13 +300,13 @@
values.add("d"); //$NON-NLS-1$
//Create plan
- helpGetProcessorPlan(preparedSql, values, new PreparedPlanCache());
+ helpGetProcessorPlan(preparedSql, values, new SessionAwareCache<PreparedPlan>());
}
@Test public void testValidateWrongValues() throws Exception {
// Create query
String preparedSql = "SELECT pm1.g1.e1, e2, pm1.g1.e3 as a, e4 as b FROM pm1.g1 WHERE pm1.g1.e2=?"; //$NON-NLS-1$
- TestablePreparedPlanCache prepCache = new TestablePreparedPlanCache();
+ SessionAwareCache<PreparedPlan> prepCache = new SessionAwareCache<PreparedPlan>();
//wrong type
try{
@@ -334,7 +319,7 @@
}catch(QueryResolverException qe){
assertEquals("Error converting parameter number 1 with value \"x\" to expected type integer.", qe.getMessage()); //$NON-NLS-1$
}
- assertEquals(0, prepCache.hitCount);
+ assertEquals(0, prepCache.getCacheHitCount());
//test cached plan
try{
@@ -347,7 +332,7 @@
assertEquals("The number of bound values '2' does not match the number of parameters '1' in the prepared statement.", qe.getMessage()); //$NON-NLS-1$
}
- assertEquals(1, prepCache.hitCount);
+ assertEquals(1, prepCache.getCacheHitCount());
//wrong number of values
try{
@@ -368,7 +353,7 @@
List values = Arrays.asList("0"); //$NON-NLS-1$
- helpGetProcessorPlan(preparedSql, values, new PreparedPlanCache());
+ helpGetProcessorPlan(preparedSql, values, new SessionAwareCache<PreparedPlan>());
}
/**
@@ -380,13 +365,13 @@
List values = Arrays.asList("0"); //$NON-NLS-1$
- TestablePreparedPlanCache planCache = new TestablePreparedPlanCache();
+ SessionAwareCache<PreparedPlan> planCache = new SessionAwareCache<PreparedPlan>();
helpGetProcessorPlan(preparedSql, values, new DefaultCapabilitiesFinder(), FakeMetadataFactory.example1Cached(), planCache, SESSION_ID, false, true);
helpGetProcessorPlan(preparedSql, values, new DefaultCapabilitiesFinder(), FakeMetadataFactory.example1Cached(), planCache, SESSION_ID, false, true);
//make sure the plan wasn't reused
- assertEquals(0, planCache.hitCount);
+ assertEquals(0, planCache.getCacheHitCount());
}
@Test public void testUpdateProcedureCriteria() throws Exception {
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatementBatchedUpdate.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatementBatchedUpdate.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatementBatchedUpdate.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -29,7 +29,6 @@
import java.util.List;
import org.junit.Test;
-import org.teiid.dqp.internal.process.TestPreparedStatement.TestablePreparedPlanCache;
import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
@@ -53,7 +52,7 @@
String preparedSql = "UPDATE pm1.g1 SET pm1.g1.e1=?, pm1.g1.e3=? WHERE pm1.g1.e2=?"; //$NON-NLS-1$
// Create a testable prepared plan cache
- TestablePreparedPlanCache prepPlanCache = new TestablePreparedPlanCache();
+ SessionAwareCache<PreparedPlan> prepPlanCache = new SessionAwareCache<PreparedPlan>();
// Construct data manager with data
HardcodedDataManager dataManager = new HardcodedDataManager();
@@ -115,7 +114,7 @@
// Create query
String preparedSql = "UPDATE pm1.g1 SET pm1.g1.e1=?, pm1.g1.e3=? WHERE pm1.g1.e2=?"; //$NON-NLS-1$
// Create a testable prepared plan cache
- TestablePreparedPlanCache prepPlanCache = new TestablePreparedPlanCache();
+ SessionAwareCache<PreparedPlan> prepPlanCache = new SessionAwareCache<PreparedPlan>();
// Construct data manager with data
FakeDataManager dataManager = new FakeDataManager();
@@ -211,7 +210,7 @@
// Create query
String preparedSql = "UPDATE vm1.g1 SET vm1.g1.e2=? WHERE vm1.g1.e1=?"; //$NON-NLS-1$
// Create a testable prepared plan cache
- TestablePreparedPlanCache prepPlanCache = new TestablePreparedPlanCache();
+ SessionAwareCache<PreparedPlan> prepPlanCache = new SessionAwareCache<PreparedPlan>();
// Construct data manager with data
FakeDataManager dataManager = new FakeDataManager();
@@ -304,7 +303,7 @@
// Create query
String preparedSql = "UPDATE pm1.g1 SET pm1.g1.e1=?, pm1.g1.e3=? WHERE pm1.g1.e2=?"; //$NON-NLS-1$
// Create a testable prepared plan cache
- TestablePreparedPlanCache prepPlanCache = new TestablePreparedPlanCache();
+ SessionAwareCache<PreparedPlan> prepPlanCache = new SessionAwareCache<PreparedPlan>();
// Construct data manager with data
FakeDataManager dataManager = new FakeDataManager();
@@ -427,7 +426,7 @@
// Create query
String preparedSql = "UPDATE vm1.g1 SET vm1.g1.e1=?, vm1.g1.e3=? WHERE vm1.g1.e2=?"; //$NON-NLS-1$
// Create a testable prepared plan cache
- TestablePreparedPlanCache prepPlanCache = new TestablePreparedPlanCache();
+ SessionAwareCache<PreparedPlan> prepPlanCache = new SessionAwareCache<PreparedPlan>();
// Construct data manager with data
FakeDataManager dataManager = new FakeDataManager();
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java 2010-01-26 17:51:24 UTC (rev 1781)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java 2010-01-27 04:57:41 UTC (rev 1782)
@@ -176,7 +176,7 @@
}
private Request helpProcessMessage(FakeApplicationEnvironment environment,
- RequestMessage message, PreparedPlanCache cache, DQPWorkContext workContext) throws QueryValidatorException,
+ RequestMessage message, SessionAwareCache<PreparedPlan> cache, DQPWorkContext workContext) throws QueryValidatorException,
QueryParserException,
QueryResolverException,
MetaMatrixComponentException,
@@ -206,7 +206,7 @@
*/
public void testProcessRequestPreparedStatement() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example1Cached();
- PreparedPlanCache cache = new PreparedPlanCache();
+ SessionAwareCache<PreparedPlan> cache = new SessionAwareCache<PreparedPlan>();
FakeApplicationEnvironment environment =
new FakeApplicationEnvironment(metadata, VDB, VDB_VERSION, MODEL, BINDING_ID, BINDING_NAME);
14 years, 11 months
teiid SVN: r1781 - in trunk/connectors/connector-jdbc/src: main/java/org/teiid/connector/jdbc/translator and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-01-26 12:51:24 -0500 (Tue, 26 Jan 2010)
New Revision: 1781
Modified:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/ModFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/translator/TestModFunctionModifier.java
Log:
TEIID-941 fix to postgresql mod function for float and double types.
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java 2010-01-26 16:02:53 UTC (rev 1780)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/postgresql/PostgreSQLTranslator.java 2010-01-26 17:51:24 UTC (rev 1781)
@@ -41,6 +41,7 @@
import org.teiid.connector.jdbc.translator.EscapeSyntaxModifier;
import org.teiid.connector.jdbc.translator.ExtractFunctionModifier;
import org.teiid.connector.jdbc.translator.FunctionModifier;
+import org.teiid.connector.jdbc.translator.ModFunctionModifier;
import org.teiid.connector.jdbc.translator.Translator;
import org.teiid.connector.language.IAggregate;
import org.teiid.connector.language.IExpression;
@@ -93,6 +94,8 @@
registerFunctionModifier(SourceSystemFunctions.YEAR, new ExtractFunctionModifier());
registerFunctionModifier(SourceSystemFunctions.LOCATE, new LocateFunctionModifier(getLanguageFactory()));
registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("coalesce")); //$NON-NLS-1$
+
+ registerFunctionModifier(SourceSystemFunctions.MOD, new ModFunctionModifier("%", getLanguageFactory(), Arrays.asList(TypeFacility.RUNTIME_TYPES.BIG_INTEGER, TypeFacility.RUNTIME_TYPES.BIG_DECIMAL))); //$NON-NLS-1$
//specific to 8.2 client or later
registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new EscapeSyntaxModifier());
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/ModFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/ModFunctionModifier.java 2010-01-26 16:02:53 UTC (rev 1780)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/ModFunctionModifier.java 2010-01-26 17:51:24 UTC (rev 1781)
@@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -39,20 +40,27 @@
*/
public class ModFunctionModifier extends AliasModifier {
- private static Set<Class> SUPPORTED_TYPES = new HashSet<Class>(Arrays.asList(TypeFacility.RUNTIME_TYPES.INTEGER, TypeFacility.RUNTIME_TYPES.LONG));
+ private Set<Class> supportedTypes = new HashSet<Class>(Arrays.asList(TypeFacility.RUNTIME_TYPES.INTEGER, TypeFacility.RUNTIME_TYPES.LONG));
private ILanguageFactory langFactory;
-
+
public ModFunctionModifier(String modFunction, ILanguageFactory langFactory) {
+ this(modFunction, langFactory, null);
+ }
+
+ public ModFunctionModifier(String modFunction, ILanguageFactory langFactory, Collection<Class> supportedTypes) {
super(modFunction);
- this.langFactory = langFactory;
+ this.langFactory = langFactory;
+ if (supportedTypes != null) {
+ this.supportedTypes.addAll(supportedTypes);
+ }
}
@Override
public List<?> translate(IFunction function) {
List<IExpression> expressions = function.getParameters();
Class<?> type = function.getType();
- if (SUPPORTED_TYPES.contains(type)) {
+ if (supportedTypes.contains(type)) {
modify(function);
return null;
}
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/translator/TestModFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/translator/TestModFunctionModifier.java 2010-01-26 16:02:53 UTC (rev 1780)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/translator/TestModFunctionModifier.java 2010-01-26 17:51:24 UTC (rev 1781)
@@ -145,22 +145,6 @@
/**
* Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to
- * MOD(x,y) using {@link Integer} constants for both parameters returns
- * MOD(x,y). {@link ModFunctionModifier} will be constructed with a
- * function name of "MOD" and a supported type list which contains {@link Integer}.
- *
- * @throws Exception
- */
- public void testTwoIntConst3() throws Exception {
- IExpression[] args = new IExpression[] {
- LANG_FACTORY.createLiteral(new Integer(10), Integer.class),
- LANG_FACTORY.createLiteral(new Integer(6), Integer.class)
- };
- helpTestMod("MOD", args, "MOD(10, 6)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to
* x % y using {@link Integer} constants for both parameters returns (x % y).
* {@link ModFunctionModifier} will be constructed with a function name of
* "%" and no supported type list.
@@ -177,22 +161,6 @@
/**
* Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to
- * x % y using {@link Integer} constants for both parameters returns (x % y).
- * {@link ModFunctionModifier} will be constructed with a function name of
- * "%" and a supported type list which contains {@link Integer}.
- *
- * @throws Exception
- */
- public void testTwoIntConst6() throws Exception {
- IExpression[] args = new IExpression[] {
- LANG_FACTORY.createLiteral(new Integer(10), Integer.class),
- LANG_FACTORY.createLiteral(new Integer(6), Integer.class)
- };
- helpTestMod("%", args, "(10 % 6)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to
* MOD(x,y) using {@link Long} constants for both parameters returns
* MOD(x,y). {@link ModFunctionModifier} will be constructed without
* specifying a function name or a supported type list.
@@ -225,22 +193,6 @@
/**
* Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to
- * MOD(x,y) using {@link Long} constants for both parameters returns
- * MOD(x,y). {@link ModFunctionModifier} will be constructed with a
- * function name of "MOD" and a supported type list which contains {@link Long}.
- *
- * @throws Exception
- */
- public void testTwoLongConst3() throws Exception {
- IExpression[] args = new IExpression[] {
- LANG_FACTORY.createLiteral(new Long(10), Long.class),
- LANG_FACTORY.createLiteral(new Long(6), Long.class)
- };
- helpTestMod("MOD", args, "MOD(10, 6)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to
* x % y using {@link Long} constants for both parameters returns (x % y).
* {@link ModFunctionModifier} will be constructed with a function name of
* "%" and no supported type list.
@@ -257,22 +209,6 @@
/**
* Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to
- * x % y using {@link Long} constants for both parameters returns (x % y).
- * {@link ModFunctionModifier} will be constructed with a function name of
- * "%" and a supported type list which contains {@link Long}.
- *
- * @throws Exception
- */
- public void testTwoLongConst6() throws Exception {
- IExpression[] args = new IExpression[] {
- LANG_FACTORY.createLiteral(new Long(10), Long.class),
- LANG_FACTORY.createLiteral(new Long(6), Long.class)
- };
- helpTestMod("%", args, "(10 % 6)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to
* MOD(x,y) using {@link Float} constants for both parameters returns
* (x - (TRUNC((x / y), 0) * y)). {@link ModFunctionModifier} will be
* constructed without specifying a function name or a supported type list.
@@ -355,23 +291,6 @@
/**
* Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to
- * MOD(e1,y) using a {@link Integer} element and a {@link Integer} constant
- * for parameters returns MOD(e1,y). {@link ModFunctionModifier} will be
- * constructed with a function name of "MOD" and a supported type list which
- * contains {@link Integer}.
- *
- * @throws Exception
- */
- public void testOneIntElemOneIntConst3() throws Exception {
- IExpression[] args = new IExpression[] {
- LANG_FACTORY.createElement("e1", null, null, Integer.class), //$NON-NLS-1$
- LANG_FACTORY.createLiteral(new Integer(6), Integer.class)
- };
- helpTestMod("MOD", args, "MOD(e1, 6)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to
* e1 % y using a {@link Integer} element and a {@link Integer} constant for
* parameters returns (e1 % y). {@link ModFunctionModifier} will be
* constructed with a function name of "%" and no supported type list.
@@ -389,23 +308,6 @@
/**
* Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to
- * e1 % y using a {@link Integer} element and a {@link Integer} constant for
- * parameters returns (e1 % y). {@link ModFunctionModifier} will be
- * constructed with a function name of "%" and a supported type list which
- * contains {@link Integer}.
- *
- * @throws Exception
- */
- public void testOneIntElemOneIntConst6() throws Exception {
- IExpression[] args = new IExpression[] {
- LANG_FACTORY.createElement("e1", null, null, Integer.class), //$NON-NLS-1$
- LANG_FACTORY.createLiteral(new Integer(6), Integer.class)
- };
- helpTestMod("%", args, "(e1 % 6)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Test {@link ModFunctionModifier#modify(IFunction)} to validate a call to
* MOD(e1,y) using a {@link BigDecimal} element and a {@link BigDecimal}
* constant for parameters returns (e1 - (TRUNC((e1 / y), 0) * y)).
* {@link ModFunctionModifier} will be constructed without specifying a
14 years, 12 months
teiid SVN: r1780 - in trunk: connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql and 2 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-01-26 11:02:53 -0500 (Tue, 26 Jan 2010)
New Revision: 1780
Modified:
trunk/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java
trunk/test-integration/common/src/test/java/com/metamatrix/connector/jdbc/extension/TestSQLConversionVisitor.java
Log:
TEIID-939 fix for too eagerly adding set query nesting parens, which are not supported on mysql.
Modified: trunk/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java
===================================================================
--- trunk/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java 2010-01-26 04:55:59 UTC (rev 1779)
+++ trunk/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java 2010-01-26 16:02:53 UTC (rev 1780)
@@ -72,6 +72,7 @@
import org.teiid.connector.language.ISubqueryInCriteria;
import org.teiid.connector.language.IUpdate;
import org.teiid.connector.language.IParameter.Direction;
+import org.teiid.connector.language.ISetQuery.Operation;
import org.teiid.connector.metadata.runtime.MetadataObject;
import org.teiid.connector.visitor.framework.AbstractLanguageVisitor;
@@ -971,7 +972,7 @@
}
public void visit(ISetQuery obj) {
- appendSetQuery(obj.getLeftQuery());
+ appendSetQuery(obj, obj.getLeftQuery(), false);
buffer.append(SQLReservedWords.SPACE);
@@ -983,7 +984,7 @@
}
buffer.append(SQLReservedWords.SPACE);
- appendSetQuery(obj.getRightQuery());
+ appendSetQuery(obj, obj.getRightQuery(), true);
IOrderBy orderBy = obj.getOrderBy();
if(orderBy != null) {
@@ -1006,8 +1007,11 @@
return false;
}
- protected void appendSetQuery(IQueryCommand obj) {
- if(obj instanceof ISetQuery || useParensForSetQueries()) {
+ protected void appendSetQuery(ISetQuery parent, IQueryCommand obj, boolean right) {
+ if((!(obj instanceof ISetQuery) && useParensForSetQueries())
+ || (right && obj instanceof ISetQuery
+ && ((parent.isAll() && !((ISetQuery)obj).isAll())
+ || parent.getOperation() != ((ISetQuery)obj).getOperation()))) {
buffer.append(SQLReservedWords.LPAREN);
append(obj);
buffer.append(SQLReservedWords.RPAREN);
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java 2010-01-26 04:55:59 UTC (rev 1779)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java 2010-01-26 16:02:53 UTC (rev 1780)
@@ -25,6 +25,7 @@
import java.util.Properties;
import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Test;
import org.teiid.connector.api.ConnectorException;
import org.teiid.connector.jdbc.TranslationHelper;
@@ -342,4 +343,23 @@
output, TRANSLATOR);
}
+ @Test public void testThreeUnionBranches() throws Exception {
+ String input = "select part_id id FROM parts UNION ALL select part_name FROM parts UNION ALL select part_id FROM parts ORDER BY id"; //$NON-NLS-1$
+ String output = "(SELECT PARTS.PART_ID AS id FROM PARTS) UNION ALL (SELECT PARTS.PART_NAME FROM PARTS) UNION ALL (SELECT PARTS.PART_ID FROM PARTS) ORDER BY id"; //$NON-NLS-1$
+
+ TranslationHelper.helpTestVisitor(TranslationHelper.PARTS_VDB,
+ input,
+ output, TRANSLATOR);
+ }
+
+ @Ignore("There's no good workaround for this case on mysql 4 and for 5 can be done with a suquery, but only if the first union branch has no parens...")
+ @Test public void testNestedSetQuery() throws Exception {
+ String input = "select part_id id FROM parts UNION ALL (select part_name FROM parts UNION select part_id FROM parts)"; //$NON-NLS-1$
+ String output = ""; //$NON-NLS-1$
+
+ TranslationHelper.helpTestVisitor(TranslationHelper.PARTS_VDB,
+ input,
+ output, TRANSLATOR);
+ }
+
}
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java 2010-01-26 04:55:59 UTC (rev 1779)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java 2010-01-26 16:02:53 UTC (rev 1780)
@@ -139,7 +139,7 @@
helpTestVisitor(getTestVDB(),
"select part_id id FROM parts UNION ALL select part_name FROM parts UNION ALL select part_id FROM parts ORDER BY id", //$NON-NLS-1$
null,
- "(SELECT g_2.PART_ID AS c_0 FROM PARTS g_2 UNION ALL SELECT g_1.PART_NAME AS c_0 FROM PARTS g_1) UNION ALL SELECT g_0.PART_ID AS c_0 FROM PARTS g_0 ORDER BY c_0 NULLS FIRST", //$NON-NLS-1$
+ "SELECT g_2.PART_ID AS c_0 FROM PARTS g_2 UNION ALL SELECT g_1.PART_NAME AS c_0 FROM PARTS g_1 UNION ALL SELECT g_0.PART_ID AS c_0 FROM PARTS g_0 ORDER BY c_0 NULLS FIRST", //$NON-NLS-1$
true);
}
Modified: trunk/test-integration/common/src/test/java/com/metamatrix/connector/jdbc/extension/TestSQLConversionVisitor.java
===================================================================
--- trunk/test-integration/common/src/test/java/com/metamatrix/connector/jdbc/extension/TestSQLConversionVisitor.java 2010-01-26 04:55:59 UTC (rev 1779)
+++ trunk/test-integration/common/src/test/java/com/metamatrix/connector/jdbc/extension/TestSQLConversionVisitor.java 2010-01-26 16:02:53 UTC (rev 1780)
@@ -22,10 +22,12 @@
package com.metamatrix.connector.jdbc.extension;
+import static org.junit.Assert.*;
+
import java.util.Properties;
-import junit.framework.TestCase;
-
+import org.junit.BeforeClass;
+import org.junit.Test;
import org.teiid.connector.api.ConnectorException;
import org.teiid.connector.api.ExecutionContext;
import org.teiid.connector.jdbc.JDBCPropertyNames;
@@ -43,10 +45,9 @@
import org.teiid.dqp.internal.datamgr.language.TstLanguageBridgeFactory;
import com.metamatrix.cdk.api.EnvironmentUtility;
-
/**
*/
-public class TestSQLConversionVisitor extends TestCase {
+public class TestSQLConversionVisitor {
public static final ExecutionContext context = new ExecutionContextImpl("VDB", //$NON-NLS-1$
"Version", //$NON-NLS-1$
@@ -55,15 +56,17 @@
"ExecutionPayload", //$NON-NLS-1$
"ConnectionID", //$NON-NLS-1$
"Connector", //$NON-NLS-1$
- "RequestID", "PartID", "ExecCount"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- /**
- * Constructor for TestSQLConversionVisitor.
- * @param name
- */
- public TestSQLConversionVisitor(String name) {
- super(name);
- }
-
+ "RequestID", "PartID", "ExecCount"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ private static Translator TRANSLATOR;
+
+ @BeforeClass public static void oneTimeSetup() throws ConnectorException {
+ TRANSLATOR = new Translator();
+ Properties p = new Properties();
+ p.setProperty(JDBCPropertyNames.TRIM_STRINGS, Boolean.TRUE.toString());
+ TRANSLATOR.initialize(EnvironmentUtility.createEnvironment(p, false));
+ }
+
public String getTestVDB() {
return TranslationHelper.PARTS_VDB;
}
@@ -99,244 +102,244 @@
return visitor.toString();
}
- public void testSimple() {
+ @Test public void testSimple() {
helpTestVisitor(getTestVDB(),
"select part_name from parts", //$NON-NLS-1$
"SELECT PARTS.PART_NAME FROM PARTS"); //$NON-NLS-1$
}
- public void testAliasInSelect() {
+ @Test public void testAliasInSelect() {
helpTestVisitor(getTestVDB(),
"select part_name as x from parts", //$NON-NLS-1$
"SELECT PARTS.PART_NAME AS x FROM PARTS"); //$NON-NLS-1$
}
- public void testAliasedGroup() {
+ @Test public void testAliasedGroup() {
helpTestVisitor(getTestVDB(),
"select y.part_name from parts y", //$NON-NLS-1$
"SELECT y.PART_NAME FROM PARTS AS y"); //$NON-NLS-1$
}
- public void testAliasedGroupAndElement() {
+ @Test public void testAliasedGroupAndElement() {
helpTestVisitor(getTestVDB(),
"select y.part_name AS z from parts y", //$NON-NLS-1$
"SELECT y.PART_NAME AS z FROM PARTS AS y"); //$NON-NLS-1$
}
- public void testLiteralString() {
+ @Test public void testLiteralString() {
helpTestVisitor(getTestVDB(),
"select 'x' from parts", //$NON-NLS-1$
"SELECT 'x' FROM PARTS"); //$NON-NLS-1$
}
- public void testLiteralInteger() {
+ @Test public void testLiteralInteger() {
helpTestVisitor(getTestVDB(),
"select 5 from parts", //$NON-NLS-1$
"SELECT 5 FROM PARTS"); //$NON-NLS-1$
}
- public void testLiteralFloat() {
+ @Test public void testLiteralFloat() {
helpTestVisitor(getTestVDB(),
"select 5.2 from parts", //$NON-NLS-1$
"SELECT 5.2 FROM PARTS"); //$NON-NLS-1$
}
- public void testLiteralLowFloat() {
+ @Test public void testLiteralLowFloat() {
helpTestVisitor(getTestVDB(),
"select 0.012 from parts", //$NON-NLS-1$
"SELECT 0.012 FROM PARTS"); //$NON-NLS-1$
}
- public void testLiteralLowFloat2() {
+ @Test public void testLiteralLowFloat2() {
helpTestVisitor(getTestVDB(),
"select 0.00012 from parts", //$NON-NLS-1$
"SELECT 0.00012 FROM PARTS"); //$NON-NLS-1$
}
- public void testLiteralHighFloat() {
+ @Test public void testLiteralHighFloat() {
helpTestVisitor(getTestVDB(),
"select 12345.123 from parts", //$NON-NLS-1$
"SELECT 12345.123 FROM PARTS"); //$NON-NLS-1$
}
- public void testLiteralHighFloat2() {
+ @Test public void testLiteralHighFloat2() {
helpTestVisitor(getTestVDB(),
"select 1234567890.1234567 from parts", //$NON-NLS-1$
"SELECT 1234567890.1234567 FROM PARTS"); //$NON-NLS-1$
}
- public void testLiteralBoolean() {
+ @Test public void testLiteralBoolean() {
helpTestVisitor(getTestVDB(),
"select {b'true'}, {b'false'} from parts", //$NON-NLS-1$
"SELECT 1, 0 FROM PARTS"); //$NON-NLS-1$
}
- public void testLiteralDate() {
+ @Test public void testLiteralDate() {
helpTestVisitor(getTestVDB(),
"select {d '2003-12-31'} from parts", //$NON-NLS-1$
"SELECT {d '2003-12-31'} FROM PARTS"); //$NON-NLS-1$
}
- public void testLiteralTime() {
+ @Test public void testLiteralTime() {
helpTestVisitor(getTestVDB(),
"select {t '23:59:59'} from parts", //$NON-NLS-1$
"SELECT {t '23:59:59'} FROM PARTS"); //$NON-NLS-1$
}
- public void testLiteralNull() {
+ @Test public void testLiteralNull() {
helpTestVisitor(getTestVDB(),
"select null from parts", //$NON-NLS-1$
"SELECT NULL FROM PARTS"); //$NON-NLS-1$
}
- public void testLiteralTimestamp() {
+ @Test public void testLiteralTimestamp() {
helpTestVisitor(getTestVDB(),
"select {ts '2003-12-31 23:59:59.123'} from parts", //$NON-NLS-1$
"SELECT {ts '2003-12-31 23:59:59.123'} FROM PARTS"); //$NON-NLS-1$
}
- public void testSQL89Join() {
+ @Test public void testSQL89Join() {
helpTestVisitor(getTestVDB(),
"select p.part_name from parts p, supplier_parts s where p.part_id = s.part_id", //$NON-NLS-1$
"SELECT p.PART_NAME FROM PARTS AS p, SUPPLIER_PARTS AS s WHERE p.PART_ID = s.PART_ID"); //$NON-NLS-1$
}
- public void testSQL92Join() {
+ @Test public void testSQL92Join() {
helpTestVisitor(getTestVDB(),
"select p.part_name from parts p join supplier_parts s on p.part_id = s.part_id", //$NON-NLS-1$
"SELECT p.PART_NAME FROM PARTS AS p INNER JOIN SUPPLIER_PARTS AS s ON p.PART_ID = s.PART_ID"); //$NON-NLS-1$
}
- public void testSelfJoin() {
+ @Test public void testSelfJoin() {
helpTestVisitor(getTestVDB(),
"select p.part_name from parts p join parts p2 on p.part_id = p2.part_id", //$NON-NLS-1$
"SELECT p.PART_NAME FROM PARTS AS p INNER JOIN PARTS AS p2 ON p.PART_ID = p2.PART_ID"); //$NON-NLS-1$
}
- public void testRightOuterJoin() {
+ @Test public void testRightOuterJoin() {
helpTestVisitor(getTestVDB(),
"select p.part_name from parts p right join supplier_parts s on p.part_id = s.part_id", //$NON-NLS-1$
"SELECT p.PART_NAME FROM SUPPLIER_PARTS AS s LEFT OUTER JOIN PARTS AS p ON p.PART_ID = s.PART_ID"); //$NON-NLS-1$
}
- public void testLeftOuterJoin() {
+ @Test public void testLeftOuterJoin() {
helpTestVisitor(getTestVDB(),
"select p.part_name from parts p left join supplier_parts s on p.part_id = s.part_id", //$NON-NLS-1$
"SELECT p.PART_NAME FROM PARTS AS p LEFT OUTER JOIN SUPPLIER_PARTS AS s ON p.PART_ID = s.PART_ID"); //$NON-NLS-1$
}
- public void testFullOuterJoin() {
+ @Test public void testFullOuterJoin() {
helpTestVisitor(getTestVDB(),
"select p.part_name from parts p full join supplier_parts s on p.part_id = s.part_id", //$NON-NLS-1$
"SELECT p.PART_NAME FROM PARTS AS p FULL OUTER JOIN SUPPLIER_PARTS AS s ON p.PART_ID = s.PART_ID"); //$NON-NLS-1$
}
- public void testCompare1() {
+ @Test public void testCompare1() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id = 'x'", //$NON-NLS-1$
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID = 'x'"); //$NON-NLS-1$
}
- public void testCompare2() {
+ @Test public void testCompare2() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id <> 'x'", //$NON-NLS-1$
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID <> 'x'"); //$NON-NLS-1$
}
- public void testCompare3() {
+ @Test public void testCompare3() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id < 'x'", //$NON-NLS-1$
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID < 'x'"); //$NON-NLS-1$
}
- public void testCompare4() {
+ @Test public void testCompare4() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id <= 'x'", //$NON-NLS-1$
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID <= 'x'"); //$NON-NLS-1$
}
- public void testCompare5() {
+ @Test public void testCompare5() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id > 'x'", //$NON-NLS-1$
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID > 'x'"); //$NON-NLS-1$
}
- public void testCompare6() {
+ @Test public void testCompare6() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id >= 'x'", //$NON-NLS-1$
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID >= 'x'"); //$NON-NLS-1$
}
- public void testIn1() {
+ @Test public void testIn1() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id in ('x')", //$NON-NLS-1$
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID = 'x'"); //$NON-NLS-1$
}
- public void testIn2() {
+ @Test public void testIn2() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id in ('x', 'y')", //$NON-NLS-1$
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID IN ('x', 'y')"); //$NON-NLS-1$
}
- public void testIn3() {
+ @Test public void testIn3() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id not in ('x', 'y')", //$NON-NLS-1$
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID NOT IN ('x', 'y')"); //$NON-NLS-1$
}
- public void testIsNull1() {
+ @Test public void testIsNull1() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id is null", //$NON-NLS-1$
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID IS NULL"); //$NON-NLS-1$
}
- public void testIsNull2() {
+ @Test public void testIsNull2() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id is not null", //$NON-NLS-1$
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID IS NOT NULL"); //$NON-NLS-1$
}
- public void testInsertNull() {
+ @Test public void testInsertNull() {
helpTestVisitor(getTestVDB(),
"insert into parts (part_id, part_name, part_color, part_weight) values ('a', null, 'c', 'd')", //$NON-NLS-1$
"INSERT INTO PARTS (PART_ID, PART_NAME, PART_COLOR, PART_WEIGHT) VALUES ('a', NULL, 'c', 'd')"); //$NON-NLS-1$
}
- public void testUpdateNull() {
+ @Test public void testUpdateNull() {
helpTestVisitor(getTestVDB(),
"update parts set part_weight = null where part_color = 'b'", //$NON-NLS-1$
"UPDATE PARTS SET PART_WEIGHT = NULL WHERE PARTS.PART_COLOR = 'b'"); //$NON-NLS-1$
}
- public void testUpdateWhereNull() {
+ @Test public void testUpdateWhereNull() {
helpTestVisitor(getTestVDB(),
"update parts set part_weight = 'a' where part_weight = null", //$NON-NLS-1$
"UPDATE PARTS SET PART_WEIGHT = 'a' WHERE NULL <> NULL"); //$NON-NLS-1$
}
- public void testPreparedStatementCreationWithUpdate() {
+ @Test public void testPreparedStatementCreationWithUpdate() {
helpTestVisitor(getTestVDB(),
"update parts set part_weight = 'a' where part_weight < 5", //$NON-NLS-1$
"UPDATE PARTS SET PART_WEIGHT = ? WHERE PARTS.PART_WEIGHT < ?", //$NON-NLS-1$
true);
}
- public void testPreparedStatementCreationWithInsert() {
+ @Test public void testPreparedStatementCreationWithInsert() {
helpTestVisitor(getTestVDB(),
"insert into parts (part_weight) values (5)", //$NON-NLS-1$
"INSERT INTO PARTS (PART_WEIGHT) VALUES (?)", //$NON-NLS-1$
true);
}
- public void testPreparedStatementCreationWithSelect() {
+ @Test public void testPreparedStatementCreationWithSelect() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id not in ('x', 'y') and part_weight < 6", //$NON-NLS-1$
"SELECT PARTS.PART_NAME FROM PARTS WHERE (PARTS.PART_ID NOT IN (?, ?)) AND (PARTS.PART_WEIGHT < ?)", //$NON-NLS-1$
true);
}
- public void testPreparedStatementCreationWithLike() {
+ @Test public void testPreparedStatementCreationWithLike() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_name like '%foo'", //$NON-NLS-1$
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_NAME LIKE ?", //$NON-NLS-1$
@@ -358,53 +361,76 @@
* In the future, functions can be made smarter about which of their literal arguments
* either are (or are not) eligible to be bind variables
*/
- public void testPreparedStatementCreationWithFunction() {
+ @Test public void testPreparedStatementCreationWithFunction() {
helpTestVisitor(getTestVDB(),
"select part_name from parts where concat(part_name, 'x') = concat('y', part_weight)", //$NON-NLS-1$
"SELECT PARTS.PART_NAME FROM PARTS WHERE concat(PARTS.PART_NAME, 'x') = concat('y', PARTS.PART_WEIGHT)", //$NON-NLS-1$
true);
}
- public void testPreparedStatementCreationWithCase() {
+ @Test public void testPreparedStatementCreationWithCase() {
helpTestVisitor(getTestVDB(),
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_WEIGHT = CASE WHEN PARTS.PART_NAME='a' THEN 'b' ELSE 'c' END", //$NON-NLS-1$
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_WEIGHT = CASE WHEN PARTS.PART_NAME = ? THEN 'b' ELSE 'c' END", //$NON-NLS-1$
true);
}
- public void testVisitIDeleteWithComment() throws Exception {
+ @Test public void testVisitIDeleteWithComment() throws Exception {
String expected = "DELETE /*teiid sessionid:ConnectionID, requestid:RequestID.PartID*/ FROM g1 WHERE (100 >= 200) AND (500 < 600)"; //$NON-NLS-1$
assertEquals(expected, getStringWithContext(TestDeleteImpl.example()));
}
- public void testVisitIInsertWithComment() throws Exception {
+ @Test public void testVisitIInsertWithComment() throws Exception {
String expected = "INSERT /*teiid sessionid:ConnectionID, requestid:RequestID.PartID*/ INTO g1 (e1, e2, e3, e4) VALUES (1, 2, 3, 4)"; //$NON-NLS-1$
assertEquals(expected, getStringWithContext(TestInsertImpl.example("g1"))); //$NON-NLS-1$
}
- public void testVisitISelectWithComment() throws Exception {
+ @Test public void testVisitISelectWithComment() throws Exception {
String expected = "SELECT /*teiid sessionid:ConnectionID, requestid:RequestID.PartID*/ g1.e1, g1.e2, g1.e3, g1.e4"; //$NON-NLS-1$
assertEquals(expected, getStringWithContext(TestSelectImpl.example(false)));
expected = "SELECT /*teiid sessionid:ConnectionID, requestid:RequestID.PartID*/ DISTINCT g1.e1, g1.e2, g1.e3, g1.e4"; //$NON-NLS-1$
assertEquals(expected, getStringWithContext(TestSelectImpl.example(true)));
}
- public void testVisitIUpdateWithComment() throws Exception {
+ @Test public void testVisitIUpdateWithComment() throws Exception {
String expected = "UPDATE /*teiid sessionid:ConnectionID, requestid:RequestID.PartID*/ g1 SET e1 = 1, e2 = 1, e3 = 1, e4 = 1 WHERE 1 = 1"; //$NON-NLS-1$
assertEquals(expected, getStringWithContext(TestUpdateImpl.example()));
}
- public void testVisitIProcedureWithComment() throws Exception {
+ @Test public void testVisitIProcedureWithComment() throws Exception {
String expected = "{ /*teiid sessionid:ConnectionID, requestid:RequestID.PartID*/ call sq3(?,?)}"; //$NON-NLS-1$
assertEquals(expected, getStringWithContext(TestProcedureImpl.example()));
}
- public void testTrimStrings() throws Exception {
- Translator trans = new Translator();
- Properties p = new Properties();
- p.setProperty(JDBCPropertyNames.TRIM_STRINGS, Boolean.TRUE.toString());
- trans.initialize(EnvironmentUtility.createEnvironment(p, false));
-
- TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, "select stringkey from bqt1.smalla", "SELECT rtrim(SmallA.StringKey) FROM SmallA", trans); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ @Test public void testTrimStrings() throws Exception {
+ TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, "select stringkey from bqt1.smalla", "SELECT rtrim(SmallA.StringKey) FROM SmallA", TRANSLATOR); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ @Test public void testNestedSetQuery() throws Exception {
+ String input = "select part_id id FROM parts UNION ALL (select part_name FROM parts UNION select part_id FROM parts)"; //$NON-NLS-1$
+ String output = "SELECT rtrim(PARTS.PART_ID) AS id FROM PARTS UNION ALL (SELECT PARTS.PART_NAME FROM PARTS UNION SELECT rtrim(PARTS.PART_ID) FROM PARTS)"; //$NON-NLS-1$
+
+ TranslationHelper.helpTestVisitor(TranslationHelper.PARTS_VDB,
+ input,
+ output, TRANSLATOR);
+ }
+
+ @Test public void testNestedSetQuery1() throws Exception {
+ String input = "select part_id id FROM parts UNION (select part_name FROM parts EXCEPT select part_id FROM parts)"; //$NON-NLS-1$
+ String output = "SELECT rtrim(PARTS.PART_ID) AS id FROM PARTS UNION (SELECT PARTS.PART_NAME FROM PARTS EXCEPT SELECT rtrim(PARTS.PART_ID) FROM PARTS)"; //$NON-NLS-1$
+
+ TranslationHelper.helpTestVisitor(TranslationHelper.PARTS_VDB,
+ input,
+ output, TRANSLATOR);
+ }
+
+ @Test public void testNestedSetQuery2() throws Exception {
+ String input = "select part_id id FROM parts UNION select part_name FROM parts EXCEPT select part_id FROM parts"; //$NON-NLS-1$
+ String output = "SELECT rtrim(PARTS.PART_ID) AS id FROM PARTS UNION SELECT PARTS.PART_NAME FROM PARTS EXCEPT SELECT rtrim(PARTS.PART_ID) FROM PARTS"; //$NON-NLS-1$
+
+ TranslationHelper.helpTestVisitor(TranslationHelper.PARTS_VDB,
+ input,
+ output, TRANSLATOR);
+ }
+
}
14 years, 12 months
teiid SVN: r1779 - in trunk: client-jdbc/src/main/java/com/metamatrix/jdbc and 6 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-01-25 23:55:59 -0500 (Mon, 25 Jan 2010)
New Revision: 1779
Added:
trunk/engine/src/test/java/com/metamatrix/common/buffer/TestTupleBuffer.java
Removed:
trunk/engine/src/test/java/com/metamatrix/common/buffer/storage/
Modified:
trunk/build/kit-runtime/deploy.properties
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/BatchResults.java
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMResultSet.java
trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestAllResultsImpl.java
trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestBatchResults.java
trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestMMResultSet.java
trunk/common-core/src/main/java/com/metamatrix/core/util/LRUCache.java
trunk/engine/src/main/java/com/metamatrix/common/buffer/TupleBatch.java
trunk/engine/src/main/java/com/metamatrix/common/buffer/TupleBuffer.java
trunk/engine/src/main/java/com/metamatrix/query/processor/BatchCollector.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
Log:
TEIID-913 refining forward only to not output batches consumed by the client and fixing output parameter indexing
Modified: trunk/build/kit-runtime/deploy.properties
===================================================================
--- trunk/build/kit-runtime/deploy.properties 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/build/kit-runtime/deploy.properties 2010-01-26 04:55:59 UTC (rev 1779)
@@ -37,11 +37,11 @@
#Plan debug messages allowed. see option debug.
process.optionDebugAllowed=true
-#Maximum allowed fetch size, set via JDBC. User requested value ignored above this value. (default 20000)
-process.maxRowsFetchSize=20000
+#Maximum allowed fetch size, set via JDBC. User requested value ignored above this value. (default 20480)
+process.maxRowsFetchSize=20480
-# The max lob chunk size transferred each time when processing blobs, clobs(10KB default)
-process.lobChunkSizeInKB=10
+# The max lob chunk size transferred each time when processing blobs, clobs(100KB default)
+process.lobChunkSizeInKB=100
#
# BufferManager Settings
@@ -56,8 +56,8 @@
#Defines whether to use disk buffering or not. (default true)
dqp.buffer.useDisk=true
-#The numeric memory size in MB, to be used before disk buffering kicks in (default 64)
-dqp.buffer.memory=64
+#The number of batches to actively hold in the BufferManager
+org.teiid.buffer.maxReserveBatches=64
#
# Cache Settings
@@ -66,7 +66,7 @@
#The maximum number of query plans that are cached. Note: this is a memory based cache. (default 250)
PreparedPlanCache.maxCount=250
-#Maximum number of cached lookup tables. Note: this is a memory based cache and should be set to a value of at least 10 to accomidate system usage. (default 200)
+#Maximum number of cached lookup tables. Note: this is a memory based cache. (default 200)
CodeTables.maxCount=200
#Maximum number of records in a single lookup table (default 10000)
@@ -97,8 +97,8 @@
#Maximum number of sessions allowed by the system (default 5000)
session.maxSessions=5000
-#Max allowed time before the session is terminated by the system (default unlimited, default is 86400000 - 24hrs)
-#session.expirationTimeInMilli=86400000
+#Max allowed time before the session is terminated by the system, 0 indicates unlimited (default 0)
+#session.expirationTimeInMilli=0
#
# Membership Service Settings (handles the authentication of the user)
@@ -144,7 +144,7 @@
ssl.enabled=false
#ssl.protocol=SSLv3
-#SSL Authentication Mode, may be one of 1-way, 2-way, or annonymous (default 1-way)
+#SSL Authentication Mode, may be one of 1-way, 2-way, or anonymous (default 1-way)
#ssl.authenticationMode=1-way
#ssl.keymanagementalgorithm=
#ssl.keystore.filename=ssl.keystore
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/BatchResults.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/BatchResults.java 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/BatchResults.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -73,6 +73,7 @@
private ArrayList<Batch> batches = new ArrayList<Batch>();
private int currentRowNumber;
+ private List<?> currentRow;
private int lastRowNumber = -1;
private int highestRowNumber;
private BatchFetcher batchFetcher;
@@ -93,25 +94,30 @@
* Moving backward through the results it's expected that the batches will match the fetch size.
*/
public List getCurrentRow() throws SQLException {
- if (currentRowNumber == 0 || (lastRowNumber != -1 && currentRowNumber > lastRowNumber)) {
+ if (currentRow != null) {
+ return currentRow;
+ }
+ if (this.currentRowNumber == 0 || (lastRowNumber != -1 && this.currentRowNumber > lastRowNumber)) {
return null;
}
for (int i = 0; i < batches.size(); i++) {
Batch batch = batches.get(i);
- if (currentRowNumber < batch.getBeginRow()) {
+ if (this.currentRowNumber < batch.getBeginRow()) {
continue;
}
- if (currentRowNumber > batch.getEndRow()) {
+ if (this.currentRowNumber > batch.getEndRow()) {
continue;
}
if (i != 0) {
batches.add(0, batches.remove(i));
}
- return batch.getRow(currentRowNumber);
+ currentRow = batch.getRow(this.currentRowNumber);
+ return currentRow;
}
- requestBatchAndWait(currentRowNumber);
+ requestBatchAndWait(this.currentRowNumber);
Batch batch = batches.get(0);
- return batch.getRow(currentRowNumber);
+ currentRow = batch.getRow(this.currentRowNumber);
+ return currentRow;
}
private void requestNextBatch() throws SQLException {
@@ -120,29 +126,30 @@
public boolean next() throws SQLException{
if (hasNext()) {
- currentRowNumber++;
+ setCurrentRowNumber(this.currentRowNumber + 1);
+ getCurrentRow();
return true;
}
- if (currentRowNumber == highestRowNumber) {
- currentRowNumber++;
+ if (this.currentRowNumber == highestRowNumber) {
+ setCurrentRowNumber(this.currentRowNumber + 1);
}
return false;
}
public boolean hasPrevious() {
- return (currentRowNumber != 0 && currentRowNumber != 1);
+ return (this.currentRowNumber != 0 && this.currentRowNumber != 1);
}
public boolean previous() {
if (hasPrevious()) {
- currentRowNumber--;
+ setCurrentRowNumber(this.currentRowNumber - 1);
return true;
}
if (this.currentRowNumber == 1) {
- currentRowNumber--;
+ setCurrentRowNumber(this.currentRowNumber - 1);
}
return false;
@@ -158,7 +165,7 @@
public boolean absolute(int row, int offset) throws SQLException {
if(row == 0) {
- currentRowNumber = 0;
+ setCurrentRowNumber(0);
return false;
}
@@ -169,11 +176,11 @@
}
if (row + offset <= highestRowNumber) {
- currentRowNumber = row;
+ setCurrentRowNumber(row);
return true;
}
- currentRowNumber = lastRowNumber + 1 - offset;
+ setCurrentRowNumber(lastRowNumber + 1 - offset);
return false;
}
@@ -186,11 +193,11 @@
int positiveRow = lastRowNumber + row + 1;
if (positiveRow <= 0) {
- currentRowNumber = 0;
+ setCurrentRowNumber(0);
return false;
}
- currentRowNumber = positiveRow;
+ setCurrentRowNumber(positiveRow);
return true;
}
@@ -219,11 +226,11 @@
}
public boolean hasNext(int next) throws SQLException {
- while (currentRowNumber + next > highestRowNumber && lastRowNumber == -1) {
+ while (this.currentRowNumber + next > highestRowNumber && lastRowNumber == -1) {
requestNextBatch();
}
- return (currentRowNumber + next <= highestRowNumber);
+ return (this.currentRowNumber + next <= highestRowNumber);
}
public int getFinalRowNumber() {
@@ -233,5 +240,12 @@
public int getHighestRowNumber() {
return highestRowNumber;
}
+
+ private void setCurrentRowNumber(int currentRowNumber) {
+ if (currentRowNumber != this.currentRowNumber) {
+ this.currentRow = null;
+ }
+ this.currentRowNumber = currentRowNumber;
+ }
}
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMResultSet.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMResultSet.java 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMResultSet.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -400,7 +400,7 @@
}
protected int getOffset() {
- return parameters;
+ return parameters > 0 ? 1 : 0;
}
protected int getAbsoluteRowNumber() {
Modified: trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestAllResultsImpl.java
===================================================================
--- trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestAllResultsImpl.java 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestAllResultsImpl.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -22,6 +22,7 @@
package com.metamatrix.jdbc;
+import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.sql.ResultSet;
@@ -38,10 +39,10 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import org.junit.Before;
+import org.junit.Test;
import org.mockito.Matchers;
-import junit.framework.TestCase;
-
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.common.types.MMJDBCSQLTypeInfo;
import com.metamatrix.common.util.TimestampWithTimezone;
@@ -51,7 +52,7 @@
import com.metamatrix.dqp.message.ResultsMessage;
import com.metamatrix.query.unittest.TimestampUtil;
-public class TestAllResultsImpl extends TestCase {
+public class TestAllResultsImpl {
private static final long REQUEST_ID = 0;
private static final int TYPE_FORWARD_ONLY = ResultSet.TYPE_FORWARD_ONLY;
@@ -59,17 +60,12 @@
private MMStatement statement;
- public TestAllResultsImpl(String name) {
- super(name);
+ @Before public void setUp() throws Exception {
+ statement = TestMMResultSet.createMockStatement(TYPE_SCROLL_SENSITIVE);
}
-
- @Override
- protected void setUp() throws Exception {
- statement = TestMMResultSet.createMockStatement();
- }
/** test hasNext(), actual result set should return FALSE. */
- public void testHasNext1() throws Exception {
+ @Test public void testHasNext1() throws Exception {
MMResultSet rs = new MMResultSet(exampleResultsMsg1(),
statement);
while (rs.next()) {
@@ -84,7 +80,7 @@
}
/** test hasNext(), actual result set should return TRUE. */
- public void testHasNext2() throws Exception {
+ @Test public void testHasNext2() throws Exception {
List[] results = exampleResults1(5);
MMResultSet rs = new MMResultSet(exampleResultsMsg1(),
statement);
@@ -104,7 +100,7 @@
* test next(), whether the result set's cursor is positioned on next row or
* not
*/
- public void testNext1() throws Exception {
+ @Test public void testNext1() throws Exception {
MMResultSet rs = new MMResultSet(exampleResultsMsg1(),
statement);
@@ -117,7 +113,7 @@
}
/** test next(), walk through all rows of a result set and compare each row. */
- public void testNext2() throws Exception {
+ @Test public void testNext2() throws Exception {
List[] results = exampleResults1(5);
MMResultSet rs = new MMResultSet(exampleResultsMsg1(),
statement);
@@ -135,7 +131,7 @@
}
/** test next(), get result set and close without walking through */
- public void testNext3() throws Exception {
+ @Test public void testNext3() throws Exception {
MMResultSet rs = new MMResultSet(exampleResultsMsg1(),
statement);
assertEquals(new Integer(0), new Integer(rs.getRow()));
@@ -144,7 +140,7 @@
}
/** test next(), walk through partial rows of a result set */
- public void testNext4() throws Exception {
+ @Test public void testNext4() throws Exception {
List[] results = exampleResults1(5);
MMResultSet rs = new MMResultSet(exampleResultsMsg1(),
statement);
@@ -160,7 +156,7 @@
}
/** test next(), when hasNext() == false */
- public void testNext5() throws Exception {
+ @Test public void testNext5() throws Exception {
MMResultSet rs = new MMResultSet(exampleResultsMsg1(),
statement);
while (rs.next()) {
@@ -175,7 +171,7 @@
}
/** test getObject() at columnIndex = 2 of 5th row */
- public void testGetObject1() throws Exception {
+ @Test public void testGetObject1() throws Exception {
List[] results = exampleResults2();
MMResultSet rs = new MMResultSet(exampleResultsMsg2a(),
statement);
@@ -199,7 +195,7 @@
}
/** Should fail, test getObject() at wrong columnIndex */
- public void testGetObject2() throws Exception {
+ @Test public void testGetObject2() throws Exception {
MMResultSet rs = new MMResultSet(exampleResultsMsg2a(),
statement);
@@ -218,7 +214,7 @@
rs.close();
}
- public void testGetRow() throws Exception {
+ @Test public void testGetRow() throws Exception {
MMResultSet rs = new MMResultSet(exampleResultsMsg2(),
statement);
@@ -233,7 +229,7 @@
}
- public void testPrevious() throws Exception {
+ @Test public void testPrevious() throws Exception {
List[] results = exampleResults1(5);
MMResultSet rs = new MMResultSet(exampleResultsMsg1(),
statement);
@@ -254,7 +250,7 @@
rs.close();
}
- public void testGetCurrentRecord() throws Exception {
+ @Test public void testGetCurrentRecord() throws Exception {
List[] results = exampleResults2();
MMResultSet rs = new MMResultSet(exampleResultsMsg2(),
statement);
@@ -265,7 +261,7 @@
rs.close();
}
- public void testGetMetaData() throws Exception {
+ @Test public void testGetMetaData() throws Exception {
MMResultSet rs = new MMResultSet(exampleResultsMsg2a(),
statement);
ResultSetMetaData rmetadata = rs.getMetaData();
@@ -280,20 +276,20 @@
rs.close();
}
- public void testResultsWarnings() throws Exception {
+ @Test public void testResultsWarnings() throws Exception {
MMResultSet rs = new MMResultSet(exampleResultsMsg2(),
statement);
rs.close();
}
- public void testClose() throws Exception {
+ @Test public void testClose() throws Exception {
MMResultSet rs = new MMResultSet(exampleResultsMsg2(),
statement);
rs.close();
verify(statement, times(0)).close();
}
- public void testGetFetchSize() throws Exception {
+ @Test public void testGetFetchSize() throws Exception {
MMStatement s = mock(MMStatement.class);
stub(s.getFetchSize()).toReturn(500);
MMResultSet rs = new MMResultSet(exampleResultsMsg2(), s);
@@ -304,27 +300,17 @@
// //////////////////////Functions refer to ResultSet's TYPE_FORWARD_ONLY///
// /////////////////
- public void testIsAfterLast1() throws Exception {
+ @Test(expected=SQLException.class) public void testIsAfterLast1() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_FORWARD_ONLY);
-
- // the last row
rs.last();
- boolean actual = rs.isAfterLast();
- assertEquals(false, actual);
- rs.close();
}
- public void testAfterLast1() throws Exception {
+ @Test(expected=SQLException.class) public void testAfterLast1() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_FORWARD_ONLY);
-
- // move cursor right past the last row
rs.afterLast();
- assertEquals(0, rs.getRow());
- rs.close();
-
}
- public void testIsBeforeFirst1() throws Exception {
+ @Test public void testIsBeforeFirst1() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_FORWARD_ONLY);
// right before the first row
@@ -333,7 +319,7 @@
rs.close();
}
- public void testIsBeforeFirst2() throws Exception {
+ @Test public void testIsBeforeFirst2() throws Exception {
MMResultSet rs = helpGetNoResults(TYPE_FORWARD_ONLY);
// right before the first row
@@ -342,7 +328,7 @@
rs.close();
}
- public void testBeforeFirst1() throws Exception {
+ @Test(expected=SQLException.class) public void testBeforeFirst1() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_FORWARD_ONLY);
// move cursor to the first row
@@ -350,12 +336,9 @@
// move back to before first row
rs.beforeFirst();
-
- assertEquals(0, rs.getRow());
- rs.close();
}
- public void testIsFirst1() throws Exception {
+ @Test public void testIsFirst1() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_FORWARD_ONLY);
// move cursor to the first row
@@ -365,7 +348,7 @@
rs.close();
}
- public void testIsFirst2() throws Exception {
+ @Test public void testIsFirst2() throws Exception {
MMResultSet rs = helpGetNoResults(TYPE_FORWARD_ONLY);
// move cursor to the first row
@@ -375,27 +358,23 @@
rs.close();
}
- public void testFirst1() throws Exception {
+ @Test(expected=SQLException.class) public void testFirst1() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_FORWARD_ONLY);
// move cursor to the first row
rs.next();
- boolean actual = rs.first();
- assertEquals(true, actual);
- rs.close();
+ rs.first();
}
- public void testFirst2() throws Exception {
+ @Test(expected=SQLException.class) public void testFirst2() throws Exception {
MMResultSet rs = helpGetNoResults(TYPE_FORWARD_ONLY);
// move cursor to the first row
rs.next();
- boolean actual = rs.first();
- assertEquals(false, actual);
- rs.close();
+ rs.first();
}
- public void testFindColumn() throws Exception {
+ @Test public void testFindColumn() throws Exception {
MMResultSet rs = new MMResultSet(exampleResultsMsg2a(),
statement);
@@ -403,45 +382,29 @@
rs.close();
}
- public void testIsLast1() throws Exception {
+ @Test public void testIsLast1() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_FORWARD_ONLY);
// move cursor to the last row
- rs.last();
boolean actual = rs.isLast();
- assertEquals(true, actual);
- rs.close();
+ assertEquals(false, actual);
}
- public void testIsLast2() throws Exception {
+ @Test public void testIsLast2() throws Exception {
MMResultSet rs = helpGetNoResults(TYPE_FORWARD_ONLY);
// move cursor to the last row
- rs.last();
boolean actual = rs.isLast();
assertEquals(false, actual);
- rs.close();
}
- public void testLast1() throws Exception {
+ @Test(expected=SQLException.class) public void testLast1() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_FORWARD_ONLY);
- // check whether the movement of cursor is successful
- boolean actual = rs.last();
- assertEquals(true, actual);
- rs.close();
+ rs.last();
}
- public void testLast2() throws Exception {
- MMResultSet rs = helpGetNoResults(TYPE_FORWARD_ONLY);
-
- // check whether the movement of cursor is successful
- boolean actual = rs.last();
- assertEquals(false, actual);
- rs.close();
- }
-
- public void testRelative1() throws Exception {
+ @Test public void testRelative1() throws Exception {
MMResultSet rs = new MMResultSet(exampleResultsMsg2(),
statement);
@@ -458,28 +421,16 @@
rs.close();
}
- public void testAbsolute1() throws Exception {
+ @Test(expected=SQLException.class) public void testAbsolute1() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_FORWARD_ONLY);
- // check whether the movement of cursor is successful
- boolean actual = rs.absolute(1);
- assertEquals(true, actual);
- rs.close();
+ rs.absolute(1);
}
- public void testAbsolute2() throws Exception {
- MMResultSet rs = helpGetNoResults(TYPE_FORWARD_ONLY);
-
- // check whether the movement of cursor is successful
- boolean actual = rs.absolute(1);
- assertEquals(false, actual);
- rs.close();
- }
-
// //////////Functions refer to other types other than ResultSet's
// TYPE_FORWARD_ONLY//////
- public void testAfterLast1a() throws Exception {
+ @Test public void testAfterLast1a() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// move cursor right past the last row
@@ -490,7 +441,7 @@
rs.close();
}
- public void testIsAfterLast1a() throws Exception {
+ @Test public void testIsAfterLast1a() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// the last row
@@ -505,7 +456,7 @@
rs.close();
}
- public void testIsBeforeFirst1a() throws Exception {
+ @Test public void testIsBeforeFirst1a() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// right before the first row
@@ -514,7 +465,7 @@
rs.close();
}
- public void testBeforeFirst1a() throws Exception {
+ @Test public void testBeforeFirst1a() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// move cursor to the first row
@@ -528,7 +479,7 @@
rs.close();
}
- public void testIsFirst1a() throws Exception {
+ @Test public void testIsFirst1a() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// move cursor to the first row
@@ -541,7 +492,7 @@
rs.close();
}
- public void testFirst1a() throws Exception {
+ @Test public void testFirst1a() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// move cursor to the first row
@@ -563,7 +514,7 @@
rs.close();
}
- public void testIsLast1a() throws Exception {
+ @Test public void testIsLast1a() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// check whether the movement of cursor is successful
@@ -576,7 +527,7 @@
rs.close();
}
- public void testLast1a() throws Exception {
+ @Test public void testLast1a() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// check whether the movement of cursor is successful
@@ -589,7 +540,7 @@
}
/** normal relative move, only including moving from valid row to valid one */
- public void testRelative1a() throws Exception {
+ @Test public void testRelative1a() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// move to 1st row
@@ -607,7 +558,7 @@
}
/** normal relative move, including moving from valid row to invalid one */
- public void testRelative1b() throws Exception {
+ @Test public void testRelative1b() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// move to 1st row
@@ -635,7 +586,7 @@
}
/** check only moving from an invalid row */
- public void testRelative1c() throws Exception {
+ @Test public void testRelative1c() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// test if move before first will work or not
@@ -685,7 +636,7 @@
}
/** test only valid row in result set */
- public void testAbsolute1a() throws Exception {
+ @Test public void testAbsolute1a() throws Exception {
MMResultSet rs = helpGetResultSetImpl(TYPE_SCROLL_SENSITIVE);
// start from beginning
@@ -710,7 +661,7 @@
}
/** test only valid row in result set */
- public void testAbsolute2a() throws Exception {
+ @Test public void testAbsolute2a() throws Exception {
MMResultSet rs = helpGetNoResults(TYPE_SCROLL_SENSITIVE);
// start from beginning
@@ -729,7 +680,7 @@
* Case 4293 - timestamps for begin and end processing should both be set
* server-side (from the same system clock)
*/
- public void testProcessingTime() throws Exception {
+ @Test public void testProcessingTime() throws Exception {
RequestMessage request = new RequestMessage();
request.setProcessingTimestamp(new Date(12345678L));
ResultsMessage resultsMsg = new ResultsMessage(request);
@@ -757,7 +708,7 @@
/**
* 3 batches
*/
- public void testMoreResults() throws Exception {
+ @Test public void testMoreResults() throws Exception {
int fetchSize = 5;
int batchLength = 4;
int totalLength = 10;
@@ -795,8 +746,7 @@
}
ResultsMessage msg = exampleResultsMsg4(1, batchLength, fetchSize, batchLength == totalLength);
- MMResultSet rs = new MMResultSet(msg, statement);
- return rs;
+ return new MMResultSet(msg, statement);
}
// /////////////////////Helper Method///////////////////
@@ -844,12 +794,14 @@
private MMResultSet helpGetResultSetImpl(int type)
throws SQLException {
ResultsMessage rsMsg = exampleResultsMsg2();
+ statement = TestMMResultSet.createMockStatement(type);
MMResultSet rs = new MMResultSet(rsMsg, statement);
return rs;
}
private MMResultSet helpGetNoResults(int type) throws SQLException {
ResultsMessage rsMsg = exampleResultsMsg3();
+ statement = TestMMResultSet.createMockStatement(type);
MMResultSet rs = new MMResultSet(rsMsg, statement);
return rs;
}
@@ -913,7 +865,7 @@
return resultsMsg;
}
- public void testNotCallingNext() throws SQLException {
+ @Test public void testNotCallingNext() throws SQLException {
MMResultSet cs = new MMResultSet(exampleResultsMsg2a(),
statement);
@@ -925,7 +877,7 @@
}
}
- public void testDateType() throws SQLException {
+ @Test public void testDateType() throws SQLException {
RequestMessage request = new RequestMessage();
request.setProcessingTimestamp(new Date(1L));
request.setExecutionId(REQUEST_ID);
@@ -947,8 +899,8 @@
assertEquals(new Timestamp(0), rs.getTimestamp(1, Calendar.getInstance(TimeZone.getTimeZone("GMT-05:00")))); //$NON-NLS-1$
}
- public void testWasNull() throws SQLException{
- ResultsMessage message = exampleMessage(new List[] { Arrays.asList((String)null), Arrays.asList("1") }, new String[] { "string" }, //$NON-NLS-1$ //$NON-NLS-1$
+ @Test public void testWasNull() throws SQLException{
+ ResultsMessage message = exampleMessage(new List[] { Arrays.asList((String)null), Arrays.asList("1") }, new String[] { "string" }, //$NON-NLS-1$
new String[] { MMJDBCSQLTypeInfo.STRING });
MMResultSet rs = new MMResultSet(message, statement);
assertTrue(rs.next());
@@ -960,9 +912,9 @@
assertTrue(rs.wasNull());
assertEquals(0l, rs.getLong(1));
assertTrue(rs.wasNull());
- assertEquals(0f, rs.getFloat(1));
+ assertEquals(0f, rs.getFloat(1), 0);
assertTrue(rs.wasNull());
- assertEquals(0d, rs.getDouble(1));
+ assertEquals(0d, rs.getDouble(1), 0);
assertTrue(rs.wasNull());
assertNull(rs.getString(1));
assertTrue(rs.wasNull());
@@ -972,7 +924,7 @@
assertFalse(rs.next());
}
- public void testGetters() throws SQLException{
+ @Test public void testGetters() throws SQLException{
TimeZone.setDefault(TimeZone.getTimeZone("GMT-05:00")); //$NON-NLS-1$
ResultsMessage message = exampleMessage(new List[] { Arrays.asList(1, TimestampUtil.createTime(0, 0, 0), TimestampUtil.createDate(1, 1, 1), TimestampUtil.createTimestamp(1, 1, 1, 1, 1, 1, 1), "<root/>") }, //$NON-NLS-1$
new String[] { "int", "time", "date", "timestamp", "sqlxml" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
@@ -984,8 +936,8 @@
assertEquals(1, rs.getShort(1));
assertEquals(1, rs.getInt(1));
assertEquals(1l, rs.getLong(1));
- assertEquals(1f, rs.getFloat(1));
- assertEquals(1d, rs.getDouble(1));
+ assertEquals(1f, rs.getFloat(1), 0);
+ assertEquals(1d, rs.getDouble(1), 0);
assertEquals("1", rs.getString(1)); //$NON-NLS-1$
assertEquals(Integer.valueOf(1), rs.getObject(1));
//the mock statement is in GMT-6 the server results are from GMT-5, so we expect them to display the same
Modified: trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestBatchResults.java
===================================================================
--- trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestBatchResults.java 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestBatchResults.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -22,20 +22,20 @@
package com.metamatrix.jdbc;
+import static org.junit.Assert.*;
+
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
+import org.junit.Test;
+
import com.metamatrix.jdbc.BatchResults.Batch;
-import junit.framework.TestCase;
-
-
-
/**
* @since 4.3
*/
-public class TestBatchResults extends TestCase {
+public class TestBatchResults {
static class MockBatchFetcher implements BatchFetcher {
@@ -81,10 +81,6 @@
}
- public TestBatchResults (String name) {
- super(name);
- }
-
private static List[] createBatch(int begin, int end) {
List[] results = new List[end - begin + 1];
for(int i=0; i<(end - begin + 1); i++) {
@@ -98,9 +94,8 @@
List[] results = new List[0];
return results;
}
-
- public void testGetCurrentRow1() throws Exception{
+ @Test public void testGetCurrentRow1() throws Exception{
//empty batch
BatchResults batchResults = new BatchResults(createEmptyBatch(), 0, 0, true);
assertNull(batchResults.getCurrentRow());
@@ -108,7 +103,7 @@
assertNull(batchResults.getCurrentRow());
}
- public void testGetCurrentRow2() throws Exception{
+ @Test public void testGetCurrentRow2() throws Exception{
BatchResults batchResults = new BatchResults(createBatch(1, 10), 1, 10, true);
assertNull(batchResults.getCurrentRow());
batchResults.next();
@@ -117,30 +112,30 @@
assertEquals(batchResults.getCurrentRow(), expectedResult);
}
- public void testHasNext1() throws Exception{
+ @Test public void testHasNext1() throws Exception{
//empty batch
BatchResults batchResults = new BatchResults(createEmptyBatch(), 0, 0, true);
assertFalse(batchResults.hasNext());
}
- public void testHasNext2() throws Exception{
+ @Test public void testHasNext2() throws Exception{
//one row batch
BatchResults batchResults = new BatchResults(createBatch(1, 1), 1, 1, true);
assertTrue(batchResults.hasNext());
}
- public void testHasNext3() throws Exception{
+ @Test public void testHasNext3() throws Exception{
BatchResults batchResults = new BatchResults(createBatch(1, 10), 1, 10, true);
assertTrue(batchResults.hasNext());
}
- public void testNext1() throws Exception{
+ @Test public void testNext1() throws Exception{
//empty batch
BatchResults batchResults = new BatchResults(createEmptyBatch(), 0, 0, true);
assertFalse(batchResults.next());
}
- public void testNext2() throws Exception{
+ @Test public void testNext2() throws Exception{
//one row batch
BatchResults batchResults = new BatchResults(createBatch(1, 1), 1, 1, true);
assertTrue(batchResults.next());
@@ -150,7 +145,7 @@
assertFalse(batchResults.next());
}
- public void testNext3() throws Exception{
+ @Test public void testNext3() throws Exception{
//one row batch, multiple batches
BatchResults batchResults = new BatchResults(createBatch(1, 1), 1, 1, false);
batchResults.setBatchFetcher(new MockBatchFetcher());
@@ -161,7 +156,7 @@
assertEquals(batchResults.getCurrentRow(), expectedResult);
}
- public void testNext4() throws Exception{
+ @Test public void testNext4() throws Exception{
BatchResults batchResults = new BatchResults(createBatch(1, 10), 1, 10, false);
batchResults.setBatchFetcher(new MockBatchFetcher());
int i;
@@ -179,13 +174,13 @@
assertFalse(batchResults.next());
}
- public void testHasPrevious1() throws Exception{
+ @Test public void testHasPrevious1() throws Exception{
//empty batch
BatchResults batchResults = new BatchResults(createEmptyBatch(), 0, 0, true);
assertFalse(batchResults.hasPrevious());
}
- public void testHasPrevious2() throws Exception{
+ @Test public void testHasPrevious2() throws Exception{
//one row batch
BatchResults batchResults = new BatchResults(createBatch(1, 1), 1, 1, true);
assertFalse(batchResults.hasPrevious());
@@ -195,13 +190,13 @@
assertTrue(batchResults.hasPrevious());
}
- public void testPrevious1() throws Exception{
+ @Test public void testPrevious1() throws Exception{
//empty batch
BatchResults batchResults = new BatchResults(createEmptyBatch(), 0, 0, true);
assertFalse(batchResults.previous());
}
- public void testPrevious2() throws Exception{
+ @Test public void testPrevious2() throws Exception{
//one row batch
BatchResults batchResults = new BatchResults(createBatch(1, 1), 1, 1, true);
assertTrue(batchResults.next());
@@ -214,7 +209,7 @@
assertEquals(batchResults.getCurrentRow(), expectedResult);
}
- public void testPrevious3() throws Exception{
+ @Test public void testPrevious3() throws Exception{
//one row batch, multiple batches
BatchResults batchResults = new BatchResults(createBatch(1, 1), 1, 1, false);
batchResults.setBatchFetcher(new MockBatchFetcher());
@@ -235,7 +230,7 @@
assertEquals(batchResults.getCurrentRow(), expectedResult);
}
- public void testPrevious4() throws Exception{
+ @Test public void testPrevious4() throws Exception{
BatchResults batchResults = new BatchResults(createBatch(1, 10), 1, 10, false);
batchResults.setBatchFetcher(new MockBatchFetcher());
int i;
@@ -250,14 +245,14 @@
}
}
- public void testAbsolute1() throws Exception{
+ @Test public void testAbsolute1() throws Exception{
//empty batch
BatchResults batchResults = new BatchResults(createEmptyBatch(), 0, 0, true);
assertFalse(batchResults.absolute(0));
assertFalse(batchResults.absolute(1));
}
- public void testAbsolute2() throws Exception{
+ @Test public void testAbsolute2() throws Exception{
//one row batch
BatchResults batchResults = new BatchResults(createBatch(1, 1), 1, 1, true);
batchResults.setBatchFetcher(new MockBatchFetcher());
@@ -269,7 +264,7 @@
assertEquals(batchResults.getCurrentRow(), expectedResult);
}
- public void testAbsolute3() throws Exception{
+ @Test public void testAbsolute3() throws Exception{
BatchResults batchResults = new BatchResults(createBatch(1, 10), 1, 10, false);
batchResults.setBatchFetcher(new MockBatchFetcher(200));
assertFalse(batchResults.absolute(0));
@@ -288,7 +283,7 @@
}
//move backwards with absolute
- public void testAbsolute4() throws Exception{
+ @Test public void testAbsolute4() throws Exception{
//one row batch
BatchResults batchResults = new BatchResults(createBatch(1, 1), 1, 1, false);
batchResults.setBatchFetcher(new MockBatchFetcher());
@@ -299,7 +294,7 @@
assertEquals(batchResults.getCurrentRow(), expectedResult);
}
- public void testAbsolute5() throws Exception{
+ @Test public void testAbsolute5() throws Exception{
//one row batch
BatchResults batchResults = new BatchResults(createBatch(1, 1), 1, 1, false);
batchResults.setBatchFetcher(new MockBatchFetcher());
@@ -311,7 +306,7 @@
assertFalse(batchResults.absolute(-100));
}
- public void testCurrentRowNumber() throws Exception {
+ @Test public void testCurrentRowNumber() throws Exception {
BatchResults batchResults = new BatchResults(createBatch(1, 1), 1, 1, true);
assertEquals(0, batchResults.getCurrentRowNumber());
batchResults.next();
@@ -322,7 +317,7 @@
assertEquals(2, batchResults.getCurrentRowNumber());
}
- public void testSetException() throws Exception {
+ @Test public void testSetException() throws Exception {
BatchResults batchResults = new BatchResults(createBatch(1, 1), 1, 1, false);
MockBatchFetcher batchFetcher = new MockBatchFetcher();
batchResults.setBatchFetcher(batchFetcher);
@@ -335,7 +330,7 @@
}
}
- public void testBatching() throws Exception {
+ @Test public void testBatching() throws Exception {
BatchResults batchResults = new BatchResults(createBatch(1, 10), 1, 10, false);
MockBatchFetcher batchFetcher = new MockBatchFetcher(60);
batchResults.setBatchFetcher(batchFetcher);
Modified: trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestMMResultSet.java
===================================================================
--- trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestMMResultSet.java 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/client-jdbc/src/test/java/com/metamatrix/jdbc/TestMMResultSet.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -22,6 +22,7 @@
package com.metamatrix.jdbc;
+import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.sql.ResultSet;
@@ -29,32 +30,30 @@
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import java.util.TimeZone;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
-import junit.framework.TestCase;
+import org.junit.Test;
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.dqp.client.ClientSideDQP;
+import com.metamatrix.dqp.message.ResultsMessage;
-public class TestMMResultSet extends TestCase {
+public class TestMMResultSet {
- public TestMMResultSet(String name) {
- super(name);
- }
-
/** test next() without walking through */
- public void testNext1() throws SQLException {
+ @Test public void testNext1() throws SQLException {
ResultSet cs = helpExecuteQuery();
assertEquals(" Actual doesn't match with expected. ", new Integer(0), new Integer(cs.getRow())); //$NON-NLS-1$
cs.close();
}
/** test next() with walking through all the rows and compare records */
- public void testNext2() throws SQLException {
+ @Test public void testNext2() throws SQLException {
List[] expected = TestAllResultsImpl.exampleResults1(1000);
MMResultSet cs = helpExecuteQuery();
@@ -75,37 +74,37 @@
public static final int PROC_BATCH_SIZE = 100;
/** Test stability when next() is called beyond the rowcount. */
- public void testNextBeyondEnd_fetchEqualsCount() throws Exception {
+ @Test public void testNextBeyondEnd_fetchEqualsCount() throws Exception {
helpTestNextBeyondResultSet(1000, 1000);
}
/** Test stability when next() is called beyond the rowcount. */
- public void testNextBeyondEnd_fetchLessThanCount() throws Exception {
+ @Test public void testNextBeyondEnd_fetchLessThanCount() throws Exception {
helpTestNextBeyondResultSet(100, 1000);
}
/** Test stability when next() is called beyond the rowcount with one more row. */
- public void testNextBeyondEnd_fetchLessThanCount1() throws Exception {
+ @Test public void testNextBeyondEnd_fetchLessThanCount1() throws Exception {
helpTestNextBeyondResultSet(100, 101);
}
/** Test stability when next() is called beyond the rowcount. */
- public void testNextBeyondEnd_fetchLessThanCountNonMultiple() throws Exception {
+ @Test public void testNextBeyondEnd_fetchLessThanCountNonMultiple() throws Exception {
helpTestNextBeyondResultSet(120, 1000);
}
/** Test stability when next() is called beyond the rowcount. */
- public void testNextBeyondEnd_fetchGreaterThanCount() throws Exception {
+ @Test public void testNextBeyondEnd_fetchGreaterThanCount() throws Exception {
helpTestNextBeyondResultSet(300, PROC_BATCH_SIZE);
}
/** Test stability when next() is called beyond the rowcount. */
- public void testNextBeyondEnd_fetchGreaterThanCountNonMultiple() throws Exception {
+ @Test public void testNextBeyondEnd_fetchGreaterThanCountNonMultiple() throws Exception {
helpTestNextBeyondResultSet(310, PROC_BATCH_SIZE-50);
}
/** Test stability when next() is called beyond the rowcount. */
- public void testNextBeyondEnd_fetchGreaterThanCountNonMultiple2() throws Exception {
+ @Test public void testNextBeyondEnd_fetchGreaterThanCountNonMultiple2() throws Exception {
helpTestNextBeyondResultSet(300, PROC_BATCH_SIZE+10);
}
@@ -113,12 +112,12 @@
* fetchSize < rows < proc batch size.
* Test for defect 11356
*/
- public void testNextBeyondEnd_fetchLessThanCount_ResultsBetweenFetchAndProcBatch() throws Exception {
+ @Test public void testNextBeyondEnd_fetchLessThanCount_ResultsBetweenFetchAndProcBatch() throws Exception {
helpTestNextBeyondResultSet(30, PROC_BATCH_SIZE-25);
}
public void helpTestNextBeyondResultSet(int fetchSize, int numRows) throws Exception {
- ResultSet cs = helpExecuteQuery(fetchSize, numRows);
+ ResultSet cs = helpExecuteQuery(fetchSize, numRows, ResultSet.TYPE_SCROLL_INSENSITIVE);
try {
Object lastRowValue = null;
for (int rowNum = 1; rowNum <= numRows; rowNum++) {
@@ -144,7 +143,7 @@
}
/** test both next() and previous() -- when result set scroll in bidirection */
- public void testBidirection() throws SQLException {
+ @Test public void testBidirection() throws SQLException {
MMResultSet cs = helpExecuteQuery();
assertNotNull(cs);
cs.absolute(290);
@@ -161,14 +160,14 @@
}
/** test hasNext() without walking through any row */
- public void testHasNext1() throws SQLException {
+ @Test public void testHasNext1() throws SQLException {
MMResultSet cs = helpExecuteQuery();
assertEquals(" hasNext() doesn't match expected value. ", true, cs.hasNext()); //$NON-NLS-1$
cs.close();
}
/** test hasNext() with blocking for the Next batch -- triggering point */
- public void testHasNext2() throws SQLException {
+ @Test public void testHasNext2() throws SQLException {
MMResultSet cs = helpExecuteQuery();
cs.absolute(100);
assertEquals(" hasNext() doesn't match expected value. ", true, cs.hasNext()); //$NON-NLS-1$
@@ -176,7 +175,7 @@
}
/** test hasNext() with nextBatch!=null -- short response */
- public void testHasNext3() throws SQLException {
+ @Test public void testHasNext3() throws SQLException {
MMResultSet cs = helpExecuteQuery();
int i = 0;
while (cs.next()) {
@@ -190,7 +189,7 @@
}
/** at the end of all batches */
- public void testHasNext4() throws SQLException {
+ @Test public void testHasNext4() throws SQLException {
MMResultSet cs = helpExecuteQuery();
cs.absolute(1000);
assertTrue(!cs.hasNext());
@@ -198,7 +197,7 @@
}
/** walk all way through from the end back to first row */
- public void testPrevious1() throws SQLException {
+ @Test public void testPrevious1() throws SQLException {
MMResultSet cs = helpExecuteQuery();
List[] expected = TestAllResultsImpl.exampleResults1(1000);
while(cs.next()) {
@@ -218,7 +217,7 @@
}
/** test the previous in the middle of a batch */
- public void testPrevious2() throws SQLException {
+ @Test public void testPrevious2() throws SQLException {
MMResultSet cs = helpExecuteQuery();
cs.absolute(290);
@@ -229,9 +228,9 @@
}
/** walk all way through from the end back to first row */
- public void testPrevious3() throws SQLException {
+ @Test public void testPrevious3() throws Exception {
//large batch size
- MMResultSet cs = helpExecuteQuery(600, 10000);
+ MMResultSet cs = helpExecuteQuery(600, 10000, ResultSet.TYPE_SCROLL_INSENSITIVE);
List[] expected = TestAllResultsImpl.exampleResults1(10000);
while(cs.next()) {
}
@@ -249,9 +248,9 @@
}
/** walk all way through from the end back to first row */
- public void testPrevious4() throws SQLException {
+ @Test public void testPrevious4() throws Exception {
//small batch size
- MMResultSet cs = helpExecuteQuery(50, 1000);
+ MMResultSet cs = helpExecuteQuery(50, 1000, ResultSet.TYPE_SCROLL_INSENSITIVE);
List[] expected = TestAllResultsImpl.exampleResults1(1000);
while(cs.next()) {
//System.out.println(" rs.next == " + cs.getCurrentRecord());
@@ -270,7 +269,7 @@
}
/** test rare case that cursor change direction */
- public void testChangeDirection() throws SQLException {
+ @Test public void testChangeDirection() throws SQLException {
MMResultSet cs = helpExecuteQuery();
cs.absolute(291);
cs.previous();
@@ -279,7 +278,7 @@
cs.close();
}
- public void testIsFirst() throws SQLException {
+ @Test public void testIsFirst() throws SQLException {
MMResultSet cs = helpExecuteQuery();
cs.next();
assertTrue(cs.isFirst());
@@ -287,7 +286,7 @@
}
/** test cursor is in the middle of all batches */
- public void testIsLast1() throws SQLException {
+ @Test public void testIsLast1() throws SQLException {
MMResultSet cs = helpExecuteQuery();
cs.next();
assertTrue(!cs.isLast());
@@ -295,7 +294,7 @@
}
/** test cursor at the triggering point -- blocking case*/
- public void testIsLast2() throws SQLException {
+ @Test public void testIsLast2() throws SQLException {
MMResultSet cs = helpExecuteQuery();
int i = 0;
@@ -311,20 +310,20 @@
}
/** test cursor at the last row of all batches */
- public void testIsLast3() throws SQLException {
+ @Test public void testIsLast3() throws SQLException {
MMResultSet cs = helpExecuteQuery();
cs.absolute(1000);
assertTrue(cs.isLast());
cs.close();
}
- public void testIsBeforeFirst() throws SQLException {
+ @Test public void testIsBeforeFirst() throws SQLException {
MMResultSet cs = helpExecuteQuery();
assertTrue(cs.isBeforeFirst());
cs.close();
}
- public void testBeforeFirst() throws SQLException {
+ @Test public void testBeforeFirst() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// move to row 1
@@ -337,7 +336,7 @@
cs.close();
}
- public void testFirst() throws SQLException {
+ @Test public void testFirst() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// move to row #2
@@ -351,7 +350,7 @@
cs.close();
}
- public void testAfterLast() throws SQLException {
+ @Test public void testAfterLast() throws SQLException {
MMResultSet cs = helpExecuteQuery();
cs.afterLast();
assertTrue(cs.isAfterLast());
@@ -359,7 +358,7 @@
}
/** right after the last row */
- public void testIsAfterLast1() throws SQLException {
+ @Test public void testIsAfterLast1() throws SQLException {
MMResultSet cs = helpExecuteQuery();
cs.absolute(1000);
cs.next();
@@ -368,14 +367,14 @@
}
/** right before the first */
- public void testIsAfterLast2() throws Exception {
+ @Test public void testIsAfterLast2() throws Exception {
MMResultSet cs = helpExecuteQuery();
assertTrue(!cs.isAfterLast());
cs.close();
}
/** absolute with cursor movement backward in the same batch -- absolute(positive) */
- public void testAbsolute1() throws SQLException {
+ @Test public void testAbsolute1() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// move to row #2
@@ -390,7 +389,7 @@
}
/** absolute with cursor movement forward in the same batch -- absolute(positive) */
- public void testAbsolute2() throws SQLException {
+ @Test public void testAbsolute2() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// move to row #2
@@ -405,7 +404,7 @@
}
/** absolute with cursor movement forward -- absolute(positive) -- blocking */
- public void testAbsolute3() throws SQLException {
+ @Test public void testAbsolute3() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// move to row #2
@@ -420,7 +419,7 @@
}
/** absolute with cursor movement forward -- absolute(positive) -- triggering point */
- public void testAbsolute4() throws SQLException {
+ @Test public void testAbsolute4() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// move to row #2
@@ -435,7 +434,7 @@
}
/** absolute with cursor movement back in the same batch -- absolute(negative) */
- public void testAbsolute5() throws SQLException {
+ @Test public void testAbsolute5() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// move to row #2
@@ -450,7 +449,7 @@
}
/** absolute after last row */
- public void testAbsolute6() throws SQLException {
+ @Test public void testAbsolute6() throws SQLException {
MMResultSet cs = helpExecuteQuery();
cs.absolute(1005);
// Cursor should be after last row. getRow() should return 0 because
@@ -460,7 +459,7 @@
}
/** relative(positive) -- forward to another batch */
- public void testRelative1() throws SQLException {
+ @Test public void testRelative1() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// move to the row #3
@@ -474,7 +473,7 @@
}
/** relative(negative) -- backward to another batch */
- public void testRelative2() throws SQLException {
+ @Test public void testRelative2() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// move to the row #137
@@ -488,7 +487,7 @@
}
/** relative(negative) -- backward to triggering point or blocking batch */
- public void testRelative3() throws SQLException {
+ @Test public void testRelative3() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// move to the row #137
@@ -502,7 +501,7 @@
}
/** relative(negative) -- backward to triggering point or blocking batch */
- public void testRelative4() throws SQLException {
+ @Test public void testRelative4() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// move to the row #237 in the third batch, so that the fourth batch has been requested when we switch direction
@@ -516,7 +515,7 @@
}
/** in the first fetched batch */
- public void testGetRow1() throws SQLException {
+ @Test public void testGetRow1() throws SQLException {
ResultSet cs = helpExecuteQuery();
int i = 0;
@@ -532,7 +531,7 @@
}
/** in the first batch */
- public void testGetRow2() throws SQLException {
+ @Test public void testGetRow2() throws SQLException {
ResultSet cs = helpExecuteQuery();
cs.next();
@@ -541,7 +540,7 @@
}
/** in the triggering point -- blocking */
- public void testGetRow3() throws SQLException {
+ @Test public void testGetRow3() throws SQLException {
ResultSet cs = helpExecuteQuery();
int i = 0;
while (cs.next()) {
@@ -554,7 +553,7 @@
cs.close();
}
- public void testGetCurrentRecord() throws SQLException {
+ @Test public void testGetCurrentRecord() throws SQLException {
ResultSet cs = helpExecuteQuery();
cs.absolute(103);
assertEquals(" Current record doesn't match with expected one.", new Integer(103), ((MMResultSet)cs).getCurrentRecord().get(0)); //$NON-NLS-1$
@@ -562,14 +561,14 @@
}
/** test close() without walking through any of the record*/
- public void testClose() throws SQLException {
+ @Test public void testClose() throws SQLException {
MMResultSet cs = helpExecuteQuery();
assertEquals(" Actual doesn't match with expected. ", new Integer(0), new Integer(cs.getRow())); //$NON-NLS-1$
cs.close();
}
/** test basic results-related metadata */
- public void testGetMetaData() throws SQLException {
+ @Test public void testGetMetaData() throws SQLException {
MMResultSet cs = helpExecuteQuery();
// check result set metadata
@@ -590,7 +589,7 @@
cs.close();
}
- public void testFindColumn() throws SQLException {
+ @Test public void testFindColumn() throws SQLException {
MMResultSet cs = helpExecuteQuery();
ResultSetMetaData rm = cs.getMetaData();
assertNotNull(rm);
@@ -599,7 +598,7 @@
cs.close();
}
- public void testFindNonExistentColumn() throws SQLException {
+ @Test public void testFindNonExistentColumn() throws SQLException {
ResultSet rs = helpExecuteQuery();
rs.next();
try {
@@ -614,13 +613,13 @@
rs.close();
}
- public void testGetStatement() throws SQLException {
+ @Test public void testGetStatement() throws SQLException {
MMResultSet cs = helpExecuteQuery();
assertNotNull(cs.getStatement());
cs.close();
}
- public void testGetPlanDescription() throws SQLException {
+ @Test public void testGetPlanDescription() throws SQLException {
MMResultSet cs = helpExecuteQuery();
assertNotNull(cs);
@@ -629,7 +628,7 @@
}
/** getObject(String) */
- public void testGetObject2() throws SQLException {
+ @Test public void testGetObject2() throws SQLException {
ResultSet cs = helpExecuteQuery();
// move to the 1st row
@@ -638,19 +637,19 @@
cs.close();
}
- public void testGetWarnings() throws SQLException {
+ @Test public void testGetWarnings() throws SQLException {
ResultSet cs = helpExecuteQuery();
assertNull(cs.getWarnings());
cs.close();
}
- public void testGetCursorName() throws SQLException {
+ @Test public void testGetCursorName() throws SQLException {
MMResultSet cs = helpExecuteQuery();
assertNull(cs.getCursorName());
cs.close();
}
- public void testAllGetters() throws SQLException {
+ @Test public void testAllGetters() throws SQLException {
MMResultSet cs = helpExecuteQuery();
cs.next();
assertEquals(" Actual value of getInt() doesn't match with expected one. ", 1, cs.getInt("IntKey")); //$NON-NLS-1$ //$NON-NLS-2$
@@ -664,7 +663,7 @@
}
/** test wasNull() for ResultSet, this result actually is not a cursor result, but AllResults here. */
- public void testWasNull() throws SQLException {
+ @Test public void testWasNull() throws SQLException {
ResultSet cs = helpExecuteQuery();
cs.next();
assertNotNull(cs.getObject("IntKey")); //$NON-NLS-1$
@@ -672,38 +671,64 @@
}
/** test getProcessingTime() -- include test for getProcessingTimestamp() and getCompletedTimestamp() */
- public void testGetProcessingTime() throws SQLException {
+ @Test public void testGetProcessingTime() throws SQLException {
MMResultSet cs = helpExecuteQuery();
assertTrue(cs.getProcessingTime() == cs.getCompletedTimestamp().getTime() - 1);
cs.close();
}
+
+ @Test public void testForwardOnly() throws Exception {
+ MMResultSet cs = helpExecuteQuery(400, 1000, ResultSet.TYPE_FORWARD_ONLY);
+
+ while (cs.next()) {
+ cs.getObject(1);
+ }
+
+ assertTrue(cs.isAfterLast());
+ cs.close();
+ }
+
+ @Test public void testOutputParameter() throws Exception {
+ MMStatement statement = createMockStatement(ResultSet.TYPE_FORWARD_ONLY);
+ ResultsMessage resultsMsg = new ResultsMessage();
+ resultsMsg.setResults(new List<?>[] {Arrays.asList(1, null, null), Arrays.asList(null, 2, 3)});
+ resultsMsg.setLastRow(2);
+ resultsMsg.setFirstRow(1);
+ resultsMsg.setFinalRow(2);
+ resultsMsg.setColumnNames(new String[] {"x", "out1", "out2"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ resultsMsg.setDataTypes(new String[] {"integer", "integer", "integer"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ MMResultSet cs = new MMResultSet(resultsMsg, statement, null, 2);
+
+ int count = 0;
+ while (cs.next()) {
+ cs.getObject(1);
+ count++;
+ }
+ assertEquals(1, count);
+ assertTrue(cs.isAfterLast());
+ assertEquals(2, cs.getOutputParamValue(2));
+ assertEquals(3, cs.getOutputParamValue(3));
+ }
/////////////////////// Helper Method ///////////////////
- private MMResultSet helpExecuteQuery() throws SQLException {
- return helpExecuteQuery(400, 1000);
- }
-
- private MMResultSet helpExecuteQuery(int fetchSize, int totalResults) throws SQLException {
- MMStatement statement = createMockStatement();
+ private MMResultSet helpExecuteQuery() {
try {
- return TestAllResultsImpl.helpTestBatching(statement, fetchSize, Math.min(fetchSize, totalResults), totalResults);
- } catch (MetaMatrixProcessingException e) {
- throw new SQLException(e.getMessage());
- } catch (InterruptedException e) {
- throw new SQLException(e.getMessage());
- } catch (ExecutionException e) {
- throw new SQLException(e.getMessage());
- } catch (TimeoutException e) {
- throw new SQLException(e.getMessage());
+ return helpExecuteQuery(400, 1000, ResultSet.TYPE_SCROLL_INSENSITIVE);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
}
}
+
+ private MMResultSet helpExecuteQuery(int fetchSize, int totalResults, int cursorType) throws SQLException, MetaMatrixProcessingException, InterruptedException, ExecutionException, TimeoutException {
+ MMStatement statement = createMockStatement(cursorType);
+ return TestAllResultsImpl.helpTestBatching(statement, fetchSize, Math.min(fetchSize, totalResults), totalResults);
+ }
- static MMStatement createMockStatement() throws SQLException {
+ static MMStatement createMockStatement(int cursorType) throws SQLException {
MMStatement statement = mock(MMStatement.class);
stub(statement.getDQP()).toReturn(mock(ClientSideDQP.class));
- stub(statement.getResultSetType()).toReturn(
- ResultSet.TYPE_SCROLL_INSENSITIVE);
+ stub(statement.getResultSetType()).toReturn(cursorType);
TimeZone tz = TimeZone.getTimeZone("GMT-06:00"); //$NON-NLS-1$
TimeZone serverTz = TimeZone.getTimeZone("GMT-05:00"); //$NON-NLS-1$
stub(statement.getDefaultCalendar()).toReturn(Calendar.getInstance(tz));
Modified: trunk/common-core/src/main/java/com/metamatrix/core/util/LRUCache.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/LRUCache.java 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/common-core/src/main/java/com/metamatrix/core/util/LRUCache.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -27,7 +27,6 @@
/**
* This class replaces a verbose legacy implementation of LRUCaching.
- * However technically this is an eldest first purging policy.
*/
public class LRUCache<K, V> extends LinkedHashMap<K, V> {
Modified: trunk/engine/src/main/java/com/metamatrix/common/buffer/TupleBatch.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/common/buffer/TupleBatch.java 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/engine/src/main/java/com/metamatrix/common/buffer/TupleBatch.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -26,7 +26,6 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
-import java.io.Serializable;
import java.util.List;
import com.metamatrix.common.batch.BatchSerializer;
@@ -151,6 +150,10 @@
this.types = types;
}
+ public boolean containsRow(int row) {
+ return rowOffset <= row && getEndRow() >= row;
+ }
+
/**
* Return a String describing this object
* @param String representation of this TupleBatch
Modified: trunk/engine/src/main/java/com/metamatrix/common/buffer/TupleBuffer.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/common/buffer/TupleBuffer.java 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/engine/src/main/java/com/metamatrix/common/buffer/TupleBuffer.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -200,21 +200,39 @@
}
batchBuffer.add(tuple);
if (batchBuffer.size() == batchSize) {
- saveBatch(false);
+ saveBatch(false, false);
}
}
/**
+ * Adds the given batch preserving row offsets.
+ * @param batch
+ * @throws MetaMatrixComponentException
+ */
+ public void addTupleBatch(TupleBatch batch, boolean save) throws MetaMatrixComponentException {
+ Assertion.assertTrue(this.rowCount < batch.getBeginRow());
+ if (this.rowCount != batch.getBeginRow() - 1) {
+ saveBatch(false, true);
+ this.rowCount = batch.getBeginRow() - 1;
+ }
+ if (save) {
+ for (List<?> tuple : batch.getAllTuples()) {
+ addTuple(tuple);
+ }
+ }
+ }
+
+ /**
* Force the persistence of any rows held in memory.
* @throws MetaMatrixComponentException
*/
public void saveBatch() throws MetaMatrixComponentException {
- this.saveBatch(false);
+ this.saveBatch(false, false);
}
- void saveBatch(boolean finalBatch) throws MetaMatrixComponentException {
+ void saveBatch(boolean finalBatch, boolean force) throws MetaMatrixComponentException {
Assertion.assertTrue(!this.isRemoved());
- if (batchBuffer == null || batchBuffer.isEmpty() || batchBuffer.size() < Math.max(1, batchSize / 32)) {
+ if (batchBuffer == null || batchBuffer.isEmpty() || (!force && batchBuffer.size() < Math.max(1, batchSize / 32))) {
return;
}
TupleBatch writeBatch = new TupleBatch(rowCount - batchBuffer.size() + 1, batchBuffer);
@@ -230,7 +248,7 @@
public void close() throws MetaMatrixComponentException {
//if there is only a single batch, let it stay in memory
if (!this.batches.isEmpty()) {
- saveBatch(true);
+ saveBatch(true, false);
}
this.isFinal = true;
}
@@ -252,36 +270,35 @@
* @throws MetaMatrixComponentException
*/
public TupleBatch getBatch(int row) throws MetaMatrixComponentException {
+ TupleBatch result = null;
if (row > rowCount) {
- TupleBatch batch = new TupleBatch(rowCount + 1, new List[] {});
- if (isFinal) {
- batch.setTerminationFlag(true);
- }
- return batch;
- }
- if (this.batchBuffer != null && row > rowCount - this.batchBuffer.size()) {
- TupleBatch result = new TupleBatch(rowCount - this.batchBuffer.size() + 1, batchBuffer);
+ result = new TupleBatch(rowCount + 1, new List[] {});
+ } else if (this.batchBuffer != null && row > rowCount - this.batchBuffer.size()) {
+ result = new TupleBatch(rowCount - this.batchBuffer.size() + 1, batchBuffer);
if (forwardOnly) {
this.batchBuffer = null;
}
- return result;
+ } else {
+ if (this.batchBuffer != null && !this.batchBuffer.isEmpty()) {
+ //this is just a sanity check to ensure we're not holding too many
+ //hard references to batches.
+ saveBatch(isFinal, false);
+ }
+ Map.Entry<Integer, BatchManager.ManagedBatch> entry = batches.floorEntry(row);
+ Assertion.isNotNull(entry);
+ BatchManager.ManagedBatch batch = entry.getValue();
+ result = batch.getBatch(!forwardOnly, types);
+ if (lobs && result.getDataTypes() == null) {
+ correctLobReferences(result.getAllTuples());
+ }
+ result.setDataTypes(types);
+ if (forwardOnly) {
+ batches.remove(entry.getKey());
+ }
}
- if (this.batchBuffer != null && !this.batchBuffer.isEmpty()) {
- //this is just a sanity check to ensure we're not holding too many
- //hard references to batches.
- saveBatch(isFinal);
+ if (isFinal && result.getEndRow() == rowCount) {
+ result.setTerminationFlag(true);
}
- Map.Entry<Integer, BatchManager.ManagedBatch> entry = batches.floorEntry(row);
- Assertion.isNotNull(entry);
- BatchManager.ManagedBatch batch = entry.getValue();
- TupleBatch result = batch.getBatch(!forwardOnly, types);
- if (lobs && result.getDataTypes() == null) {
- correctLobReferences(result.getAllTuples());
- }
- result.setDataTypes(types);
- if (forwardOnly) {
- batches.remove(entry.getKey());
- }
return result;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/BatchCollector.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/BatchCollector.java 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/BatchCollector.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -51,7 +51,7 @@
}
public interface BatchHandler {
- void batchProduced(TupleBatch batch) throws MetaMatrixProcessingException, MetaMatrixComponentException;
+ boolean batchProduced(TupleBatch batch) throws MetaMatrixProcessingException, MetaMatrixComponentException;
}
private BatchProducer sourceNode;
@@ -59,7 +59,6 @@
private boolean done = false;
private TupleBuffer buffer;
- private boolean collectedAny;
public BatchCollector(BatchProducer sourceNode, TupleBuffer buffer) {
this.sourceNode = sourceNode;
@@ -91,28 +90,20 @@
* Flush the batch by giving it to the buffer manager.
*/
private void flushBatch(TupleBatch batch) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+ boolean add = true;
+ if (this.batchHandler != null && (batch.getRowCount() > 0 || batch.getTerminationFlag())) {
+ add = this.batchHandler.batchProduced(batch);
+ }
// Add batch
if(batch.getRowCount() > 0) {
- for (List tuple : batch.getAllTuples()) {
- buffer.addTuple(tuple);
- }
- collectedAny = true;
+ buffer.addTupleBatch(batch, add);
}
- if (this.batchHandler != null && (batch.getRowCount() > 0 || batch.getTerminationFlag())) {
- this.batchHandler.batchProduced(batch);
- }
}
public void setBatchHandler(BatchHandler batchHandler) {
this.batchHandler = batchHandler;
}
- public boolean collectedAny() {
- boolean result = collectedAny;
- collectedAny = false;
- return result;
- }
-
public int getRowCount() {
return buffer.getRowCount();
}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -129,7 +129,7 @@
private static final int DEFAULT_MAX_CODE_TABLE_RECORDS = 10000;
private static final int DEFAULT_MAX_CODE_TABLES = 200;
private static final int DEFAULT_MAX_CODE_RECORDS = 200000;
- private static final int DEFAULT_FETCH_SIZE = 2000;
+ private static final int DEFAULT_MAX_FETCH_SIZE = RequestMessage.DEFAULT_FETCH_SIZE * 10;
private static final int DEFAULT_PROCESSOR_TIMESLICE = 2000;
private static final String PROCESS_PLAN_QUEUE_NAME = "QueryProcessorQueue"; //$NON-NLS-1$
private static final int DEFAULT_MAX_PROCESS_WORKERS = 15;
@@ -139,7 +139,7 @@
private int maxCodeTables = DEFAULT_MAX_CODE_TABLES;
private int maxCodeRecords = DEFAULT_MAX_CODE_RECORDS;
- private int maxFetchSize = DEFAULT_FETCH_SIZE;
+ private int maxFetchSize = DEFAULT_MAX_FETCH_SIZE;
// Resources
private BufferManager bufferManager;
@@ -601,7 +601,7 @@
PropertiesUtils.setBeanProperties(this, props, null);
this.processorTimeslice = PropertiesUtils.getIntProperty(props, DQPEmbeddedProperties.PROCESS_TIMESLICE, DEFAULT_PROCESSOR_TIMESLICE);
- this.maxFetchSize = PropertiesUtils.getIntProperty(props, DQPEmbeddedProperties.MAX_FETCH_SIZE, DEFAULT_FETCH_SIZE);
+ this.maxFetchSize = PropertiesUtils.getIntProperty(props, DQPEmbeddedProperties.MAX_FETCH_SIZE, DEFAULT_MAX_FETCH_SIZE);
this.processorDebugAllowed = PropertiesUtils.getBooleanProperty(props, DQPEmbeddedProperties.PROCESSOR_DEBUG_ALLOWED, true);
this.maxCodeTableRecords = PropertiesUtils.getIntProperty(props, DQPEmbeddedProperties.MAX_CODE_TABLE_RECORDS_PER_TABLE, DEFAULT_MAX_CODE_TABLE_RECORDS);
this.maxCodeTables = PropertiesUtils.getIntProperty(props, DQPEmbeddedProperties.MAX_CODE_TABLES, DEFAULT_MAX_CODE_TABLES);
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2010-01-25 04:30:54 UTC (rev 1778)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -343,8 +343,8 @@
processor = request.processor;
collector = processor.createBatchCollector();
collector.setBatchHandler(new BatchHandler() {
- public void batchProduced(TupleBatch batch) throws MetaMatrixComponentException {
- sendResultsIfNeeded(batch);
+ public boolean batchProduced(TupleBatch batch) throws MetaMatrixComponentException {
+ return sendResultsIfNeeded(batch);
}
});
resultsBuffer = collector.getTupleBuffer();
@@ -373,82 +373,91 @@
/**
* Send results if they have been requested. This should only be called from the processing thread.
*/
- protected void sendResultsIfNeeded(TupleBatch batch) throws MetaMatrixComponentException {
+ protected boolean sendResultsIfNeeded(TupleBatch batch) throws MetaMatrixComponentException {
ResultsMessage response = null;
ResultsReceiver<ResultsMessage> receiver = null;
-
+ boolean result = true;
synchronized (this) {
if (this.resultsReceiver == null
- || (this.begin > this.resultsBuffer.getRowCount() && !doneProducingBatches)
+ || (this.begin > (batch != null?batch.getEndRow():this.resultsBuffer.getRowCount()) && !doneProducingBatches)
|| (this.transactionState == TransactionState.ACTIVE)) {
- return;
+ return result;
}
- }
- if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
- LogManager.logDetail(LogConstants.CTX_DQP, "[RequestWorkItem.sendResultsIfNeeded] requestID: " + requestID + " resultsID: " + this.resultsBuffer + " done: " + doneProducingBatches ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- if (batch == null || !(batch.getBeginRow() <= this.begin && batch.getEndRow() >= this.begin)) {
- if (savedBatch != null && savedBatch.getBeginRow() <= this.begin && savedBatch.getEndRow() >= this.begin) {
- batch = savedBatch;
- } else {
- batch = resultsBuffer.getBatch(begin);
- }
- //TODO: support fetching more than 1 batch
+
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
+ LogManager.logDetail(LogConstants.CTX_DQP, "[RequestWorkItem.sendResultsIfNeeded] requestID:", requestID, "resultsID:", this.resultsBuffer, "done:", doneProducingBatches ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ //TODO: support fetching more than 1 batch
+ boolean fromBuffer = false;
+ if (batch == null || !(batch.containsRow(this.begin))) {
+ if (savedBatch != null && savedBatch.containsRow(this.begin)) {
+ batch = savedBatch;
+ } else {
+ batch = resultsBuffer.getBatch(begin);
+ }
+ savedBatch = null;
+ fromBuffer = true;
+ }
int count = this.end - this.begin + 1;
if (batch.getRowCount() > count) {
- if (requestMsg.getCursorType() == ResultSet.TYPE_FORWARD_ONLY) {
- savedBatch = batch;
- }
int beginRow = Math.min(this.begin, batch.getEndRow() - count + 1);
int endRow = Math.min(beginRow + count - 1, batch.getEndRow());
+ boolean last = false;
+ if (endRow == batch.getEndRow()) {
+ last = batch.getTerminationFlag();
+ } else if (fromBuffer && requestMsg.getCursorType() == ResultSet.TYPE_FORWARD_ONLY) {
+ savedBatch = batch;
+ }
int firstOffset = beginRow - batch.getBeginRow();
List[] memoryRows = batch.getAllTuples();
List[] rows = new List[count];
System.arraycopy(memoryRows, firstOffset, rows, 0, endRow - beginRow + 1);
batch = new TupleBatch(beginRow, rows);
+ batch.setTerminationFlag(last);
+ } else if (!fromBuffer){
+ result = requestMsg.getCursorType() != ResultSet.TYPE_FORWARD_ONLY;
}
- }
- int finalRowCount = this.resultsBuffer.isFinal()?this.resultsBuffer.getRowCount():-1;
-
- response = createResultsMessage(requestMsg, batch.getAllTuples(), this.processor.getProcessorPlan().getOutputElements(), analysisRecord);
- response.setFirstRow(batch.getBeginRow());
- response.setLastRow(batch.getEndRow());
- response.setUpdateResult(this.returnsUpdateCount);
- // set final row
- response.setFinalRow(finalRowCount);
-
- // send any schemas associated with the results
- response.setSchemas(this.schemas);
-
- // send any warnings with the response object
- List<Throwable> responseWarnings = new ArrayList<Throwable>();
- List<Exception> currentWarnings = processor.getAndClearWarnings();
- if (currentWarnings != null) {
- responseWarnings.addAll(currentWarnings);
- }
- synchronized (warnings) {
- responseWarnings.addAll(this.warnings);
- this.warnings.clear();
- }
- response.setWarnings(responseWarnings);
-
- // If it is stored procedure, set parameters
- if (originalCommand instanceof StoredProcedure) {
- StoredProcedure proc = (StoredProcedure)originalCommand;
- if (proc.returnParameters()) {
- response.setParameters(getParameterInfo(proc));
- }
- }
- /*
- * mark the results sent at this point.
- * communication exceptions will be treated as non-recoverable
- */
- synchronized (this) {
+ int finalRowCount = this.resultsBuffer.isFinal()?this.resultsBuffer.getRowCount():(batch.getTerminationFlag()?batch.getEndRow():-1);
+
+ response = createResultsMessage(requestMsg, batch.getAllTuples(), this.processor.getProcessorPlan().getOutputElements(), analysisRecord);
+ response.setFirstRow(batch.getBeginRow());
+ response.setLastRow(batch.getEndRow());
+ response.setUpdateResult(this.returnsUpdateCount);
+ // set final row
+ response.setFinalRow(finalRowCount);
+
+ // send any schemas associated with the results
+ response.setSchemas(this.schemas);
+
+ // send any warnings with the response object
+ List<Throwable> responseWarnings = new ArrayList<Throwable>();
+ List<Exception> currentWarnings = processor.getAndClearWarnings();
+ if (currentWarnings != null) {
+ responseWarnings.addAll(currentWarnings);
+ }
+ synchronized (warnings) {
+ responseWarnings.addAll(this.warnings);
+ this.warnings.clear();
+ }
+ response.setWarnings(responseWarnings);
+
+ // If it is stored procedure, set parameters
+ if (originalCommand instanceof StoredProcedure) {
+ StoredProcedure proc = (StoredProcedure)originalCommand;
+ if (proc.returnParameters()) {
+ response.setParameters(getParameterInfo(proc));
+ }
+ }
+ /*
+ * mark the results sent at this point.
+ * communication exceptions will be treated as non-recoverable
+ */
receiver = this.resultsReceiver;
this.resultsReceiver = null;
}
receiver.receiveResults(response);
+ return result;
}
public static ResultsMessage createResultsMessage(RequestMessage message, List[] batch, List columnSymbols, AnalysisRecord analysisRecord) {
Added: trunk/engine/src/test/java/com/metamatrix/common/buffer/TestTupleBuffer.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/common/buffer/TestTupleBuffer.java (rev 0)
+++ trunk/engine/src/test/java/com/metamatrix/common/buffer/TestTupleBuffer.java 2010-01-26 04:55:59 UTC (rev 1779)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.common.buffer;
+
+import static org.junit.Assert.*;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+
+import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.common.types.DataTypeManager;
+import com.metamatrix.query.sql.symbol.ElementSymbol;
+
+public class TestTupleBuffer {
+
+ @Test public void testForwardOnly() throws Exception {
+ ElementSymbol x = new ElementSymbol("x"); //$NON-NLS-1$
+ x.setType(DataTypeManager.DefaultDataClasses.INTEGER);
+ List<ElementSymbol> schema = Arrays.asList(x);
+ TupleBuffer tb = new TupleBuffer(new BatchManager() {
+
+ @Override
+ public void remove() {
+
+ }
+
+ @Override
+ public ManagedBatch createManagedBatch(final TupleBatch batch)
+ throws MetaMatrixComponentException {
+ return new ManagedBatch() {
+
+ @Override
+ public void remove() {
+
+ }
+
+ @Override
+ public TupleBatch getBatch(boolean cache, String[] types)
+ throws MetaMatrixComponentException {
+ return batch;
+ }
+ };
+ }
+ }, "x", schema, 32); //$NON-NLS-1$
+ tb.setForwardOnly(true);
+ tb.addTuple(Arrays.asList(1));
+ TupleBatch batch = tb.getBatch(1);
+ assertTrue(!batch.getTerminationFlag());
+ assertEquals(1, batch.getBeginRow());
+ try {
+ tb.getBatch(1);
+ fail("expected exception"); //$NON-NLS-1$
+ } catch (AssertionError e) {
+
+ }
+ tb.addTuple(Arrays.asList(1));
+ tb.close();
+ batch = tb.getBatch(2);
+ assertTrue(batch.getTerminationFlag());
+ assertEquals(2, batch.getBeginRow());
+ }
+
+}
Property changes on: trunk/engine/src/test/java/com/metamatrix/common/buffer/TestTupleBuffer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
14 years, 12 months
teiid SVN: r1778 - in trunk/connectors/connector-jdbc/src: test/java/org/teiid/connector/jdbc/mysql and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-01-24 23:30:54 -0500 (Sun, 24 Jan 2010)
New Revision: 1778
Modified:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLTranslator.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java
Log:
TEIID-934 boolean is not a valid type conversion, changing to signed.
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLTranslator.java 2010-01-25 03:26:22 UTC (rev 1777)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLTranslator.java 2010-01-25 04:30:54 UTC (rev 1778)
@@ -72,7 +72,7 @@
registerFunctionModifier(SourceSystemFunctions.RPAD, new PadFunctionModifier());
//add in type conversion
ConvertModifier convertModifier = new ConvertModifier();
- convertModifier.addTypeMapping("signed", FunctionModifier.BYTE, FunctionModifier.SHORT, FunctionModifier.INTEGER, FunctionModifier.LONG); //$NON-NLS-1$
+ convertModifier.addTypeMapping("signed", FunctionModifier.BOOLEAN, FunctionModifier.BYTE, FunctionModifier.SHORT, FunctionModifier.INTEGER, FunctionModifier.LONG); //$NON-NLS-1$
//char(n) assume 4.1 or later
convertModifier.addTypeMapping("char(1)", FunctionModifier.CHAR); //$NON-NLS-1$
convertModifier.addTypeMapping("char", FunctionModifier.STRING); //$NON-NLS-1$
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java 2010-01-25 03:26:22 UTC (rev 1777)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java 2010-01-25 04:30:54 UTC (rev 1778)
@@ -333,4 +333,13 @@
output, TRANSLATOR);
}
+ @Test public void testBooleanToString() throws Exception {
+ String input = "SELECT convert(INTKEY, boolean) FROM BQT1.SmallA ORDER BY INTKEY"; //$NON-NLS-1$
+ String output = "SELECT CASE WHEN SmallA.IntKey = 0 THEN 0 WHEN SmallA.IntKey IS NOT NULL THEN 1 END FROM SmallA ORDER BY INTKEY"; //$NON-NLS-1$
+
+ TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB,
+ input,
+ output, TRANSLATOR);
+ }
+
}
14 years, 12 months