[teiid-commits] teiid SVN: r786 - in trunk: connector-api/src/main/java/org/teiid/connector/api and 21 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Thu Apr 16 12:26:10 EDT 2009


Author: rareddy
Date: 2009-04-16 12:26:10 -0400 (Thu, 16 Apr 2009)
New Revision: 786

Added:
   trunk/connector-api/src/main/java/org/teiid/connector/api/CacheScope.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/cache/DQPContextCache.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestDQPContextCache.java
Modified:
   trunk/cache-jbosscache/src/main/java/com/metamatrix/cache/jboss/JBossCache.java
   trunk/connector-api/src/main/java/org/teiid/connector/api/ConnectorEnvironment.java
   trunk/connector-api/src/main/java/org/teiid/connector/api/ExecutionContext.java
   trunk/console/
   trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/EmbeddedConfigSource.java
   trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedBufferService.java
   trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedVDBService.java
   trunk/embedded/src/main/java/com/metamatrix/jdbc/EmbeddedGuiceModule.java
   trunk/embedded/src/test/java/com/metamatrix/dqp/embedded/services/TestEmbeddedVDBService.java
   trunk/engine/src/main/java/com/metamatrix/cache/Cache.java
   trunk/engine/src/main/java/com/metamatrix/dqp/service/BufferService.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorEnvironmentImpl.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorManager.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorWorkItem.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ExecutionContextImpl.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
   trunk/engine/src/main/resources/com/metamatrix/dqp/i18n.properties
   trunk/engine/src/test/java/com/metamatrix/cache/FakeCache.java
   trunk/engine/src/test/java/com/metamatrix/dqp/service/FakeBufferService.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/FakeExecutionContextImpl.java
   trunk/server/src/main/java/com/metamatrix/server/ResourceFinder.java
   trunk/server/src/main/java/com/metamatrix/server/ServerGuiceModule.java
   trunk/server/src/main/java/com/metamatrix/server/dqp/config/PlatformConfigSource.java
   trunk/server/src/main/java/com/metamatrix/server/dqp/service/PlatformBufferService.java
   trunk/server/src/main/java/com/metamatrix/server/dqp/service/PlatformVDBService.java
   trunk/server/src/test/java/com/metamatrix/platform/security/api/TestAuthorizationCache.java
   trunk/server/src/test/java/com/metamatrix/platform/security/authorization/service/TestAuthorizationServiceImpl.java
   trunk/server/src/test/java/com/metamatrix/platform/security/session/service/TestSessionServiceImpl.java
Log:
TEIID-444: Exposing the Cache to the Connectors. The cache implementation is based on the JBoss Cache. This cache is also context based cache, which provides connector developers with REQUEST/SESSION/SERVICE/VDB/GLOBAL scoped caches for their use. This cache can also be used in the engine with the same scopes. 

Modified: trunk/cache-jbosscache/src/main/java/com/metamatrix/cache/jboss/JBossCache.java
===================================================================
--- trunk/cache-jbosscache/src/main/java/com/metamatrix/cache/jboss/JBossCache.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/cache-jbosscache/src/main/java/com/metamatrix/cache/jboss/JBossCache.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -173,5 +173,10 @@
 	public boolean removeChild(String name) {
 		Node<K, V> node = this.cacheStore.getNode(this.rootFqn);
 		return node.removeChild(Fqn.fromString(name));
+	}
+
+	@Override
+	public String getName() {
+		return this.rootFqn.toString();
 	} 	
 }

Added: trunk/connector-api/src/main/java/org/teiid/connector/api/CacheScope.java
===================================================================
--- trunk/connector-api/src/main/java/org/teiid/connector/api/CacheScope.java	                        (rev 0)
+++ trunk/connector-api/src/main/java/org/teiid/connector/api/CacheScope.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -0,0 +1,46 @@
+/*
+ * 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.connector.api;
+
+import java.io.Serializable;
+
+/**
+ * Cache Scope
+ * 
+ * REQUEST - Items placed in this scope are retained until the end of the top level request. The items to be placed
+ * does not need to implement {@link Serializable}, however recommended. These items are not replicated across the cluster.
+ * SERVICE - Items from this scope are available to the identified connector
+ * 
+ * All the items placed in the below scopes must be {@link Serializable}, as they are replicated across cluster.
+ *  
+ * SESSION - Items placed in the scope retained until the particular User's session of top level request is alive. 
+ * VDB - Items placed with this scope retained until the life of the VDB; 
+ * 
+ * GLOBAL - Items placed in this will available to all until the Query Service is recycled. 
+ */
+public enum CacheScope {
+	REQUEST, 
+	SERVICE,
+	SESSION, 
+	VDB, 
+	GLOBAL;
+}


Property changes on: trunk/connector-api/src/main/java/org/teiid/connector/api/CacheScope.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/connector-api/src/main/java/org/teiid/connector/api/ConnectorEnvironment.java
===================================================================
--- trunk/connector-api/src/main/java/org/teiid/connector/api/ConnectorEnvironment.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/connector-api/src/main/java/org/teiid/connector/api/ConnectorEnvironment.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -86,4 +86,26 @@
             long initialDelay,
             long period,
             TimeUnit unit);
+
+
+	/**
+	 * Get the item from cache based on the scope provided; The required information like session-id, or vdb-name etc 
+	 * are gleaned from runtime context. If such information is not available then error will be raised.
+	 * @param scope - scope of the cache; {@link CacheScope.REQUEST}, scope is not supported, as request information is not
+     * visible. use ExecutionContext. 
+	 * on {@link ExecutionContext}
+	 * @param key
+	 * @return
+	 */
+	Object getFromCache(CacheScope scope, Object key);
+
+	/**
+	 * Store the item in the cache based on the scope provided.The required information like session-id, or vdb-name etc 
+	 * are gleaned from runtime context. If such information is not available then error will be raised.
+	 * @param scope  - scope of the cache; {@link CacheScope.REQUEST}, scope is not supported. 
+	 * on {@link ExecutionContext}
+	 * @param key
+	 * @param value
+	 */
+	void storeInCache(CacheScope scope, Object key, Object value);
 }

Modified: trunk/connector-api/src/main/java/org/teiid/connector/api/ExecutionContext.java
===================================================================
--- trunk/connector-api/src/main/java/org/teiid/connector/api/ExecutionContext.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/connector-api/src/main/java/org/teiid/connector/api/ExecutionContext.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -152,4 +152,18 @@
     
     boolean isTransactional();
 
+	/**
+	 * Get a item that has been placed previously from cache. If no such object then a null will be returned. 
+	 * The item is placed in {@link CacheScope.REQUEST} scope.
+	 * @param key
+	 * @return
+	 */
+	Object get(Object key);
+	
+	/**
+	 * Place a item in the Cache in {@link CacheScope.REQUEST} scope.
+	 * @param key
+	 * @param value
+	 */
+	void put(Object key, Object value);    
 }


Property changes on: trunk/console
___________________________________________________________________
Name: svn:ignore
   - target

.project

.settings

.classpath

   + target

.project

.settings

.classpath

console_pref.properties


Modified: trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/EmbeddedConfigSource.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/EmbeddedConfigSource.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/EmbeddedConfigSource.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -29,7 +29,10 @@
 import java.util.Map;
 import java.util.Properties;
 
+import org.teiid.dqp.internal.cache.DQPContextCache;
+
 import com.google.inject.Binder;
+import com.google.inject.Inject;
 import com.metamatrix.common.application.ApplicationService;
 import com.metamatrix.common.application.DQPConfigSource;
 import com.metamatrix.common.application.exception.ApplicationInitializationException;
@@ -59,6 +62,9 @@
 	private Properties props;
     private boolean useTxn;
     
+    @Inject
+    DQPContextCache contextCache;
+    
     /**  
     * Based the configuration file load the DQP services
     * @param configFile
@@ -90,9 +96,7 @@
             in.close();
 
             // Merge any user properties with the mm.properties
-            if (connectionProperties != null) {
-                props.putAll(connectionProperties);
-            }
+            props.putAll(connectionProperties);
             
             // this will resolve any nested properties in the properties
             // file; this created for testing purpose
@@ -136,7 +140,9 @@
     
 	@Override
 	public void updateBindings(Binder binder) {
-		
+		if (contextCache != null) {
+			binder.bind(DQPContextCache.class).toInstance(contextCache);
+		}
 	}
 
 	@Override

Modified: trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedBufferService.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedBufferService.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedBufferService.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -26,7 +26,14 @@
 import java.io.IOException;
 import java.util.Properties;
 
+import org.teiid.connector.api.CacheScope;
+import org.teiid.connector.api.ExecutionContext;
+import org.teiid.dqp.internal.cache.DQPContextCache;
+import org.teiid.dqp.internal.process.DQPWorkContext;
+
+import com.google.inject.Inject;
 import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.cache.Cache;
 import com.metamatrix.common.application.ApplicationEnvironment;
 import com.metamatrix.common.application.exception.ApplicationInitializationException;
 import com.metamatrix.common.application.exception.ApplicationLifecycleException;
@@ -58,6 +65,9 @@
     // Instance
     private BufferManager bufferMgr;
 	private File bufferDir;
+	
+	@Inject
+	private DQPContextCache contextCache;
 
     /**  
      * @param props
@@ -156,4 +166,9 @@
     public BufferManager getBufferManager() {
         return this.bufferMgr;
     }
+
+	@Override
+	public DQPContextCache getContextCache() {
+		return this.contextCache;
+	}
 }

Modified: trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedVDBService.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedVDBService.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedVDBService.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -31,6 +31,11 @@
 import java.util.Map;
 import java.util.Properties;
 
+import org.teiid.connector.api.CacheScope;
+import org.teiid.dqp.internal.cache.DQPContextCache;
+import org.teiid.dqp.internal.process.DQPWorkContext;
+
+import com.google.inject.Inject;
 import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.common.application.ApplicationEnvironment;
 import com.metamatrix.common.application.exception.ApplicationInitializationException;
@@ -42,7 +47,12 @@
 import com.metamatrix.common.vdb.api.VDBDefn;
 import com.metamatrix.core.util.StringUtil;
 import com.metamatrix.core.vdb.VDBStatus;
+import com.metamatrix.dqp.ResourceFinder;
 import com.metamatrix.dqp.embedded.DQPEmbeddedPlugin;
+import com.metamatrix.dqp.embedded.DQPEmbeddedProperties;
+import com.metamatrix.dqp.service.BufferService;
+import com.metamatrix.dqp.service.DQPServiceNames;
+import com.metamatrix.dqp.service.VDBLifeCycleListener;
 import com.metamatrix.dqp.service.VDBService;
 import com.metamatrix.vdb.runtime.BasicModelInfo;
 import com.metamatrix.vdb.runtime.BasicVDBDefn;
@@ -52,9 +62,12 @@
  * A VDBService implementation for Embedded DQP.
  * @since 4.3
  */
-public class EmbeddedVDBService extends EmbeddedBaseDQPService implements VDBService {   
+public class EmbeddedVDBService extends EmbeddedBaseDQPService implements VDBService, VDBLifeCycleListener {   
     static final String[] VDB_STATUS = {"INCOMPLETE", "INACTIVE", "ACTIVE", "DELETED"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-
+    
+    @Inject
+    private DQPContextCache contextCache;
+    
     /**
      * Find the VDB in the list of VDBs available 
      * @param name
@@ -300,6 +313,7 @@
     public void startService(ApplicationEnvironment environment) throws ApplicationLifecycleException {        
         // deploying VDB at this stage created issues with data service prematurely
         // asking for unfinished VDB and starting it
+    	getConfigurationService().register(this);
     }
 
     /** 
@@ -307,5 +321,14 @@
      * @since 4.3
      */
     public void stopService() throws ApplicationLifecycleException {
-    }    
+    }
+
+	@Override
+	public void loaded(String vdbName, String vdbVersion) {
+	}
+
+	@Override
+	public void unloaded(String vdbName, String vdbVersion) {
+		this.contextCache.removeVDBScopedCache(vdbName, vdbVersion);
+	}    
 }

Modified: trunk/embedded/src/main/java/com/metamatrix/jdbc/EmbeddedGuiceModule.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/jdbc/EmbeddedGuiceModule.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/embedded/src/main/java/com/metamatrix/jdbc/EmbeddedGuiceModule.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -25,9 +25,11 @@
 import java.util.Properties;
 
 import org.jboss.cache.Cache;
+import org.teiid.dqp.internal.cache.DQPContextCache;
 
 import com.google.inject.AbstractModule;
 import com.google.inject.Scopes;
+import com.google.inject.name.Names;
 import com.metamatrix.cache.CacheFactory;
 import com.metamatrix.cache.jboss.JBossCacheFactory;
 import com.metamatrix.common.application.DQPConfigSource;
@@ -49,12 +51,15 @@
 				
 		bind(Cache.class).toProvider(CacheProvider.class).in(Scopes.SINGLETON);
 		bind(CacheFactory.class).to(JBossCacheFactory.class).in(Scopes.SINGLETON);
+		bindConstant().annotatedWith(Names.named("HostName")).to("embedded"); //$NON-NLS-1$ //$NON-NLS-2$
+		bindConstant().annotatedWith(Names.named("ProcessName")).to("embedded"); //$NON-NLS-1$ //$NON-NLS-2$
+		bind(DQPContextCache.class).in(Scopes.SINGLETON);
 		bind(DQPConfigSource.class).toInstance(new EmbeddedConfigSource(this.props));
 		
 		bind(LogConfiguration.class).toProvider(LogConfigurationProvider.class).in(Scopes.SINGLETON);		
 		bind(LogListener.class).toProvider(LogListernerProvider.class).in(Scopes.SINGLETON);  
-
 		
+		
 		// this needs to be removed.
 		binder().requestStaticInjection(LogManager.class);
 	}

Modified: trunk/embedded/src/test/java/com/metamatrix/dqp/embedded/services/TestEmbeddedVDBService.java
===================================================================
--- trunk/embedded/src/test/java/com/metamatrix/dqp/embedded/services/TestEmbeddedVDBService.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/embedded/src/test/java/com/metamatrix/dqp/embedded/services/TestEmbeddedVDBService.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -169,14 +169,14 @@
     
     
     public void testVDBResource() throws Exception {
-        Properties p = EmbeddedTestUtil.getProperties(); //$NON-NLS-1$        
+        Properties p = EmbeddedTestUtil.getProperties();         
         configService.userPreferences = p;
         configService.initializeService(p);                
         assertNotNull(vdbService.getVDBResource("Admin", "1")); //$NON-NLS-1$ //$NON-NLS-2$              
     }
     
     public void testAvailableVDBs() throws Exception {
-        Properties p = EmbeddedTestUtil.getProperties(); //$NON-NLS-1$        
+        Properties p = EmbeddedTestUtil.getProperties();         
         configService.userPreferences = p;
         configService.initializeService(p);                
         assertEquals(2, vdbService.getAvailableVDBs().size()); 

Modified: trunk/engine/src/main/java/com/metamatrix/cache/Cache.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/cache/Cache.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/engine/src/main/java/com/metamatrix/cache/Cache.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -39,7 +39,8 @@
 						AUTHORIZATION_PRINCIPAL("Auhtorization-Principal"), //$NON-NLS-1$ 
 						RESULTSET("ResultSet"), //$NON-NLS-1$
 						VDBMETADATA("VdbMetadata"), //$NON-NLS-1$
-						VDBMODELS("VdbModels"); //$NON-NLS-1$
+						VDBMODELS("VdbModels"), //$NON-NLS-1$
+						SCOPED_CACHE("Scoped-Cache"); //$NON-NLS-1$
 		
 		private String location;
 		
@@ -140,7 +141,7 @@
 	/**
 	 * Destroys the child from the current node; no-op if node not found
 	 * @param name
-	 * @return true if removed; false otehrwise
+	 * @return true if removed; false otherwise
 	 */
 	boolean removeChild(String name);
 	
@@ -150,4 +151,10 @@
 	 * @return
 	 */
 	List<Cache> getChildren();
+	
+	/**
+	 * Name of the cache node
+	 * @return
+	 */
+	String getName();
 }

Modified: trunk/engine/src/main/java/com/metamatrix/dqp/service/BufferService.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/dqp/service/BufferService.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/engine/src/main/java/com/metamatrix/dqp/service/BufferService.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -22,13 +22,21 @@
 
 package com.metamatrix.dqp.service;
 
+import org.teiid.connector.api.CacheScope;
+import org.teiid.dqp.internal.cache.DQPContextCache;
+import org.teiid.dqp.internal.process.DQPWorkContext;
+
+import com.metamatrix.cache.Cache;
 import com.metamatrix.common.application.ApplicationService;
 import com.metamatrix.common.buffer.BufferManager;
+import com.metamatrix.dqp.message.RequestID;
 
 /**
  */
 public interface BufferService extends ApplicationService {
 
     BufferManager getBufferManager();
-    
-}
+
+    DQPContextCache getContextCache();
+ }
+

Added: trunk/engine/src/main/java/org/teiid/dqp/internal/cache/DQPContextCache.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/cache/DQPContextCache.java	                        (rev 0)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/cache/DQPContextCache.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -0,0 +1,112 @@
+/*
+ * 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.cache;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import com.google.inject.name.Named;
+import com.metamatrix.cache.Cache;
+import com.metamatrix.cache.CacheConfiguration;
+import com.metamatrix.cache.CacheFactory;
+import com.metamatrix.cache.CacheConfiguration.Policy;
+import com.metamatrix.dqp.message.RequestID;
+import com.metamatrix.platform.security.api.SessionToken;
+
+ at Singleton
+public class DQPContextCache {
+	private static enum Scope {REQUEST,SESSION,SERVICE,VDB,GLOBAL;}
+	
+	private Cache cache;
+	private String processIdentifier;
+	
+	@Inject
+	public DQPContextCache(@Named("HostName") String hostName, @Named("ProcessName") String processName, CacheFactory cacheFactory) {
+		this.cache = cacheFactory.get(Cache.Type.SCOPED_CACHE, new CacheConfiguration(Policy.LRU, 600, 10000));
+		this.processIdentifier = hostName + "-" + processName; //$NON-NLS-1$
+	}
+	
+	public Cache getGlobalScopedCache() {
+		return this.cache.addChild(Scope.GLOBAL.name());
+	}
+
+	public void shutdown() {
+		this.cache.removeChild(this.processIdentifier);
+	}
+	
+	public Cache getRequestScopedCache(String request) {
+		Cache processCache = this.cache.addChild(this.processIdentifier);
+		Cache scopeNode = processCache.addChild(Scope.REQUEST.name());
+		return scopeNode.addChild(request.toString());
+	}
+
+	public void removeRequestScopedCache(String request) {
+		Cache processCache = this.cache.getChild(this.processIdentifier);
+		if (processCache != null) {
+			Cache scopeNode = processCache.getChild(Scope.REQUEST.name());
+			if (scopeNode != null) {
+				scopeNode.removeChild(request.toString());
+			}
+		}
+	}
+	
+	public Cache getServiceScopedCache(String serviceId) {
+		Cache processCache = this.cache.addChild(this.processIdentifier);
+		Cache scopeNode = processCache.addChild(Scope.SERVICE.name());
+		return scopeNode.addChild(serviceId);
+	}
+	
+	public void removeServiceScopedCache(String serviceId) {
+		Cache processCache = this.cache.getChild(this.processIdentifier);
+		if (processCache != null) {
+			Cache scopeNode = processCache.addChild(Scope.SERVICE.name());
+			if (scopeNode != null) {
+				scopeNode.removeChild(serviceId);
+			}
+		}
+	}
+
+	public Cache getSessionScopedCache(String session) {
+		Cache scopeNode = this.cache.addChild(Scope.SESSION.name());
+		return scopeNode.addChild(session);
+	}
+
+	public void removeSessionScopedCache(String session) {
+		Cache scopeNode = this.cache.addChild(Scope.SESSION.name());
+		if (scopeNode != null) {
+			scopeNode.removeChild(session);
+		}
+	}
+
+	public Cache getVDBScopedCache(String vdbName, String vdbVersion) {
+		Cache scopeNode = this.cache.addChild(Scope.VDB.name());
+		String id = vdbName+"-"+vdbVersion; //$NON-NLS-1$
+		return scopeNode.addChild(id.toUpperCase());
+	}
+
+	public void removeVDBScopedCache(String vdbName, String vdbVersion) {
+		Cache scopeNode = this.cache.addChild(Scope.VDB.name());
+		if (scopeNode != null) {
+			String id = vdbName+"-"+vdbVersion; //$NON-NLS-1$
+			scopeNode.removeChild(id.toUpperCase());
+		}
+	}
+}


Property changes on: trunk/engine/src/main/java/org/teiid/dqp/internal/cache/DQPContextCache.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorEnvironmentImpl.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorEnvironmentImpl.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorEnvironmentImpl.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -30,15 +30,22 @@
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 
+import org.teiid.connector.api.CacheScope;
 import org.teiid.connector.api.ConnectorEnvironment;
 import org.teiid.connector.api.ConnectorLogger;
 import org.teiid.connector.api.TypeFacility;
 import org.teiid.connector.internal.ConnectorPropertyNames;
 import org.teiid.connector.language.ILanguageFactory;
+import org.teiid.dqp.internal.cache.DQPContextCache;
 import org.teiid.dqp.internal.datamgr.language.LanguageFactoryImpl;
+import org.teiid.dqp.internal.process.DQPWorkContext;
 
+import com.metamatrix.cache.Cache;
 import com.metamatrix.common.application.ApplicationEnvironment;
 import com.metamatrix.common.queue.WorkerPool;
+import com.metamatrix.dqp.DQPPlugin;
+import com.metamatrix.dqp.service.BufferService;
+import com.metamatrix.dqp.service.DQPServiceNames;
 
 /**
  * Default Connector Environment. 
@@ -156,4 +163,62 @@
 		}
 		return null;
 	}
+	
+	@Override
+	public Object getFromCache(CacheScope scope, Object key) {
+		DQPWorkContext context = DQPWorkContext.getWorkContext();
+		checkScopeValidity(scope, context);
+
+		Cache cache = getScopedCache(scope, context);
+		if (cache != null) {
+			return cache.get(key);
+		}
+		return null;
+	}
+	
+	@Override
+	public void storeInCache(CacheScope scope, Object key, Object value) {
+		DQPWorkContext context = DQPWorkContext.getWorkContext();
+		checkScopeValidity(scope, context);
+		Cache cache = getScopedCache(scope, context);
+		if (cache != null) {
+			cache.put(key, value);
+		}
+	}
+	
+	private Cache getScopedCache(CacheScope scope, DQPWorkContext context) {
+		BufferService service = (BufferService) findResource(DQPServiceNames.BUFFER_SERVICE);
+		if (service != null) {
+			DQPContextCache contextCache = service.getContextCache();
+			switch (scope) {
+			case SERVICE:
+				return contextCache.getServiceScopedCache(properties.getProperty(ConnectorPropertyNames.CONNECTOR_ID));
+			case SESSION:
+				return contextCache.getSessionScopedCache(context.getSessionToken().getSessionIDValue());
+			case VDB:
+				return contextCache.getVDBScopedCache(context.getVdbName(), context.getVdbVersion());
+			case GLOBAL:
+				return contextCache.getGlobalScopedCache();
+			}
+		}
+		return null;
+	}
+	
+	
+	private void checkScopeValidity(CacheScope scope, DQPWorkContext context) {
+		if (scope == CacheScope.REQUEST) {
+			throw new IllegalStateException(DQPPlugin.Util.getString("ConnectorEnvironmentImpl.request_scope_error")); //$NON-NLS-1$
+		}
+		
+		if (scope == CacheScope.SESSION) {
+			if (context == null || context.getSessionToken() == null) {
+				throw new IllegalStateException(DQPPlugin.Util.getString("ConnectorEnvironmentImpl.session_scope_error")); //$NON-NLS-1$
+			}
+		}
+		else if (scope == CacheScope.VDB) {
+			if (context == null || context.getVdbName() == null || context.getVdbVersion() == null) {
+				throw new IllegalStateException(DQPPlugin.Util.getString("ConnectorEnvironmentImpl.vdb_scope_error")); //$NON-NLS-1$
+			}
+		}
+	}
 }

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorManager.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorManager.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -51,6 +51,7 @@
 import org.teiid.connector.internal.ConnectorPropertyNames;
 import org.teiid.connector.xa.api.XAConnection;
 import org.teiid.connector.xa.api.XAConnector;
+import org.teiid.dqp.internal.cache.DQPContextCache;
 import org.teiid.dqp.internal.cache.ResultSetCache;
 import org.teiid.dqp.internal.datamgr.CapabilitiesConverter;
 import org.teiid.dqp.internal.pooling.connector.PooledConnector;
@@ -77,6 +78,7 @@
 import com.metamatrix.dqp.message.AtomicRequestMessage;
 import com.metamatrix.dqp.message.AtomicResultsMessage;
 import com.metamatrix.dqp.message.RequestID;
+import com.metamatrix.dqp.service.BufferService;
 import com.metamatrix.dqp.service.DQPServiceNames;
 import com.metamatrix.dqp.service.MetadataService;
 import com.metamatrix.dqp.service.TrackingService;
@@ -116,6 +118,7 @@
     private MetadataService metadataService;
     private TrackingService tracker;
     private TransactionService transactionService;
+    private DQPContextCache contextCache;
     
     private volatile Boolean started;
 
@@ -149,7 +152,7 @@
             currentThread.setContextClassLoader(classloader);
             boolean global = true;
             if (caps == null) {
-            	ExecutionContext context = new ExecutionContextImpl(
+            	ExecutionContextImpl context = new ExecutionContextImpl(
                         message.getVdbName(),
                         message.getVdbVersion(),
                         message.getUserName(),
@@ -159,6 +162,8 @@
                         connectorID.getID(), 
                         requestID.toString(), 
                         "capabilities-request", "0"); //$NON-NLS-1$ //$NON-NLS-2$ 
+            	
+            	context.setContextCache(this.contextCache);
 
             	conn = connector.getConnection(context);
             	caps = conn.getCapabilities();
@@ -322,6 +327,11 @@
         this.exceptionOnMaxRows = PropertiesUtils.getBooleanProperty(props, ConnectorPropertyNames.EXCEPTION_ON_MAX_ROWS, false);
     	this.synchWorkers = PropertiesUtils.getBooleanProperty(props, ConnectorPropertyNames.SYNCH_WORKERS, true);
 
+    	BufferService bufferService = (BufferService)env.findService(DQPServiceNames.BUFFER_SERVICE);
+    	if (bufferService != null) {
+    		this.contextCache = bufferService.getContextCache();
+    	}
+    		
         // Initialize and start the connector
         initStartConnector(connectorEnv);
         //check result set cache
@@ -617,6 +627,10 @@
         return connectorID;
     }
     
+    DQPContextCache getContextCache() {
+    	return this.contextCache;
+    }
+    
     /**
      * Get the human-readable name that this connector is known by.
      * <p>Will be <code>null</code> if connector is not started.</p>

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorWorkItem.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorWorkItem.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorWorkItem.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -120,6 +120,7 @@
                 Integer.toString(requestID.getExecutionId())
                 );
         this.securityContext.setBatchSize(this.requestMsg.getFetchSize());
+        this.securityContext.setContextCache(manager.getContextCache());
     }
 
     protected void createConnection(Connector connector, QueryMetadataInterface queryMetadata) throws ConnectorException, MetaMatrixComponentException {

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ExecutionContextImpl.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ExecutionContextImpl.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ExecutionContextImpl.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -27,11 +27,16 @@
 import java.util.LinkedList;
 import java.util.List;
 
+import org.teiid.connector.api.CacheScope;
 import org.teiid.connector.api.ConnectorIdentity;
 import org.teiid.connector.api.ExecutionContext;
+import org.teiid.dqp.internal.cache.DQPContextCache;
+import org.teiid.dqp.internal.process.DQPWorkContext;
 
+import com.metamatrix.cache.Cache;
 import com.metamatrix.common.buffer.impl.BufferConfig;
 import com.metamatrix.core.util.HashCodeUtil;
+import com.metamatrix.dqp.service.BufferService;
 
 /**
  */
@@ -64,6 +69,8 @@
     
     private ConnectorIdentity connectorIdentity;
     
+    private DQPContextCache contextCache;
+    
     private int batchSize = BufferConfig.DEFAULT_CONNECTOR_BATCH_SIZE;
 	private List<Exception> warnings = new LinkedList<Exception>();
     
@@ -204,4 +211,25 @@
 		warnings.clear();
 		return result;
 	}
+	
+	public void setContextCache(DQPContextCache cache) {
+		this.contextCache = cache;
+	}
+	
+	@Override
+	public Object get(Object key) {
+		if (this.contextCache != null) {
+			Cache cache = contextCache.getRequestScopedCache(getRequestIdentifier());
+			return cache.get(key);
+		}
+		return null;
+	}
+	
+	@Override
+	public void put(Object key, Object value) {
+		if (this.contextCache != null) {
+			Cache cache = contextCache.getRequestScopedCache(getRequestIdentifier());
+			cache.put(key, value);
+		}
+	}	
 }

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	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -37,7 +37,9 @@
 import javax.transaction.SystemException;
 import javax.transaction.xa.Xid;
 
+import org.teiid.connector.api.CacheScope;
 import org.teiid.dqp.internal.cache.CacheID;
+import org.teiid.dqp.internal.cache.DQPContextCache;
 import org.teiid.dqp.internal.cache.ResultSetCache;
 import org.teiid.dqp.internal.cache.ResultSetCacheUtil;
 
@@ -146,6 +148,7 @@
     
 	private Map<RequestID, RequestWorkItem> requests = Collections.synchronizedMap(new HashMap<RequestID, RequestWorkItem>());			
 	private Map<String, List<RequestID>> requestsByClients = Collections.synchronizedMap(new HashMap<String, List<RequestID>>());
+	private DQPContextCache contextCache;
 	
 	public DQPCore() { 
 		
@@ -164,6 +167,7 @@
 	@Override
     public void stop() throws ApplicationLifecycleException {
     	processWorkerPool.shutdown();
+    	contextCache.shutdown();
     	super.stop();
     }
     
@@ -296,6 +300,7 @@
         		clientRequests.remove(workItem.requestID);
         	}
 		}
+    	contextCache.removeRequestScopedCache(workItem.requestID.toString());
     }
            
     boolean areResultsInCache(final RequestMessage requestMsg) {
@@ -434,6 +439,7 @@
                 throw new MetaMatrixComponentException(err);
             }
         }
+        contextCache.removeSessionScopedCache(sessionId);
     }
 
     public boolean cancelRequest(RequestID requestID)
@@ -609,6 +615,7 @@
         //get buffer manager
         BufferService bufferService = (BufferService) env.findService(DQPServiceNames.BUFFER_SERVICE);
         bufferManager = bufferService.getBufferManager();
+        contextCache = bufferService.getContextCache();
 
         //Get tracking service
         tracker = (TrackingService) env.findService(DQPServiceNames.TRACKING_SERVICE);

Modified: trunk/engine/src/main/resources/com/metamatrix/dqp/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/com/metamatrix/dqp/i18n.properties	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/engine/src/main/resources/com/metamatrix/dqp/i18n.properties	2009-04-16 16:26:10 UTC (rev 786)
@@ -460,4 +460,8 @@
 
 TransactionContextImpl.remote_not_supported=Remote connector calls under a transaction are not supported
 
-CodeTableCache.duplicate_key=Duplicate code table ''{0}'' key ''{1}'' value ''{2}''
\ No newline at end of file
+CodeTableCache.duplicate_key=Duplicate code table ''{0}'' key ''{1}'' value ''{2}''
+connector_cache_closed=Connector cache has been already closed.
+ConnectorEnvironmentImpl.request_scope_error=CacheScope.REQUEST not support on this interface. Use methods on ExecutionContext for REQUEST scoped cache.
+ConnectorEnvironmentImpl.session_scope_error=Session information is not available; SESSION scoped cache can not be accessed.
+ConnectorEnvironmentImpl.vdb_scope_error=VDB information is not available; VDB scoped cache can not be accessed.
\ No newline at end of file

Modified: trunk/engine/src/test/java/com/metamatrix/cache/FakeCache.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/cache/FakeCache.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/engine/src/test/java/com/metamatrix/cache/FakeCache.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -34,7 +34,7 @@
     public static class FakeCacheFactory implements CacheFactory{
 
 		public Cache get(Type type, CacheConfiguration config) {
-			return new FakeCache();
+			return new FakeCache("root"); //$NON-NLS-1$
 		}
 		
 		public void destroy() {
@@ -43,7 +43,10 @@
     
 	Map<K, V> map = new HashMap();
 	Map<String, Cache> children = new HashMap();
-	
+	String name;
+	public FakeCache(String name) {
+		this.name = name;
+	}
 	public void addListener(CacheListener listener) {
 	}
 
@@ -81,7 +84,11 @@
 
 	@Override
 	public Cache addChild(String name) {
-		Cache c = new FakeCache();
+		if (children.get(name) != null) {
+			return children.get(name);
+		}
+		
+		Cache c = new FakeCache(name);
 		children.put(name, c);
 		return c;
 	}
@@ -101,4 +108,9 @@
 		Object obj = children.remove(name);
 		return obj != null;
 	}
+
+	@Override
+	public String getName() {
+		return name;
+	}
 }

Modified: trunk/engine/src/test/java/com/metamatrix/dqp/service/FakeBufferService.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/dqp/service/FakeBufferService.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/engine/src/test/java/com/metamatrix/dqp/service/FakeBufferService.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -22,7 +22,10 @@
 
 package com.metamatrix.dqp.service;
 
+import org.teiid.dqp.internal.cache.DQPContextCache;
+
 import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.cache.FakeCache.FakeCacheFactory;
 import com.metamatrix.common.buffer.BufferManager;
 import com.metamatrix.common.buffer.BufferManagerFactory;
 
@@ -52,4 +55,8 @@
         return bufferMgr;
     }
 
+	@Override
+	public DQPContextCache getContextCache() {
+		return new DQPContextCache("test", "test", new FakeCacheFactory()); //$NON-NLS-1$ //$NON-NLS-2$
+	}
 }

Added: trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestDQPContextCache.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestDQPContextCache.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestDQPContextCache.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -0,0 +1,105 @@
+/*
+ * 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.cache;
+
+import junit.framework.TestCase;
+
+import org.teiid.connector.api.CacheScope;
+import org.teiid.connector.api.ExecutionContext;
+import org.teiid.dqp.internal.datamgr.impl.FakeExecutionContextImpl;
+import org.teiid.dqp.internal.process.DQPWorkContext;
+
+import com.metamatrix.cache.Cache;
+import com.metamatrix.cache.FakeCache.FakeCacheFactory;
+import com.metamatrix.dqp.message.RequestID;
+import com.metamatrix.platform.security.api.MetaMatrixSessionID;
+import com.metamatrix.platform.security.api.SessionToken;
+
+
+public class TestDQPContextCache extends TestCase {
+
+	DQPContextCache cacheContext = null;
+	
+	@Override
+	protected void setUp() throws Exception {
+		cacheContext = new DQPContextCache("host", "process", new FakeCacheFactory()); //$NON-NLS-1$ //$NON-NLS-2$
+			
+	}
+	
+	private DQPWorkContext getContext() {
+        DQPWorkContext workContext = new DQPWorkContext();
+        workContext.setVdbName("MyVDB"); //$NON-NLS-1$
+        workContext.setVdbVersion("1"); //$NON-NLS-1$
+        workContext.setSessionToken(new SessionToken(new MetaMatrixSessionID(1), "foo")); //$NON-NLS-1$
+        return workContext;
+	}
+
+	// killing a request scope does not kill the session scope
+	public void testRequestScope() {
+		DQPWorkContext context = getContext();
+		Cache cache = this.cacheContext.getRequestScopedCache(context.getRequestID(12L).toString());
+		cache.put("key", "request-value"); //$NON-NLS-1$ //$NON-NLS-2$
+
+		cache = this.cacheContext.getSessionScopedCache(context.getSessionToken().getSessionIDValue());		
+		cache.put("key", "session-value"); //$NON-NLS-1$ //$NON-NLS-2$
+	
+		assertEquals("request-value", this.cacheContext.getRequestScopedCache(context.getRequestID(12L).toString()).get("key")); //$NON-NLS-1$ //$NON-NLS-2$
+		assertEquals("session-value", this.cacheContext.getSessionScopedCache(context.getSessionToken().getSessionIDValue()).get("key")); //$NON-NLS-1$ //$NON-NLS-2$
+	
+		// close the request
+		this.cacheContext.removeRequestScopedCache(context.getRequestID(12L).toString());
+		
+		assertNull(this.cacheContext.getRequestScopedCache(context.getRequestID(12L).toString()).get("key")); //$NON-NLS-1$ 
+		assertEquals("session-value", this.cacheContext.getSessionScopedCache(context.getSessionToken().getSessionIDValue()).get("key")); //$NON-NLS-1$ //$NON-NLS-2$
+	}
+		
+	
+	public void testServiceScope() {
+		DQPWorkContext context = getContext();
+		Cache cache = this.cacheContext.getServiceScopedCache("my-connector"); //$NON-NLS-1$
+		cache.put("key", "service-value"); //$NON-NLS-1$ //$NON-NLS-2$
+	
+		assertEquals("service-value", this.cacheContext.getServiceScopedCache("my-connector").get("key")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+		
+		this.cacheContext.removeServiceScopedCache("my-Connector"); //$NON-NLS-1$
+		
+		assertNull(this.cacheContext.getRequestScopedCache(context.getRequestID(12L).toString()).get("key")); //$NON-NLS-1$
+	}	
+	
+	public void testGlobalScope() {
+		DQPWorkContext context = getContext();
+		Cache cache = this.cacheContext.getRequestScopedCache(context.getRequestID(12L).toString());
+		cache.put("key", "request-value"); //$NON-NLS-1$ //$NON-NLS-2$
+
+		cache = this.cacheContext.getGlobalScopedCache();		
+		cache.put("key", "global-value"); //$NON-NLS-1$ //$NON-NLS-2$
+
+		assertEquals("request-value", this.cacheContext.getRequestScopedCache(context.getRequestID(12L).toString()).get("key")); //$NON-NLS-1$ //$NON-NLS-2$
+		assertEquals("global-value", this.cacheContext.getGlobalScopedCache().get("key")); //$NON-NLS-1$ //$NON-NLS-2$
+		
+		this.cacheContext.shutdown();
+		
+		assertNull(this.cacheContext.getRequestScopedCache(context.getRequestID(12L).toString()).get("key")); //$NON-NLS-1$
+		// global only dies when the engine is shutdown
+		assertEquals("global-value", this.cacheContext.getGlobalScopedCache().get("key")); //$NON-NLS-1$ //$NON-NLS-2$
+	}	
+}


Property changes on: trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestDQPContextCache.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/FakeExecutionContextImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/FakeExecutionContextImpl.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/FakeExecutionContextImpl.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -24,29 +24,37 @@
 
 import java.util.concurrent.atomic.AtomicInteger;
 
-import org.teiid.dqp.internal.datamgr.impl.ExecutionContextImpl;
+import org.teiid.connector.api.ExecutionContext;
 
 /**
  */
 public class FakeExecutionContextImpl extends ExecutionContextImpl {
 
-    private final static AtomicInteger COUNT = new AtomicInteger(0);
+	private final static AtomicInteger COUNT = new AtomicInteger(0);
 
-    public FakeExecutionContextImpl() {
-    	this(COUNT.getAndIncrement());
-    }
-    
-    public FakeExecutionContextImpl(int unique) {
-        super("VDB"+unique,  //$NON-NLS-1$
-            "Version"+unique,  //$NON-NLS-1$
-            "User"+unique,  //$NON-NLS-1$ 
-            "Payload"+unique,  //$NON-NLS-1$
-            "ExecutionPayload"+unique,  //$NON-NLS-1$            
-            "ConnectionID"+unique,   //$NON-NLS-1$
-            "ConnectorID"+unique,   //$NON-NLS-1$
-            "RequestID"+unique,   //$NON-NLS-1$
-            "PartID"+unique, //$NON-NLS-1$
-            "ExecCount"+unique); 
-    }
-    
+	public FakeExecutionContextImpl() {
+		this(COUNT.getAndIncrement());
+	}
+
+	public FakeExecutionContextImpl(int unique) {
+		super("VDB" + unique, //$NON-NLS-1$
+				"Version" + unique, //$NON-NLS-1$
+				"User" + unique, //$NON-NLS-1$ 
+				"Payload" + unique, //$NON-NLS-1$
+				"ExecutionPayload" + unique, //$NON-NLS-1$            
+				"ConnectionID" + unique, //$NON-NLS-1$
+				"ConnectorID" + unique, //$NON-NLS-1$
+				"RequestID" + unique, //$NON-NLS-1$
+				"PartID" + unique, //$NON-NLS-1$
+				"ExecCount" + unique); //$NON-NLS-1$
+	}
+
+	public FakeExecutionContextImpl(ExecutionContext c) {
+		super(c.getVirtualDatabaseName(), c.getVirtualDatabaseVersion(), c
+				.getUser(), c.getTrustedPayload(), c.getExecutionPayload(), c
+				.getConnectionIdentifier(), c.getConnectorIdentifier(), c
+				.getRequestIdentifier(), c.getPartIdentifier(), c
+				.getExecutionCountIdentifier());
+	}
+
 }

Modified: trunk/server/src/main/java/com/metamatrix/server/ResourceFinder.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/ResourceFinder.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/server/src/main/java/com/metamatrix/server/ResourceFinder.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -23,6 +23,8 @@
 package com.metamatrix.server;
 
 
+import org.teiid.dqp.internal.cache.DQPContextCache;
+
 import com.google.inject.Injector;
 import com.metamatrix.common.messaging.MessageBus;
 import com.metamatrix.common.messaging.NoOpMessageBus;
@@ -41,4 +43,8 @@
 		ResourceFinder.setInjector(injector);
 		XMLConfigurationMgr.getInstance().setMessageBus(getMessageBus());
 	}
+
+	public static DQPContextCache getContextCache() {
+		return injector.getInstance(DQPContextCache.class);
+	}
 }

Modified: trunk/server/src/main/java/com/metamatrix/server/ServerGuiceModule.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/ServerGuiceModule.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/server/src/main/java/com/metamatrix/server/ServerGuiceModule.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -24,6 +24,7 @@
 
 import org.jboss.cache.Cache;
 import org.jgroups.mux.Multiplexer;
+import org.teiid.dqp.internal.cache.DQPContextCache;
 
 import com.google.inject.AbstractModule;
 import com.google.inject.Scopes;
@@ -86,6 +87,7 @@
 		bind(ProcessManagement.class).to(SocketVMController.class).in(Scopes.SINGLETON);
 		bind(ServerEvents.class).to(ProcessMonitor.class).in(Scopes.SINGLETON);
 		bind(HostManagement.class).toProvider(HostManagementProvider.class).in(Scopes.SINGLETON);
+		bind(DQPContextCache.class).in(Scopes.SINGLETON);
 		
 		// this needs to be removed.
 		binder().requestStaticInjection(PlatformProxyHelper.class);

Modified: trunk/server/src/main/java/com/metamatrix/server/dqp/config/PlatformConfigSource.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/dqp/config/PlatformConfigSource.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/server/src/main/java/com/metamatrix/server/dqp/config/PlatformConfigSource.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -26,6 +26,8 @@
 import java.util.Map;
 import java.util.Properties;
 
+import org.teiid.dqp.internal.cache.DQPContextCache;
+
 import com.google.inject.Binder;
 import com.google.inject.name.Names;
 import com.metamatrix.common.application.ApplicationService;
@@ -42,6 +44,7 @@
 import com.metamatrix.platform.security.api.service.AuthorizationServiceInterface;
 import com.metamatrix.platform.util.PlatformProxyHelper;
 import com.metamatrix.server.Configuration;
+import com.metamatrix.server.ResourceFinder;
 import com.metamatrix.server.dqp.service.PlatformAuthorizationService;
 import com.metamatrix.server.dqp.service.PlatformBufferService;
 import com.metamatrix.server.dqp.service.PlatformDataService;
@@ -127,6 +130,7 @@
 		}
 		binder.bindConstant().annotatedWith(Names.named(Configuration.PROCESSNAME)).to(processName);
 		binder.bind(Host.class).annotatedWith(Names.named(Configuration.HOST)).toInstance(host);
+		binder.bind(DQPContextCache	.class).toInstance(ResourceFinder.getContextCache());
 	}
     
 }
\ No newline at end of file

Modified: trunk/server/src/main/java/com/metamatrix/server/dqp/service/PlatformBufferService.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/dqp/service/PlatformBufferService.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/server/src/main/java/com/metamatrix/server/dqp/service/PlatformBufferService.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -24,6 +24,8 @@
 
 import java.util.Properties;
 
+import org.teiid.dqp.internal.cache.DQPContextCache;
+
 import com.google.inject.Inject;
 import com.google.inject.name.Named;
 import com.metamatrix.api.exception.MetaMatrixComponentException;
@@ -49,11 +51,13 @@
     
     private String processName;
     private Host host;
+    private DQPContextCache contextCache;
     
     @Inject
-    public PlatformBufferService(@Named(Configuration.HOST) Host host, @Named(Configuration.PROCESSNAME) String processName) {
+    public PlatformBufferService(@Named(Configuration.HOST) Host host, @Named(Configuration.PROCESSNAME) String processName, DQPContextCache cache) {
     	this.host = host;
     	this.processName = processName;
+    	this.contextCache = cache;
 	}
 
     /* 
@@ -96,4 +100,10 @@
     	bufferMgr.stop();
     }
 
+	@Override
+	public DQPContextCache getContextCache() {
+		return this.contextCache;
+	}
+
+
 }

Modified: trunk/server/src/main/java/com/metamatrix/server/dqp/service/PlatformVDBService.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/dqp/service/PlatformVDBService.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/server/src/main/java/com/metamatrix/server/dqp/service/PlatformVDBService.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -31,6 +31,9 @@
 import java.util.Map;
 import java.util.Properties;
 
+import org.teiid.dqp.internal.cache.DQPContextCache;
+
+import com.google.inject.Inject;
 import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.common.application.ApplicationEnvironment;
 import com.metamatrix.common.application.exception.ApplicationInitializationException;
@@ -64,7 +67,12 @@
 
     private Map vdbIDs = Collections.synchronizedMap(new HashMap());
     private EventObjectListener listener = null;
+    private DQPContextCache contextCache;
 
+    @Inject
+    public PlatformVDBService(DQPContextCache cache) {
+    	this.contextCache = cache;
+    }
     /* 
      * @see com.metamatrix.dqp.service.VDBService#isActiveVDB(java.lang.String, java.lang.String)
      */
@@ -142,7 +150,7 @@
      */
     public int getFileVisibility(final String vdbName, final String vdbVersion, final String pathInVDB) throws MetaMatrixComponentException {
         // get the name of model
-    	String modelName = StringUtil.getFirstToken(StringUtil.getLastToken(pathInVDB, "/"), ".");
+    	String modelName = StringUtil.getFirstToken(StringUtil.getLastToken(pathInVDB, "/"), "."); //$NON-NLS-1$ //$NON-NLS-2$
 
 
         //return configuration.getModelVisibility(vdbName, vdbVersion, modelName);
@@ -234,8 +242,10 @@
             VirtualDatabaseID vdbID = event.getVirtualDatabaseID();
             // update the cache for this vdb
             removeVirtualDatabaseID(vdbID);
+
+            // remove any cached items
+            this.contextCache.removeVDBScopedCache(vdbID.getName(), vdbID.getVersion());
         }
-        
     }    
     
     /**

Modified: trunk/server/src/test/java/com/metamatrix/platform/security/api/TestAuthorizationCache.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/platform/security/api/TestAuthorizationCache.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/server/src/test/java/com/metamatrix/platform/security/api/TestAuthorizationCache.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -36,31 +36,18 @@
 import com.metamatrix.platform.security.authorization.cache.AuthorizationCache;
 
 public class TestAuthorizationCache extends TestCase {
-
-	Cache cacheStore;
 	
-	@Override
-	protected void setUp() throws Exception {
-		CacheFactory factory = new DefaultCacheFactory();
-		cacheStore = factory.createCache();
-	}
-
-	@Override
-	protected void tearDown() throws Exception {
-		cacheStore.stop();
-	}
-	
     public void testFindPolicyIdsWithNoResult() throws Exception {
-        AuthorizationCache cache = new AuthorizationCache(new FakeCache(), new FakeCache(), null); 
+        AuthorizationCache cache = new AuthorizationCache(new FakeCache("1"), new FakeCache("2"), null); //$NON-NLS-1$ //$NON-NLS-2$ 
         Collection result = cache.findPolicyIDs(new MetaMatrixPrincipalName("a", MetaMatrixPrincipal.TYPE_USER), null); //$NON-NLS-1$
         assertTrue(result.isEmpty());
     }
     
     public void testFindPolicyIds() throws Exception {
-        AuthorizationCache cache = new AuthorizationCache(new FakeCache(), new FakeCache(),null);
+    	AuthorizationCache cache = new AuthorizationCache(new FakeCache("1"), new FakeCache("2"), null); //$NON-NLS-1$ //$NON-NLS-2$
         List policyIDs = new LinkedList();
         policyIDs.add(new Integer(1));
-        SessionToken token =  new SessionToken(new MetaMatrixSessionID(1), "dummy"); //$NON-NLS-1$ //$NON-NLS-2$
+        SessionToken token =  new SessionToken(new MetaMatrixSessionID(1), "dummy"); //$NON-NLS-1$s
         cache.cachePolicyIDsForPrincipal(new MetaMatrixPrincipalName("a", MetaMatrixPrincipal.TYPE_USER), token, policyIDs); //$NON-NLS-1$
         Collection result = cache.findPolicyIDs(new MetaMatrixPrincipalName("a", MetaMatrixPrincipal.TYPE_USER), new SessionToken(new MetaMatrixSessionID(2), "dummy")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
         //different session, result should be empty

Modified: trunk/server/src/test/java/com/metamatrix/platform/security/authorization/service/TestAuthorizationServiceImpl.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/platform/security/authorization/service/TestAuthorizationServiceImpl.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/server/src/test/java/com/metamatrix/platform/security/authorization/service/TestAuthorizationServiceImpl.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -51,23 +51,10 @@
 	private static final String TEST_GROUP = "g1+p1"; //$NON-NLS-1$
 	private static final String INVALID_GROUP = "foo"; //$NON-NLS-1$
 
-	Cache cacheStore;
-	
-	@Override
-	protected void setUp() throws Exception {
-		CacheFactory factory = new DefaultCacheFactory();
-		cacheStore = factory.createCache();
-	}
-
-	@Override
-	protected void tearDown() throws Exception {
-		cacheStore.stop();
-	}
-	
 	public class FakeAuthorizationService extends AuthorizationServiceImpl {
 		
 		public FakeAuthorizationService() throws Exception {
-			this.authorizationCache = new AuthorizationCache(new FakeCache(), new FakeCache(), null);
+			this.authorizationCache = new AuthorizationCache(new FakeCache("1"), new FakeCache("2"), null); //$NON-NLS-1$ //$NON-NLS-2$
 			this.membershipServiceProxy = Mockito.mock(MembershipServiceInterface.class);
 			Mockito.stub(this.membershipServiceProxy.getPrincipal(new MetaMatrixPrincipalName(TEST_GROUP, MetaMatrixPrincipal.TYPE_GROUP))).toReturn(new BasicMetaMatrixPrincipal(TEST_GROUP, MetaMatrixPrincipal.TYPE_GROUP));
 			Mockito.stub(this.membershipServiceProxy.getPrincipal(new MetaMatrixPrincipalName(INVALID_GROUP, MetaMatrixPrincipal.TYPE_GROUP))).toThrow(new InvalidPrincipalException());

Modified: trunk/server/src/test/java/com/metamatrix/platform/security/session/service/TestSessionServiceImpl.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/platform/security/session/service/TestSessionServiceImpl.java	2009-04-16 15:55:11 UTC (rev 785)
+++ trunk/server/src/test/java/com/metamatrix/platform/security/session/service/TestSessionServiceImpl.java	2009-04-16 16:26:10 UTC (rev 786)
@@ -19,7 +19,7 @@
 	public void testValidateSession() throws Exception {
 		SessionServiceImpl ssi = new SessionServiceImpl();
 		ssi.setIdGenerator(new InMemoryIDController());
-		ssi.setSessionCache(new FakeCache<MetaMatrixSessionID, MetaMatrixSessionInfo>());
+		ssi.setSessionCache(new FakeCache<MetaMatrixSessionID, MetaMatrixSessionInfo>("1")); //$NON-NLS-1$
 		MembershipServiceInterface msi = Mockito.mock(MembershipServiceInterface.class);
 		Mockito.stub(msi.authenticateUser("steve", null, null, "foo")).toReturn(new SuccessfulAuthenticationToken(null, "steve at somedomain")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 		ssi.setMembershipService(msi);
@@ -32,7 +32,7 @@
 			
 		}
 		
-		MetaMatrixSessionInfo info = ssi.createSession("steve", null, null, "foo", new Properties()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+		MetaMatrixSessionInfo info = ssi.createSession("steve", null, null, "foo", new Properties()); //$NON-NLS-1$ //$NON-NLS-2$
 		id1 = info.getSessionID();
 		ssi.validateSession(id1);
 		




More information about the teiid-commits mailing list