[teiid-commits] teiid SVN: r1782 - in trunk: client/src/main/java/com/metamatrix/dqp/embedded and 12 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Tue Jan 26 23:57:42 EST 2010


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);        
         



More information about the teiid-commits mailing list