[teiid-commits] teiid SVN: r3351 - in trunk: build/kits/jboss-container and 20 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Sat Jul 30 08:41:33 EDT 2011


Author: shawkins
Date: 2011-07-30 08:41:32 -0400 (Sat, 30 Jul 2011)
New Revision: 3351

Added:
   trunk/engine/src/test/resources/TestXMLPlanningEnhancements-testThreeWayOrWithNestedSiblings.xml
Modified:
   trunk/api/src/main/java/org/teiid/events/EventDistributor.java
   trunk/build/kits/jboss-container/deploy/teiid/teiid-cache-manager-jboss-beans-rename-me.xml
   trunk/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml
   trunk/build/kits/jboss-container/teiid-releasenotes.html
   trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/JBossCacheFactory.java
   trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/TupleBatchCacheLoader.java
   trunk/documentation/caching-guide/src/main/docbook/en-US/content/matviews.xml
   trunk/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java
   trunk/engine/src/main/java/org/teiid/query/mapping/xml/ResultSetInfo.java
   trunk/engine/src/main/java/org/teiid/query/optimizer/xml/CriteriaPlanner.java
   trunk/engine/src/main/java/org/teiid/query/optimizer/xml/SourceNodePlannerVisitor.java
   trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java
   trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStagaingQueryPlanner.java
   trunk/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java
   trunk/engine/src/main/java/org/teiid/query/processor/xml/ExecSqlInstruction.java
   trunk/engine/src/main/java/org/teiid/query/processor/xml/ExecStagingTableInstruction.java
   trunk/engine/src/main/java/org/teiid/query/processor/xml/PlanExecutor.java
   trunk/engine/src/main/java/org/teiid/query/processor/xml/RelationalPlanExecutor.java
   trunk/engine/src/main/java/org/teiid/query/processor/xml/XMLPlan.java
   trunk/engine/src/main/java/org/teiid/query/processor/xml/XMLProcessorEnvironment.java
   trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
   trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java
   trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
   trunk/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java
   trunk/engine/src/main/resources/org/teiid/query/i18n.properties
   trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
   trunk/engine/src/test/java/org/teiid/query/processor/xml/FakePlanExecutor.java
   trunk/engine/src/test/java/org/teiid/query/processor/xml/TestProcessorEnvironment.java
   trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLPlanningEnhancements.java
   trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java
   trunk/jboss-integration/src/main/java/org/teiid/jboss/JBossLifeCycleListener.java
   trunk/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java
   trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties
   trunk/runtime/src/main/java/org/teiid/deployers/ContainerLifeCycleListener.java
Log:
forward merge from 7.4.1

Modified: trunk/api/src/main/java/org/teiid/events/EventDistributor.java
===================================================================
--- trunk/api/src/main/java/org/teiid/events/EventDistributor.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/api/src/main/java/org/teiid/events/EventDistributor.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -121,4 +121,11 @@
 	 */
 	void setViewDefinition(String vdbName, int vdbVersion, String schema, String viewName, String definition);
 	
+	/**
+	 * 
+	 * @param vdbName
+	 * @param vdbVersion
+	 * @param viewName
+	 */
+	void refreshMatView(String vdbName, int vdbVersion, String tableName);
 }


Property changes on: trunk/api/src/main/java/org/teiid/events/EventDistributor.java
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/7.4.x/api/src/main/java/org/teiid/events/EventDistributor.java:3340-3349

Modified: trunk/build/kits/jboss-container/deploy/teiid/teiid-cache-manager-jboss-beans-rename-me.xml
===================================================================
--- trunk/build/kits/jboss-container/deploy/teiid/teiid-cache-manager-jboss-beans-rename-me.xml	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/build/kits/jboss-container/deploy/teiid/teiid-cache-manager-jboss-beans-rename-me.xml	2011-07-30 12:41:32 UTC (rev 3351)
@@ -145,7 +145,7 @@
         </property>
         <property name="clusterName">${jboss.partition.name:DefaultPartition}-teiid-events</property>
         <property name="multiplexerStack">${jboss.default.jgroups.stack:udp}</property>        
-        <property name="localEventDistributorName">teiid/runtime-engine</property>
+        <property name="localEventDistributorName">teiid/engine-deployer</property>
     </bean>
 
 </deployment>
\ No newline at end of file

Modified: trunk/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml
===================================================================
--- trunk/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml	2011-07-30 12:41:32 UTC (rev 3351)
@@ -102,6 +102,7 @@
         <property name="resultsetCacheConfig"><inject bean="ResultsetCacheConfig"/></property>
         <property name="preparedPlanCacheConfig"><inject bean="PreparedPlanCacheConfig"/></property>
         <property name="authorizationValidator"><inject bean="AuthorizationValidator"/></property>
+        <property name="containerLifeCycleListener"><inject bean="JBossLifeCycleListener"/></property>
         <!-- Process pool maximum thread count. (default 64) -->
         <property name="maxThreads">64</property>
         <!-- Max active plans (default 20).  Increase this value on highly concurrent systems - but ensure that the underlying pools can handle the increased load without timeouts. -->

Modified: trunk/build/kits/jboss-container/teiid-releasenotes.html
===================================================================
--- trunk/build/kits/jboss-container/teiid-releasenotes.html	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/build/kits/jboss-container/teiid-releasenotes.html	2011-07-30 12:41:32 UTC (rev 3351)
@@ -36,6 +36,12 @@
 	<LI><B>Logging Procedures</B> - added SYSADMIN.isLoggable and SYSADMIN.logMsg to aid in debugging procedure logic.
 	<LI><B>ANSI OFFSET/FETCH FIRST</B> - instead of the limit clause, a standard OFFSET and/or FETCH FIRST/NEXT clause can be used to limit results.
 	<LI><B>ODBC Cursors</B> - Capability to use "UseDeclareFetch" with ODBC is added. This enables user to read the results in batches, especially useful when dealing with large row count of results.
+	<LI><B>Internal Materialized Views</B>
+		<UL>
+			<LI><B>Distributed Refresh</B> - When a internal materialized view is refreshed at one node, an event is issued to all other nodes in the cluster to asynchronously fetch the new contents.
+			<LI><B>Sync at Start</B> - When a node is restarted in a cluster, at end of start cycle Teiid will asynchronously fetch the cached internal materialized view contents from other nodes.
+		</UL>
+	</LI>
 </UL>
 
 <h2><a name="Compatibility">Compatibility Issues</a></h2>

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-07-30 12:31:35 UTC (rev 3350)
+++ trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/JBossCacheFactory.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -59,7 +59,9 @@
 			
 			if (!this.cacheStore.getCacheStatus().allowInvocations()) {
 				this.cacheStore.start();
-				this.cacheStore.getRegion(this.cacheStore.getRoot().getFqn(), true).activate();
+				if (this.cacheStore.getRegion(this.cacheStore.getRoot().getFqn(), false) != null) {
+					this.cacheStore.getRegion(this.cacheStore.getRoot().getFqn(), true).activate();	
+				}
 			}
 			
 			Node cacheRoot = this.cacheStore.getRoot().addChild(Fqn.fromString("Teiid")); //$NON-NLS-1$

Modified: trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/TupleBatchCacheLoader.java
===================================================================
--- trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/TupleBatchCacheLoader.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/TupleBatchCacheLoader.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -62,9 +62,8 @@
 				map.put(id, b);
 				return map;
 			}
-			return super.get(fqn);
 		}
-		return null;
+		return super.get(fqn);
 	}
 
 	@Override

Modified: trunk/documentation/caching-guide/src/main/docbook/en-US/content/matviews.xml
===================================================================
--- trunk/documentation/caching-guide/src/main/docbook/en-US/content/matviews.xml	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/documentation/caching-guide/src/main/docbook/en-US/content/matviews.xml	2011-07-30 12:41:32 UTC (rev 3351)
@@ -120,6 +120,22 @@
 			subsequent refreshes performed with <code>refreshMatView</code> will use dependent materialized view tables if they exist.  Only one load may occur at a time.  If a load is already in progress when
 			the <code>SYSADMIN.refreshMatView</code> procedure is called, it will return -1 immediately rather than preempting the current load.
 			</para>
+            <para>
+            When Teiid is running clustered mode, after of loading of internal materialized view contents, an event will be sent to all
+            the other participating nodes in the cluster to refresh the contents from the original node in asynchronus fashion.
+            During this remote node loading process, if the node that is reading the contents gets a request from user to serve the
+            results of that view, then the current results in cache will be served. If no results were available at that node, then 
+            request will be blocked until load process is finished.
+            </para>
+            <para>
+            When a Teiid node joins the cluster, at the end of start-up cycle, an asynchronus job
+            will be started to fetch all the previously cached internal materialized views at other nodes
+            for the deployed VDBs. The query request behaviour during this load process is same as above. 
+            </para>  
+            <note><para>In the clustered mode, the "invalidate=true" flag in the "SYSADMIN.refreshMatView" procedure
+            will only apply to the node that is refreshing the contents from source. All other nodes, will still serve the 
+            old contents during the refresh process.</para>
+            </note>          
 			<section>
 		   		<title>TTL Snapshot Refresh</title>
 		   		<para>The <link linkend="cache-hint">cache hint</link> may be used to automatically trigger a full snapshot refresh after a specified time to live (ttl).  

Modified: trunk/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -99,8 +99,12 @@
 			this.uuid = java.util.UUID.randomUUID().toString();
 		}
 		return this.uuid;
-	}	
+	}
 	
+	public void setId(String uuid) {
+		this.uuid = uuid;
+	}
+	
 	public boolean isLobs() {
 		return lobIndexes != null;
 	}


Property changes on: trunk/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/7.4.x/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java:3149-3217,3220-3275
   + /branches/7.4.x/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java:3149-3217,3220-3275,3340-3349

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -139,6 +139,7 @@
 				}
 				buffer = bufferManager.createTupleBuffer(schema, "cached", TupleSourceType.FINAL); //$NON-NLS-1$
 				buffer.setBatchSize(this.batchSize);
+				buffer.setId(this.uuid);
 				if (this.hint != null) {
 					buffer.setPrefersMemory(this.hint.getPrefersMemory());
 				}
@@ -151,6 +152,7 @@
 						return false;
 					}		
 					buffer.addTupleBatch(batch, true);
+					cache.remove(uuid+","+row); //$NON-NLS-1$
 				}
 				this.results = buffer;	
 				bufferManager.addTupleBuffer(this.results);

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	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -28,6 +28,7 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.FutureTask;
@@ -42,10 +43,11 @@
 import org.teiid.adminapi.Request.ThreadState;
 import org.teiid.adminapi.impl.CacheStatisticsMetadata;
 import org.teiid.adminapi.impl.RequestMetadata;
+import org.teiid.adminapi.impl.VDBMetaData;
 import org.teiid.adminapi.impl.WorkerPoolStatisticsMetadata;
 import org.teiid.cache.CacheConfiguration;
+import org.teiid.cache.CacheConfiguration.Policy;
 import org.teiid.cache.CacheFactory;
-import org.teiid.cache.CacheConfiguration.Policy;
 import org.teiid.client.DQP;
 import org.teiid.client.RequestMessage;
 import org.teiid.client.ResultsMessage;
@@ -57,24 +59,29 @@
 import org.teiid.client.xa.XidImpl;
 import org.teiid.common.buffer.BufferManager;
 import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidException;
 import org.teiid.core.TeiidProcessingException;
 import org.teiid.core.TeiidRuntimeException;
 import org.teiid.core.types.Streamable;
+import org.teiid.dqp.internal.process.SessionAwareCache.CacheID;
 import org.teiid.dqp.internal.process.ThreadReuseExecutor.PrioritizedRunnable;
 import org.teiid.dqp.message.AtomicRequestMessage;
 import org.teiid.dqp.message.RequestID;
 import org.teiid.dqp.service.BufferService;
 import org.teiid.dqp.service.TransactionContext;
+import org.teiid.dqp.service.TransactionContext.Scope;
 import org.teiid.dqp.service.TransactionService;
-import org.teiid.dqp.service.TransactionContext.Scope;
 import org.teiid.events.EventDistributor;
 import org.teiid.logging.CommandLogMessage;
+import org.teiid.logging.CommandLogMessage.Event;
 import org.teiid.logging.LogConstants;
 import org.teiid.logging.LogManager;
 import org.teiid.logging.MessageLevel;
-import org.teiid.logging.CommandLogMessage.Event;
 import org.teiid.metadata.MetadataRepository;
 import org.teiid.query.QueryPlugin;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.TempMetadataAdapter;
+import org.teiid.query.optimizer.relational.RelationalPlanner;
 import org.teiid.query.tempdata.TempTableDataManager;
 import org.teiid.query.tempdata.TempTableStore;
 
@@ -173,9 +180,12 @@
 				requests.remove(requestID);
 			}
 		}
-		
 	}
 	
+	public static interface ContextProvider {
+		DQPWorkContext getContext(String vdbName, int vdbVersion);
+	}
+	
 	private ThreadReuseExecutor processWorkerPool;
     
     // Resources
@@ -730,10 +740,92 @@
         processorDataManager.setMetadataRepository(metadataRepository);
 		dataTierMgr = new TempTableDataManager(processorDataManager, this.bufferManager, this.processWorkerPool, this.rsCache, this.matTables, this.cacheFactory);
         dataTierMgr.setEventDistributor(eventDistributor);
-        
+                
         LogManager.logDetail(LogConstants.CTX_DQP, "DQPCore started maxThreads", this.config.getMaxThreads(), "maxActivePlans", this.maxActivePlans, "source concurrency", this.userRequestSourceConcurrency); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 	}
 	
+	public void synchronizeInternalMaterializedViews(final ContextProvider contextProvider) {
+        if (!cacheFactory.isReplicated() || matTables == null) {
+        	return;
+        }
+        Set<CacheID> keys = this.matTables.replicatableKeys();
+        for (final CacheID key:keys) {
+        	refreshMatView(contextProvider, key.getVDBKey().getName(), key.getVDBKey().getVersion(), key.getSql());
+        }
+	}
+	
+	public void refreshMatView(final ContextProvider contextProvider, final String vdbName, final int vdbVersion, final String viewName) {
+        if (!cacheFactory.isReplicated() || matTables == null) {
+        	return;
+        }
+        
+        final DQPWorkContext context = contextProvider.getContext(vdbName, vdbVersion); 
+        
+		final VDBMetaData vdb = context.getVDB();
+		if (vdb == null) {
+			return;
+		}
+		
+		final TempTableStore globalStore = vdb.getAttachment(TempTableStore.class);
+		if (globalStore == null) {
+			return;
+		}        
+		DQPWorkContext.setWorkContext(context);
+		
+		Runnable work = new Runnable() {
+			@Override
+			public void run() {
+				QueryMetadataInterface metadata = vdb.getAttachment(QueryMetadataInterface.class);
+				TempTableStore tempStore = new TempTableStore("internal"); //$NON-NLS-1$
+				TempMetadataAdapter tma = new TempMetadataAdapter(metadata, tempStore.getMetadataStore());
+				try {
+					dataTierMgr.refreshMatView(vdb.getName(), vdb.getVersion(), viewName, tma, globalStore);
+				} catch (TeiidException e) {
+					LogManager.logError(LogConstants.CTX_DQP, e, QueryPlugin.Util.getString("error_refresh", viewName )); //$NON-NLS-1$
+				}						
+			}
+		};
+		addWork(work);
+	}
+	
+	public void updateMatViewRow(final ContextProvider contextProvider, final String vdbName, final int vdbVersion, final String schema,
+			final String viewName, final List<?> tuple, final boolean delete) {
+		
+        if (!cacheFactory.isReplicated() || matTables == null) {
+        	return;
+        }
+        
+        final DQPWorkContext context = contextProvider.getContext(vdbName, vdbVersion); 
+        
+		final VDBMetaData vdb = context.getVDB();
+		if (vdb == null) {
+			return;
+		}
+		
+		final TempTableStore globalStore = vdb.getAttachment(TempTableStore.class);
+		if (globalStore == null) {
+			return;
+		}        
+		
+		Runnable work = new Runnable() {
+			@Override
+			public void run() {
+				context.runInContext(new Runnable() {
+					@Override
+					public void run() {
+						try {
+							dataTierMgr.updateMatViewRow(globalStore, RelationalPlanner.MAT_PREFIX + (schema + '.' + viewName).toUpperCase(), tuple, delete);
+						} catch (TeiidException e) {
+							LogManager.logError(LogConstants.CTX_DQP, e, QueryPlugin.Util.getString("DQPCore.unable_to_process_event")); //$NON-NLS-1$
+						}					
+					}
+				});
+			}
+		};
+		addWork(work);		
+		
+	}
+
 	public void setBufferService(BufferService service) {
 		this.bufferService = service;
 	}
@@ -925,5 +1017,4 @@
 	SessionAwareCache<PreparedPlan> getPrepPlanCache() {
 		return prepPlanCache;
 	}
-	
 }
\ No newline at end of file

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -24,6 +24,7 @@
 
 import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -291,6 +292,10 @@
 		void setUserName(String name) {
 			this.userName = name;
 		}
+		
+		public VDBKey getVDBKey() {
+			return vdbInfo;
+		}
 						
 		public boolean equals(Object obj){
 	        if(obj == this) {
@@ -328,4 +333,11 @@
     public void setModTime(long modTime) {
 		this.modTime = modTime;
 	}
+    
+    public Set<CacheID> replicatableKeys() {
+    	if (this.distributedCache == this.localCache) {
+    		return Collections.EMPTY_SET;
+    	}
+    	return this.distributedCache.keys();
+    }
 }

Modified: trunk/engine/src/main/java/org/teiid/query/mapping/xml/ResultSetInfo.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/mapping/xml/ResultSetInfo.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/main/java/org/teiid/query/mapping/xml/ResultSetInfo.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -66,6 +66,8 @@
     //joined source node state
     private int mappingClassNumber = 0;
     private ElementSymbol mappingClassSymbol;
+	private boolean inputSet;
+	private boolean isCritNullDependent;
     
     public ResultSetInfo(String resultName) {
         this(resultName, false);
@@ -176,4 +178,20 @@
     public boolean isStagedResult() {
         return this.stagedResult;
     }
+    
+	public boolean hasInputSet() {
+		return inputSet;
+	}
+
+	public void setInputSet(boolean inputSet) {
+		this.inputSet = inputSet;
+	}
+	
+	public void setCritNullDependent(boolean isCritNullDependent) {
+		this.isCritNullDependent = isCritNullDependent;
+	}
+	
+	public boolean isCritNullDependent(){
+		return this.isCritNullDependent;
+	}
 }

Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/xml/CriteriaPlanner.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/xml/CriteriaPlanner.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/xml/CriteriaPlanner.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -37,6 +37,7 @@
 import org.teiid.query.mapping.xml.MappingSourceNode;
 import org.teiid.query.mapping.xml.ResultSetInfo;
 import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.relational.rules.JoinUtil;
 import org.teiid.query.sql.lang.CompareCriteria;
 import org.teiid.query.sql.lang.Criteria;
 import org.teiid.query.sql.symbol.Constant;
@@ -44,6 +45,7 @@
 import org.teiid.query.sql.symbol.Function;
 import org.teiid.query.sql.symbol.GroupSymbol;
 import org.teiid.query.sql.visitor.ElementCollectorVisitor;
+import org.teiid.query.sql.visitor.GroupsUsedByElementsVisitor;
 
 
 public class CriteriaPlanner {
@@ -106,9 +108,15 @@
             //TODO: this can be replaced with method on the source node?
             MappingSourceNode criteriaRs = findRootResultSetNode(context, sourceNodes, criteria);
             
+            Collection<GroupSymbol> groups = GroupsUsedByElementsVisitor.getGroups(conjunct);
+            boolean userCritNullDependent = JoinUtil.isNullDependent(planEnv.getGlobalMetadata(), groups, conjunct);
+            ResultSetInfo rs = criteriaRs.getResultSetInfo();
+            if(userCritNullDependent){
+            	rs.setCritNullDependent(true);
+            }
+            
             Criteria convertedCrit = XMLNodeMappingVisitor.convertCriteria(conjunct, planEnv.mappingDoc, planEnv.getGlobalMetadata());
             
-            ResultSetInfo rs = criteriaRs.getResultSetInfo();
             rs.setCriteria(Criteria.combineCriteria(rs.getCriteria(), convertedCrit));
             rs.addToCriteriaResultSets(sourceNodes);
         }

Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/xml/SourceNodePlannerVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/xml/SourceNodePlannerVisitor.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/xml/SourceNodePlannerVisitor.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -122,11 +122,12 @@
                         
             MappingSourceNode parent = sourceNode.getParentSourceNode();
             Collection<ElementSymbol> bindings = QueryUtil.getBindingElements(modifiedNode);
+            rsInfo.setInputSet(!bindings.isEmpty());
             // root source nodes do not have any inputset criteria on them; so there is no use in
             // going through the raising the criteria.
             // if the original query is not a select.. we are out of luck. we can expand on this later
             // versions. make sure bindings are only to parent.
-            if (parent == null || !canRaiseInputset(command, bindings) || !areBindingsOnlyToNode(modifiedNode, parent)) {
+            if (!rsInfo.hasInputSet() || !canRaiseInputset(command, bindings) || !areBindingsOnlyToNode(modifiedNode, parent)) {
                 return;
             }
             
@@ -152,6 +153,10 @@
                 }
             }
             
+            if (inputSetCriteria == null) {
+            	return;
+            }
+            
             // Keep the criteria which is not reference based.
             transformationQuery.setCriteria(nonInputsetCriteria);
 

Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -300,9 +300,7 @@
         
         Query currentQuery = contextQuery;
         
-        for (Iterator i = resultSets.iterator(); i.hasNext();) {
-            MappingSourceNode rsNode = (MappingSourceNode)i.next();
-            
+        for (MappingSourceNode rsNode : resultSets) {
             ResultSetInfo childRsInfo = rsNode.getResultSetInfo();
             
             QueryNode planNode = QueryUtil.getQueryNode(childRsInfo.getResultSetName(), planEnv.getGlobalMetadata());    
@@ -313,35 +311,19 @@
             updateSymbolMap(symbolMap, childRsInfo.getResultSetName(), inlineViewName, planEnv.getGlobalMetadata());
             
             // check if the criteria has been raised, if it is then we can update this as a join.
-            if (childRsInfo.isCriteriaRaised()) {
+            if (!rsInfo.isCritNullDependent() && childRsInfo.hasInputSet() && childRsInfo.isCriteriaRaised()) {
                 Query transformationQuery = (Query) command;
                 SubqueryFromClause sfc = (SubqueryFromClause)transformationQuery.getFrom().getClauses().get(0);
                 
                 Criteria joinCriteria = ((Query)childRsInfo.getCommand()).getCriteria();
                 
-                if (joinCriteria == null) {
-                    joinCriteria = QueryRewriter.TRUE_CRITERIA;
-                }
-                
                 joinCriteria = (Criteria)joinCriteria.clone();
                 
                 //update the from clause
                 FromClause clause = currentQuery.getFrom().getClauses().remove(0);
                 
-                JoinPredicate join = null;
+                JoinPredicate join = new JoinPredicate(clause, sfc, JoinType.JOIN_LEFT_OUTER, Criteria.separateCriteriaByAnd(joinCriteria));
                 
-                if (clause instanceof JoinPredicate) {
-                    join = (JoinPredicate)clause;
-                    
-                    FromClause right = join.getRightClause();
-                    
-                    JoinPredicate newRight = new JoinPredicate(right, sfc, JoinType.JOIN_LEFT_OUTER, Criteria.separateCriteriaByAnd(joinCriteria));
-                    
-                    join.setRightClause(newRight);
-                } else {
-                    join = new JoinPredicate(clause, sfc, JoinType.JOIN_LEFT_OUTER, Criteria.separateCriteriaByAnd(joinCriteria));
-                }
-                
                 currentQuery.getFrom().addClause(join);
                 
                 currentQuery.getSelect().setDistinct(true);

Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStagaingQueryPlanner.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStagaingQueryPlanner.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStagaingQueryPlanner.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -104,7 +104,7 @@
         ResultSetInfo rsInfo = sourceNode.getResultSetInfo();
 
         // If this node has been eligible for raising, it will be eligible for staging.
-        if (!rsInfo.isCriteriaRaised()) {
+        if (rsInfo.hasInputSet() && !rsInfo.isCriteriaRaised()) {
             return false;
         }
         

Modified: trunk/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -169,7 +169,7 @@
 		return result;
 	}
 
-	private void init() throws TeiidComponentException, TeiidProcessingException {
+	public void init() throws TeiidComponentException, TeiidProcessingException {
 		// initialize if necessary
 		if(!initialized) {
 			reserved = this.bufferMgr.reserveBuffers(this.bufferMgr.getSchemaSize(this.getOutputElements()), BufferReserveMode.FORCE);
@@ -184,7 +184,6 @@
 		}
 	}
 
-	                   
     /**
      * Close processing and clean everything up.  Should only be called by the same thread that called process.
      */


Property changes on: trunk/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/7.4.x/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java:3220-3275
   + /branches/7.4.x/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java:3220-3275,3340-3349

Modified: trunk/engine/src/main/java/org/teiid/query/processor/xml/ExecSqlInstruction.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/xml/ExecSqlInstruction.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/main/java/org/teiid/query/processor/xml/ExecSqlInstruction.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -49,14 +49,10 @@
         throws BlockedException, TeiidComponentException, TeiidProcessingException{
 
         LogManager.logTrace(org.teiid.logging.LogConstants.CTX_XML_PLAN, new Object[]{"SQL: Result set DOESN'T exist:",resultSetName}); //$NON-NLS-1$
-        PlanExecutor executor = context.getResultExecutor(resultSetName);
-        if (executor == null) {
-            executor = env.createResultExecutor(resultSetName, info);
-            context.setResultExecutor(resultSetName, executor);
-        }
+        PlanExecutor executor = getPlanExecutor(env, context);
         
         // this execute can throw the blocked exception
-        executor.execute(context.getReferenceValues());
+        executor.execute(context.getReferenceValues(), false);
         
         // now that we done executing the plan; remove the plan from context
         context.removeResultExecutor(resultSetName);
@@ -68,6 +64,16 @@
         env.incrementCurrentProgramCounter();
         return context;
     }
+
+	public PlanExecutor getPlanExecutor(XMLProcessorEnvironment env,
+			XMLContext context) throws TeiidComponentException {
+		PlanExecutor executor = context.getResultExecutor(resultSetName);
+        if (executor == null) {
+            executor = env.createResultExecutor(resultSetName, info);
+            context.setResultExecutor(resultSetName, executor);
+        }
+		return executor;
+	}
     
     public String toString() {
         return "SQL  " + resultSetName; //$NON-NLS-1$ 

Modified: trunk/engine/src/main/java/org/teiid/query/processor/xml/ExecStagingTableInstruction.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/xml/ExecStagingTableInstruction.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/main/java/org/teiid/query/processor/xml/ExecStagingTableInstruction.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -73,7 +73,7 @@
             // bound references; they are not part of the document; so they do not know about document
             // details.
             Map referenceValues = null;
-            executor.execute(referenceValues);
+            executor.execute(referenceValues, false);
             env.markStagingTableAsLoaded(this.resultSetName);
             
             // now that we done executing the plan; remove the plan from context

Modified: trunk/engine/src/main/java/org/teiid/query/processor/xml/PlanExecutor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/xml/PlanExecutor.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/main/java/org/teiid/query/processor/xml/PlanExecutor.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -39,8 +39,9 @@
     /**
      * Execute the plan   
      * @param referenceValues - values for any external references
+     * @param openOnly
      */
-    public void execute(Map referenceValues) throws TeiidComponentException, BlockedException, TeiidProcessingException;
+    public void execute(Map referenceValues, boolean openOnly) throws TeiidComponentException, BlockedException, TeiidProcessingException;
 
     /**
      * Get the ElementSymbol list which represents the schema of the result set

Modified: trunk/engine/src/main/java/org/teiid/query/processor/xml/RelationalPlanExecutor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/xml/RelationalPlanExecutor.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/main/java/org/teiid/query/processor/xml/RelationalPlanExecutor.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -87,15 +87,20 @@
 
     /**
      * @throws TeiidProcessingException 
-     * @see org.teiid.query.processor.xml.PlanExecutor#execute(java.util.Map)
+     * @see org.teiid.query.processor.xml.PlanExecutor#execute(java.util.Map, boolean)
      */
-    public void execute(Map referenceValues) throws TeiidComponentException, BlockedException, TeiidProcessingException {        
+    public void execute(Map referenceValues, boolean openOnly) throws TeiidComponentException, BlockedException, TeiidProcessingException {        
         if (this.tupleSource == null) {
         	setReferenceValues(referenceValues);
             this.tupleSource = new BatchIterator(internalProcessor);
+            if (openOnly) {
+            	internalProcessor.init();
+            }
         }
-        //force execution
-        this.tupleSource.hasNext();
+        if (!openOnly) {
+	        //force execution
+	        this.tupleSource.hasNext();
+        }
     }    
     
     void setReferenceValues(Map<ElementSymbol, Object> referencesValues) {

Modified: trunk/engine/src/main/java/org/teiid/query/processor/xml/XMLPlan.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/xml/XMLPlan.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/main/java/org/teiid/query/processor/xml/XMLPlan.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -155,7 +155,7 @@
         
         while(true){
         	// do the xml processing.
-            ProcessorInstruction inst = env.getCurrentInstruction();
+            ProcessorInstruction inst = env.getCurrentInstruction(this.context);
             while (inst != null){
             	LogManager.logTrace(LogConstants.CTX_XML_PLAN, "Executing instruction", inst); //$NON-NLS-1$
                 this.context = inst.process(this.env, this.context);
@@ -186,7 +186,7 @@
         	        TupleBatch batch = new TupleBatch(nextBatchCount++, Arrays.asList(Arrays.asList(xml)));
         	        return batch;
                 }
-                inst = env.getCurrentInstruction();
+                inst = env.getCurrentInstruction(this.context);
             }
             
         	TupleBatch batch = new TupleBatch(nextBatchCount++, Collections.EMPTY_LIST); 

Modified: trunk/engine/src/main/java/org/teiid/query/processor/xml/XMLProcessorEnvironment.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/xml/XMLProcessorEnvironment.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/main/java/org/teiid/query/processor/xml/XMLProcessorEnvironment.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -26,10 +26,12 @@
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedList;
+import java.util.List;
 import java.util.Set;
 
 import org.teiid.common.buffer.BufferManager;
 import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
 import org.teiid.logging.LogManager;
 import org.teiid.logging.MessageLevel;
 import org.teiid.query.mapping.xml.ResultSetInfo;
@@ -84,6 +86,7 @@
     private static class ProgramState {
         private Program program;
         private int programCounter = 0;
+        private int lookaheadCounter;
         private int recursionCount = NOT_RECURSIVE;
         
         private static final int NOT_RECURSIVE = 0;
@@ -156,7 +159,7 @@
         this.programStack.addFirst(programState);
     }
 
-    public ProcessorInstruction getCurrentInstruction() {
+    public ProcessorInstruction getCurrentInstruction(XMLContext context) throws TeiidComponentException, TeiidProcessingException {
         ProgramState programState = this.programStack.getFirst();
         
         //Case 5266: account for an empty program on to the stack; 
@@ -171,6 +174,23 @@
             return null;
         }
         
+        //start all siblings
+        List<ProcessorInstruction> instrs = programState.program.getProcessorInstructions();
+        if (programState.programCounter >= programState.lookaheadCounter && instrs.size() > programState.programCounter + 1) {
+        	for (programState.lookaheadCounter = programState.programCounter; programState.lookaheadCounter < instrs.size(); programState.lookaheadCounter++) {
+        		ProcessorInstruction pi = instrs.get(programState.lookaheadCounter);
+        		if (pi instanceof ExecStagingTableInstruction) {
+        			//need to load staging tables prior to source queries
+        			break;
+        		}
+        		if (pi instanceof ExecSqlInstruction) {
+        			ExecSqlInstruction esi = (ExecSqlInstruction)pi;
+        			PlanExecutor pe = esi.getPlanExecutor(this, context);
+        			pe.execute(context.getReferenceValues(), true);
+        		}
+        	}
+        }
+        
         return programState.program.getInstructionAt(programState.programCounter);
     }
     
@@ -251,8 +271,6 @@
         ProgramState initialProgramState = this.programStack.getLast();
         ProgramState newState = new ProgramState();
         newState.program = initialProgramState.program;
-        newState.programCounter = 0;
-        newState.recursionCount = ProgramState.NOT_RECURSIVE;
         clone.programStack.addFirst(newState);
                
         // XML results form and format

Modified: trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -309,15 +309,27 @@
 		QueryMetadataInterface metadata = context.getMetadata();
 		TempTableStore globalStore = context.getGlobalTableStore();
 		if (StringUtil.endsWithIgnoreCase(proc.getProcedureCallableName(), REFRESHMATVIEW)) {
-			Object groupID = validateMatView(metadata, proc);
+			Object groupID = validateMatView(metadata, (String)((Constant)proc.getParameter(1).getExpression()).getValue());
 			Object matTableId = context.getGlobalTableStore().getGlobalTempTableMetadataId(groupID, metadata);
 			String matViewName = metadata.getFullName(groupID);
 			String matTableName = metadata.getFullName(matTableId);
 			LogManager.logDetail(LogConstants.CTX_MATVIEWS, "processing refreshmatview for", matViewName); //$NON-NLS-1$
 			MatTableInfo info = globalStore.getMatTableInfo(matTableName);
+			Long loadTime = null;
+			boolean useCache = false;
+			if (this.distributedCache != null) {
+				MatTableKey key = new MatTableKey();
+				key.name = matTableName;
+				key.vdb = new VDBKey(context.getVdbName(),context.getVdbVersion());
+				MatTableEntry entry = this.tables.get(key);
+				useCache = (entry != null && entry.valid && entry.lastUpdate > info.getUpdateTime());
+				if (useCache) {
+					loadTime = entry.lastUpdate;
+				}
+			}			
 			boolean invalidate = Boolean.TRUE.equals(((Constant)proc.getParameter(2).getExpression()).getValue());
 			if (invalidate) {
-				touchTable(context, matTableName, false);
+				touchTable(context, matTableName, false, System.currentTimeMillis());
 			}
 			MatState oldState = info.setState(MatState.NEEDS_LOADING, invalidate?Boolean.FALSE:null, null);
 			if (oldState == MatState.LOADING) {
@@ -325,10 +337,10 @@
 			}
 			GroupSymbol matTable = new GroupSymbol(matTableName);
 			matTable.setMetadataID(matTableId);
-			int rowCount = loadGlobalTable(context, matTable, matTableName, globalStore, info, null, false);
+			int rowCount = loadGlobalTable(context, matTable, matTableName, matViewName, globalStore, info, invalidate?null:loadTime, !invalidate && useCache);
 			return CollectionTupleSource.createUpdateCountTupleSource(rowCount);
 		} else if (StringUtil.endsWithIgnoreCase(proc.getProcedureCallableName(), REFRESHMATVIEWROW)) {
-			Object groupID = validateMatView(metadata, proc);
+			Object groupID = validateMatView(metadata, (String)((Constant)proc.getParameter(1).getExpression()).getValue());
 			Object pk = metadata.getPrimaryKey(groupID);
 			String matViewName = metadata.getFullName(groupID);
 			if (pk == null) {
@@ -377,15 +389,36 @@
 		TempTable tempTable = globalStore.getOrCreateTempTable(matTableName, new Query(), bufferManager, false);
 		return tempTable.updateTuple(tuple, delete);
 	}
+	
+	public void refreshMatView(String vdbName, int vdbVersion, String viewName, 
+			QueryMetadataInterface metadata, TempTableStore globalStore) 
+			throws QueryProcessingException, TeiidComponentException, TeiidProcessingException {
+			
+		Object groupID = validateMatView(metadata, viewName);
+		Object matTableId = globalStore.getGlobalTempTableMetadataId(groupID, metadata);
+		String matViewName = metadata.getFullName(groupID);
+		String matTableName = metadata.getFullName(matTableId);
+		LogManager.logDetail(LogConstants.CTX_MATVIEWS, "processing refreshmatview for", matViewName); //$NON-NLS-1$
+		MatTableInfo info = globalStore.getMatTableInfo(matTableName);
 
-	private Object validateMatView(QueryMetadataInterface metadata,
-			StoredProcedure proc) throws TeiidComponentException,
+		MatState oldState = info.setState(MatState.NEEDS_LOADING, Boolean.FALSE, null);
+		if (oldState == MatState.LOADING) {
+			return;
+		}
+		GroupSymbol matTable = new GroupSymbol(matTableName);
+		matTable.setMetadataID(matTableId);
+		CommandContext context = new CommandContext(new Object(), "internal", "internal", vdbName, vdbVersion); //$NON-NLS-1$ //$NON-NLS-2$
+		context.setMetadata(metadata);
+		context.setGlobalTableStore(globalStore);
+		loadGlobalTable(context, matTable, matTableName, matViewName, globalStore, info, null, true);		
+	}	
+
+	private Object validateMatView(QueryMetadataInterface metadata,	String viewName) throws TeiidComponentException,
 			TeiidProcessingException {
-		String name = (String)((Constant)proc.getParameter(1).getExpression()).getValue();
 		try {
-			Object groupID = metadata.getGroupID(name);
+			Object groupID = metadata.getGroupID(viewName);
 			if (!metadata.hasMaterialization(groupID) || metadata.getMaterialization(groupID) != null) {
-				throw new QueryProcessingException(QueryPlugin.Util.getString("TempTableDataManager.not_implicit_matview", name)); //$NON-NLS-1$
+				throw new QueryProcessingException(QueryPlugin.Util.getString("TempTableDataManager.not_implicit_matview", viewName)); //$NON-NLS-1$
 			}
 			return groupID;
 		} catch (QueryMetadataException e) {
@@ -402,8 +435,13 @@
 		if (!group.isTempGroupSymbol()) {
 			return null;
 		}
+		String viewName = null;
 		final String tableName = group.getNonCorrelationName().toUpperCase();
 		boolean remapColumns = !tableName.equalsIgnoreCase(group.getName());
+		TempMetadataID groupID = (TempMetadataID)group.getMetadataID();
+		if (groupID.getOriginalMetadataID() != null) {
+			viewName = context.getMetadata().getFullName(groupID.getOriginalMetadataID());
+		}		
 		TempTable table = null;
 		if (group.isGlobalTable()) {
 			final TempTableStore globalStore = context.getGlobalTableStore();
@@ -429,9 +467,9 @@
 			if (load) {
 				if (!info.isValid()) {
 					//blocking load
-					loadGlobalTable(context, group, tableName, globalStore, info, loadTime, true);
+					loadGlobalTable(context, group, tableName, viewName, globalStore, info, loadTime, true);
 				} else {
-					loadAsynch(context, group, tableName, globalStore, info, loadTime);
+					loadAsynch(context, group, tableName, viewName, globalStore, info, loadTime);
 				}
 			} 
 			table = globalStore.getOrCreateTempTable(tableName, query, bufferManager, false);
@@ -464,13 +502,13 @@
 	}
 
 	private void loadAsynch(final CommandContext context,
-			final GroupSymbol group, final String tableName,
+			final GroupSymbol group, final String tableName, final String viewName,
 			final TempTableStore globalStore, final MatTableInfo info,
 			final Long loadTime) {
 		Callable<Integer> toCall = new Callable<Integer>() {
 			@Override
 			public Integer call() throws Exception {
-				return loadGlobalTable(context, group, tableName, globalStore, info, loadTime, true);
+				return loadGlobalTable(context, group, tableName, viewName, globalStore, info, loadTime, true);
 			}
 		};
 		FutureTask<Integer> task = new FutureTask<Integer>(toCall);
@@ -478,7 +516,7 @@
 	}
 
 	private int loadGlobalTable(CommandContext context,
-			GroupSymbol group, final String tableName,
+			GroupSymbol group, final String tableName, final String viewName,
 			TempTableStore globalStore, MatTableInfo info, Long loadTime, boolean useCache)
 			throws TeiidComponentException, TeiidProcessingException {
 		LogManager.logInfo(LogConstants.CTX_MATVIEWS, QueryPlugin.Util.getString("TempTableDataManager.loading", tableName)); //$NON-NLS-1$
@@ -506,17 +544,19 @@
 			}
 		}
 		int rowCount = -1;
+		boolean viewFetched = false;
 		try {
 			String fullName = metadata.getFullName(group.getMetadataID());
 			TupleSource ts = null;
 			CacheID cid = null;
 			if (distributedCache != null) {
-				cid = new CacheID(new ParseInfo(), fullName, context.getVdbName(), 
+				cid = new CacheID(new ParseInfo(), viewName, context.getVdbName(), 
 						context.getVdbVersion(), context.getConnectionID(), context.getUserName());
 				if (useCache) {
 					CachedResults cr = this.distributedCache.get(cid);
 					if (cr != null) {
 						ts = cr.getResults().createIndexedTupleSource();
+						LogManager.logInfo(LogConstants.CTX_MATVIEWS, QueryPlugin.Util.getString("TempTableDataManager.cache_load", tableName)); //$NON-NLS-1$
 					}
 				}
 			}
@@ -536,9 +576,10 @@
 					BatchCollector bc = qp.createBatchCollector();
 					TupleBuffer tb = bc.collectTuples();
 					cr.setResults(tb, qp.getProcessorPlan());
-					touchTable(context, fullName, true);
+					touchTable(context, fullName, true, info.getUpdateTime());
 					this.distributedCache.put(cid, Determinism.VDB_DETERMINISTIC, cr, info.getTtl());
 					ts = tb.createIndexedTupleSource();
+					viewFetched = true;
 				} else {
 					ts = new BatchCollector.BatchProducerTupleSource(qp);
 				}
@@ -570,18 +611,22 @@
 			} else {
 				globalStore.swapTempTable(tableName, table);
 				info.setState(MatState.LOADED, true, loadTime);
+				if (viewFetched & viewName != null && this.eventDistributor != null) {
+					this.eventDistributor.refreshMatView(context.getVdbName(), context.getVdbVersion(), viewName);
+				}
 				LogManager.logInfo(LogConstants.CTX_MATVIEWS, QueryPlugin.Util.getString("TempTableDataManager.loaded", tableName, rowCount)); //$NON-NLS-1$
 			}
 		}
 		return rowCount;
 	}
 
-	private void touchTable(CommandContext context, String fullName, boolean valid) {
+	private void touchTable(CommandContext context, String fullName, boolean valid, long loadtime) {
 		MatTableKey key = new MatTableKey();
 		key.name = fullName;
 		key.vdb = new VDBKey(context.getVdbName(), context.getVdbVersion());
 		MatTableEntry matTableEntry = new MatTableEntry();
 		matTableEntry.valid = valid;
+		matTableEntry.lastUpdate = loadtime;
 		tables.put(key, matTableEntry, null);
 	}
 
@@ -644,5 +689,4 @@
 	public MetadataRepository getMetadataRepository() {
 		return this.processorDataManager.getMetadataRepository();
 	}
-
 }

Modified: trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -264,6 +264,7 @@
 					id = tempMetadataStore.addTempGroup(matTableName, ResolverUtil.resolveElementsInGroup(group, metadata), false, true);
 					id.setQueryNode(metadata.getVirtualPlan(viewId));
 					id.setCardinality(metadata.getCardinality(viewId));
+					id.setOriginalMetadataID(viewId);
 					
 					Object pk = metadata.getPrimaryKey(viewId);
 					if (pk != null) {

Modified: trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -1232,6 +1232,9 @@
         if (windowFunction.getFunction().getOrderBy() != null || windowFunction.getFunction().isDistinct()) {
         	handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0042", new Object[] {windowFunction.getFunction(), windowFunction}), windowFunction); //$NON-NLS-1$
         }
+        if (windowFunction.getWindowSpecification().getPartition() != null) {
+        	validateSortable(windowFunction.getWindowSpecification().getPartition());
+        }
     }
     
     @Override

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-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -242,8 +242,11 @@
     public SaxonXQueryExpression clone() {
     	SaxonXQueryExpression clone = new SaxonXQueryExpression();
     	clone.xQuery = xQuery;
+    	clone.xQueryString = xQueryString;
     	clone.config = config;
     	clone.contextRoot = contextRoot;
+    	clone.namespaceMap = namespaceMap;
+    	clone.streamingPathFilter = streamingPathFilter;
     	return clone;
     }
     

Modified: trunk/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/i18n.properties	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/main/resources/org/teiid/query/i18n.properties	2011-07-30 12:41:32 UTC (rev 3351)
@@ -817,6 +817,7 @@
 TempTableDataManager.failed_load=Failed to load materialized view table {0}.
 TempTableDataManager.loaded=Loaded materialized view table {0} with row count {1}.
 TempTableDataManager.loading=Loading materialized view table {0}
+TempTableDataManager.cache_load=Loaded materialized view table {0} from cached contents from another clustered node.
 TempTableDataManager.not_implicit_matview={0} does not target an internal materialized view.
 TempTableDataManager.row_refresh_pk=Materialized view {0} cannot have a row refreshed since there is no primary key.
 TempTableDataManager.row_refresh_composite=Materialized view {0} cannot have a row refreshed because it uses a composite key.
@@ -926,4 +927,5 @@
 ValidationVisitor.not_a_procedure={0} is not a valid virtual procedure.
 
 DdlPlan.event_not_exists={0} does not have an INSTEAD OF trigger defined for {1}.
-DdlPlan.event_already_exists={0} already has an INSTEAD OF trigger defined for {1}.
\ No newline at end of file
+DdlPlan.event_already_exists={0} already has an INSTEAD OF trigger defined for {1}.
+error_refresh=error occurred during refreshing the materialized view entries for view {0}
\ No newline at end of file

Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -38,10 +38,16 @@
 import org.teiid.api.exception.query.ExpressionEvaluationException;
 import org.teiid.core.types.BlobImpl;
 import org.teiid.core.types.BlobType;
+import org.teiid.core.types.DataTypeManager;
 import org.teiid.core.types.InputStreamFactory;
 import org.teiid.core.util.ObjectConverterUtil;
 import org.teiid.core.util.TimestampWithTimezone;
 import org.teiid.core.util.UnitTestUtil;
+import org.teiid.metadata.MetadataStore;
+import org.teiid.metadata.Schema;
+import org.teiid.metadata.Table;
+import org.teiid.query.mapping.relational.QueryNode;
+import org.teiid.query.metadata.TransformationMetadata;
 import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
 import org.teiid.query.unittest.RealMetadataFactory;
 import org.teiid.query.unittest.TimestampUtil;
@@ -187,6 +193,32 @@
         process(sql, expected);
     }
     
+    @Test public void testXmlTableInView() throws Exception {
+        String sql = "select * from g1"; //$NON-NLS-1$
+        
+        List<?>[] expected = new List<?>[] {
+        		Arrays.asList(null, "first"),
+        		Arrays.asList("attr", "second"),
+        };    
+        
+		MetadataStore metadataStore = new MetadataStore();
+	    // Create models
+	    Schema vm1 = RealMetadataFactory.createVirtualModel("vm1", metadataStore);  //$NON-NLS-1$
+	
+	    QueryNode vm1g1n1 = new QueryNode("select * from xmltable('/a/b' passing convert('<a><b>first</b><b x=\"attr\">second</b></a>', xml) columns x string path '@x', val string path '/.') as x"); //$NON-NLS-1$ //$NON-NLS-2$
+	    Table vm1g1 = RealMetadataFactory.createVirtualGroup("g1", vm1, vm1g1n1); //$NON-NLS-1$
+	    
+	    RealMetadataFactory.createElements(vm1g1, 
+	                                new String[] { "x", "val" }, //$NON-NLS-1$
+	                                new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING });
+	    // Create the facade from the store
+	    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "example");
+
+	    ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, new DefaultCapabilitiesFinder(), createCommandContext());
+        
+        helpProcess(plan, createCommandContext(), dataManager, expected);
+    }
+    
 	@Test public void testXmlTableDefaultAndParent() throws Exception {
         String sql = "select * from xmltable('/a/b' passing convert('<a y=\"rev\"><b>first</b><b x=\"1\">second</b></a>', xml) columns x integer default -1 path '@x' , val string path '../@y') as x"; //$NON-NLS-1$
         


Property changes on: trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java:3149-3217,3220-3275,3281-3325
   + /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java:3149-3217,3220-3275,3281-3325,3340-3349

Modified: trunk/engine/src/test/java/org/teiid/query/processor/xml/FakePlanExecutor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/xml/FakePlanExecutor.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/test/java/org/teiid/query/processor/xml/FakePlanExecutor.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -56,7 +56,7 @@
         return this.currentRow;
     }
 
-    public void execute(Map values) throws TeiidComponentException, BlockedException {
+    public void execute(Map values, boolean openOnly) throws TeiidComponentException, BlockedException {
         tupleSource.openSource();
     }
 

Modified: trunk/engine/src/test/java/org/teiid/query/processor/xml/TestProcessorEnvironment.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/xml/TestProcessorEnvironment.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/test/java/org/teiid/query/processor/xml/TestProcessorEnvironment.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -119,31 +119,31 @@
         env.pushProgram(p1, true); //simulate recursion
         
         assertEquals(p1, env.getCurrentProgram());
-        assertEquals(i1, env.getCurrentInstruction());
+        assertEquals(i1, env.getCurrentInstruction(null));
         assertEquals(p1, env.getCurrentProgram());
         i1.process(env, context);
         assertEquals(p1, env.getCurrentProgram());
-        assertEquals(i2, env.getCurrentInstruction());
+        assertEquals(i2, env.getCurrentInstruction(null));
         assertEquals(p1, env.getCurrentProgram());
         i2.process(env, context);
         assertEquals(p2, env.getCurrentProgram());
-        assertEquals(i3, env.getCurrentInstruction());
+        assertEquals(i3, env.getCurrentInstruction(null));
         assertEquals(p2, env.getCurrentProgram());
         i3.process(env, context);
         assertEquals(p2, env.getCurrentProgram());
-        assertEquals(i4, env.getCurrentInstruction());
+        assertEquals(i4, env.getCurrentInstruction(null));
         assertEquals(p2, env.getCurrentProgram());
         i4.process(env, context);
         assertEquals(p1, env.getCurrentProgram());
-        assertEquals(i1, env.getCurrentInstruction());
+        assertEquals(i1, env.getCurrentInstruction(null));
         assertEquals(p1, env.getCurrentProgram());
         i1.process(env, context);
         assertEquals(p1, env.getCurrentProgram());
-        assertEquals(i2, env.getCurrentInstruction());
+        assertEquals(i2, env.getCurrentInstruction(null));
         assertEquals(p1, env.getCurrentProgram());
         i2.process(env, context);
         assertEquals(p1, env.getCurrentProgram());
-        assertEquals(null, env.getCurrentInstruction());
+        assertEquals(null, env.getCurrentInstruction(null));
         assertEquals(p1, env.getCurrentProgram());
     }
     
@@ -173,31 +173,31 @@
         env.pushProgram(p2);
         
         assertEquals(p2, env.getCurrentProgram());
-        assertEquals(i3, env.getCurrentInstruction());
+        assertEquals(i3, env.getCurrentInstruction(null));
         assertEquals(p2, env.getCurrentProgram());
         i3.process(env, context);
         assertEquals(p2, env.getCurrentProgram());
-        assertEquals(i4, env.getCurrentInstruction());
+        assertEquals(i4, env.getCurrentInstruction(null));
         assertEquals(p2, env.getCurrentProgram());
         i4.process(env, context);
         assertEquals(p1, env.getCurrentProgram());
-        assertEquals(i1, env.getCurrentInstruction());
+        assertEquals(i1, env.getCurrentInstruction(null));
         assertEquals(p1, env.getCurrentProgram());
         i1.process(env, context);
         assertEquals(p1, env.getCurrentProgram());
-        assertEquals(i2, env.getCurrentInstruction());
+        assertEquals(i2, env.getCurrentInstruction(null));
         assertEquals(p1, env.getCurrentProgram());
         i2.process(env, context);
         assertEquals(p1, env.getCurrentProgram());
-        assertEquals(i1, env.getCurrentInstruction());
+        assertEquals(i1, env.getCurrentInstruction(null));
         assertEquals(p1, env.getCurrentProgram());
         i1.process(env, context);
         assertEquals(p1, env.getCurrentProgram());
-        assertEquals(i2, env.getCurrentInstruction());
+        assertEquals(i2, env.getCurrentInstruction(null));
         assertEquals(p1, env.getCurrentProgram());
         i2.process(env, context);
         assertEquals(p1, env.getCurrentProgram());
-        assertEquals(null, env.getCurrentInstruction());
+        assertEquals(null, env.getCurrentInstruction(null));
         assertEquals(p1, env.getCurrentProgram());
     }    
     

Modified: trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLPlanningEnhancements.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLPlanningEnhancements.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLPlanningEnhancements.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -154,6 +154,15 @@
         return doc;  
     } 
     
+    @Test public void testThreeWayOrWithNestedSiblings() throws Exception {
+    	QueryMetadataInterface metadata = TestXMLProcessor.exampleMetadataNestedWithSibling();
+    	FakeDataManager dataMgr = TestXMLProcessor.exampleDataManagerNestedWithSibling(metadata);
+    	String resultFile = "TestXMLPlanningEnhancements-testThreeWayOrWithNestedSiblings.xml"; //$NON-NLS-1$
+        String expectedDoc = TestXMLProcessor.readFile(resultFile);
+        
+        TestXMLProcessor.helpTestProcess("select * from xmltest.doc9c where itemid='003' or supplierid = '600' or orderid = '1'", expectedDoc, metadata, dataMgr);         //$NON-NLS-1$
+    } 
+    
     @Test public void testBaseballPlayersDocDefect19541() throws Exception {
         
         QueryMetadataInterface metadata = RealMetadataFactory.exampleCase3225();

Modified: trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -606,7 +606,7 @@
         return RealMetadataFactory.createTransformationMetadata(metadataStore, "example1");
     }
 
-    public QueryMetadataInterface exampleMetadataNestedWithSibling() {
+    public static QueryMetadataInterface exampleMetadataNestedWithSibling() {
 		MetadataStore metadataStore = new MetadataStore();
         
 		// Create models
@@ -1231,7 +1231,7 @@
     }
 
 	/** nested with sibling*/
-	private MappingDocument createXMLPlanNested2c() {
+	private static MappingDocument createXMLPlanNested2c() {
         
         MappingDocument doc = new MappingDocument(true);
         MappingElement root = doc.addChildElement(new MappingElement("Catalogs")); //$NON-NLS-1$
@@ -2256,7 +2256,7 @@
         return dataMgr;
     }                    
 
-	private FakeDataManager exampleDataManagerNestedWithSibling(QueryMetadataInterface metadata) {
+	static FakeDataManager exampleDataManagerNestedWithSibling(QueryMetadataInterface metadata) {
 		FakeDataManager dataMgr = new FakeDataManager();
     
 		try { 

Copied: trunk/engine/src/test/resources/TestXMLPlanningEnhancements-testThreeWayOrWithNestedSiblings.xml (from rev 3349, branches/7.4.x/engine/src/test/resources/TestXMLPlanningEnhancements-testThreeWayOrWithNestedSiblings.xml)
===================================================================
--- trunk/engine/src/test/resources/TestXMLPlanningEnhancements-testThreeWayOrWithNestedSiblings.xml	                        (rev 0)
+++ trunk/engine/src/test/resources/TestXMLPlanningEnhancements-testThreeWayOrWithNestedSiblings.xml	2011-07-30 12:41:32 UTC (rev 3351)
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Catalogs>
+   <Catalog>
+      <Items>
+         <Item ItemID="001">
+            <Name>Lamp</Name>
+            <Quantity>5</Quantity>
+            <Suppliers>
+               <Supplier SupplierID="51">
+                  <Name>Chucky</Name>
+                  <Zip>11111</Zip>
+               </Supplier>
+               <Supplier SupplierID="52">
+                  <Name>Biff's Stuff</Name>
+                  <Zip>22222</Zip>
+               </Supplier>
+               <Supplier SupplierID="53">
+                  <Name>AAAA</Name>
+                  <Zip>33333</Zip>
+               </Supplier>
+               <Supplier SupplierID="56">
+                  <Name>Microsoft</Name>
+                  <Zip>66666</Zip>
+               </Supplier>
+            </Suppliers>
+            <Orders>
+               <Order OrderID="1">
+                  <Name>KMart</Name>
+                  <Zip>12345</Zip>
+               </Order>
+               <Order OrderID="2">
+                  <Name>Sun</Name>
+                  <Zip>94040</Zip>
+               </Order>
+               <Order OrderID="3">
+                  <Name>Cisco</Name>
+                  <Zip>94041</Zip>
+               </Order>
+               <Order OrderID="4">
+                  <Name>Doc</Name>
+                  <Zip>94042</Zip>
+               </Order>
+            </Orders>
+         </Item>
+         <Item ItemID="003">
+            <Name>Goat</Name>
+            <Quantity>4</Quantity>
+            <Suppliers>
+               <Supplier SupplierID="56">
+                  <Name>Microsoft</Name>
+                  <Zip>66666</Zip>
+               </Supplier>
+            </Suppliers>
+            <Orders>
+               <Order OrderID="7">
+                  <Name>Inktomi</Name>
+                  <Zip>94044</Zip>
+               </Order>
+            </Orders>
+         </Item>
+      </Items>
+   </Catalog>
+</Catalogs>
\ No newline at end of file

Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/JBossLifeCycleListener.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/JBossLifeCycleListener.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/JBossLifeCycleListener.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -21,6 +21,10 @@
  */
 package org.teiid.jboss;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
 import javax.management.InstanceNotFoundException;
 import javax.management.MBeanServer;
 import javax.management.MBeanServerFactory;
@@ -39,6 +43,7 @@
 	public final String STOP_NOTIFICATION_TYPE = "org.jboss.system.server.stopped"; //$NON-NLS-1$
 	
 	private boolean shutdownInProgress = false;
+	private List<ContainerLifeCycleListener.LifeCycleEventListener> listeners = Collections.synchronizedList(new ArrayList<ContainerLifeCycleListener.LifeCycleEventListener>());
 	
 	public JBossLifeCycleListener() {
 		try {
@@ -56,10 +61,16 @@
 	public void handleNotification(Notification msg, Object handback) {
 		String type = msg.getType();
 		if (type.equals(START_NOTIFICATION_TYPE)) {
+			for (ContainerLifeCycleListener.LifeCycleEventListener l:listeners) {
+				l.onStartupFinish();
+			}
 		}
 		
 		if (type.equals(STOP_NOTIFICATION_TYPE)) {
 			shutdownInProgress = true;
+			for (ContainerLifeCycleListener.LifeCycleEventListener l:listeners) {
+				l.onShutdownStart();
+			}			
 		}	
 	}
 
@@ -67,4 +78,9 @@
 	public boolean isShutdownInProgress() {
 		return shutdownInProgress;
 	}
+
+	@Override
+	public void addListener(LifeCycleEventListener listener) {
+		listeners.add(listener);
+	}
 }

Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -60,10 +60,10 @@
 import org.jboss.profileservice.spi.ProfileService;
 import org.jboss.util.naming.Util;
 import org.teiid.adminapi.Admin;
+import org.teiid.adminapi.Admin.Cache;
 import org.teiid.adminapi.AdminComponentException;
 import org.teiid.adminapi.AdminException;
 import org.teiid.adminapi.AdminProcessingException;
-import org.teiid.adminapi.Admin.Cache;
 import org.teiid.adminapi.impl.CacheStatisticsMetadata;
 import org.teiid.adminapi.impl.DQPManagement;
 import org.teiid.adminapi.impl.RequestMetadata;
@@ -81,14 +81,15 @@
 import org.teiid.client.util.ResultsFuture;
 import org.teiid.core.ComponentNotFoundException;
 import org.teiid.core.TeiidComponentException;
-import org.teiid.core.TeiidException;
 import org.teiid.core.TeiidRuntimeException;
 import org.teiid.core.util.LRUCache;
+import org.teiid.deployers.ContainerLifeCycleListener;
 import org.teiid.deployers.VDBLifeCycleListener;
 import org.teiid.deployers.VDBRepository;
 import org.teiid.deployers.VDBStatusChecker;
 import org.teiid.dqp.internal.process.DQPConfiguration;
 import org.teiid.dqp.internal.process.DQPCore;
+import org.teiid.dqp.internal.process.DQPCore.ContextProvider;
 import org.teiid.dqp.internal.process.DQPWorkContext;
 import org.teiid.dqp.internal.process.DataTierManagerImpl;
 import org.teiid.dqp.internal.process.TransactionServerImpl;
@@ -109,14 +110,11 @@
 import org.teiid.metadata.Procedure;
 import org.teiid.metadata.Schema;
 import org.teiid.metadata.Table;
+import org.teiid.metadata.Table.TriggerEvent;
 import org.teiid.metadata.TableStats;
-import org.teiid.metadata.Table.TriggerEvent;
 import org.teiid.net.TeiidURL;
-import org.teiid.query.QueryPlugin;
 import org.teiid.query.metadata.TransformationMetadata;
-import org.teiid.query.optimizer.relational.RelationalPlanner;
 import org.teiid.query.processor.DdlPlan;
-import org.teiid.query.tempdata.TempTableStore;
 import org.teiid.security.SecurityHelper;
 import org.teiid.transport.ClientServiceRegistry;
 import org.teiid.transport.ClientServiceRegistryImpl;
@@ -153,6 +151,7 @@
 	private String eventDistributorName;
 	private transient EventDistributor eventDistributor;
 	private transient EventDistributor eventDistributorProxy;
+	private transient ContainerLifeCycleListener lifecycleListener;
 	
     public RuntimeEngineDeployer() {
 		// TODO: this does not belong here
@@ -294,7 +293,9 @@
 				dqpCore.clearCache(Cache.PREPARED_PLAN_CACHE.toString(), name, version);
 				dqpCore.clearCache(Cache.QUERY_SERVICE_RESULT_SET_CACHE.toString(), name, version);
 			}			
-		});    	
+		});
+		
+		synchronizeMaterializeViews();
 	}	
     
     public void stop() {
@@ -548,21 +549,11 @@
 	@Override
     @ManagementOperation(description="Execute a sql query", params={@ManagementParameter(name="vdbName"), at ManagementParameter(name="vdbVersion"), @ManagementParameter(name="command"), @ManagementParameter(name="timoutInMilli")})	
 	public List<List> executeQuery(final String vdbName, final int version, final String command, final long timoutInMilli) throws AdminException {
-		Properties properties = new Properties();
-		properties.setProperty(TeiidURL.JDBC.VDB_NAME, vdbName);
-		properties.setProperty(TeiidURL.JDBC.VDB_VERSION, String.valueOf(version));
 		
 		String user = "JOPR ADMIN"; //$NON-NLS-1$
 		LogManager.logDetail(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.getString("admin_executing", user, command)); //$NON-NLS-1$
 		
-		SessionMetadata session = null;
-		try {
-			session = this.sessionService.createSession(user, null, "JOPR", properties, false, false); //$NON-NLS-1$
-		} catch (SessionServiceException e1) {
-			throw new AdminProcessingException(e1);
-		} catch (LoginException e1) {
-			throw new AdminProcessingException(e1);
-		}
+		SessionMetadata session = createTemporarySession(vdbName, version, user);
 
 		final long requestID =  0L;
 		
@@ -580,8 +571,12 @@
 					request.setExecutionId(0L);
 					request.setRowLimit(getMaxRowsFetchSize()); // this would limit the number of rows that are returned.
 					Future<ResultsMessage> message = dqpCore.executeRequest(requestID, request);
-					ResultsMessage rm = message.get(timoutInMilli, TimeUnit.MILLISECONDS);
-					
+					ResultsMessage rm = null;
+					if (timoutInMilli < 0) {
+						rm = message.get();
+					} else {
+						rm = message.get(timoutInMilli, TimeUnit.MILLISECONDS);
+					}
 			        if (rm.getException() != null) {
 			            throw new AdminProcessingException(rm.getException());
 			        }
@@ -616,6 +611,23 @@
 			} catch (InvalidSessionException e) { //ignore
 			}			
 		}
+	}
+
+	private SessionMetadata createTemporarySession(final String vdbName, final int version, final String user)
+			throws AdminProcessingException {
+		Properties properties = new Properties();
+		properties.setProperty(TeiidURL.JDBC.VDB_NAME, vdbName);
+		properties.setProperty(TeiidURL.JDBC.VDB_VERSION, String.valueOf(version));
+		
+		SessionMetadata session = null;
+		try {
+			session = this.sessionService.createSession(user, null, "JOPR", properties, false, false); //$NON-NLS-1$
+		} catch (SessionServiceException e1) {
+			throw new AdminProcessingException(e1);
+		} catch (LoginException e1) {
+			throw new AdminProcessingException(e1);
+		}
+		return session;
 	}	
 	
 	/**
@@ -669,22 +681,15 @@
 	@Override
 	public void updateMatViewRow(String vdbName, int vdbVersion, String schema,
 			String viewName, List<?> tuple, boolean delete) {
-		VDBMetaData vdb = this.vdbRepository.getVDB(vdbName, vdbVersion);
-		if (vdb == null) {
-			return;
-		}
-		TempTableStore globalStore = vdb.getAttachment(TempTableStore.class);
-		if (globalStore == null) {
-			return;
-		}
-		try {
-			this.dqpCore.getDataTierManager().updateMatViewRow(globalStore, RelationalPlanner.MAT_PREFIX + (schema + '.' + viewName).toUpperCase(), tuple, delete);
-		} catch (TeiidException e) {
-			LogManager.logError(LogConstants.CTX_DQP, e, QueryPlugin.Util.getString("DQPCore.unable_to_process_event")); //$NON-NLS-1$
-		}
+		this.dqpCore.updateMatViewRow(getcontextProvider(), vdbName, vdbVersion, schema, viewName, tuple, delete);
 	}
 	
 	@Override
+	public void refreshMatView(final String vdbName, final int vdbVersion, final String viewName) {
+		this.dqpCore.refreshMatView(getcontextProvider(), vdbName, vdbVersion, viewName);
+	}
+	
+	@Override
 	public void dataModification(String vdbName, int vdbVersion, String schema,
 			String... tableNames) {
 		updateModified(true, vdbName, vdbVersion, schema, tableNames);
@@ -816,4 +821,38 @@
 		return this.eventDistributorProxy;
 	}
 	
+	private void synchronizeMaterializeViews() {
+		this.lifecycleListener.addListener(new ContainerLifeCycleListener.LifeCycleEventListener() {
+			@Override
+			public void onStartupFinish() {
+				dqpCore.synchronizeInternalMaterializedViews(getcontextProvider());
+			}
+			@Override
+			public void onShutdownStart() {
+			}
+		});
+	}
+
+	private ContextProvider getcontextProvider() {
+		return new DQPCore.ContextProvider() {
+			@Override
+			public DQPWorkContext getContext(final String vdbName, final int vdbVersion) {
+				return new DQPWorkContext() {
+					public VDBMetaData getVDB() {
+						return vdbRepository.getVDB(vdbName, vdbVersion);
+					}
+				    public String getVdbName() {
+				        return vdbName;
+				    }
+				    public int getVdbVersion() {
+				        return vdbVersion;
+				    }					
+				};
+			}
+		};
+	}
+	
+	public void setContainerLifeCycleListener(ContainerLifeCycleListener listener) {
+		this.lifecycleListener = listener;
+	}	
 }

Modified: trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties
===================================================================
--- trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties	2011-07-30 12:41:32 UTC (rev 3351)
@@ -47,4 +47,4 @@
 template_not_found=Template not found for {0}
 admin_executing=JOPR admin {0} is executing command {1}
 
-DQPCore.unable_to_process_event=Unable to process event.
+DQPCore.unable_to_process_event=Unable to process event. 

Modified: trunk/runtime/src/main/java/org/teiid/deployers/ContainerLifeCycleListener.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/ContainerLifeCycleListener.java	2011-07-30 12:31:35 UTC (rev 3350)
+++ trunk/runtime/src/main/java/org/teiid/deployers/ContainerLifeCycleListener.java	2011-07-30 12:41:32 UTC (rev 3351)
@@ -23,4 +23,10 @@
 
 public interface ContainerLifeCycleListener {
 	boolean isShutdownInProgress();
+	void addListener(LifeCycleEventListener listener);
+	
+	public static interface LifeCycleEventListener{
+		void onStartupFinish();
+		void onShutdownStart();
+	}
 }



More information about the teiid-commits mailing list