[teiid-commits] teiid SVN: r2054 - in trunk: engine/src/main/java/org/teiid/dqp/internal/process and 1 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Tue Apr 13 13:52:41 EDT 2010


Author: shawkins
Date: 2010-04-13 13:52:41 -0400 (Tue, 13 Apr 2010)
New Revision: 2054

Added:
   trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestResultsCache.java
Modified:
   trunk/engine/src/main/java/com/metamatrix/query/analysis/AnalysisRecord.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
Log:
TEIID-168 fixing regressions with cached results

Modified: trunk/engine/src/main/java/com/metamatrix/query/analysis/AnalysisRecord.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/analysis/AnalysisRecord.java	2010-04-13 17:50:43 UTC (rev 2053)
+++ trunk/engine/src/main/java/com/metamatrix/query/analysis/AnalysisRecord.java	2010-04-13 17:52:41 UTC (rev 2054)
@@ -106,6 +106,7 @@
     private boolean recordQueryPlan;
     private boolean recordDebug;
     
+    private PlanNode queryPlan;
     // Annotations
     private Collection<Annotation> annotations;
     
@@ -130,6 +131,14 @@
     public static AnalysisRecord createNonRecordingRecord() {
         return new AnalysisRecord(false, false);
     }
+    
+    public PlanNode getQueryPlan() {
+		return queryPlan;
+	}
+    
+    public void setQueryPlan(PlanNode queryPlan) {
+		this.queryPlan = queryPlan;
+	}
 
     /**
      * Determine whether query plan should be recorded

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-04-13 17:50:43 UTC (rev 2053)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java	2010-04-13 17:52:41 UTC (rev 2054)
@@ -214,6 +214,9 @@
         } finally {
         	if (this.state == ProcessingState.CLOSE && !isClosed) {
         		attemptClose();
+        		if (this.processingException != null) {
+        			sendError();
+        		}
         	} else if (isClosed) {
         		/*
         		 * since there may be a client waiting notify them of a problem
@@ -248,6 +251,14 @@
 			sendResultsIfNeeded(null);
 			collector.collectTuples();
 		    doneProducingBatches = this.resultsBuffer.isFinal();
+		    if (doneProducingBatches && cid != null) {
+		    	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);
+		    }
 		}
 		if (doneProducingBatches) {
 			if (this.transactionState == TransactionState.ACTIVE) {
@@ -285,26 +296,21 @@
 	protected void attemptClose() {
 		int rowcount = -1;
 		if (this.resultsBuffer != null) {
-			this.processor.closeProcessing();
+			if (this.processor != null) {
+				this.processor.closeProcessing();
 			
-			if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
-		        LogManager.logDetail(LogConstants.CTX_DQP, "Removing tuplesource for the request " + requestID); //$NON-NLS-1$
-		    }
-			rowcount = resultsBuffer.getRowCount();
-			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);
+				if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
+			        LogManager.logDetail(LogConstants.CTX_DQP, "Removing tuplesource for the request " + requestID); //$NON-NLS-1$
+			    }
+				rowcount = resultsBuffer.getRowCount();
+				if (this.cid == null || !this.doneProducingBatches) {
+					resultsBuffer.remove();
+				}
+				
+				for (DataTierTupleSource connectorRequest : this.connectorInfo.values()) {
+					connectorRequest.fullyCloseSource();
+			    }
 			}
-			
-			for (DataTierTupleSource connectorRequest : this.connectorInfo.values()) {
-				connectorRequest.fullyCloseSource();
-		    }
 
 			this.resultsBuffer = null;
 			
@@ -366,6 +372,7 @@
 		resultsBuffer = collector.getTupleBuffer();
 		resultsBuffer.setForwardOnly(isForwardOnly());
 		analysisRecord = request.analysisRecord;
+		analysisRecord.setQueryPlan(processor.getProcessorPlan().getDescriptionProperties());
 		transactionContext = request.transactionContext;
 		if (this.transactionContext != null && this.transactionContext.getTransactionType() != Scope.NONE) {
 			this.transactionState = TransactionState.ACTIVE;
@@ -438,10 +445,12 @@
 	
 	        // 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();
@@ -481,9 +490,12 @@
     }
     
 	private void setAnalysisRecords(ResultsMessage response) {
-        if(analysisRecord != null) {
+		if(analysisRecord != null) {
         	if (requestMsg.getShowPlan() != ShowPlan.OFF) {
-	            response.setPlanDescription(processor.getProcessorPlan().getDescriptionProperties());
+        		if (processor != null) {
+        			analysisRecord.setQueryPlan(processor.getProcessorPlan().getDescriptionProperties());
+        		}
+        		response.setPlanDescription(analysisRecord.getQueryPlan());
 	            response.setAnnotations(analysisRecord.getAnnotations());
         	}
             if (requestMsg.getShowPlan() == ShowPlan.DEBUG) {

Added: trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestResultsCache.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestResultsCache.java	                        (rev 0)
+++ trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestResultsCache.java	2010-04-13 17:52:41 UTC (rev 2054)
@@ -0,0 +1,59 @@
+/*
+ * 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.jdbc;
+
+import static org.junit.Assert.*;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.metamatrix.core.util.UnitTestUtil;
+
+ at SuppressWarnings("nls")
+public class TestResultsCache {
+
+	private Connection conn;
+	
+	@Before public void setUp() throws Exception {
+    	FakeServer server = new FakeServer();
+    	server.deployVDB("test", UnitTestUtil.getTestDataPath() + "/TestCase3473/test.vdb");
+    	conn = server.createConnection("jdbc:teiid:test"); //$NON-NLS-1$ //$NON-NLS-2$		
+    }
+	
+	@Test public void testCache() throws Exception {
+		Statement s = conn.createStatement();
+		s.execute("set showplan on");
+		ResultSet rs = s.executeQuery("/* cache */ select 1");
+		assertTrue(rs.next());
+		s.execute("set noexec on");
+		rs = s.executeQuery("/* cache */ select 1");
+		assertTrue(rs.next());
+		rs = s.executeQuery("select 1");
+		assertFalse(rs.next());
+	}
+	
+}


Property changes on: trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestResultsCache.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain



More information about the teiid-commits mailing list