[teiid-commits] teiid SVN: r955 - in trunk: embedded/src/main/java/com/metamatrix/dqp/embedded/services and 2 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Fri May 15 17:56:27 EDT 2009


Author: rareddy
Date: 2009-05-15 17:56:27 -0400 (Fri, 15 May 2009)
New Revision: 955

Modified:
   trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/configuration/ExtensionModuleReader.java
   trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java
   trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedDataService.java
   trunk/embedded/src/test/java/com/metamatrix/dqp/embedded/services/TestEmbeddedConfigurationService.java
   trunk/engine/src/main/java/com/metamatrix/dqp/service/ConfigurationService.java
Log:
TEIID-600: Adding the  "ConnectorClasspath" entries into "dqp.extension.CommonClasspath" in the embedded mode.

Modified: trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/configuration/ExtensionModuleReader.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/configuration/ExtensionModuleReader.java	2009-05-15 20:59:59 UTC (rev 954)
+++ trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/configuration/ExtensionModuleReader.java	2009-05-15 21:56:27 UTC (rev 955)
@@ -29,17 +29,18 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.StringTokenizer;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.common.config.api.ExtensionModule;
 import com.metamatrix.common.config.model.BasicExtensionModule;
-import com.metamatrix.common.log.LogManager;
 import com.metamatrix.common.protocol.URLHelper;
 import com.metamatrix.common.util.ByteArrayHelper;
 import com.metamatrix.dqp.embedded.DQPEmbeddedPlugin;
-import com.metamatrix.dqp.util.LogConstants;
 
 
 /** 
@@ -135,10 +136,10 @@
      * @throws MalformedURLException
      * @since 4.3
      */
-    public static List<URL> resolveExtensionClasspath(String extClassPath, URL[] contexts) 
+    public static Set<URL> resolveExtensionClasspath(String extClassPath, URL[] contexts) 
         throws IOException {
         
-        List<URL> urls = new ArrayList<URL>();
+        Set<URL> urls = new LinkedHashSet<URL>();
         StringTokenizer st = new StringTokenizer(extClassPath, ";"); //$NON-NLS-1$
         while (st.hasMoreTokens()) {
             String  extModule = st.nextToken();

Modified: trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java	2009-05-15 20:59:59 UTC (rev 954)
+++ trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java	2009-05-15 21:56:27 UTC (rev 955)
@@ -38,6 +38,8 @@
 import java.util.Set;
 import java.util.StringTokenizer;
 
+import org.teiid.connector.internal.ConnectorPropertyNames;
+
 import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.common.application.ApplicationEnvironment;
 import com.metamatrix.common.application.exception.ApplicationInitializationException;
@@ -50,10 +52,8 @@
 import com.metamatrix.common.config.api.ConnectorBinding;
 import com.metamatrix.common.config.api.ConnectorBindingType;
 import com.metamatrix.common.config.api.ExtensionModule;
-import com.metamatrix.common.config.model.BasicComponentType;
 import com.metamatrix.common.config.model.BasicConnectorBinding;
 import com.metamatrix.common.log.LogManager;
-import com.metamatrix.common.object.PropertyDefinition;
 import com.metamatrix.common.protocol.URLHelper;
 import com.metamatrix.common.util.PropertiesUtils;
 import com.metamatrix.common.util.crypto.CryptoException;
@@ -222,15 +222,28 @@
     /**  
      * @see com.metamatrix.dqp.service.ConfigurationService#getCommonExtensionClasspath()
      */
-    public List<URL> getCommonExtensionClasspath() {
+    public Set<URL> getCommonExtensionClasspath() {
         String classpath= userPreferences.getProperty(DQPEmbeddedProperties.COMMON_EXTENSION_CLASPATH);
+        
+        // add the "ConnectorClasspath" to the common extension path
+        Collection<ConnectorBinding> bindings = this.loadedConnectorBindings.values();
+        for (ConnectorBinding b:bindings) {
+        	if (classpath == null) {
+        		classpath = b.getProperty(ConnectorPropertyNames.CONNECTOR_CLASSPATH);
+        	}
+        	else {
+        		classpath += ";"; //$NON-NLS-1$
+        		classpath += b.getProperty(ConnectorPropertyNames.CONNECTOR_CLASSPATH);
+        	}
+        }
+        
         if (valid(classpath)) {            
             try {
             	return ExtensionModuleReader.resolveExtensionClasspath(classpath, getExtensionPath());
             } catch (IOException e) {
                 DQPEmbeddedPlugin.logError(e, "EmbeddedConfigurationService.udf_classspath_failure", new Object[] {}); //$NON-NLS-1$                
             }
-        }
+        }        
         return null;
     }
     
@@ -900,7 +913,7 @@
     public void loadUDF() throws MetaMatrixComponentException {
         URL udfFile = getUDFFile();
         if(udfFile != null && exists(udfFile)) {
-            List<URL> urls = getCommonExtensionClasspath();            
+            Set<URL> urls = getCommonExtensionClasspath();            
             try {
             	
             	// un-register the old UDF model, if there is one.

Modified: trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedDataService.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedDataService.java	2009-05-15 20:59:59 UTC (rev 954)
+++ trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedDataService.java	2009-05-15 21:56:27 UTC (rev 955)
@@ -24,13 +24,13 @@
 
 import java.net.URL;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.teiid.connector.api.ConnectorException;
@@ -566,10 +566,10 @@
             
             DQPEmbeddedPlugin.logInfo("DataService.useClassloader", new Object[] {classPath}); //$NON-NLS-1$
 
-            List<URL> userPath = ExtensionModuleReader.resolveExtensionClasspath(classPath, getConfigurationService().getExtensionPath());
+            Set<URL> userPath = ExtensionModuleReader.resolveExtensionClasspath(classPath, getConfigurationService().getExtensionPath());
 
             // since we are using the extensions, get the common extension path 
-            List<URL> commonExtensionPath = getConfigurationService().getCommonExtensionClasspath();
+            Set<URL> commonExtensionPath = getConfigurationService().getCommonExtensionClasspath();
             
             ArrayList<URL> urlPath = new ArrayList<URL>();            
             urlPath.addAll(userPath);

Modified: trunk/embedded/src/test/java/com/metamatrix/dqp/embedded/services/TestEmbeddedConfigurationService.java
===================================================================
--- trunk/embedded/src/test/java/com/metamatrix/dqp/embedded/services/TestEmbeddedConfigurationService.java	2009-05-15 20:59:59 UTC (rev 954)
+++ trunk/embedded/src/test/java/com/metamatrix/dqp/embedded/services/TestEmbeddedConfigurationService.java	2009-05-15 21:56:27 UTC (rev 955)
@@ -31,9 +31,12 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Set;
 
 import junit.framework.TestCase;
 
+import org.teiid.connector.internal.ConnectorPropertyNames;
+
 import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.common.application.ApplicationEnvironment;
 import com.metamatrix.common.config.api.ComponentType;
@@ -533,11 +536,12 @@
         
         modules = service.getExtensionModules();
         assertEquals(2,  modules.size()); 
-                
-        // test common class path; also makes sure that the conect in position (1) has the newly added module
+        
+        // test common class path; also makes sure that the connect in position (1) has the newly added module
         service.userPreferences.setProperty("dqp.extension.CommonClasspath", "extensionjar:added-ext.jar;extensionjar:extfile.jar"); //$NON-NLS-1$ //$NON-NLS-2$
-        assertEquals("mmfile:target/scratch/dqp/foo/added-ext.jar", service.getCommonExtensionClasspath().get(0).toString()); //$NON-NLS-1$
-        assertEquals("mmfile:target/scratch/dqp/bar/extfile.jar", service.getCommonExtensionClasspath().get(1).toString()); //$NON-NLS-1$
+        Iterator<URL> i = service.getCommonExtensionClasspath().iterator();
+        assertEquals("mmfile:target/scratch/dqp/foo/added-ext.jar", i.next().toString()); //$NON-NLS-1$
+        assertEquals("mmfile:target/scratch/dqp/bar/extfile.jar", i.next().toString()); //$NON-NLS-1$
         
         // test delete 
         service.deleteExtensionModule("added-ext.jar"); //$NON-NLS-1$
@@ -554,4 +558,39 @@
 		f.delete();
     }      
     
+    public void testCommonExtensionPath() throws Exception{
+        Properties p = EmbeddedTestUtil.getProperties();
+        File f = new File("target/scratch/dqp/bar"); //$NON-NLS-1$
+        f.mkdirs();
+        FileWriter fw = new FileWriter("target/scratch/dqp/bar/extfile.jar"); //$NON-NLS-1$
+        fw.write("testing extension modules"); //$NON-NLS-1$
+        fw.flush();
+        fw.close();
+        
+        fw = new FileWriter("target/scratch/dqp/bar/driver.jar"); //$NON-NLS-1$
+        fw.write("testing extension modules"); //$NON-NLS-1$
+        fw.flush();
+        fw.close();        
+        
+        p.setProperty("dqp.extensions", "./foo/;./bar/"); //$NON-NLS-1$ //$NON-NLS-2$
+        service.userPreferences = p;
+        
+        assertNull(service.getCommonExtensionClasspath());
+        
+        p.setProperty(DQPEmbeddedProperties.COMMON_EXTENSION_CLASPATH, "extensionjar:extfile.jar"); //$NON-NLS-1$
+               
+        Set<URL> urls  = service.getCommonExtensionClasspath();
+        assertEquals("mmfile:target/scratch/dqp/bar/extfile.jar", urls.iterator().next().toString()); //$NON-NLS-1$
+        
+        BasicConnectorBinding binding = new BasicConnectorBinding(new ConfigurationID("foo"), new ConnectorBindingID(new ConfigurationID("foo"), "foo"), new ComponentTypeID("foo type")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+        Properties props = new Properties();
+        props.setProperty(ConnectorPropertyNames.CONNECTOR_CLASSPATH, "extensionjar:driver.jar"); //$NON-NLS-1$ 
+        binding.setProperties(props);
+        service.loadedConnectorBindings.put("Foo", binding); //$NON-NLS-1$
+
+        Iterator<URL> i  = service.getCommonExtensionClasspath().iterator();
+        
+        assertEquals("mmfile:target/scratch/dqp/bar/extfile.jar", i.next().toString()); //$NON-NLS-1$
+        assertEquals("mmfile:target/scratch/dqp/bar/driver.jar", i.next().toString()); //$NON-NLS-1$
+    }
 }

Modified: trunk/engine/src/main/java/com/metamatrix/dqp/service/ConfigurationService.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/dqp/service/ConfigurationService.java	2009-05-15 20:59:59 UTC (rev 954)
+++ trunk/engine/src/main/java/com/metamatrix/dqp/service/ConfigurationService.java	2009-05-15 21:56:27 UTC (rev 955)
@@ -102,7 +102,7 @@
      * files are loaded usually as the extension modules. 
      * @return URL[] - Classpath for the UDF jar files
      */
-    public List<URL> getCommonExtensionClasspath();
+    public Set<URL> getCommonExtensionClasspath();
     
     /**
      * URL to Log file name  




More information about the teiid-commits mailing list