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

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Thu Sep 1 15:48:31 EDT 2011


Author: shawkins
Date: 2011-09-01 15:48:30 -0400 (Thu, 01 Sep 2011)
New Revision: 3441

Modified:
   trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/ExpirationAwareCache.java
   trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/JBossCache.java
   trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/JBossCacheFactory.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataRolePolicyDecider.java
   trunk/engine/src/main/java/org/teiid/query/processor/BatchCollector.java
   trunk/engine/src/main/java/org/teiid/query/processor/relational/SortNode.java
   trunk/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java
   trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java
   trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java
   trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
   trunk/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestAuthorizationValidationVisitor.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
   trunk/engine/src/test/java/org/teiid/dqp/service/AutoGenDataService.java
   trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
   trunk/engine/src/test/java/org/teiid/query/processor/TestWithClauseProcessing.java
   trunk/engine/src/test/java/org/teiid/query/processor/relational/TestSortNode.java
   trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java
Log:
forward merge from 7.4.1 and minor changes to undo behavior

Modified: trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/ExpirationAwareCache.java
===================================================================
--- trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/ExpirationAwareCache.java	2011-08-31 18:43:49 UTC (rev 3440)
+++ trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/ExpirationAwareCache.java	2011-09-01 19:48:30 UTC (rev 3441)
@@ -35,6 +35,12 @@
 	public ExpirationAwareCache(Cache cacheStore, Fqn fqn) {
 		super(cacheStore, fqn);
 	}
+	
+	@Override
+	protected boolean validateNode(Node node) {
+		Long future = (Long) node.get(ExpirationAlgorithmConfig.EXPIRATION_KEY);
+		return future == null || future > System.currentTimeMillis();
+	}
 
 	@Override
 	public V put(K key, V value) {

Modified: trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/JBossCache.java
===================================================================
--- trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/JBossCache.java	2011-08-31 18:43:49 UTC (rev 3440)
+++ trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/JBossCache.java	2011-09-01 19:48:30 UTC (rev 3441)
@@ -52,10 +52,17 @@
 		Node<K, V> node = getRootNode();
 		Node child = node.getChild(getFqn(key));
 		if (child != null) {
-			return (V)child.get(key);
+			if (validateNode(child)) {
+				return (V)child.get(key);
+			}
+			remove(key);
 		}
 		return null;
 	}
+	
+	protected boolean validateNode(Node node) {
+		return true;
+	}
 
 	protected Fqn<String> getFqn(K key) {
 		if (key.getClass().isPrimitive() || key instanceof String) {

Modified: trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/JBossCacheFactory.java
===================================================================
--- trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/JBossCacheFactory.java	2011-08-31 18:43:49 UTC (rev 3440)
+++ trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/JBossCacheFactory.java	2011-09-01 19:48:30 UTC (rev 3441)
@@ -29,6 +29,7 @@
 import org.jboss.cache.Node;
 import org.jboss.cache.Region;
 import org.jboss.cache.config.EvictionAlgorithmConfig;
+import org.jboss.cache.config.EvictionConfig;
 import org.jboss.cache.config.EvictionRegionConfig;
 import org.jboss.cache.eviction.ExpirationAlgorithmConfig;
 import org.jboss.cache.eviction.LRUAlgorithmConfig;
@@ -71,6 +72,8 @@
 			Region cacheRegion = this.cacheStore.getRegion(node.getFqn(), true);
 			cacheRegion.setEvictionRegionConfig(buildEvictionConfig(node.getFqn(), config));
 			cacheRegion.activate();
+			cacheRegion = this.cacheStore.getRegion(node.getFqn(), true);
+			cacheRegion.setEvictionRegionConfig(buildEvictionConfig(node.getFqn(), config));
 						
 			JBossCache jc = null;
 			if (config != null && config.getPolicy().equals(Policy.EXPIRATION)) {

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataRolePolicyDecider.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataRolePolicyDecider.java	2011-08-31 18:43:49 UTC (rev 3440)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataRolePolicyDecider.java	2011-09-01 19:48:30 UTC (rev 3441)
@@ -1,3 +1,25 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
 package org.teiid.dqp.internal.process;
 
 import java.util.Collections;
@@ -49,13 +71,20 @@
 	@Override
 	public boolean isTempAccessable(PermissionType action, String resource,
 			Context context, CommandContext commandContext) {
+		Boolean result = null;
     	for(DataPolicy p:commandContext.getAllowedDataPolicies().values()) {
 			DataPolicyMetadata policy = (DataPolicyMetadata)p;
 			
 			if (policy.isAllowCreateTemporaryTables() != null) {
-				return policy.isAllowCreateTemporaryTables();
+				if (policy.isAllowCreateTemporaryTables()) {
+					return true;
+				}
+				result = policy.isAllowCreateTemporaryTables();
 			}
 		}
+    	if (result != null) {
+    		return result;
+    	}
     	return allowCreateTemporaryTablesByDefault;
 	}
 	

Modified: trunk/engine/src/main/java/org/teiid/query/processor/BatchCollector.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/BatchCollector.java	2011-08-31 18:43:49 UTC (rev 3440)
+++ trunk/engine/src/main/java/org/teiid/query/processor/BatchCollector.java	2011-09-01 19:48:30 UTC (rev 3441)
@@ -120,11 +120,12 @@
     private TupleBuffer buffer;
     private boolean forwardOnly;
     
-    public BatchCollector(BatchProducer sourceNode, BufferManager bm, CommandContext context, boolean fowardOnly) throws TeiidComponentException {
+    public BatchCollector(BatchProducer sourceNode, BufferManager bm, CommandContext context, boolean forwardOnly) throws TeiidComponentException {
         this.sourceNode = sourceNode;
+        this.forwardOnly = forwardOnly;
         if (!this.sourceNode.hasFinalBuffer()) {
             this.buffer = bm.createTupleBuffer(sourceNode.getOutputElements(), context.getConnectionID(), TupleSourceType.PROCESSOR);
-            this.buffer.setForwardOnly(fowardOnly);
+            this.buffer.setForwardOnly(forwardOnly);
         }
     }
 

Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/SortNode.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/SortNode.java	2011-08-31 18:43:49 UTC (rev 3440)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/SortNode.java	2011-09-01 19:48:30 UTC (rev 3441)
@@ -133,7 +133,9 @@
 
     public void closeDirect() {
         if(this.output != null) {
-    		this.output.remove();
+        	if (!usingOutput) {
+        		this.output.remove();
+        	}
         	this.output = null;
         }
         this.outputTs = null;

Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java	2011-08-31 18:43:49 UTC (rev 3440)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java	2011-09-01 19:48:30 UTC (rev 3441)
@@ -50,6 +50,8 @@
 
 /**
  * Implements several modes of a multi-pass sort.
+ * 
+ * TODO: could consider using an index for dup_removal and maintaining a separate output buffer
  */
 public class SortUtility {
 	
@@ -324,7 +326,7 @@
 	            while (sublists.size() > 0) {
 	            	SortedSublist sortedSublist = sublists.remove(sublists.size() - 1);
 	        		merged.addTuple(sortedSublist.tuple);
-	                if (this.output != null && sortedSublist.index > masterSortIndex) {
+	                if (this.output != null && masterSortIndex < maxSortIndex && sortedSublist.index != masterSortIndex) {
 	                	this.output.addTuple(sortedSublist.tuple); //a new distinct row
 	            	}
 	            	incrementWorkingTuple(sublists, sortedSublist);
@@ -339,7 +341,7 @@
 	            }
 	            merged.saveBatch();
 	            this.activeTupleBuffers.add(merged);           
-	            masterSortIndex = masterSortIndex - maxSortIndex + 1;
+	            masterSortIndex = masterSortIndex - maxSortIndex;
 	            if (masterSortIndex < 0) {
 	            	masterSortIndex = this.activeTupleBuffers.size() - 1;
 	            }

Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java	2011-08-31 18:43:49 UTC (rev 3440)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java	2011-09-01 19:48:30 UTC (rev 3441)
@@ -95,7 +95,9 @@
 	public void closeDirect() {
 		super.closeDirect();
 		if(this.buffer != null) {
-    		this.buffer.remove();
+			if (!usingOutput) {
+				this.buffer.remove();
+			}
         	this.buffer = null;
         }
 		reset();

Modified: trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java	2011-08-31 18:43:49 UTC (rev 3440)
+++ trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java	2011-09-01 19:48:30 UTC (rev 3441)
@@ -82,9 +82,9 @@
 		private boolean addRowId;
 		private int[] indexes;
 		
-		private InsertUpdateProcessor(TupleSource ts, boolean addRowId, int[] indexes)
+		private InsertUpdateProcessor(TupleSource ts, boolean addRowId, int[] indexes, boolean canUndo)
 				throws TeiidComponentException {
-			super(null, ts);
+			super(null, ts, canUndo);
 			this.addRowId = addRowId;
 			this.indexes = indexes;
 		}
@@ -117,14 +117,14 @@
 			currentTuple = tuple;
 			for (int i : notNull) {
 				if (tuple.get(i) == null) {
-					throw new TeiidProcessingException(QueryPlugin.Util.getString("TempTable.not_null", columns.get(i)));
+					throw new TeiidProcessingException(QueryPlugin.Util.getString("TempTable.not_null", columns.get(i))); //$NON-NLS-1$
 				}
 			}
 			insertTuple(tuple, addRowId);
 		}
 
 		@Override
-		protected void undo(List tuple) throws TeiidComponentException,
+		protected void undo(List<?> tuple) throws TeiidComponentException,
 				TeiidProcessingException {
 			deleteTuple(tuple);
 		}
@@ -197,18 +197,20 @@
 
 	private abstract class UpdateProcessor {
 		private TupleSource ts;
-		protected final Evaluator eval;
-		private final Criteria crit;
+		protected Evaluator eval;
+		private Criteria crit;
 		protected int updateCount = 0;
 		protected List currentTuple;
 		
 		protected TupleBuffer undoLog;
 
-		UpdateProcessor(Criteria crit, TupleSource ts) throws TeiidComponentException {
+		UpdateProcessor(Criteria crit, TupleSource ts, boolean canUndo) throws TeiidComponentException {
 			this.ts = ts;
 			this.eval = new Evaluator(columnMap, null, null);
 			this.crit = crit;
-			this.undoLog = bm.createTupleBuffer(columns, sessionID, TupleSourceType.PROCESSOR);
+			if (canUndo) {
+				this.undoLog = bm.createTupleBuffer(columns, sessionID, TupleSourceType.PROCESSOR);
+			}
 		}
 		
 		int process() throws ExpressionEvaluationException, TeiidComponentException, TeiidProcessingException {
@@ -221,7 +223,9 @@
 					if (crit == null || eval.evaluate(crit, currentTuple)) {
 						tuplePassed(currentTuple);
 						updateCount++;
-						undoLog.addTuple(currentTuple);
+						if (undoLog != null) {
+							undoLog.addTuple(currentTuple);
+						}
 					}
 					currentTuple = null;
 				}
@@ -230,19 +234,21 @@
 				success();
 				success = true;
 			} finally {
-				bm.releaseBuffers(reserved);
 				try {
-					if (!success) {
+					if (!success && undoLog != null) {
 						undoLog.setFinal(true);
 						TupleSource undoTs = undoLog.createIndexedTupleSource();
 						List<?> tuple = null;
 						while ((tuple = undoTs.nextTuple()) != null) {
-							undo(tuple);
+							try {
+								undo(tuple);
+							} catch (TeiidException e) {
+								LogManager.logError(LogConstants.CTX_DQP, e, e.getMessage());								
+							}
 						}
 					}
-				} catch (TeiidException e) {
-					LogManager.logError(LogConstants.CTX_DQP, e, e.getMessage());
 				} finally {
+					bm.releaseBuffers(reserved);
 					if (!held) {
 						lock.writeLock().unlock();
 					}
@@ -257,11 +263,14 @@
 
 		protected abstract void tuplePassed(List tuple) throws BlockedException, TeiidComponentException, TeiidProcessingException;
 		
-		protected abstract void undo(List tuple) throws TeiidComponentException, TeiidProcessingException;
+		protected abstract void undo(List<?> tuple) throws TeiidComponentException, TeiidProcessingException;
 		
 		public void close() {
 			ts.closeSource();
-			undoLog.remove();
+			ts = null;
+			if (undoLog != null) {
+				undoLog.remove();
+			}
 		}
 		
 	}
@@ -332,7 +341,7 @@
 		TempTable indexTable = createIndexTable(indexColumns, unique);
 		//TODO: ordered insert optimization
 		TupleSource ts = createTupleSource(indexTable.getColumns(), null, null);
-		indexTable.insert(ts, indexTable.getColumns());
+		indexTable.insert(ts, indexTable.getColumns(), false);
 		indexTable.getTree().compact();
 	}
 
@@ -497,11 +506,16 @@
 	}
 	
 	public void remove() {
-		tree.remove();
-		if (this.indexTables != null) {
-			for (TempTable indexTable : this.indexTables.values()) {
-				indexTable.remove();
+		lock.writeLock().lock();
+		try {
+			tree.remove();
+			if (this.indexTables != null) {
+				for (TempTable indexTable : this.indexTables.values()) {
+					indexTable.remove();
+				}
 			}
+		} finally {
+			lock.writeLock().unlock();
 		}
 	}
 	
@@ -512,7 +526,7 @@
 		return columns;
 	}
 	
-	public TupleSource insert(TupleSource tuples, final List<ElementSymbol> variables) throws TeiidComponentException, ExpressionEvaluationException, TeiidProcessingException {
+	public TupleSource insert(TupleSource tuples, final List<ElementSymbol> variables, boolean canUndo) throws TeiidComponentException, ExpressionEvaluationException, TeiidProcessingException {
 		List<ElementSymbol> cols = getColumns();
 		final int[] indexes = new int[cols.size()];
 		boolean shouldProject = false;
@@ -520,7 +534,7 @@
 			indexes[i] = variables.indexOf(cols.get(i));
 			shouldProject |= (indexes[i] != i);
 		}
-        UpdateProcessor up = new InsertUpdateProcessor(tuples, rowId != null, shouldProject?indexes:null);
+        UpdateProcessor up = new InsertUpdateProcessor(tuples, rowId != null, shouldProject?indexes:null, canUndo);
         int updateCount = up.process();
         tid.setCardinality(tree.getRowCount());
         tid.getTableData().dataModified(updateCount);
@@ -530,7 +544,7 @@
 	public TupleSource update(Criteria crit, final SetClauseList update) throws TeiidComponentException, ExpressionEvaluationException, TeiidProcessingException {
 		final boolean primaryKeyChangePossible = canChangePrimaryKey(update);
 		final TupleBrowser browser = createTupleBrower(crit, OrderBy.ASC);
-		UpdateProcessor up = new UpdateProcessor(crit, browser) {
+		UpdateProcessor up = new UpdateProcessor(crit, browser, true) {
 			
 			protected TupleBuffer changeSet;
 			protected UpdateProcessor changeSetProcessor;
@@ -556,7 +570,7 @@
 			}
 			
 			@Override
-			protected void undo(List tuple) throws TeiidComponentException, TeiidProcessingException {
+			protected void undo(List<?> tuple) throws TeiidComponentException, TeiidProcessingException {
 				if (primaryKeyChangePossible) {
 					insertTuple(tuple, false);
 				} else {
@@ -570,7 +584,7 @@
 				//changeSet contains possible updates
 				if (primaryKeyChangePossible) {
 					if (changeSetProcessor == null) {
-						changeSetProcessor = new InsertUpdateProcessor(changeSet.createIndexedTupleSource(true), false, null);
+						changeSetProcessor = new InsertUpdateProcessor(changeSet.createIndexedTupleSource(true), false, null, true);
 					}
 					changeSetProcessor.process(); //when this returns, we're up to date
 				}
@@ -579,11 +593,10 @@
 			@Override
 			public void close() {
 				super.close();
-				if (changeSetProcessor != null) {
-					changeSetProcessor.close(); // causes a revert of the change set
-				}
+				changeSetProcessor = null;
 				if (changeSet != null) {
 					changeSet.remove();
+					changeSet = null;
 				}
 			}
 			
@@ -606,7 +619,7 @@
 	
 	public TupleSource delete(Criteria crit) throws TeiidComponentException, ExpressionEvaluationException, TeiidProcessingException {
 		final TupleBrowser browser = createTupleBrower(crit, OrderBy.ASC);
-		UpdateProcessor up = new UpdateProcessor(crit, browser) {
+		UpdateProcessor up = new UpdateProcessor(crit, browser, true) {
 			@Override
 			protected void tuplePassed(List tuple)
 					throws ExpressionEvaluationException,
@@ -616,7 +629,7 @@
 			}
 			
 			@Override
-			protected void undo(List tuple) throws TeiidComponentException, TeiidProcessingException {
+			protected void undo(List<?> tuple) throws TeiidComponentException, TeiidProcessingException {
 				insertTuple(tuple, false);
 			}
 		};

Modified: trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java	2011-08-31 18:43:49 UTC (rev 3440)
+++ trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java	2011-09-01 19:48:30 UTC (rev 3441)
@@ -56,6 +56,7 @@
 import org.teiid.query.QueryPlugin;
 import org.teiid.query.eval.Evaluator;
 import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.TempMetadataAdapter;
 import org.teiid.query.metadata.TempMetadataID;
 import org.teiid.query.optimizer.relational.RelationalPlanner;
 import org.teiid.query.parser.ParseInfo;
@@ -139,6 +140,9 @@
     	TempTableStore contextStore = context.getTempTableStore();
         if (command instanceof Query) {
             Query query = (Query)command;
+            if (modelName != null && !modelName.equals(TempMetadataAdapter.TEMP_MODEL.getID())) {
+            	return null;
+            }
             return registerQuery(context, contextStore, query);
         }
         if (command instanceof ProcedureContainer) {
@@ -171,7 +175,7 @@
 					}
         			ts = new CollectionTupleSource(Arrays.asList(values).iterator());
         		}
-        		return table.insert(ts, insert.getVariables());
+        		return table.insert(ts, insert.getVariables(), true);
         	}
         	if (command instanceof Update) {
         		final Update update = (Update)command;
@@ -442,8 +446,7 @@
 			qp.getContext().setDataObjects(null);
 			TupleSource ts = new BatchCollector.BatchProducerTupleSource(qp);
 			
-			//TODO: if this insert fails, it's unnecessary to do the undo processing
-			table.insert(ts, allColumns);
+			table.insert(ts, allColumns, false);
 			table.getTree().compact();
 			rowCount = table.getRowCount();
 			//TODO: could pre-process indexes to remove overlap

Modified: trunk/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java	2011-08-31 18:43:49 UTC (rev 3440)
+++ trunk/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java	2011-09-01 19:48:30 UTC (rev 3441)
@@ -171,7 +171,7 @@
     throws QueryResolverException {
         config.setErrorListener(ERROR_LISTENER);
         this.xQueryString = xQueryString;
-        StaticQueryContext context = new StaticQueryContext(config);
+        StaticQueryContext context = config.newStaticQueryContext();
         IndependentContext ic = new IndependentContext(config);
         namespaceMap.put(EMPTY_STRING, EMPTY_STRING);
         if (namespaces != null) {
@@ -242,7 +242,13 @@
 			}
 		}
 		this.contextRoot = null;
-		PathMap map = this.xQuery.getPathMap();
+		//we'll use a new pathmap, since we don't want to modify the one associated with the xquery.
+		PathMap map = null;
+		if (columns == null) {
+			map = this.xQuery.getPathMap();
+		} else {
+			map = new PathMap(this.xQuery.getExpression());
+		}
 		PathMapRoot parentRoot;
 		try {
 			parentRoot = map.getContextRoot();

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestAuthorizationValidationVisitor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestAuthorizationValidationVisitor.java	2011-08-31 18:43:49 UTC (rev 3440)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestAuthorizationValidationVisitor.java	2011-09-01 19:48:30 UTC (rev 3441)
@@ -170,7 +170,7 @@
         return svc;
     }
 
-    private void helpTest(DataPolicyMetadata policy, String sql, QueryMetadataInterface metadata, String[] expectedInaccesible, VDBMetaData vdb) throws QueryParserException, QueryResolverException, TeiidComponentException {
+    private void helpTest(String sql, QueryMetadataInterface metadata, String[] expectedInaccesible, VDBMetaData vdb, DataPolicyMetadata... roles) throws QueryParserException, QueryResolverException, TeiidComponentException {
         QueryParser parser = QueryParser.getQueryParser();
         Command command = parser.parseCommand(sql);
         QueryResolver.resolveCommand(command, metadata);
@@ -178,7 +178,9 @@
         vdb.addAttchment(QueryMetadataInterface.class, metadata);
         
         HashMap<String, DataPolicy> policies = new HashMap<String, DataPolicy>();
-        policies.put(policy.getName(), policy);
+        for (DataPolicyMetadata dataPolicyMetadata : roles) {
+            policies.put(dataPolicyMetadata.getName(), dataPolicyMetadata);
+		}
         this.context.getDQPWorkContext().setPolicies(policies);
         DataRolePolicyDecider dataRolePolicyDecider = new DataRolePolicyDecider();
         dataRolePolicyDecider.setAllowFunctionCallsByDefault(false);
@@ -206,125 +208,127 @@
     
     @Test public void testTemp() throws Exception {
     	//allowed by default
-    	helpTest(exampleAuthSvc1(), "create local temporary table x (y string)", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$
+    	helpTest("create local temporary table x (y string)", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$
     	//explicitly denied
-        helpTest(exampleAuthSvc2(), "create local temporary table x (y string)", RealMetadataFactory.example1Cached(), new String[] {"x"}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$
+        helpTest("create local temporary table x (y string)", RealMetadataFactory.example1Cached(), new String[] {"x"}, RealMetadataFactory.example1VDB(), exampleAuthSvc2()); //$NON-NLS-1$
     }
     
     @Test public void testFunction() throws Exception {
         QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
-    	helpTest(exampleAuthSvc1(), "SELECT e1 FROM pm1.g1 where xyz() > 0", metadata, new String[] {}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$
-        helpTest(exampleAuthSvc2(), "SELECT e1, curdate() FROM pm1.g2 where xyz() > 0", metadata, new String[] {"xyz()"}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$ 
+    	helpTest("SELECT e1 FROM pm1.g1 where xyz() > 0", metadata, new String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$
+        helpTest("SELECT e1, curdate() FROM pm1.g2 where xyz() > 0", metadata, new String[] {"xyz()"}, RealMetadataFactory.example1VDB(), exampleAuthSvc2()); //$NON-NLS-1$ 
     }
     
     @Test public void testEverythingAccessible() throws Exception {
-        helpTest(exampleAuthSvc1(), "SELECT e1 FROM pm1.g1", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$
+        helpTest("SELECT e1 FROM pm1.g1", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$
     }
     
     @Test public void testEverythingAccessible1() throws Exception {
-        helpTest(exampleAuthSvc1(), "SELECT e1 FROM (select e1 from pm1.g1) x", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$
+        helpTest("SELECT e1 FROM (select e1 from pm1.g1) x", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$
     }
     
     @Test public void testEverythingAccessible2() throws Exception {
-        helpTest(exampleAuthSvc1(), "SELECT lookup('pm1.g1', 'e1', 'e1', '1'), e1 FROM (select e1 from pm1.g1) x", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$
+        helpTest("SELECT lookup('pm1.g1', 'e1', 'e1', '1'), e1 FROM (select e1 from pm1.g1) x", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$
     }
 
     @Test public void testInaccesibleElement() throws Exception {        
-        helpTest(exampleAuthSvc1(), "SELECT e2 FROM pm1.g1", RealMetadataFactory.example1Cached(), new String[] {"pm1.g1.e2"}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$ //$NON-NLS-2$
+        helpTest("SELECT e2 FROM pm1.g1", RealMetadataFactory.example1Cached(), new String[] {"pm1.g1.e2"}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$ //$NON-NLS-2$
     }
     
     @Test public void testInaccesibleElement2() throws Exception {        
-        helpTest(exampleAuthSvc1(), "SELECT lookup('pm1.g1', 'e1', 'e2', '1')", RealMetadataFactory.example1Cached(), new String[] {"pm1.g1.e2"}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$ //$NON-NLS-2$
+        helpTest("SELECT lookup('pm1.g1', 'e1', 'e2', '1')", RealMetadataFactory.example1Cached(), new String[] {"pm1.g1.e2"}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$ //$NON-NLS-2$
     }
 
     @Test public void testInaccesibleGroup() throws Exception {        
-        helpTest(exampleAuthSvc1(), "SELECT e1 FROM pm1.g2", RealMetadataFactory.example1Cached(), new String[] {"pm1.g2", "pm1.g2.e1"}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+        helpTest("SELECT e1 FROM pm1.g2", RealMetadataFactory.example1Cached(), new String[] {"pm1.g2", "pm1.g2.e1"}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
     }
 
     @Test public void testInsert() throws Exception {        
-        helpTest(exampleAuthSvc1(), "INSERT INTO pm1.g1 (e1, e2, e3, e4) VALUES ('x', 5, {b'true'}, 1.0)", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$
+        helpTest("INSERT INTO pm1.g1 (e1, e2, e3, e4) VALUES ('x', 5, {b'true'}, 1.0)", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$
     }
 
     @Test public void testInsertInaccessible() throws Exception {        
-        helpTest(exampleAuthSvc1(), "INSERT INTO pm1.g2 (e1, e2, e3, e4) VALUES ('x', 5, {b'true'}, 1.0)", RealMetadataFactory.example1Cached(), new String[] {"pm1.g2.e1"}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$ //$NON-NLS-2$
+        helpTest("INSERT INTO pm1.g2 (e1, e2, e3, e4) VALUES ('x', 5, {b'true'}, 1.0)", RealMetadataFactory.example1Cached(), new String[] {"pm1.g2.e1"}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$ //$NON-NLS-2$
     }
 
     @Test public void testUpdate() throws Exception {        
-        helpTest(exampleAuthSvc1(), "UPDATE pm1.g1 SET e2 = 5", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$
+        helpTest("UPDATE pm1.g1 SET e2 = 5", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$
     }
 
     @Test public void testUpdateCriteriaInaccessibleForRead() throws Exception {        
-        helpTest(exampleAuthSvc1(), "UPDATE pm1.g2 SET e2 = 5 WHERE e1 = 'x'", RealMetadataFactory.example1Cached(), new String[] {"pm1.g2.e1"}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$ //$NON-NLS-2$
+        helpTest("UPDATE pm1.g2 SET e2 = 5 WHERE e1 = 'x'", RealMetadataFactory.example1Cached(), new String[] {"pm1.g2.e1"}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$ //$NON-NLS-2$
     }
     
     @Test public void testUpdateCriteriaInaccessibleForRead1() throws Exception {        
-        helpTest(exampleAuthSvc1(), "UPDATE pm1.g2 SET e2 = cast(e1 as integer)", RealMetadataFactory.example1Cached(), new String[] {"pm1.g2.e1"}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$ //$NON-NLS-2$
+        helpTest("UPDATE pm1.g2 SET e2 = cast(e1 as integer)", RealMetadataFactory.example1Cached(), new String[] {"pm1.g2.e1"}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$ //$NON-NLS-2$
     }
 
     @Test public void testUpdateElementInaccessibleForUpdate() throws Exception {        
-        helpTest(exampleAuthSvc1(), "UPDATE pm1.g1 SET e1 = 5 WHERE e1 = 'x'", RealMetadataFactory.example1Cached(), new String[] {"pm1.g1.e1"}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$ //$NON-NLS-2$
+        helpTest("UPDATE pm1.g1 SET e1 = 5 WHERE e1 = 'x'", RealMetadataFactory.example1Cached(), new String[] {"pm1.g1.e1"}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$ //$NON-NLS-2$
     }
 
     @Test public void testDelete() throws Exception {        
-        helpTest(exampleAuthSvc1(), "DELETE FROM pm1.g1", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$
+        helpTest("DELETE FROM pm1.g1", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$
     }
 
     @Test public void testDeleteCriteriaInaccesibleForRead() throws Exception {        
-        helpTest(exampleAuthSvc1(), "DELETE FROM pm1.g2 WHERE e1 = 'x'", RealMetadataFactory.example1Cached(), new String[] {"pm1.g2.e1"}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$ //$NON-NLS-2$
+        helpTest("DELETE FROM pm1.g2 WHERE e1 = 'x'", RealMetadataFactory.example1Cached(), new String[] {"pm1.g2.e1"}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$ //$NON-NLS-2$
     }
 
     @Test public void testDeleteInaccesibleGroup() throws Exception {        
-        helpTest(exampleAuthSvc1(), "DELETE FROM pm1.g3", RealMetadataFactory.example1Cached(), new String[] {"pm1.g3"}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$ //$NON-NLS-2$
+        helpTest("DELETE FROM pm1.g3", RealMetadataFactory.example1Cached(), new String[] {"pm1.g3"}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$ //$NON-NLS-2$
     }
     
     @Test public void testProc() throws Exception {
-        helpTest(exampleAuthSvc1(), "EXEC pm1.sq1()", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB());         //$NON-NLS-1$
+        helpTest("EXEC pm1.sq1()", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1());         //$NON-NLS-1$
     }
 
     @Test public void testProcInaccesible() throws Exception {
-        helpTest(exampleAuthSvc1(), "EXEC pm1.sq2('xyz')", RealMetadataFactory.example1Cached(), new String[] {"pm1.sq2"}, RealMetadataFactory.example1VDB());         //$NON-NLS-1$ //$NON-NLS-2$
+        helpTest("EXEC pm1.sq2('xyz')", RealMetadataFactory.example1Cached(), new String[] {"pm1.sq2"}, RealMetadataFactory.example1VDB(), exampleAuthSvc1());         //$NON-NLS-1$ //$NON-NLS-2$
     }
 
     @Test public void testSelectIntoEverythingAccessible() throws Exception {
-        helpTest(exampleAuthSvc2(), "SELECT e1, e2, e3, e4 INTO pm1.g2 FROM pm2.g1", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$
+        helpTest("SELECT e1, e2, e3, e4 INTO pm1.g2 FROM pm2.g1", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc2()); //$NON-NLS-1$
     }
 
     @Test public void testSelectIntoTarget_e1_NotAccessible() throws Exception {
-        helpTest(exampleAuthSvc2(), "SELECT e1, e2, e3, e4 INTO pm2.g2 FROM pm2.g1", RealMetadataFactory.example1Cached(), new String[] {"pm2.g2", "pm2.g2.e2","pm2.g2.e4","pm2.g2.e3"}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+        helpTest("SELECT e1, e2, e3, e4 INTO pm2.g2 FROM pm2.g1", RealMetadataFactory.example1Cached(), new String[] {"pm2.g2", "pm2.g2.e2","pm2.g2.e4","pm2.g2.e3"}, RealMetadataFactory.example1VDB(), exampleAuthSvc2()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
     }
 
     @Test public void testSelectIntoTarget_e1e2_NotAccessible() throws Exception {
-        helpTest(exampleAuthSvc2(), "SELECT e1, e2, e3, e4 INTO pm3.g2 FROM pm2.g1", RealMetadataFactory.example1Cached(), new String[] {"pm3.g2", "pm3.g2.e4", "pm3.g2.e3"},RealMetadataFactory.example1VDB()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+        helpTest("SELECT e1, e2, e3, e4 INTO pm3.g2 FROM pm2.g1", RealMetadataFactory.example1Cached(), new String[] {"pm3.g2", "pm3.g2.e4", "pm3.g2.e3"}, RealMetadataFactory.example1VDB(),exampleAuthSvc2()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
     }
     
     @Test public void testTempTableSelectInto() throws Exception {
-        helpTest(exampleAuthSvc1(), "SELECT e1 INTO #temp FROM pm1.g1", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$
-        helpTest(exampleAuthSvc2(), "SELECT e1 INTO #temp FROM pm1.g1", RealMetadataFactory.example1Cached(), new String[] {"#temp"}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$
+        helpTest("SELECT e1 INTO #temp FROM pm1.g1", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$
+        helpTest("SELECT e1 INTO #temp FROM pm1.g1", RealMetadataFactory.example1Cached(), new String[] {"#temp"}, RealMetadataFactory.example1VDB(), exampleAuthSvc2()); //$NON-NLS-1$
+        helpTest("SELECT e1 INTO #temp FROM pm1.g1", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc2(), exampleAuthSvc1()); //$NON-NLS-1$
+
     }
     
     @Test public void testTempTableSelectInto1() throws Exception {
-        helpTest(exampleAuthSvc1(), "SELECT e1, e2 INTO #temp FROM pm1.g1", RealMetadataFactory.example1Cached(), new String[] {"pm1.g1.e2"}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$ //$NON-NLS-2$
+        helpTest("SELECT e1, e2 INTO #temp FROM pm1.g1", RealMetadataFactory.example1Cached(), new String[] {"pm1.g1.e2"}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$ //$NON-NLS-2$
     }
     
     @Test public void testTempTableInsert() throws Exception {
-        helpTest(exampleAuthSvc1(), "insert into #temp (e1, e2, e3, e4) values ('1', '2', '3', '4')", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$
-        helpTest(exampleAuthSvc2(), "insert into #temp (e1, e2, e3, e4) values ('1', '2', '3', '4')", RealMetadataFactory.example1Cached(), new String[] {"#temp"}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$
+        helpTest("insert into #temp (e1, e2, e3, e4) values ('1', '2', '3', '4')", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$
+        helpTest("insert into #temp (e1, e2, e3, e4) values ('1', '2', '3', '4')", RealMetadataFactory.example1Cached(), new String[] {"#temp"}, RealMetadataFactory.example1VDB(), exampleAuthSvc2()); //$NON-NLS-1$
     }
     
     @Test public void testXMLAccessible() throws Exception {
-        helpTest(exampleAuthSvc2(), "select * from xmltest.doc1", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$ //$NON-NLS-2$
+        helpTest("select * from xmltest.doc1", RealMetadataFactory.example1Cached(), new String[] {}, RealMetadataFactory.example1VDB(), exampleAuthSvc2()); //$NON-NLS-1$ //$NON-NLS-2$
     }
     
     @Test public void testXMLInAccessible() throws Exception {
-        helpTest(exampleAuthSvc1(), "select * from xmltest.doc1", RealMetadataFactory.example1Cached(), new String[] {"xmltest.doc1"}, RealMetadataFactory.example1VDB()); //$NON-NLS-1$ //$NON-NLS-2$
+        helpTest("select * from xmltest.doc1", RealMetadataFactory.example1Cached(), new String[] {"xmltest.doc1"}, RealMetadataFactory.example1VDB(), exampleAuthSvc1()); //$NON-NLS-1$ //$NON-NLS-2$
     }
     
     @Test public void testAlter() throws Exception {
-        helpTest(exampleAuthSvc1(), "alter view SmallA_2589 as select * from bqt1.smalla", RealMetadataFactory.exampleBQTCached(), new String[] {"SmallA_2589"}, RealMetadataFactory.exampleBQTVDB()); //$NON-NLS-1$ //$NON-NLS-2$
-        helpTest(examplePolicyBQT(), "alter view SmallA_2589 as select * from bqt1.smalla", RealMetadataFactory.exampleBQTCached(), new String[] {}, RealMetadataFactory.exampleBQTVDB()); //$NON-NLS-1$ //$NON-NLS-2$
+        helpTest("alter view SmallA_2589 as select * from bqt1.smalla", RealMetadataFactory.exampleBQTCached(), new String[] {"SmallA_2589"}, RealMetadataFactory.exampleBQTVDB(), exampleAuthSvc1()); //$NON-NLS-1$ //$NON-NLS-2$
+        helpTest("alter view SmallA_2589 as select * from bqt1.smalla", RealMetadataFactory.exampleBQTCached(), new String[] {}, RealMetadataFactory.exampleBQTVDB(), examplePolicyBQT()); //$NON-NLS-1$ //$NON-NLS-2$
         
-        helpTest(exampleAuthSvc1(), "alter trigger on SmallA_2589 INSTEAD OF UPDATE enabled", RealMetadataFactory.exampleBQTCached(), new String[] {"SmallA_2589"}, RealMetadataFactory.exampleBQTVDB()); //$NON-NLS-1$ //$NON-NLS-2$
-        helpTest(examplePolicyBQT(), "alter trigger on SmallA_2589 INSTEAD OF UPDATE enabled", RealMetadataFactory.exampleBQTCached(), new String[] {}, RealMetadataFactory.exampleBQTVDB()); //$NON-NLS-1$ //$NON-NLS-2$
+        helpTest("alter trigger on SmallA_2589 INSTEAD OF UPDATE enabled", RealMetadataFactory.exampleBQTCached(), new String[] {"SmallA_2589"}, RealMetadataFactory.exampleBQTVDB(), exampleAuthSvc1()); //$NON-NLS-1$ //$NON-NLS-2$
+        helpTest("alter trigger on SmallA_2589 INSTEAD OF UPDATE enabled", RealMetadataFactory.exampleBQTCached(), new String[] {}, RealMetadataFactory.exampleBQTVDB(), examplePolicyBQT()); //$NON-NLS-1$ //$NON-NLS-2$
     }
     
 }

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java	2011-08-31 18:43:49 UTC (rev 3440)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java	2011-09-01 19:48:30 UTC (rev 3441)
@@ -333,6 +333,37 @@
         assertEquals(100, item.resultsBuffer.getRowCount());
     }
     
+    @Test public void testBufferReuse1() throws Exception {
+    	//the sql should return 100 rows
+        String sql = "SELECT IntKey FROM texttable('1112131415' columns intkey integer width 2 no row delimiter) t " +
+        		"union " +
+        		"SELECT IntKey FROM bqt1.smalla"; //$NON-NLS-1$
+        String userName = "1"; //$NON-NLS-1$
+        String sessionid = "1"; //$NON-NLS-1$
+        agds.sleep = 500;
+        agds.setUseIntCounter(true);
+        RequestMessage reqMsg = exampleRequestMessage(sql);
+        reqMsg.setCursorType(ResultSet.TYPE_FORWARD_ONLY);
+        DQPWorkContext.getWorkContext().getSession().setSessionId(sessionid);
+        DQPWorkContext.getWorkContext().getSession().setUserName(userName);
+        BufferManagerImpl bufferManager = (BufferManagerImpl)core.getBufferManager();
+		bufferManager.setProcessorBatchSize(20);
+        Future<ResultsMessage> message = core.executeRequest(reqMsg.getExecutionId(), reqMsg);
+        ResultsMessage rm = message.get(500000, TimeUnit.MILLISECONDS);
+        assertNull(rm.getException());
+        assertEquals(5, rm.getResults().length);
+        
+        message = core.processCursorRequest(reqMsg.getExecutionId(), 6, 5);
+        rm = message.get(500000, TimeUnit.MILLISECONDS);
+        assertNull(rm.getException());
+        assertEquals(5, rm.getResults().length);
+        
+        message = core.processCursorRequest(reqMsg.getExecutionId(), 11, 5);
+        rm = message.get(500000, TimeUnit.MILLISECONDS);
+        assertNull(rm.getException());
+        assertEquals(5, rm.getResults().length);
+    }
+    
     @Test public void testSourceConcurrency() throws Exception {
     	//setup default of 2
     	agds.setSleep(100);

Modified: trunk/engine/src/test/java/org/teiid/dqp/service/AutoGenDataService.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/service/AutoGenDataService.java	2011-08-31 18:43:49 UTC (rev 3440)
+++ trunk/engine/src/test/java/org/teiid/dqp/service/AutoGenDataService.java	2011-09-01 19:48:30 UTC (rev 3441)
@@ -59,13 +59,17 @@
 	public int sleep;
     private final AtomicInteger executeCount = new AtomicInteger();
     private final AtomicInteger closeCount = new AtomicInteger();
+    private boolean useIntCounter;
 
-    
     public AutoGenDataService() {
     	super("FakeConnector","FakeConnector"); //$NON-NLS-1$ //$NON-NLS-2$
         caps = TestOptimizer.getTypicalCapabilities();
     }
     
+    public void setUseIntCounter(boolean useIntCounter) {
+		this.useIntCounter = useIntCounter;
+	}
+    
     public void setSleep(int sleep) {
 		this.sleep = sleep;
 	}
@@ -151,7 +155,7 @@
             while(iter.hasNext()) {
                 SingleElementSymbol symbol = (SingleElementSymbol) iter.next();
                 Class type = symbol.getType();
-                row.add( getValue(type) );
+                row.add( getValue(type, i) );
             }
             rows[i] = row;
         }   
@@ -174,11 +178,11 @@
     private static final java.sql.Time TIME_VAL = new java.sql.Time(0);
     private static final java.sql.Timestamp TIMESTAMP_VAL = new java.sql.Timestamp(0);
     
-    private Object getValue(Class<?> type) {
+    private Object getValue(Class<?> type, int row) {
         if(type.equals(DataTypeManager.DefaultDataClasses.STRING)) {
             return STRING_VAL;
         } else if(type.equals(DataTypeManager.DefaultDataClasses.INTEGER)) {
-            return INTEGER_VAL;
+            return useIntCounter?row:INTEGER_VAL;
         } else if(type.equals(DataTypeManager.DefaultDataClasses.SHORT)) { 
             return SHORT_VAL;    
         } else if(type.equals(DataTypeManager.DefaultDataClasses.LONG)) {

Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java	2011-08-31 18:43:49 UTC (rev 3440)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java	2011-09-01 19:48:30 UTC (rev 3441)
@@ -216,7 +216,11 @@
 
 	    ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, new DefaultCapabilitiesFinder(), createCommandContext());
         
-        helpProcess(plan, createCommandContext(), dataManager, expected);
+	    helpProcess(plan, createCommandContext(), dataManager, expected);
+        
+	    plan = helpGetPlan(helpParse(sql), metadata, new DefaultCapabilitiesFinder(), createCommandContext());
+        
+	    doProcess(plan, dataManager, expected, createCommandContext());
     }
     
 	@Test public void testXmlTableDefaultAndParent() throws Exception {

Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestWithClauseProcessing.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestWithClauseProcessing.java	2011-08-31 18:43:49 UTC (rev 3440)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestWithClauseProcessing.java	2011-09-01 19:48:30 UTC (rev 3441)
@@ -64,10 +64,16 @@
         
 	    String sql = "with a (x, y, z) as (select e1, e2, e3 from pm1.g1) SELECT a.x from a, a z"; //$NON-NLS-1$
 	    
-	    FakeDataManager dataManager = new FakeDataManager();
-	    sampleData1(dataManager);
+	    HardcodedDataManager dataManager = new HardcodedDataManager();
+	    List[] expected = new List[] { 
+		        Arrays.asList("a", 1, Boolean.FALSE),
+		    };    
+
+	    dataManager.addData("WITH a (x, y, z) AS (SELECT g_0.e1, g_0.e2, g_0.e3 FROM pm1.g1 AS g_0) SELECT g_0.x FROM a AS g_0, a AS g_1", expected);
 	    
-	    TestOptimizer.helpPlan(sql, RealMetadataFactory.example1Cached(), null, capFinder, new String[] {"WITH a (x, y, z) AS (SELECT g_0.e1, g_0.e2, g_0.e3 FROM pm1.g1 AS g_0) SELECT g_0.x FROM a AS g_0, a AS g_1"}, ComparisonMode.EXACT_COMMAND_STRING);
+	    ProcessorPlan plan = TestOptimizer.helpPlan(sql, RealMetadataFactory.example1Cached(), null, capFinder, new String[] {"WITH a (x, y, z) AS (SELECT g_0.e1, g_0.e2, g_0.e3 FROM pm1.g1 AS g_0) SELECT g_0.x FROM a AS g_0, a AS g_1"}, ComparisonMode.EXACT_COMMAND_STRING);
+	    
+	    helpProcess(plan, dataManager, expected);
 	}
 	
 	@Test public void testWithPushdownWithConstants() throws TeiidException {

Modified: trunk/engine/src/test/java/org/teiid/query/processor/relational/TestSortNode.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/relational/TestSortNode.java	2011-08-31 18:43:49 UTC (rev 3440)
+++ trunk/engine/src/test/java/org/teiid/query/processor/relational/TestSortNode.java	2011-09-01 19:48:30 UTC (rev 3441)
@@ -46,7 +46,7 @@
 import org.teiid.query.sql.symbol.ElementSymbol;
 import org.teiid.query.util.CommandContext;
 
-
+ at SuppressWarnings("unchecked")
 public class TestSortNode {
     
     public static final int BATCH_SIZE = 100;
@@ -321,4 +321,37 @@
     	assertEquals(Arrays.asList(2), ts.nextTuple());
     }
     
+    @Test public void testDupRemoveLowMemory() throws Exception {
+    	ElementSymbol es1 = new ElementSymbol("e1"); //$NON-NLS-1$
+        es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
+        BufferManager bm = BufferManagerFactory.getTestBufferManager(0, 2);
+        TupleBuffer tsid = bm.createTupleBuffer(Arrays.asList(es1), "test", TupleSourceType.PROCESSOR); //$NON-NLS-1$
+        tsid.addTuple(Arrays.asList(1));
+        tsid.addTuple(Arrays.asList(2));
+    	SortUtility su = new SortUtility(tsid.createIndexedTupleSource(), Arrays.asList(es1), Arrays.asList(Boolean.TRUE), Mode.DUP_REMOVE, bm, "test", tsid.getSchema()); //$NON-NLS-1$
+    	TupleBuffer out = su.sort();
+    	TupleSource ts = out.createIndexedTupleSource();
+    	assertEquals(Arrays.asList(1), ts.nextTuple());
+    	assertEquals(Arrays.asList(2), ts.nextTuple());
+    	try {
+    		ts.nextTuple();
+    		fail();
+    	} catch (BlockedException e) {
+    		
+    	}
+    	tsid.addTuple(Arrays.asList(3));
+    	tsid.addTuple(Arrays.asList(4));
+    	tsid.addTuple(Arrays.asList(5));
+    	tsid.addTuple(Arrays.asList(6));
+    	tsid.addTuple(Arrays.asList(6));
+    	tsid.addTuple(Arrays.asList(6));
+    	tsid.close();
+    	su.sort();
+		ts.nextTuple();
+		ts.nextTuple();
+		assertNotNull(ts.nextTuple());
+		assertNotNull(ts.nextTuple());
+		assertNull(ts.nextTuple());
+    }
+
 }

Modified: trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java	2011-08-31 18:43:49 UTC (rev 3440)
+++ trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java	2011-09-01 19:48:30 UTC (rev 3441)
@@ -488,7 +488,6 @@
 		                	List<PgColInfo> cols = getPgColInfo(stmt.getResultSet().getMetaData());
                             client.sendResults(query.sql, stmt.getResultSet(), cols, result, true);
 		                } else {
-		                	// null future
 		                	client.sendUpdateCount(query.sql, stmt.getUpdateCount());
 		                	setEncoding();
 		                	result.getResultsReceiver().receiveResults(1);
@@ -627,7 +626,7 @@
 	}
 
 	@Override
-	public void executeQuery(final String query) {
+	public void executeQuery(String query) {
 		if (beginExecution()) {
 			errorOccurred("Awaiting asynch result"); //$NON-NLS-1$
 			ready();
@@ -636,12 +635,12 @@
 		//46.2.3 Note that a simple Query message also destroys the unnamed portal.
 		this.portalMap.remove(UNNAMED);
 		this.preparedMap.remove(UNNAMED);
-		
-		if (query.trim().length() == 0) {
-    		this.client.emptyQueryReceived();
+		query = query.trim();
+		if (query.length() == 0) {
+    		client.emptyQueryReceived();
     		ready();
-    		return;
     	}
+		
         QueryWorkItem r = new QueryWorkItem(query);
 		r.run();
 	}
@@ -871,6 +870,15 @@
 		private QueryWorkItem(String query) {
 			this.reader = new ScriptReader(new StringReader(query));		
 		}
+		
+		private void done(Throwable error) {
+			if (error != null) {
+				errorOccurred(error);
+			} else {
+				doneExecuting();
+			}
+			ready();
+		}
 
 		@Override
 		public void run() {
@@ -890,14 +898,14 @@
 		    					} catch (InterruptedException e) {
 		    						throw new AssertionError(e);
 		    					} catch (IOException e) {
-		    						client.errorOccurred(e);
+		    						done(e);
 		    						return;
 		    					} catch (ExecutionException e) {
 		    						Throwable cause = e;
 		    						while (cause instanceof ExecutionException && cause.getCause() != null && cause != cause.getCause()) {
 		    							cause = cause.getCause();
 		    						}
-		    						client.errorOccurred(cause);
+		    						done(cause);
 		    						return;
 		    					}
 		            			QueryWorkItem.this.run(); //continue processing
@@ -943,15 +951,15 @@
 		    			}
 		                return; //wait for the execution to finish
 		            } catch (SQLException e) {
-		                errorOccurred(e);
-		                break;
+		            	done(e);
+		            	return;
 		            } 
 		        }
 			} catch(IOException e) {
-				errorOccurred(e);
+				done(e);
+				return;
 			}
-			doneExecuting();
-			ready();
+			done(null);
 		}
 	}
     



More information about the teiid-commits mailing list